|
|
@@ -4139,3 +4139,125 @@ TEST_F(ApiFixture, AnIndexOnAnEncryptedFieldIsRefusedPermanentlyNotAs503) {
|
|
|
EXPECT_EQ(nlohmann::json::parse(dup->body)["error"].value("code", ""), "duplicate_values");
|
|
|
c.Delete(base.c_str());
|
|
|
}
|
|
|
+
|
|
|
+// THE CLASS, NOT THE INSTANCE. #72 fixed the index-values route and left six
|
|
|
+// siblings answering 200 to a parameter they could not honour, which is the
|
|
|
+// exact failure mode that defect was the specimen of. One test per route,
|
|
|
+// because a settings key - or a refusal - is not done until a test drives its
|
|
|
+// ROUTE: the `network_egress` edit that landed in the wrong handler compiled,
|
|
|
+// passed the suite and was caught by prod acceptance.
|
|
|
+TEST_F(ApiFixture, EveryListingRouteRefusesParamsItCannotHonour) {
|
|
|
+ auto c = admin();
|
|
|
+ const std::string proj = "/api/v1/projects/" + project_;
|
|
|
+ const std::string coll = proj + "/collections/qparams";
|
|
|
+ c.Delete(coll.c_str());
|
|
|
+ ASSERT_EQ(c.Post((proj + "/collections").c_str(),
|
|
|
+ nlohmann::json{{"name", "qparams"}, {"kind", "json"}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ ASSERT_EQ(c.Post((coll + "/documents").c_str(),
|
|
|
+ nlohmann::json{{"id", "q1"}, {"tag", "a"}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+
|
|
|
+ struct Case { const char* path; const char* param; const char* instead; };
|
|
|
+ // `instead` is the sibling route's spelling where there is one - the whole
|
|
|
+ // reason these lists are not hypothetical is that our own routes disagree
|
|
|
+ // about how to say the same thing.
|
|
|
+ const std::vector<Case> cases = {
|
|
|
+ // /documents implements limit/offset/sort/desc, so the refusals are
|
|
|
+ // the OTHER routes' names for them.
|
|
|
+ {"/documents?order=desc", "order", "desc"},
|
|
|
+ {"/documents?q=hello", "q", "filter"},
|
|
|
+ {"/documents?page=2", "page", nullptr},
|
|
|
+ {"/documents?search=hello", "search", "filter"},
|
|
|
+ };
|
|
|
+ for (const Case& k : cases) {
|
|
|
+ auto res = c.Get((coll + k.path).c_str());
|
|
|
+ ASSERT_TRUE(res) << k.param;
|
|
|
+ ASSERT_EQ(res->status, 422) << k.param << ": " << res->body;
|
|
|
+ auto err = nlohmann::json::parse(res->body)["error"];
|
|
|
+ EXPECT_EQ(err.value("code", ""), "unknown_option") << k.param;
|
|
|
+ // `unsupported` keeps the flat-array shape 0.13.0 published.
|
|
|
+ ASSERT_TRUE(err["details"]["unsupported"].is_array()) << res->body;
|
|
|
+ EXPECT_EQ(err["details"]["unsupported"][0].get<std::string>(), k.param);
|
|
|
+ if (k.instead)
|
|
|
+ EXPECT_EQ(err["details"]["instead"][k.param].get<std::string>(), k.instead)
|
|
|
+ << res->body;
|
|
|
+ else
|
|
|
+ EXPECT_FALSE(err["details"].contains("instead")) << res->body;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Collections listing: refuses pagination it does not have.
|
|
|
+ auto cl = c.Get((proj + "/collections?limit=5").c_str());
|
|
|
+ ASSERT_EQ(cl->status, 422) << cl->body;
|
|
|
+ EXPECT_EQ(nlohmann::json::parse(cl->body)["error"].value("code", ""), "unknown_option");
|
|
|
+ // ...and still honours the two it does implement, or the refusal has
|
|
|
+ // broken the web UI, which sends exactly these.
|
|
|
+ auto okc = c.Get((proj + "/collections?q=qpar&sort=name&desc=true").c_str());
|
|
|
+ EXPECT_EQ(okc->status, 200) << okc->body;
|
|
|
+
|
|
|
+ // Files listing: fixed order, no search.
|
|
|
+ auto fl = c.Get((proj + "/files?sort=name").c_str());
|
|
|
+ ASSERT_EQ(fl->status, 422) << fl->body;
|
|
|
+ auto flok = c.Get((proj + "/files?limit=5&offset=0").c_str());
|
|
|
+ ASSERT_EQ(flok->status, 200) << flok->body;
|
|
|
+ // The completeness the client hands us and we used to discard. Emitted
|
|
|
+ // unconditionally, so ABSENCE means only "older server".
|
|
|
+ auto flj = nlohmann::json::parse(flok->body);
|
|
|
+ EXPECT_TRUE(flj.contains("has_more")) << flok->body;
|
|
|
+ EXPECT_TRUE(flj["has_more"].is_boolean()) << flok->body;
|
|
|
+ EXPECT_TRUE(flj.contains("total")) << flok->body;
|
|
|
+
|
|
|
+ // Export: `format` for `vector_format` is the costly one - it silently
|
|
|
+ // produces the array export, which is ~3x the bytes of base64.
|
|
|
+ auto ex = c.Get((coll + "/export?format=base64").c_str());
|
|
|
+ ASSERT_EQ(ex->status, 422) << ex->body;
|
|
|
+ EXPECT_EQ(nlohmann::json::parse(ex->body)["error"]["details"]["instead"]["format"]
|
|
|
+ .get<std::string>(), "vector_format");
|
|
|
+ // An export cannot take a subset, so asking for one is refused rather than
|
|
|
+ // answered with the whole collection.
|
|
|
+ auto exl = c.Get((coll + "/export?limit=10").c_str());
|
|
|
+ EXPECT_EQ(exl->status, 422) << exl->body;
|
|
|
+
|
|
|
+ // The run log takes `limit` and nothing else. `status=failed` is the one
|
|
|
+ // everybody reaches for, and it would have returned runs of EVERY outcome.
|
|
|
+ const std::string fn = proj + "/functions/nosuchfn/logs";
|
|
|
+ auto rl = c.Get((fn + "?status=failed").c_str());
|
|
|
+ ASSERT_TRUE(rl);
|
|
|
+ // 422 BEFORE the 404: the parameter is wrong whether or not the function
|
|
|
+ // exists, and answering 404 first would hide it until they created one.
|
|
|
+ EXPECT_EQ(rl->status, 422) << rl->body;
|
|
|
+
|
|
|
+ // Schema suggest: `limit` would be ignored and scan every row.
|
|
|
+ auto sg = c.Get((coll + "/schema/suggest?limit=10").c_str());
|
|
|
+ ASSERT_TRUE(sg);
|
|
|
+ if (sg->status != 501) // older database: no collection_schema capability
|
|
|
+ EXPECT_EQ(sg->status, 422) << sg->body;
|
|
|
+}
|
|
|
+
|
|
|
+// The pairing that proves the refusals above are SELECTIVE. Without this, the
|
|
|
+// whole family could be a blanket refusal of unknown parameters and every test
|
|
|
+// above would still pass - and a blanket refusal would break callers over
|
|
|
+// cache-busters and proxy additions that were never asking for behaviour.
|
|
|
+TEST_F(ApiFixture, NoListingRouteRefusesAnIncidentalParameter) {
|
|
|
+ auto c = admin();
|
|
|
+ const std::string proj = "/api/v1/projects/" + project_;
|
|
|
+ const std::string coll = proj + "/collections/qincidental";
|
|
|
+ // Creates its own collection rather than reusing the one the previous test
|
|
|
+ // made. The first version leaned on that leftover and failed the moment
|
|
|
+ // ctest ran it first: a 404 for a collection that did not exist yet, which
|
|
|
+ // would ALSO have masked a wrongly refused parameter. The fixture already
|
|
|
+ // shares one database and a fixed project name, so a test that depends on
|
|
|
+ // another test's residue passes or fails on ordering.
|
|
|
+ c.Delete(coll.c_str());
|
|
|
+ ASSERT_EQ(c.Post((proj + "/collections").c_str(),
|
|
|
+ nlohmann::json{{"name", "qincidental"}, {"kind", "json"}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+
|
|
|
+ for (const std::string& path : {coll + "/documents?_=1760000000",
|
|
|
+ proj + "/collections?_=1760000000&utm_source=x",
|
|
|
+ proj + "/files?_=1760000000"}) {
|
|
|
+ auto res = c.Get(path.c_str());
|
|
|
+ ASSERT_TRUE(res) << path;
|
|
|
+ EXPECT_EQ(res->status, 200) << path << ": " << res->body;
|
|
|
+ }
|
|
|
+}
|