|
@@ -3942,12 +3942,41 @@ TEST_F(ApiFixture, EachCredentialStoreSetsTheEncryptedFLAG_whichProtectsNothing)
|
|
|
// The fix is to call createCollection unconditionally. 2.17.0 turns encryption
|
|
// The fix is to call createCollection unconditionally. 2.17.0 turns encryption
|
|
|
// ON for an existing collection (never off); older servers treat the re-call
|
|
// ON for an existing collection (never off); older servers treat the re-call
|
|
|
// as a no-op.
|
|
// as a no-op.
|
|
|
|
|
+namespace {
|
|
|
|
|
+
|
|
|
|
|
+/// Drop a list of qualified collections however the test exits.
|
|
|
|
|
+///
|
|
|
|
|
+/// WHY RAII AND NOT A DROP AT THE END: the drops WERE at the end, on every
|
|
|
|
|
+/// path the author thought about - success and skip. An ASSERT_* failure
|
|
|
|
|
+/// returns immediately and reaches none of them, so a single red run leaked two
|
|
|
|
|
+/// collections into the SHARED `default` project and left them there forever.
|
|
|
|
|
+/// They accumulated until another team auditing that instance reported them as
|
|
|
|
|
+/// unexplained data, and one of them requests an encryption RESEAL at the next
|
|
|
|
|
+/// restart, so the cost was a compaction nobody asked for.
|
|
|
|
|
+///
|
|
|
|
|
+/// A test that cleans up only when it passes is a test that litters precisely
|
|
|
|
|
+/// when something is already wrong.
|
|
|
|
|
+struct DropCollections {
|
|
|
|
|
+ svapi::DbGateway* db;
|
|
|
|
|
+ std::vector<std::string> qualified;
|
|
|
|
|
+ ~DropCollections() {
|
|
|
|
|
+ for (const std::string& q : qualified) {
|
|
|
|
|
+ try { db->client().dropCollection(q); } catch (...) {}
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+} // namespace
|
|
|
|
|
+
|
|
|
TEST_F(ApiFixture, BootstrapAsksForEncryptionOnAnAlreadyEXISTINGCollection) {
|
|
TEST_F(ApiFixture, BootstrapAsksForEncryptionOnAnAlreadyEXISTINGCollection) {
|
|
|
const std::string suffix = std::to_string(::getpid()) + "_" + std::to_string(::time(nullptr));
|
|
const std::string suffix = std::to_string(::getpid()) + "_" + std::to_string(::time(nullptr));
|
|
|
const std::string target = "enc_upgrade_target_" + suffix;
|
|
const std::string target = "enc_upgrade_target_" + suffix;
|
|
|
const std::string control = "enc_upgrade_control_" + suffix;
|
|
const std::string control = "enc_upgrade_control_" + suffix;
|
|
|
const std::string qTarget = svapi::qualify("default", target);
|
|
const std::string qTarget = svapi::qualify("default", target);
|
|
|
const std::string qControl = svapi::qualify("default", control);
|
|
const std::string qControl = svapi::qualify("default", control);
|
|
|
|
|
+ // Registered BEFORE anything is created, so an ASSERT between here and the
|
|
|
|
|
+ // end still cleans up.
|
|
|
|
|
+ DropCollections cleanup{db_.get(), {qTarget, qControl}};
|
|
|
|
|
|
|
|
// Both collections are created PLAIN and by hand, standing in for one the
|
|
// Both collections are created PLAIN and by hand, standing in for one the
|
|
|
// database made implicitly before our store ever ran.
|
|
// database made implicitly before our store ever ran.
|
|
@@ -3987,8 +4016,6 @@ TEST_F(ApiFixture, BootstrapAsksForEncryptionOnAnAlreadyEXISTINGCollection) {
|
|
|
"not measuring what it claims to";
|
|
"not measuring what it claims to";
|
|
|
|
|
|
|
|
if (!target_info->encrypted) {
|
|
if (!target_info->encrypted) {
|
|
|
- db_->client().dropCollection(qTarget);
|
|
|
|
|
- db_->client().dropCollection(qControl);
|
|
|
|
|
GTEST_SKIP() << "this server does not switch encryption on for an existing collection "
|
|
GTEST_SKIP() << "this server does not switch encryption on for an existing collection "
|
|
|
"(database 2.17.0 and later do); our side asked for it, which is all "
|
|
"(database 2.17.0 and later do); our side asked for it, which is all "
|
|
|
"this code controls - verify the bytes with `smartbotic-db-cli "
|
|
"this code controls - verify the bytes with `smartbotic-db-cli "
|
|
@@ -3997,8 +4024,6 @@ TEST_F(ApiFixture, BootstrapAsksForEncryptionOnAnAlreadyEXISTINGCollection) {
|
|
|
|
|
|
|
|
// Reached only on 2.17.0+: the upgrade happened, driven by our re-call.
|
|
// Reached only on 2.17.0+: the upgrade happened, driven by our re-call.
|
|
|
EXPECT_TRUE(target_info->encrypted);
|
|
EXPECT_TRUE(target_info->encrypted);
|
|
|
- db_->client().dropCollection(qTarget);
|
|
|
|
|
- db_->client().dropCollection(qControl);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|