diff --git a/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java b/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java index 27da74047a0..6fc99c596fc 100644 --- a/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java +++ b/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java @@ -136,7 +136,7 @@ private static BsonDocument toBsonDocument(final Map optionsMap) public static boolean isMongocryptdSpawningDisabled(@Nullable final String cryptSharedLibVersion, final AutoEncryptionSettings settings) { - boolean cryptSharedLibIsAvailable = cryptSharedLibVersion != null && cryptSharedLibVersion.isEmpty(); + boolean cryptSharedLibIsAvailable = cryptSharedLibVersion != null && !cryptSharedLibVersion.isEmpty(); boolean cryptSharedLibRequired = (boolean) settings.getExtraOptions().getOrDefault("cryptSharedLibRequired", false); return settings.isBypassAutoEncryption() || settings.isBypassQueryAnalysis() || cryptSharedLibRequired || cryptSharedLibIsAvailable; } diff --git a/driver-core/src/test/functional/com/mongodb/internal/capi/MongoCryptHelperTest.java b/driver-core/src/test/functional/com/mongodb/internal/capi/MongoCryptHelperTest.java index 77b6c0bce9d..9feac3e57a8 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/capi/MongoCryptHelperTest.java +++ b/driver-core/src/test/functional/com/mongodb/internal/capi/MongoCryptHelperTest.java @@ -27,13 +27,17 @@ import java.util.HashMap; import java.util.Map; +import static com.mongodb.internal.capi.MongoCryptHelper.isMongocryptdSpawningDisabled; import static com.mongodb.internal.capi.MongoCryptHelper.validateRewrapManyDataKeyOptions; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MongoCryptHelperTest { @@ -104,6 +108,29 @@ public void validateRewrapManyDataKeyOptionsTest() { assertThrows(MongoClientException.class, () -> validateRewrapManyDataKeyOptions(new RewrapManyDataKeyOptions().masterKey(new BsonDocument()))); } + @Test + public void isMongocryptdSpawningDisabledTest() { + assertTrue(isMongocryptdSpawningDisabled(null, + initializeAutoEncryptionSettingsBuilder().bypassAutoEncryption(true).build())); + assertTrue(isMongocryptdSpawningDisabled(null, + initializeAutoEncryptionSettingsBuilder().bypassQueryAnalysis(true).build())); + assertTrue(isMongocryptdSpawningDisabled(null, + initializeAutoEncryptionSettingsBuilder().extraOptions(singletonMap("cryptSharedLibRequired", true)).build())); + assertTrue(isMongocryptdSpawningDisabled("/path/to/shared/lib.so", + initializeAutoEncryptionSettingsBuilder().build())); + assertFalse(isMongocryptdSpawningDisabled(null, + initializeAutoEncryptionSettingsBuilder().build())); + assertFalse(isMongocryptdSpawningDisabled("", + initializeAutoEncryptionSettingsBuilder().build())); + } + + private static AutoEncryptionSettings.Builder initializeAutoEncryptionSettingsBuilder() { + AutoEncryptionSettings.Builder builder = AutoEncryptionSettings.builder() + .keyVaultNamespace("test.vault") + .kmsProviders(singletonMap("local", singletonMap("key", new byte[96]))); + return builder; + } + void assertMongoCryptOptions(final MongoCryptOptions expected, final MongoCryptOptions actual) { assertEquals(expected.getAwsKmsProviderOptions(), actual.getAwsKmsProviderOptions(), "AwsKmsProviderOptions not equal"); assertEquals(expected.getEncryptedFieldsMap(), actual.getEncryptedFieldsMap(), "EncryptedFieldsMap not equal");