Skip to content

Commit 568505a

Browse files
committed
Fix client side encryption issues related to Java version
* Ensure tests run on all Java versions * Ensure implementation doesn't rely on anything not available in Java 8 * Also, re-add skipping of a problematic test JAVA-3464
1 parent 4311d95 commit 568505a

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

driver-async/src/main/com/mongodb/async/client/internal/CommandMarker.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.bson.RawBsonDocument;
3131

3232
import java.io.Closeable;
33-
import java.lang.ProcessBuilder.Redirect;
3433
import java.util.Map;
3534
import java.util.concurrent.TimeUnit;
3635

@@ -51,9 +50,7 @@ class CommandMarker implements Closeable {
5150
}
5251

5352
if (!options.containsKey("mongocryptdBypassSpawn") || !((Boolean) options.get("mongocryptdBypassSpawn"))) {
54-
processBuilder = new ProcessBuilder(createMongocryptdSpawnArgs(options))
55-
.redirectOutput(Redirect.DISCARD)
56-
.redirectError(Redirect.DISCARD);
53+
processBuilder = new ProcessBuilder(createMongocryptdSpawnArgs(options));
5754
startProcess();
5855
} else {
5956
processBuilder = null;

driver-async/src/test/functional/com/mongodb/async/client/ClientEncryptionCustomEndpointTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.mongodb.async.client.vault.ClientEncryptions;
2424
import com.mongodb.client.model.vault.DataKeyOptions;
2525
import com.mongodb.client.model.vault.EncryptOptions;
26-
import com.mongodb.crypt.capi.MongoCryptException;
2726
import com.mongodb.lang.Nullable;
2827
import org.bson.BsonBinary;
2928
import org.bson.BsonDocument;
@@ -34,7 +33,6 @@
3433
import org.junit.runner.RunWith;
3534
import org.junit.runners.Parameterized;
3635

37-
import java.net.ConnectException;
3836
import java.util.ArrayList;
3937
import java.util.Collection;
4038
import java.util.HashMap;
@@ -57,17 +55,19 @@ public class ClientEncryptionCustomEndpointTest {
5755
private ClientEncryption clientEncryption;
5856
private BsonDocument masterKey;
5957
private final Class<? extends RuntimeException> exceptionClass;
60-
private final Class<? extends RuntimeException> wrappedExceptionClass;
58+
// Delay loading this class because one of the expected classes is MongoCryptException, which should only be loaded after we
59+
// determine that we're running on Java 8+ (since MongoCryptException is compiled with Java 8 target version)
60+
private final String wrappedExceptionClassName;
6161
private final String messageContainedInException;
6262

6363
public ClientEncryptionCustomEndpointTest(@SuppressWarnings("unused") final String name,
6464
final BsonDocument masterKey,
6565
@Nullable final Class<? extends RuntimeException> exceptionClass,
66-
@Nullable final Class<? extends RuntimeException> wrappedExceptionClass,
66+
@Nullable final String wrappedExceptionClassName,
6767
@Nullable final String messageContainedInException) {
6868
this.masterKey = masterKey;
6969
this.exceptionClass = exceptionClass;
70-
this.wrappedExceptionClass = wrappedExceptionClass;
70+
this.wrappedExceptionClassName = wrappedExceptionClassName;
7171
this.messageContainedInException = messageContainedInException;
7272
}
7373

@@ -126,7 +126,7 @@ public void testEndpoint() throws Exception {
126126
}
127127
try {
128128
assertEquals(exceptionClass, e.getClass());
129-
assertEquals(wrappedExceptionClass, e.getCause().getClass());
129+
assertEquals(wrappedExceptionClassName, e.getCause().getClass().getName());
130130
} catch (AssertionError ae) {
131131
throw e;
132132
}
@@ -151,13 +151,13 @@ public static Collection<Object[]> data() {
151151
null, null, null});
152152
data.add(new Object[]{"invalid endpoint port",
153153
getDefaultMasterKey().append("endpoint", new BsonString("kms.us-east-1.amazonaws.com:12345")),
154-
MongoClientException.class, ConnectException.class, "Connection refused"});
154+
MongoClientException.class, "java.net.ConnectException", "Connection refused"});
155155
data.add(new Object[]{"invalid amazon region in endpoint",
156156
getDefaultMasterKey().append("endpoint", new BsonString("kms.us-east-2.amazonaws.com")),
157-
MongoClientException.class, MongoCryptException.class, "us-east-1"});
157+
MongoClientException.class, "com.mongodb.crypt.capi.MongoCryptException", "us-east-1"});
158158
data.add(new Object[]{"invalid endpoint host",
159159
getDefaultMasterKey().append("endpoint", new BsonString("example.com")),
160-
MongoClientException.class, MongoCryptException.class, "parse error"});
160+
MongoClientException.class, "com.mongodb.crypt.capi.MongoCryptException", "parse error"});
161161

162162
return data;
163163
}

driver-core/src/test/resources/client-side-encryption/maxWireVersion.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"tests": [
4747
{
4848
"description": "operation fails with maxWireVersion < 8",
49+
"skipReason": "waiting on SPEC-1403",
4950
"clientOptions": {
5051
"autoEncryptOpts": {
5152
"kmsProviders": {

driver-sync/src/main/com/mongodb/client/internal/CommandMarker.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import java.io.Closeable;
3333
import java.io.IOException;
34-
import java.lang.ProcessBuilder.Redirect;
3534
import java.util.Map;
3635
import java.util.concurrent.TimeUnit;
3736

@@ -52,9 +51,7 @@ class CommandMarker implements Closeable {
5251
}
5352

5453
if (!options.containsKey("mongocryptdBypassSpawn") || !((Boolean) options.get("mongocryptdBypassSpawn"))) {
55-
processBuilder = new ProcessBuilder(createMongocryptdSpawnArgs(options))
56-
.redirectOutput(Redirect.DISCARD)
57-
.redirectError(Redirect.DISCARD);
54+
processBuilder = new ProcessBuilder(createMongocryptdSpawnArgs(options));
5855
startProcess();
5956
} else {
6057
processBuilder = null;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.mongodb.client.model.vault.EncryptOptions;
2323
import com.mongodb.client.vault.ClientEncryption;
2424
import com.mongodb.client.vault.ClientEncryptions;
25-
import com.mongodb.crypt.capi.MongoCryptException;
2625
import com.mongodb.lang.Nullable;
2726
import org.bson.BsonBinary;
2827
import org.bson.BsonDocument;
@@ -33,7 +32,6 @@
3332
import org.junit.runner.RunWith;
3433
import org.junit.runners.Parameterized;
3534

36-
import java.net.ConnectException;
3735
import java.util.ArrayList;
3836
import java.util.Collection;
3937
import java.util.HashMap;
@@ -55,17 +53,19 @@ public class ClientEncryptionCustomEndpointTest {
5553
private ClientEncryption clientEncryption;
5654
private BsonDocument masterKey;
5755
private final Class<? extends RuntimeException> exceptionClass;
58-
private final Class<? extends RuntimeException> wrappedExceptionClass;
56+
// Delay loading this class because one of the expected classes is MongoCryptException, which should only be loaded after we
57+
// determine that we're running on Java 8+ (since MongoCryptException is compiled with Java 8 target version)
58+
private final String wrappedExceptionClassName;
5959
private final String messageContainedInException;
6060

6161
public ClientEncryptionCustomEndpointTest(@SuppressWarnings("unused") final String name,
6262
final BsonDocument masterKey,
6363
@Nullable final Class<? extends RuntimeException> exceptionClass,
64-
@Nullable final Class<? extends RuntimeException> wrappedExceptionClass,
64+
@Nullable final String wrappedExceptionClassName,
6565
@Nullable final String messageContainedInException) {
6666
this.masterKey = masterKey;
6767
this.exceptionClass = exceptionClass;
68-
this.wrappedExceptionClass = wrappedExceptionClass;
68+
this.wrappedExceptionClassName = wrappedExceptionClassName;
6969
this.messageContainedInException = messageContainedInException;
7070
}
7171

@@ -118,7 +118,7 @@ public void testEndpoint() throws Exception {
118118
throw e;
119119
}
120120
assertEquals(exceptionClass, e.getClass());
121-
assertEquals(wrappedExceptionClass, e.getCause().getClass());
121+
assertEquals(wrappedExceptionClassName, e.getCause().getClass().getName());
122122
if (messageContainedInException != null) {
123123
assertTrue(e.getCause().getMessage().contains(messageContainedInException));
124124
}
@@ -140,13 +140,13 @@ public static Collection<Object[]> data() {
140140
null, null, null});
141141
data.add(new Object[]{"invalid endpoint port",
142142
getDefaultMasterKey().append("endpoint", new BsonString("kms.us-east-1.amazonaws.com:12345")),
143-
MongoClientException.class, ConnectException.class, "Connection refused"});
143+
MongoClientException.class, "java.net.ConnectException", "Connection refused"});
144144
data.add(new Object[]{"invalid amazon region in endpoint",
145145
getDefaultMasterKey().append("endpoint", new BsonString("kms.us-east-2.amazonaws.com")),
146-
MongoClientException.class, MongoCryptException.class, "us-east-1"});
146+
MongoClientException.class, "com.mongodb.crypt.capi.MongoCryptException", "us-east-1"});
147147
data.add(new Object[]{"invalid endpoint host",
148148
getDefaultMasterKey().append("endpoint", new BsonString("example.com")),
149-
MongoClientException.class, MongoCryptException.class, "parse error"});
149+
MongoClientException.class, "com.mongodb.crypt.capi.MongoCryptException", "parse error"});
150150

151151
return data;
152152
}

0 commit comments

Comments
 (0)