|
|
@@ -347,6 +347,9 @@ TEST_F(UnixSocketTest, RedirectStaysOnSocket) {
|
|
|
// An absolute Location naming the Host this client sends
|
|
|
res.set_redirect("http://localhost" + pattern_);
|
|
|
});
|
|
|
+ svr.Get("/upper", [&](const httplib::Request &, httplib::Response &res) {
|
|
|
+ res.set_redirect("http://LOCALHOST" + pattern_);
|
|
|
+ });
|
|
|
svr.Get("/cross", [&](const httplib::Request &, httplib::Response &res) {
|
|
|
res.set_redirect("http://" + other_path + pattern_);
|
|
|
});
|
|
|
@@ -399,6 +402,13 @@ TEST_F(UnixSocketTest, RedirectStaysOnSocket) {
|
|
|
EXPECT_EQ(content_, res->body);
|
|
|
EXPECT_EQ("Bearer token", res->get_header_value("X-Auth"));
|
|
|
|
|
|
+ // in any case
|
|
|
+ res = cli.Get("/upper");
|
|
|
+ ASSERT_TRUE(res) << "error: " << res.error();
|
|
|
+ EXPECT_EQ(StatusCode::OK_200, res->status);
|
|
|
+ EXPECT_EQ(content_, res->body);
|
|
|
+ EXPECT_EQ("Bearer token", res->get_header_value("X-Auth"));
|
|
|
+
|
|
|
// A host the caller mapped to a socket goes there
|
|
|
cli.set_direct_hostname_addr_map({{"mapped.test", other_path}});
|
|
|
res = cli.Get("/mapped");
|
|
|
@@ -4744,6 +4754,45 @@ TEST(RedirectToSamePort, ForwardCookie) {
|
|
|
EXPECT_EQ("session_id=SECRET", captured_cookie);
|
|
|
}
|
|
|
|
|
|
+TEST(RedirectToSamePort, HostNameIsCaseInsensitive) {
|
|
|
+ // "LOCALHOST" names the same host as "localhost" (RFC 3986 3.2.2), so the
|
|
|
+ // redirect stays on this origin and keeps its credentials and cookies.
|
|
|
+ Server svr;
|
|
|
+ std::string captured_authorization;
|
|
|
+ std::string captured_cookie;
|
|
|
+ int port = 0;
|
|
|
+ svr.Get("/redir", [&](const Request & /*req*/, Response &res) {
|
|
|
+ res.set_redirect("http://LOCALHOST:" + std::to_string(port) + "/target",
|
|
|
+ 302);
|
|
|
+ });
|
|
|
+ svr.Get("/target", [&](const Request &req, Response &res) {
|
|
|
+ captured_authorization = req.get_header_value("Authorization");
|
|
|
+ captured_cookie = req.get_header_value("Cookie");
|
|
|
+ res.set_content("OK", "text/plain");
|
|
|
+ });
|
|
|
+
|
|
|
+ port = svr.bind_to_any_port(HOST);
|
|
|
+ auto thread = std::thread([&]() { svr.listen_after_bind(); });
|
|
|
+ auto se = detail::scope_exit([&] {
|
|
|
+ svr.stop();
|
|
|
+ thread.join();
|
|
|
+ ASSERT_FALSE(svr.is_running());
|
|
|
+ });
|
|
|
+
|
|
|
+ svr.wait_until_ready();
|
|
|
+
|
|
|
+ Client cli(HOST, port);
|
|
|
+ cli.set_follow_location(true);
|
|
|
+ cli.set_basic_auth("admin", "secret");
|
|
|
+
|
|
|
+ Headers headers = {{"Cookie", "session_id=SECRET"}};
|
|
|
+ auto res = cli.Get("/redir", headers);
|
|
|
+ ASSERT_TRUE(res) << "Error: " << to_string(res.error());
|
|
|
+ EXPECT_EQ(StatusCode::OK_200, res->status);
|
|
|
+ EXPECT_EQ("Basic YWRtaW46c2VjcmV0", captured_authorization);
|
|
|
+ EXPECT_EQ("session_id=SECRET", captured_cookie);
|
|
|
+}
|
|
|
+
|
|
|
TEST(RedirectTest, DoNotCarryRequestParamsToLocation) {
|
|
|
// The Location alone names the next target, on any origin.
|
|
|
Server target_svr;
|