More pagination validation.

This commit is contained in:
Kishore Nallan 2023-04-05 18:00:00 +05:30
parent 735a24e2b9
commit 2474ac0625
3 changed files with 21 additions and 2 deletions

View File

@ -952,6 +952,10 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& re
per_page = 0;
}
if(!req_params[PAGE].empty() && page == 0 && offset == UINT32_MAX) {
return Option<bool>(422, "Parameter `page` must be an integer of value greater than 0.");
}
if(req_params[PAGE].empty() && req_params[OFFSET].empty()) {
page = 1;
}

View File

@ -1058,7 +1058,6 @@ TEST_F(CollectionTest, KeywordQueryReturnsResultsBasedOnPerPageParam) {
FREQUENCY, {true}, 1000, empty, empty, 10);
ASSERT_FALSE(res_op.ok());
ASSERT_EQ(422, res_op.code());
ASSERT_STREQ("Page must be an integer of value greater than 0.", res_op.error().c_str());
// do pagination
@ -3031,7 +3030,6 @@ TEST_F(CollectionTest, WildcardQueryReturnsResultsBasedOnPerPageParam) {
FREQUENCY, {false}, 1000, empty, empty, 10);
ASSERT_FALSE(res_op.ok());
ASSERT_EQ(422, res_op.code());
ASSERT_STREQ("Page must be an integer of value greater than 0.", res_op.error().c_str());
// do pagination

View File

@ -733,6 +733,23 @@ TEST_F(CoreAPIUtilsTest, SearchPagination) {
results = nlohmann::json::parse(res->body)["results"][0];
ASSERT_EQ(400, results["code"].get<size_t>());
ASSERT_EQ("Parameter `offset` must be an unsigned integer.", results["error"].get<std::string>());
// when page is 0 and no offset is sent
search.clear();
req->params.clear();
body["searches"] = nlohmann::json::array();
search["collection"] = "coll1";
search["q"] = "title";
search["page"] = "0";
search["query_by"] = "name";
search["sort_by"] = "points:desc";
body["searches"].push_back(search);
req->body = body.dump();
post_multi_search(req, res);
results = nlohmann::json::parse(res->body)["results"][0];
ASSERT_EQ(422, results["code"].get<size_t>());
ASSERT_EQ("Parameter `page` must be an integer of value greater than 0.", results["error"].get<std::string>());
}
TEST_F(CoreAPIUtilsTest, ExportWithFilter) {