diff --git a/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.json b/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.json index d5b04b3ea5f..c266aa6b835 100644 --- a/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.json +++ b/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.json @@ -55,6 +55,38 @@ "result": { "errorContains": "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption." } + }, + { + "name": "assertCollectionNotExists", + "object": "testRunner", + "arguments": { + "database": "default", + "collection": "enxcol_.encryptedCollection.esc" + } + }, + { + "name": "assertCollectionNotExists", + "object": "testRunner", + "arguments": { + "database": "default", + "collection": "enxcol_.encryptedCollection.ecc" + } + }, + { + "name": "assertCollectionNotExists", + "object": "testRunner", + "arguments": { + "database": "default", + "collection": "enxcol_.encryptedCollection.ecoc" + } + }, + { + "name": "assertCollectionNotExists", + "object": "testRunner", + "arguments": { + "database": "default", + "collection": "encryptedCollection" + } } ] } diff --git a/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.yml b/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.yml index f55001a4294..5cc6ead0f6d 100644 --- a/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.yml +++ b/specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.yml @@ -37,3 +37,25 @@ tests: collection: "encryptedCollection" result: errorContains: "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption." + # Assert no collections were created. + - name: assertCollectionNotExists + object: testRunner + arguments: + database: *database_name + collection: &esc_collection_name "enxcol_.encryptedCollection.esc" + # ecc collection is no longer created for QEv2 + - name: assertCollectionNotExists + object: testRunner + arguments: + database: *database_name + collection: &ecc_collection_name "enxcol_.encryptedCollection.ecc" + - name: assertCollectionNotExists + object: testRunner + arguments: + database: *database_name + collection: &ecoc_collection_name "enxcol_.encryptedCollection.ecoc" + - name: assertCollectionNotExists + object: testRunner + arguments: + database: *database_name + collection: encryptedCollection diff --git a/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs b/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs index 8d1c2218313..c55d8d4fabc 100644 --- a/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs +++ b/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs @@ -41,7 +41,8 @@ internal static IWriteOperation CreateEncryptedCreateCollectionOpe { var mainOperation = new CreateCollectionOperation( collectionNamespace, - messageEncoderSettings) + messageEncoderSettings, + encryptedFields != null ? Feature.Csfle2QEv2 : null) { EncryptedFields = encryptedFields }; @@ -62,7 +63,10 @@ internal static IWriteOperation CreateEncryptedCreateCollectionOpe } CreateCollectionOperation CreateInnerCollectionOperation(string collectionName) - => new CreateCollectionOperation(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings) { ClusteredIndex = new BsonDocument { { "key", new BsonDocument("_id", 1) }, { "unique", true } } }; + => new(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings, Feature.Csfle2QEv2) + { + ClusteredIndex = new BsonDocument { { "key", new BsonDocument("_id", 1) }, { "unique", true } } + }; } #endregion @@ -89,6 +93,8 @@ CreateCollectionOperation CreateInnerCollectionOperation(string collectionName) private BsonDocument _validator; private WriteConcern _writeConcern; + private readonly Feature _supportedFeature; + // constructors /// /// Initializes a new instance of the class. @@ -109,6 +115,7 @@ private CreateCollectionOperation( { _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace)); _messageEncoderSettings = messageEncoderSettings; + _supportedFeature = supportedFeature; } // properties @@ -455,10 +462,7 @@ private WriteCommandOperation CreateOperation(ICoreSessionHandle s private void EnsureServerIsValid(int maxWireVersion) { - if (_encryptedFields != null) - { - Feature.Csfle2QEv2.ThrowIfNotSupported(maxWireVersion); - } + _supportedFeature?.ThrowIfNotSupported(maxWireVersion); } [Flags]