summaryrefslogtreecommitdiff
path: root/jstests/fle2
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /jstests/fle2
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'jstests/fle2')
-rw-r--r--jstests/fle2/convert_encrypted_to_capped.js2
-rw-r--r--jstests/fle2/rename_encrypted_collection.js70
2 files changed, 71 insertions, 1 deletions
diff --git a/jstests/fle2/convert_encrypted_to_capped.js b/jstests/fle2/convert_encrypted_to_capped.js
index 256a247258e..afed1674036 100644
--- a/jstests/fle2/convert_encrypted_to_capped.js
+++ b/jstests/fle2/convert_encrypted_to_capped.js
@@ -2,7 +2,7 @@
/**
* @tags: [
- * requires_fcv_60,
+ * requires_fcv_60
* assumes_unsharded_collection,
* requires_non_retryable_commands,
* assumes_against_mongod_not_mongos
diff --git a/jstests/fle2/rename_encrypted_collection.js b/jstests/fle2/rename_encrypted_collection.js
new file mode 100644
index 00000000000..badff5a34f3
--- /dev/null
+++ b/jstests/fle2/rename_encrypted_collection.js
@@ -0,0 +1,70 @@
+// Verify renaming to/from a collection with encrypted fields is disallowed
+
+/**
+ * @tags: [
+ * requires_fcv_60,
+ * assumes_unsharded_collection,
+ * ]
+ */
+load("jstests/fle2/libs/encrypted_client_util.js");
+
+(function() {
+'use strict';
+
+const srcDbName = 'rename_encrypted_collection_src_db';
+const tgtDbName = 'rename_encrypted_collection_tgt_db';
+const dbSrc = db.getSiblingDB(srcDbName);
+const dbTgt = db.getSiblingDB(tgtDbName);
+
+dbSrc.encrypted.drop();
+dbSrc.unencrypted.drop();
+dbSrc.renamed.drop();
+dbTgt.encrypted.drop();
+dbTgt.unencrypted.drop();
+
+const sampleEncryptedFields = {
+ "fields": [
+ {
+ "path": "firstName",
+ "keyId": UUID("11d58b8a-0c6c-4d69-a0bd-70c6d9befae9"),
+ "bsonType": "string",
+ "queries": {"queryType": "equality"}
+ },
+ ]
+};
+const srcEncryptedErrmsg = "Cannot rename an encrypted collection";
+const tgtEncryptedErrmsg = "Cannot rename to an existing encrypted collection";
+
+assert.commandWorked(dbSrc.createCollection("encrypted", {encryptedFields: sampleEncryptedFields}));
+assert.commandWorked(dbSrc.createCollection("unencrypted"));
+
+assert.commandWorked(dbTgt.createCollection("encrypted", {encryptedFields: sampleEncryptedFields}));
+
+jsTestLog("Test renaming encrypted collection to another namespace is prohibited");
+let res = assert.commandFailedWithCode(
+ dbSrc.adminCommand({renameCollection: dbSrc + ".encrypted", to: dbSrc + ".renamed"}),
+ ErrorCodes.IllegalOperation,
+ "Renaming an encrypted collection within same DB passed");
+assert.eq(res.errmsg, srcEncryptedErrmsg);
+
+res = assert.commandFailedWithCode(
+ dbSrc.adminCommand({renameCollection: dbSrc + ".encrypted", to: dbTgt + ".unencrypted"}),
+ ErrorCodes.IllegalOperation,
+ "Renaming an encrypted collection between DBs passed");
+assert.eq(res.errmsg, srcEncryptedErrmsg);
+
+jsTestLog("Test renaming unencrypted collection to an encrypted namespace is prohibited");
+res = assert.commandFailedWithCode(
+ dbSrc.adminCommand(
+ {renameCollection: dbSrc + ".unencrypted", to: dbSrc + ".encrypted", dropTarget: true}),
+ ErrorCodes.IllegalOperation,
+ "Renaming to an encrypted collection within same DB passed");
+assert.eq(res.errmsg, tgtEncryptedErrmsg);
+
+res = assert.commandFailedWithCode(
+ dbSrc.adminCommand(
+ {renameCollection: dbSrc + ".unencrypted", to: dbTgt + ".encrypted", dropTarget: true}),
+ ErrorCodes.IllegalOperation,
+ "Renaming to an encrypted collection between DBs passed");
+assert.eq(res.errmsg, tgtEncryptedErrmsg);
+}());