diff options
author | Ed Tanous <edtanous@google.com> | 2023-09-06 23:57:30 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-12-05 21:54:28 +0300 |
commit | 998e0cbdc5092bdaa783d11c2760bf62084403ce (patch) | |
tree | 95f8b39cfdbb036d84c7e9f6798dd1a8eb0dd6ec /test | |
parent | 4fa45dffd1ece21a468ed32850428b3b41bc8093 (diff) | |
download | bmcweb-998e0cbdc5092bdaa783d11c2760bf62084403ce.tar.xz |
Fix missing date
At some point, the date got removed from http1 requests. HTTP2 does not
show this issue, but this showed up in unit tests (which is why the
prior commit is adding unit tests).
The Date Header is useful for synchronizing things like
Cache-Control-Policy, with the actual server time, instead of the local
system time.
Tested: Unit tests pass.
Change-Id: I8f105f0cbb6c816c5ec6b14cbeae587d728a20d2
Signed-off-by: Ed Tanous <edtanous@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/http/http_connection_test.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/test/http/http_connection_test.cpp b/test/http/http_connection_test.cpp index c4252e1ee7..6647e61d99 100644 --- a/test/http/http_connection_test.cpp +++ b/test/http/http_connection_test.cpp @@ -31,19 +31,31 @@ struct FakeHandler { EXPECT_EQ(req.method(), boost::beast::http::verb::get); EXPECT_EQ(req.target(), "/"); + EXPECT_EQ(req.getHeaderValue(boost::beast::http::field::host), + "openbmc_project.xyz"); + EXPECT_FALSE(req.keepAlive()); + EXPECT_EQ(req.version(), 11); + EXPECT_EQ(req.body(), ""); + called = true; } bool called = false; }; -static std::string getDateStr() +struct ClockFake { - return "TestTime"; -} + bool wascalled = false; + std::string getDateStr() + { + wascalled = true; + return "TestTime"; + } +}; TEST(http_connection, RequestPropogates) { boost::asio::io_context io; + ClockFake clock; boost::beast::test::stream stream(io); boost::beast::test::stream out(io); stream.connect(out); @@ -52,7 +64,8 @@ TEST(http_connection, RequestPropogates) "GET / HTTP/1.1\r\nHost: openbmc_project.xyz\r\nConnection: close\r\n\r\n")); FakeHandler handler; boost::asio::steady_timer timer(io); - std::function<std::string()> date(&getDateStr); + std::function<std::string()> date( + std::bind_front(&ClockFake::getDateStr, &clock)); std::shared_ptr<crow::Connection<boost::beast::test::stream, FakeHandler>> conn = std::make_shared< crow::Connection<boost::beast::test::stream, FakeHandler>>( @@ -77,9 +90,10 @@ TEST(http_connection, RequestPropogates) "Cross-Origin-Opener-Policy: same-origin\r\n" "Cross-Origin-Resource-Policy: same-origin\r\n" "Content-Security-Policy: default-src 'none'; img-src 'self' data:; font-src 'self'; style-src 'self'; script-src 'self'; connect-src 'self' wss:; form-action 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'none'\r\n" - "Content-Length: 0\r\n" - "\r\n"; + "Date: TestTime\r\n" + "Content-Length: 0\r\n\r\n"; EXPECT_EQ(outStr, expected); + EXPECT_TRUE(clock.wascalled); } } // namespace crow |