Update client side encryption async corpus checks and data
@@ -247,52 +247,30 @@ public class ClientSideEncryptionCorpusTest {
}
boolean allowed = corpusEncryptedActual.getDocument(field).getBoolean("allowed").getValue();
- String kms = corpusEncryptedActual.getDocument(field).getString("kms").getValue();
- String type = corpusEncryptedActual.getDocument(field).getString("type").getValue();
String algorithm = corpusEncryptedActual.getDocument(field).getString("algo").getValue();
- BsonValue value = corpusEncryptedActual.getDocument(field).get("value");
-
- // All deterministic fields are an exact match.
- check(value, kms, type, algorithm, allowed, corpusEncryptedExpected);
+ BsonValue actualValue = corpusEncryptedActual.getDocument(field).get("value");
+ BsonValue expectedValue = corpusEncryptedExpected.getDocument(field).get("value");
+ if (algorithm.equals("det")) {
+ assertEquals(actualValue, expectedValue);
+ } else if (algorithm.equals("rand")) {
if (allowed) {
- FutureResultCallback<BsonValue> bsonValueCallback = new FutureResultCallback<BsonValue>();
- clientEncryption.decrypt(value.asBinary(), bsonValueCallback);
- BsonValue decrypted = bsonValueCallback.get();
- assertEquals("Values should be equal for field " + field, corpus.getDocument(field).get("value"), decrypted);
- } else {
- assertEquals("Values should be equal for field " + field, corpus.getDocument(field).get("value"),
- corpusEncryptedActual.getDocument(field).get("value"));
- }
+ assertNotEquals(actualValue, expectedValue);
}
+ } else {
+ throw new UnsupportedOperationException("Unsupported algorithm type: " + algorithm);
}
- private static void check(final BsonValue actualValue, final String actualKms, final String actualType,
- final String actualAlgorithm, final boolean allowed, final BsonDocument expectedDocument) {
- for (String field : expectedDocument.keySet()) {
- if (field.equals("_id") || field.equals("altname_aws") || field.equals("altname_local")) {
- continue;
- }
-
- BsonDocument subDocument = expectedDocument.getDocument(field);
-
- String kms = subDocument.getString("kms").getValue();
- String type = subDocument.getString("type").getValue();
- String algorithm = subDocument.getString("algo").getValue();
- BsonValue expectedValue = subDocument.get("value");
-
- if (kms.equals(actualKms) && type.equals(actualType)) {
- if (actualAlgorithm.equals("det")) {
- if (algorithm.equals("det")) {
- assertEquals(expectedValue, actualValue);
- }
- } else if (actualAlgorithm.equals("rand")) {
if (allowed) {
- assertNotEquals(expectedValue, actualValue);
- }
+ FutureResultCallback<BsonValue> callback = new FutureResultCallback<BsonValue>();
+ clientEncryption.decrypt(actualValue.asBinary(), callback);
+ BsonValue decrypted = callback.get();
+ callback = new FutureResultCallback<BsonValue>();
+ clientEncryption.decrypt(expectedValue.asBinary(), callback);
+ BsonValue expectedDecrypted = callback.get();
+ assertEquals("Values should be equal for field " + field, expectedDecrypted, decrypted);
} else {
- throw new UnsupportedOperationException("Unsupported algorithm type: " + actualAlgorithm);
- }
+ assertEquals("Values should be equal for field " + field, expectedValue, actualValue);
}
}
}
