mirror of https://github.com/kiwix/libkiwix.git
ServerSearchTest.searchInMultilanguageBookSetIsDenied
This commit is contained in:
parent
cb02dbd92a
commit
d1b85192c0
|
@ -7,16 +7,6 @@
|
|||
#include "server_testing_tools.h"
|
||||
|
||||
|
||||
class ServerSearchTest : public ServerTest
|
||||
{
|
||||
void SetUp() override {
|
||||
zfs1_.reset(new ZimFileServer(SERVER_PORT,
|
||||
ZimFileServer::DEFAULT_OPTIONS,
|
||||
"./test/lib_for_server_search_test.xml")
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
std::string makeSearchResultsHtml(const std::string& pattern,
|
||||
const std::string& header,
|
||||
const std::string& results,
|
||||
|
@ -927,7 +917,7 @@ struct TestData
|
|||
}
|
||||
};
|
||||
|
||||
TEST_F(ServerSearchTest, searchResults)
|
||||
TEST(ServerSearchTest, searchResults)
|
||||
{
|
||||
const TestData testData[] = {
|
||||
{
|
||||
|
@ -1468,15 +1458,86 @@ TEST_F(ServerSearchTest, searchResults)
|
|||
},
|
||||
};
|
||||
|
||||
ZimFileServer zfs(SERVER_PORT, ZimFileServer::DEFAULT_OPTIONS,
|
||||
"./test/lib_for_server_search_test.xml");
|
||||
|
||||
for ( const auto& t : testData ) {
|
||||
const std::string htmlSearchUrl = t.url();
|
||||
const auto htmlRes = zfs1_->GET(htmlSearchUrl.c_str());
|
||||
const auto htmlRes = zfs.GET(htmlSearchUrl.c_str());
|
||||
EXPECT_EQ(htmlRes->status, 200);
|
||||
t.checkHtml(htmlRes->body);
|
||||
|
||||
const std::string xmlSearchUrl = t.xmlSearchUrl();
|
||||
const auto xmlRes = zfs1_->GET(xmlSearchUrl.c_str());
|
||||
const auto xmlRes = zfs.GET(xmlSearchUrl.c_str());
|
||||
EXPECT_EQ(xmlRes->status, 200);
|
||||
t.checkXml(xmlRes->body);
|
||||
}
|
||||
}
|
||||
|
||||
std::string expectedConfusionOfTonguesErrorHtml(std::string url)
|
||||
{
|
||||
return R"(<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
|
||||
<title>Invalid request</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Invalid request</h1>
|
||||
<p>
|
||||
The requested URL ")" + url + R"(" is not a valid request.
|
||||
</p>
|
||||
<p>
|
||||
Two or more books in different languages would participate in search, which may lead to confusing results.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
)";
|
||||
}
|
||||
|
||||
std::string expectedConfusionOfTonguesErrorXml(std::string url)
|
||||
{
|
||||
return R"(<?xml version="1.0" encoding="UTF-8">
|
||||
<error>Invalid request</error>
|
||||
<detail>The requested URL ")" + url + R"(" is not a valid request.</detail>
|
||||
<detail>Two or more books in different languages would participate in search, which may lead to confusing results.</detail>
|
||||
)";
|
||||
}
|
||||
|
||||
TEST(ServerSearchTest, searchInMultilanguageBookSetIsDenied)
|
||||
{
|
||||
const std::string testQueries[] = {
|
||||
"pattern=towerofbabel",
|
||||
"pattern=babylon&books.filter.maxsize=1000000",
|
||||
"pattern=baby&books.id=" RAYCHARLESZIMID "&books.id=" EXAMPLEZIMID,
|
||||
};
|
||||
|
||||
// The default limit on the number of books in a multi-zim search is 3
|
||||
const ZimFileServer::FilePathCollection ZIMFILES{
|
||||
"./test/zimfile.zim", // eng
|
||||
"./test/example.zim", // en
|
||||
"./test/corner_cases.zim" // =en
|
||||
};
|
||||
|
||||
ZimFileServer zfs(SERVER_PORT, ZimFileServer::DEFAULT_OPTIONS, ZIMFILES);
|
||||
for ( const auto& q : testQueries ) {
|
||||
{
|
||||
// HTML mode
|
||||
const std::string url = "/ROOT/search?" + q;
|
||||
const auto r = zfs.GET(url.c_str());
|
||||
const TestContext ctx{ {"url", url} };
|
||||
EXPECT_EQ(r->status, 400) << ctx;
|
||||
EXPECT_EQ(r->body, expectedConfusionOfTonguesErrorHtml(url)) << ctx;
|
||||
}
|
||||
|
||||
{
|
||||
// XML mode
|
||||
const std::string url = "/ROOT/search?" + q + "&format=xml";
|
||||
const auto r = zfs.GET(url.c_str());
|
||||
const TestContext ctx{ {"url", url} };
|
||||
EXPECT_EQ(r->status, 400) << ctx;
|
||||
EXPECT_EQ(r->body, expectedConfusionOfTonguesErrorXml(url)) << ctx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue