Cleaned up traces of userlang control via cookie

This commit is contained in:
Veloman Yunkan 2024-01-28 16:21:10 +04:00
parent aff801e6cc
commit fc211d9a2e
1 changed files with 0 additions and 25 deletions

View File

@ -1237,7 +1237,6 @@ TEST_F(ServerTest, UserLanguageControl)
const std::string description; const std::string description;
const std::string url; const std::string url;
const std::string acceptLanguageHeader; const std::string acceptLanguageHeader;
const char* const requestCookie; // Cookie: header of the request
const std::string expectedH1; const std::string expectedH1;
operator TestContext() const operator TestContext() const
@ -1248,64 +1247,45 @@ TEST_F(ServerTest, UserLanguageControl)
{"acceptLanguageHeader", acceptLanguageHeader}, {"acceptLanguageHeader", acceptLanguageHeader},
}; };
if ( requestCookie ) {
ctx.push_back({"requestCookie", requestCookie});
}
return ctx; return ctx;
} }
}; };
const char* const NO_COOKIE = nullptr;
const TestData testData[] = { const TestData testData[] = {
{ {
"Default user language is English", "Default user language is English",
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
/*Accept-Language:*/ "", /*Accept-Language:*/ "",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "Not Found" /* expected <h1> */ "Not Found"
}, },
{ {
"userlang URL query parameter is respected", "userlang URL query parameter is respected",
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en",
/*Accept-Language:*/ "", /*Accept-Language:*/ "",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "Not Found" /* expected <h1> */ "Not Found"
}, },
{ {
"userlang URL query parameter is respected", "userlang URL query parameter is respected",
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=test", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=test",
/*Accept-Language:*/ "", /*Accept-Language:*/ "",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive" /* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
}, },
{ {
"'Accept-Language: *' is handled", "'Accept-Language: *' is handled",
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
/*Accept-Language:*/ "*", /*Accept-Language:*/ "*",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "Not Found" /* expected <h1> */ "Not Found"
}, },
{ {
"Accept-Language: header is respected", "Accept-Language: header is respected",
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
/*Accept-Language:*/ "test", /*Accept-Language:*/ "test",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive" /* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
}, },
{
"userlang cookie is ignored",
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
/*Accept-Language:*/ "",
/*Request Cookie:*/ "userlang=test",
/* expected <h1> */ "Not Found"
},
{ {
"userlang query parameter takes precedence over Accept-Language", "userlang query parameter takes precedence over Accept-Language",
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en",
/*Accept-Language:*/ "test", /*Accept-Language:*/ "test",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "Not Found" /* expected <h1> */ "Not Found"
}, },
{ {
@ -1314,7 +1294,6 @@ TEST_F(ServerTest, UserLanguageControl)
// with quality values) the most suitable language is selected. // with quality values) the most suitable language is selected.
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
/*Accept-Language:*/ "test;q=0.9, en;q=0.2", /*Accept-Language:*/ "test;q=0.9, en;q=0.2",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive" /* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
}, },
{ {
@ -1323,7 +1302,6 @@ TEST_F(ServerTest, UserLanguageControl)
// with quality values) the most suitable language is selected. // with quality values) the most suitable language is selected.
/*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article",
/*Accept-Language:*/ "test;q=0.2, en;q=0.9", /*Accept-Language:*/ "test;q=0.2, en;q=0.9",
/*Request Cookie:*/ NO_COOKIE,
/* expected <h1> */ "Not Found" /* expected <h1> */ "Not Found"
}, },
}; };
@ -1335,9 +1313,6 @@ TEST_F(ServerTest, UserLanguageControl)
if ( !t.acceptLanguageHeader.empty() ) { if ( !t.acceptLanguageHeader.empty() ) {
headers.insert({"Accept-Language", t.acceptLanguageHeader}); headers.insert({"Accept-Language", t.acceptLanguageHeader});
} }
if ( t.requestCookie ) {
headers.insert({"Cookie", t.requestCookie});
}
const auto r = zfs1_->GET(t.url.c_str(), headers); const auto r = zfs1_->GET(t.url.c_str(), headers);
EXPECT_FALSE(r->has_header("Set-Cookie")); EXPECT_FALSE(r->has_header("Set-Cookie"));
std::regex_search(r->body, h1Match, h1Regex); std::regex_search(r->body, h1Match, h1Regex);