diff --git a/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java b/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java index 3e58712ca9c..0d8968eea90 100644 --- a/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java +++ b/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java @@ -176,6 +176,14 @@ public void create(final WriteConcern writeConcern, final BsonDocument createOpt case "size": createCollectionOptions.sizeInBytes(createOptions.getNumber("size").longValue()); break; + case "encryptedFields": + createCollectionOptions.encryptedFields(createOptions.getDocument("encryptedFields")); + break; + case "validator": + ValidationOptions validationOptions = new ValidationOptions(); + validationOptions.validator(createOptions.getDocument("validator")); + createCollectionOptions.validationOptions(validationOptions); + break; default: throw new UnsupportedOperationException("Unsupported create collection option: " + option); } @@ -195,6 +203,10 @@ public void create(final String collectionName, final CreateCollectionOptions op if (indexOptionDefaults.getStorageEngine() != null) { operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine()))); } + Bson encryptedFields = options.getEncryptedFields(); + if (encryptedFields != null) { + operation.encryptedFields(encryptedFields.toBsonDocument()); + } ValidationOptions validationOptions = options.getValidationOptions(); if (validationOptions.getValidator() != null) { operation.validator(toBsonDocument(validationOptions.getValidator())); diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/TestClusterListener.java b/driver-core/src/test/unit/com/mongodb/internal/connection/TestClusterListener.java index 7a11b360046..2437a4bc8f9 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/TestClusterListener.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/TestClusterListener.java @@ -32,7 +32,6 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.function.Predicate; -import static com.mongodb.assertions.Assertions.isTrue; import static com.mongodb.assertions.Assertions.notNull; import static com.mongodb.internal.Locks.withLock; @@ -48,15 +47,17 @@ public final class TestClusterListener implements ClusterListener { @Override public void clusterOpening(final ClusterOpeningEvent event) { - isTrue("clusterOpeningEvent is null", clusterOpeningEvent == null); - clusterOpeningEvent = event; + if(clusterOpeningEvent == null) { + clusterOpeningEvent = event; + } } @Override public void clusterClosed(final ClusterClosedEvent event) { - isTrue("clusterClosingEvent is null", clusterClosingEvent == null); - closedLatch.countDown(); - clusterClosingEvent = event; + if(clusterClosingEvent == null) { + closedLatch.countDown(); + clusterClosingEvent = event; + } } @Override diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java b/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java index f1429431690..f2b8afc4fbc 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java @@ -16,6 +16,7 @@ package com.mongodb.client.unified; +import com.mongodb.AutoEncryptionSettings; import com.mongodb.ClientEncryptionSettings; import com.mongodb.ClientSessionOptions; import com.mongodb.ConnectionString; @@ -111,7 +112,7 @@ public final class Entities { private static final Set SUPPORTED_CLIENT_ENTITY_OPTIONS = new HashSet<>( asList( - "id", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities", + "id", "autoEncryptOpts", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities", "observeEvents", "observeLogMessages", "observeSensitiveCommands", "ignoreCommandMonitoringEvents")); private final Set entityNames = new HashSet<>(); private final Map threads = new HashMap<>(); @@ -604,6 +605,59 @@ private void initClient(final BsonDocument entity, final String id, } clientSettingsBuilder.serverApi(serverApiBuilder.build()); } + if (entity.containsKey("autoEncryptOpts")) { + AutoEncryptionSettings.Builder builder = AutoEncryptionSettings.builder(); + for (Map.Entry entry : entity.getDocument("autoEncryptOpts").entrySet()) { + switch (entry.getKey()) { + case "bypassAutoEncryption": + builder.bypassAutoEncryption(entry.getValue().asBoolean().getValue()); + break; + case "bypassQueryAnalysis": + builder.bypassQueryAnalysis(entry.getValue().asBoolean().getValue()); + break; + case "schemaMap": + Map schemaMap = new HashMap<>(); + for (Map.Entry entries : entry.getValue().asDocument().entrySet()) { + schemaMap.put(entries.getKey(), entries.getValue().asDocument()); + } + builder.schemaMap(schemaMap); + break; + case "encryptedFieldsMap": + Map encryptedFieldsMap = new HashMap<>(); + for (Map.Entry entries : entry.getValue().asDocument().entrySet()) { + encryptedFieldsMap.put(entries.getKey(), entries.getValue().asDocument()); + } + builder.encryptedFieldsMap(encryptedFieldsMap); + break; + case "extraOptions": + Map extraOptions = new HashMap<>(); + for (Map.Entry extraOptionsEntry : entry.getValue().asDocument().entrySet()) { + switch (extraOptionsEntry.getKey()) { + case "mongocryptdBypassSpawn": + extraOptions.put(extraOptionsEntry.getKey(), extraOptionsEntry.getValue().asBoolean().getValue()); + break; + default: + throw new UnsupportedOperationException("Unsupported extra encryption option: " + extraOptionsEntry.getKey()); + } + } + builder.extraOptions(extraOptions); + break; + case "keyVaultNamespace": + builder.keyVaultNamespace(entry.getValue().asString().getValue()); + break; + case "kmsProviders": + builder.kmsProviders(createKmsProvidersMap(entry.getValue().asDocument())); + break; + case "keyExpirationMS": + builder.keyExpiration(entry.getValue().asNumber().longValue(), TimeUnit.MILLISECONDS); + break; + default: + throw new UnsupportedOperationException("Unsupported client encryption option: " + entry.getKey()); + } + } + clientSettingsBuilder.autoEncryptionSettings(builder.build()); + } + MongoClientSettings clientSettings = clientSettingsBuilder.build(); if (entity.containsKey("observeLogMessages")) { diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java index d3945221e14..ad54b770de1 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java @@ -57,6 +57,7 @@ import com.mongodb.client.model.DeleteManyModel; import com.mongodb.client.model.DeleteOneModel; import com.mongodb.client.model.DeleteOptions; +import com.mongodb.client.model.DropCollectionOptions; import com.mongodb.client.model.DropIndexOptions; import com.mongodb.client.model.EstimatedDocumentCountOptions; import com.mongodb.client.model.FindOneAndDeleteOptions; @@ -77,6 +78,7 @@ import com.mongodb.client.model.UpdateManyModel; import com.mongodb.client.model.UpdateOneModel; import com.mongodb.client.model.UpdateOptions; +import com.mongodb.client.model.ValidationOptions; import com.mongodb.client.model.WriteModel; import com.mongodb.client.model.bulk.ClientBulkWriteOptions; import com.mongodb.client.model.bulk.ClientBulkWriteResult; @@ -1364,12 +1366,21 @@ public OperationResult executeDropCollection(final BsonDocument operation) { BsonDocument arguments = operation.getDocument("arguments", new BsonDocument()); String collectionName = arguments.getString("collection").getValue(); - if (operation.getDocument("arguments").size() > 1) { - throw new UnsupportedOperationException("Unexpected arguments " + operation.get("arguments")); + DropCollectionOptions dropCollectionOptions = new DropCollectionOptions(); + for (Map.Entry entry : arguments.entrySet()) { + switch (entry.getKey()) { + case "collection": + break; + case "encryptedFields": + dropCollectionOptions.encryptedFields(entry.getValue().asDocument()); + break; + default: + throw new UnsupportedOperationException("Unsupported drop collections option: " + entry.getKey()); + } } return resultOf(() -> { - database.getCollection(collectionName).drop(); + database.getCollection(collectionName).drop(dropCollectionOptions); return null; }); } @@ -1429,6 +1440,11 @@ public OperationResult executeCreateCollection(final BsonDocument operation) { case "clusteredIndex": options.clusteredIndexOptions(createClusteredIndexOptions(cur.getValue().asDocument())); break; + case "validator": + ValidationOptions validationOptions = new ValidationOptions(); + validationOptions.validator(cur.getValue().asDocument()); + options.validationOptions(validationOptions); + break; default: throw new UnsupportedOperationException("Unsupported argument: " + cur.getKey()); } diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java index e067e36d993..525c67e8134 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java @@ -111,7 +111,7 @@ public abstract class UnifiedTest { private static final Set PRESTART_POOL_ASYNC_WORK_MANAGER_FILE_DESCRIPTIONS = Collections.singleton( "wait queue timeout errors include details about checked out connections"); - private static final String MAX_SUPPORTED_SCHEMA_VERSION = "1.22"; + private static final String MAX_SUPPORTED_SCHEMA_VERSION = "1.23"; private static final List MAX_SUPPORTED_SCHEMA_VERSION_COMPONENTS = Arrays.stream(MAX_SUPPORTED_SCHEMA_VERSION.split("\\.")) .map(Integer::parseInt) .collect(Collectors.toList());