Skip to content

Commit c558058

Browse files
committed
Update client side encryption async corpus checks and data
JAVA-3071
1 parent 141ca2e commit c558058

File tree

1 file changed

+19
-41
lines changed

1 file changed

+19
-41
lines changed

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

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -247,52 +247,30 @@ public void testCorpus() throws IOException, URISyntaxException {
247247
}
248248

249249
boolean allowed = corpusEncryptedActual.getDocument(field).getBoolean("allowed").getValue();
250-
String kms = corpusEncryptedActual.getDocument(field).getString("kms").getValue();
251-
String type = corpusEncryptedActual.getDocument(field).getString("type").getValue();
252250
String algorithm = corpusEncryptedActual.getDocument(field).getString("algo").getValue();
253-
BsonValue value = corpusEncryptedActual.getDocument(field).get("value");
251+
BsonValue actualValue = corpusEncryptedActual.getDocument(field).get("value");
252+
BsonValue expectedValue = corpusEncryptedExpected.getDocument(field).get("value");
254253

255-
// All deterministic fields are an exact match.
256-
check(value, kms, type, algorithm, allowed, corpusEncryptedExpected);
257-
258-
if (allowed) {
259-
FutureResultCallback<BsonValue> bsonValueCallback = new FutureResultCallback<BsonValue>();
260-
clientEncryption.decrypt(value.asBinary(), bsonValueCallback);
261-
BsonValue decrypted = bsonValueCallback.get();
262-
assertEquals("Values should be equal for field " + field, corpus.getDocument(field).get("value"), decrypted);
254+
if (algorithm.equals("det")) {
255+
assertEquals(actualValue, expectedValue);
256+
} else if (algorithm.equals("rand")) {
257+
if (allowed) {
258+
assertNotEquals(actualValue, expectedValue);
259+
}
263260
} else {
264-
assertEquals("Values should be equal for field " + field, corpus.getDocument(field).get("value"),
265-
corpusEncryptedActual.getDocument(field).get("value"));
266-
}
267-
}
268-
}
269-
270-
private static void check(final BsonValue actualValue, final String actualKms, final String actualType,
271-
final String actualAlgorithm, final boolean allowed, final BsonDocument expectedDocument) {
272-
for (String field : expectedDocument.keySet()) {
273-
if (field.equals("_id") || field.equals("altname_aws") || field.equals("altname_local")) {
274-
continue;
261+
throw new UnsupportedOperationException("Unsupported algorithm type: " + algorithm);
275262
}
276263

277-
BsonDocument subDocument = expectedDocument.getDocument(field);
278-
279-
String kms = subDocument.getString("kms").getValue();
280-
String type = subDocument.getString("type").getValue();
281-
String algorithm = subDocument.getString("algo").getValue();
282-
BsonValue expectedValue = subDocument.get("value");
283-
284-
if (kms.equals(actualKms) && type.equals(actualType)) {
285-
if (actualAlgorithm.equals("det")) {
286-
if (algorithm.equals("det")) {
287-
assertEquals(expectedValue, actualValue);
288-
}
289-
} else if (actualAlgorithm.equals("rand")) {
290-
if (allowed) {
291-
assertNotEquals(expectedValue, actualValue);
292-
}
293-
} else {
294-
throw new UnsupportedOperationException("Unsupported algorithm type: " + actualAlgorithm);
295-
}
264+
if (allowed) {
265+
FutureResultCallback<BsonValue> callback = new FutureResultCallback<BsonValue>();
266+
clientEncryption.decrypt(actualValue.asBinary(), callback);
267+
BsonValue decrypted = callback.get();
268+
callback = new FutureResultCallback<BsonValue>();
269+
clientEncryption.decrypt(expectedValue.asBinary(), callback);
270+
BsonValue expectedDecrypted = callback.get();
271+
assertEquals("Values should be equal for field " + field, expectedDecrypted, decrypted);
272+
} else {
273+
assertEquals("Values should be equal for field " + field, expectedValue, actualValue);
296274
}
297275
}
298276
}

0 commit comments

Comments
 (0)