From 79d435eb5c011419f044f1adbc7ea14f7d03fe0e Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Thu, 5 Jun 2025 12:41:48 +0100 Subject: [PATCH 1/2] Support auto encryption in unified tests Added support for schema 1.23 JAVA-5792 --- .../mongodb/client/test/CollectionHelper.java | 3 + .../com/mongodb/client/unified/Entities.java | 56 ++++++++++++++++++- .../mongodb/client/unified/UnifiedTest.java | 2 +- 3 files changed, 59 insertions(+), 2 deletions(-) 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..53bd0afef66 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,9 @@ 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; default: throw new UnsupportedOperationException("Unsupported create collection option: " + option); } 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/UnifiedTest.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java index 84eb40b4e29..2ca2465dbfc 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 @@ -109,7 +109,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()); From 9286f2ede19b951c8ad6525198185094ee4ae877 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Thu, 5 Jun 2025 12:46:16 +0100 Subject: [PATCH 2/2] Update driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../functional/com/mongodb/client/unified/Entities.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 f2b8afc4fbc..2d617bf6d6d 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 @@ -617,15 +617,15 @@ private void initClient(final BsonDocument entity, final String id, break; case "schemaMap": Map schemaMap = new HashMap<>(); - for (Map.Entry entries : entry.getValue().asDocument().entrySet()) { - schemaMap.put(entries.getKey(), entries.getValue().asDocument()); + for (Map.Entry schemaEntry : entry.getValue().asDocument().entrySet()) { + schemaMap.put(schemaEntry.getKey(), schemaEntry.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()); + for (Map.Entry encryptedEntry : entry.getValue().asDocument().entrySet()) { + encryptedFieldsMap.put(encryptedEntry.getKey(), encryptedEntry.getValue().asDocument()); } builder.encryptedFieldsMap(encryptedFieldsMap); break;