Skip to content

Commit 927c0a6

Browse files
committed
Support auto encryption in unified tests
Added support for schema 1.23 JAVA-5792
1 parent 5f2c539 commit 927c0a6

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ public void create(final WriteConcern writeConcern, final BsonDocument createOpt
176176
case "size":
177177
createCollectionOptions.sizeInBytes(createOptions.getNumber("size").longValue());
178178
break;
179+
case "encryptedFields":
180+
createCollectionOptions.encryptedFields(createOptions.getDocument("encryptedFields"));
181+
break;
179182
default:
180183
throw new UnsupportedOperationException("Unsupported create collection option: " + option);
181184
}
Submodule specifications updated 62 files

driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.mongodb.client.unified;
1818

19+
import com.mongodb.AutoEncryptionSettings;
1920
import com.mongodb.ClientEncryptionSettings;
2021
import com.mongodb.ClientSessionOptions;
2122
import com.mongodb.ConnectionString;
@@ -111,7 +112,7 @@
111112
public final class Entities {
112113
private static final Set<String> SUPPORTED_CLIENT_ENTITY_OPTIONS = new HashSet<>(
113114
asList(
114-
"id", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities",
115+
"id", "autoEncryptOpts", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities",
115116
"observeEvents", "observeLogMessages", "observeSensitiveCommands", "ignoreCommandMonitoringEvents"));
116117
private final Set<String> entityNames = new HashSet<>();
117118
private final Map<String, ExecutorService> threads = new HashMap<>();
@@ -604,6 +605,59 @@ private void initClient(final BsonDocument entity, final String id,
604605
}
605606
clientSettingsBuilder.serverApi(serverApiBuilder.build());
606607
}
608+
if (entity.containsKey("autoEncryptOpts")) {
609+
AutoEncryptionSettings.Builder builder = AutoEncryptionSettings.builder();
610+
for (Map.Entry<String, BsonValue> entry : entity.getDocument("autoEncryptOpts").entrySet()) {
611+
switch (entry.getKey()) {
612+
case "bypassAutoEncryption":
613+
builder.bypassAutoEncryption(entry.getValue().asBoolean().getValue());
614+
break;
615+
case "bypassQueryAnalysis":
616+
builder.bypassQueryAnalysis(entry.getValue().asBoolean().getValue());
617+
break;
618+
case "schemaMap":
619+
Map<String, BsonDocument> schemaMap = new HashMap<>();
620+
for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) {
621+
schemaMap.put(entries.getKey(), entries.getValue().asDocument());
622+
}
623+
builder.schemaMap(schemaMap);
624+
break;
625+
case "encryptedFieldsMap":
626+
Map<String, BsonDocument> encryptedFieldsMap = new HashMap<>();
627+
for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) {
628+
encryptedFieldsMap.put(entries.getKey(), entries.getValue().asDocument());
629+
}
630+
builder.encryptedFieldsMap(encryptedFieldsMap);
631+
break;
632+
case "extraOptions":
633+
Map<String, Object> extraOptions = new HashMap<>();
634+
for (Map.Entry<String, BsonValue> extraOptionsEntry : entry.getValue().asDocument().entrySet()) {
635+
switch (extraOptionsEntry.getKey()) {
636+
case "mongocryptdBypassSpawn":
637+
extraOptions.put(extraOptionsEntry.getKey(), extraOptionsEntry.getValue().asBoolean().getValue());
638+
break;
639+
default:
640+
throw new UnsupportedOperationException("Unsupported extra encryption option: " + extraOptionsEntry.getKey());
641+
}
642+
}
643+
builder.extraOptions(extraOptions);
644+
break;
645+
case "keyVaultNamespace":
646+
builder.keyVaultNamespace(entry.getValue().asString().getValue());
647+
break;
648+
case "kmsProviders":
649+
builder.kmsProviders(createKmsProvidersMap(entry.getValue().asDocument()));
650+
break;
651+
case "keyExpirationMS":
652+
builder.keyExpiration(entry.getValue().asNumber().longValue(), TimeUnit.MILLISECONDS);
653+
break;
654+
default:
655+
throw new UnsupportedOperationException("Unsupported client encryption option: " + entry.getKey());
656+
}
657+
}
658+
clientSettingsBuilder.autoEncryptionSettings(builder.build());
659+
}
660+
607661
MongoClientSettings clientSettings = clientSettingsBuilder.build();
608662

609663
if (entity.containsKey("observeLogMessages")) {

driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public abstract class UnifiedTest {
111111
private static final Set<String> PRESTART_POOL_ASYNC_WORK_MANAGER_FILE_DESCRIPTIONS = Collections.singleton(
112112
"wait queue timeout errors include details about checked out connections");
113113

114-
private static final String MAX_SUPPORTED_SCHEMA_VERSION = "1.22";
114+
private static final String MAX_SUPPORTED_SCHEMA_VERSION = "1.23";
115115
private static final List<Integer> MAX_SUPPORTED_SCHEMA_VERSION_COMPONENTS = Arrays.stream(MAX_SUPPORTED_SCHEMA_VERSION.split("\\."))
116116
.map(Integer::parseInt)
117117
.collect(Collectors.toList());

0 commit comments

Comments
 (0)