Skip to content

Commit 7d2569d

Browse files
committed
Support auto encryption in unified tests
Added support for schema 1.23 JAVA-5792
1 parent 5e61b7a commit 7d2569d

File tree

3 files changed

+60
-3
lines changed

3 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
}

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

Lines changed: 56 additions & 2 deletions
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;
@@ -87,8 +88,8 @@
8788
public final class Entities {
8889
private static final Set<String> SUPPORTED_CLIENT_ENTITY_OPTIONS = new HashSet<>(
8990
asList(
90-
"id", "uriOptions", "serverApi", "useMultipleMongoses", "observeEvents",
91-
"observeLogMessages", "observeSensitiveCommands", "ignoreCommandMonitoringEvents"));
91+
"id", "autoEncryptOpts", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities",
92+
"observeEvents", "observeLogMessages", "observeSensitiveCommands", "ignoreCommandMonitoringEvents"));
9293
private final Set<String> entityNames = new HashSet<>();
9394
private final Map<String, ExecutorService> threads = new HashMap<>();
9495
private final Map<String, ArrayList<Future<?>>> tasks = new HashMap<>();
@@ -499,6 +500,59 @@ private void initClient(final BsonDocument entity, final String id,
499500
}
500501
clientSettingsBuilder.serverApi(serverApiBuilder.build());
501502
}
503+
if (entity.containsKey("autoEncryptOpts")) {
504+
AutoEncryptionSettings.Builder builder = AutoEncryptionSettings.builder();
505+
for (Map.Entry<String, BsonValue> entry : entity.getDocument("autoEncryptOpts").entrySet()) {
506+
switch (entry.getKey()) {
507+
case "bypassAutoEncryption":
508+
builder.bypassAutoEncryption(entry.getValue().asBoolean().getValue());
509+
break;
510+
case "bypassQueryAnalysis":
511+
builder.bypassQueryAnalysis(entry.getValue().asBoolean().getValue());
512+
break;
513+
case "schemaMap":
514+
Map<String, BsonDocument> schemaMap = new HashMap<>();
515+
for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) {
516+
schemaMap.put(entries.getKey(), entries.getValue().asDocument());
517+
}
518+
builder.schemaMap(schemaMap);
519+
break;
520+
case "encryptedFieldsMap":
521+
Map<String, BsonDocument> encryptedFieldsMap = new HashMap<>();
522+
for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) {
523+
encryptedFieldsMap.put(entries.getKey(), entries.getValue().asDocument());
524+
}
525+
builder.encryptedFieldsMap(encryptedFieldsMap);
526+
break;
527+
case "extraOptions":
528+
Map<String, Object> extraOptions = new HashMap<>();
529+
for (Map.Entry<String, BsonValue> extraOptionsEntry : entry.getValue().asDocument().entrySet()) {
530+
switch (extraOptionsEntry.getKey()) {
531+
case "mongocryptdBypassSpawn":
532+
extraOptions.put(extraOptionsEntry.getKey(), extraOptionsEntry.getValue().asBoolean().getValue());
533+
break;
534+
default:
535+
throw new UnsupportedOperationException("Unsupported extra encryption option: " + extraOptionsEntry.getKey());
536+
}
537+
}
538+
builder.extraOptions(extraOptions);
539+
break;
540+
case "keyVaultNamespace":
541+
builder.keyVaultNamespace(entry.getValue().asString().getValue());
542+
break;
543+
case "kmsProviders":
544+
builder.kmsProviders(createKmsProvidersMap(entry.getValue().asDocument()));
545+
break;
546+
case "keyExpirationMS":
547+
builder.keyExpiration(entry.getValue().asNumber().longValue(), TimeUnit.MILLISECONDS);
548+
break;
549+
default:
550+
throw new UnsupportedOperationException("Unsupported client encryption option: " + entry.getKey());
551+
}
552+
}
553+
clientSettingsBuilder.autoEncryptionSettings(builder.build());
554+
}
555+
502556
MongoClientSettings clientSettings = clientSettingsBuilder.build();
503557

504558
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
@@ -110,7 +110,7 @@ public abstract class UnifiedTest {
110110
private static final Set<String> PRESTART_POOL_ASYNC_WORK_MANAGER_FILE_DESCRIPTIONS = Collections.singleton(
111111
"wait queue timeout errors include details about checked out connections");
112112

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

0 commit comments

Comments
 (0)