|
@@ -1083,6 +1083,89 @@ TEST_F(ApiFixture, DocumentTtlAcceptedOnInsertAndPatch) {
|
|
|
EXPECT_EQ(nlohmann::json::parse(got->body)["v"], 2);
|
|
EXPECT_EQ(nlohmann::json::parse(got->body)["v"], 2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+TEST_F(ApiFixture, PutRefusesTtlSecondsRatherThanStoringAPermanentRow) {
|
|
|
|
|
+ // Reported by a consumer: PUT with `?ttl_seconds=3600` answered 201 and
|
|
|
|
|
+ // stored a PERMANENT row. Their feature existed to stop a restore
|
|
|
|
|
+ // recreating an immortal at-most-once marker, so the silent drop produced
|
|
|
|
|
+ // precisely the bug it was written to prevent - and the restore reported
|
|
|
|
|
+ // success either way.
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(), nlohmann::json{{"name","ttlput"},{"kind","json"}}.dump(),
|
|
|
|
|
+ "application/json")->status, 201);
|
|
|
|
|
+ std::string docs = base + "/ttlput/documents";
|
|
|
|
|
+
|
|
|
|
|
+ auto refused = c.Put((docs + "/row1?ttl_seconds=3600").c_str(),
|
|
|
|
|
+ nlohmann::json{{"v",1}}.dump(), "application/json");
|
|
|
|
|
+ ASSERT_TRUE(refused);
|
|
|
|
|
+ EXPECT_EQ(refused->status, 422);
|
|
|
|
|
+ const auto err = nlohmann::json::parse(refused->body)["error"];
|
|
|
|
|
+ EXPECT_EQ(err.value("code", ""), "unknown_option");
|
|
|
|
|
+ // Names the parameter, so the caller does not have to guess which one.
|
|
|
|
|
+ ASSERT_TRUE(err.contains("details"));
|
|
|
|
|
+ const auto unsup = err["details"]["unsupported"];
|
|
|
|
|
+ ASSERT_TRUE(unsup.is_array());
|
|
|
|
|
+ EXPECT_EQ(unsup.size(), 1u);
|
|
|
|
|
+ EXPECT_EQ(unsup[0], "ttl_seconds");
|
|
|
|
|
+ // And points at the routes that CAN carry an expiry.
|
|
|
|
|
+ const std::string msg = err.value("message", "");
|
|
|
|
|
+ EXPECT_NE(msg.find("POST"), std::string::npos) << msg;
|
|
|
|
|
+ EXPECT_NE(msg.find("PATCH"), std::string::npos) << msg;
|
|
|
|
|
+
|
|
|
|
|
+ // THE REFUSAL MUST NOT HAVE STORED ANYTHING. A 422 that still wrote the
|
|
|
|
|
+ // row would leave exactly the permanent document this refusal exists to
|
|
|
|
|
+ // prevent, which is the failure the consumer actually met.
|
|
|
|
|
+ EXPECT_EQ(c.Get((docs + "/row1").c_str())->status, 404);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, PutWithoutTtlSecondsStillWorksAndAnIncidentalParamIsNotRefused) {
|
|
|
|
|
+ // The PAIRING, and the only thing that proves the refusal is SELECTIVE
|
|
|
|
|
+ // rather than a blanket break of PUT. Without it the test above would pass
|
|
|
|
|
+ // just as well against a route that refused everything.
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(), nlohmann::json{{"name","ttlput2"},{"kind","json"}}.dump(),
|
|
|
|
|
+ "application/json")->status, 201);
|
|
|
|
|
+ std::string docs = base + "/ttlput2/documents";
|
|
|
|
|
+
|
|
|
|
|
+ // An ordinary PUT is untouched.
|
|
|
|
|
+ auto ok = c.Put((docs + "/row1").c_str(), nlohmann::json{{"v",1}}.dump(), "application/json");
|
|
|
|
|
+ ASSERT_TRUE(ok); EXPECT_TRUE(ok->status == 200 || ok->status == 201) << ok->status;
|
|
|
|
|
+
|
|
|
|
|
+ // A cache-buster is NOT an option anybody is asking us to honour, so it
|
|
|
|
|
+ // must still pass - refusing `ttl_seconds` is the point, refusing `_=...`
|
|
|
|
|
+ // would be a regression.
|
|
|
|
|
+ auto bust = c.Put((docs + "/row2?_=1760000000").c_str(),
|
|
|
|
|
+ nlohmann::json{{"v",2}}.dump(), "application/json");
|
|
|
|
|
+ ASSERT_TRUE(bust); EXPECT_TRUE(bust->status == 200 || bust->status == 201) << bust->status;
|
|
|
|
|
+
|
|
|
|
|
+ // `if_version` is a real PUT parameter and must not be swept up either.
|
|
|
|
|
+ auto ver = c.Put((docs + "/row2?if_version=1").c_str(),
|
|
|
|
|
+ nlohmann::json{{"v",3}}.dump(), "application/json");
|
|
|
|
|
+ ASSERT_TRUE(ver); EXPECT_NE(ver->status, 422) << ver->status;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, TheSiblingRoutesThatDoHonourTtlSecondsAreUnaffected) {
|
|
|
|
|
+ // The second half of the pairing: POST and PATCH both genuinely honour
|
|
|
|
|
+ // `ttl_seconds`, and this fix must not have touched them. If it had, the
|
|
|
|
|
+ // refusal above would be indistinguishable from having broken the TTL
|
|
|
|
|
+ // feature everywhere.
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(), nlohmann::json{{"name","ttlsib"},{"kind","json"}}.dump(),
|
|
|
|
|
+ "application/json")->status, 201);
|
|
|
|
|
+ std::string docs = base + "/ttlsib/documents";
|
|
|
|
|
+
|
|
|
|
|
+ auto made = c.Post((docs + "?ttl_seconds=3600").c_str(),
|
|
|
|
|
+ nlohmann::json{{"v",1}}.dump(), "application/json");
|
|
|
|
|
+ ASSERT_TRUE(made); EXPECT_EQ(made->status, 201);
|
|
|
|
|
+ const std::string id = nlohmann::json::parse(made->body)["id"];
|
|
|
|
|
+
|
|
|
|
|
+ auto patched = c.Patch((docs + "/" + id + "?ttl_seconds=7200").c_str(),
|
|
|
|
|
+ nlohmann::json{{"v",2}}.dump(), "application/json");
|
|
|
|
|
+ ASSERT_TRUE(patched); EXPECT_EQ(patched->status, 200);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
TEST_F(ApiFixture, DocumentTtlRejectsNonNumeric) {
|
|
TEST_F(ApiFixture, DocumentTtlRejectsNonNumeric) {
|
|
|
auto c = admin();
|
|
auto c = admin();
|
|
|
std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
std::string base = "/api/v1/projects/" + project_ + "/collections";
|