Skip to content

Commit f1d9b11

Browse files
authored
Add second case for the RewrapManyDataKeyOpts prose test. (#1138)
1 parent 14cfcdc commit f1d9b11

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.mongodb.client;
1818

1919
import com.mongodb.ClientEncryptionSettings;
20+
import com.mongodb.MongoClientException;
2021
import com.mongodb.MongoClientSettings;
2122
import com.mongodb.client.model.vault.DataKeyOptions;
2223
import com.mongodb.client.model.vault.EncryptOptions;
@@ -26,7 +27,10 @@
2627
import org.bson.BsonBinary;
2728
import org.bson.BsonDocument;
2829
import org.bson.BsonString;
30+
import org.junit.jupiter.api.AfterEach;
2931
import org.junit.jupiter.api.Assumptions;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.function.Executable;
3034
import org.junit.jupiter.params.ParameterizedTest;
3135
import org.junit.jupiter.params.provider.Arguments;
3236
import org.junit.jupiter.params.provider.MethodSource;
@@ -43,6 +47,7 @@
4347
import static com.mongodb.client.Fixture.getMongoClient;
4448
import static com.mongodb.client.Fixture.getMongoClientSettingsBuilder;
4549
import static org.junit.jupiter.api.Assertions.assertEquals;
50+
import static org.junit.jupiter.api.Assertions.assertThrows;
4651

4752
/**
4853
* See <a href="https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#rewrap">
@@ -109,12 +114,19 @@ public static Collection<Arguments> data() {
109114
return data;
110115
}
111116

112-
@ParameterizedTest
113-
@MethodSource("data")
114-
public void rewrapWithSeparateClientEncryption(final String srcProvider, final String dstProvider) {
117+
protected AbstractClientEncryptionRewrapManyDataKeyProseTest() {
115118
Assumptions.assumeTrue(serverVersionAtLeast(4, 2));
116119
Assumptions.assumeTrue(hasEncryptionTestsEnabled(), "Custom Endpoint tests disables");
120+
}
121+
122+
@AfterEach
123+
void cleanUp(){
124+
getMongoClient().getDatabase("keyvault").getCollection("datakeys").drop();
125+
}
117126

127+
@ParameterizedTest
128+
@MethodSource("data")
129+
public void rewrapWithSeparateClientEncryption(final String srcProvider, final String dstProvider) {
118130
BsonDocument srcKey = MASTER_KEYS_BY_PROVIDER.get(srcProvider);
119131
BsonDocument dstKey = MASTER_KEYS_BY_PROVIDER.get(dstProvider);
120132
BsonString testString = new BsonString("test");
@@ -147,4 +159,25 @@ public void rewrapWithSeparateClientEncryption(final String srcProvider, final S
147159
assertEquals(testString, clientEncryption1.decrypt(ciphertext));
148160
assertEquals(testString, clientEncryption2.decrypt(ciphertext));
149161
}
162+
163+
@Test
164+
public void shouldThrowClientErrorWhenProviderIsNotSpecified() {
165+
//given
166+
ClientEncryption clientEncryption = getClientEncryption(ClientEncryptionSettings.builder()
167+
.keyVaultMongoClientSettings(getMongoClientSettingsBuilder().build())
168+
.keyVaultNamespace("keyvault.datakeys")
169+
.kmsProviders(KMS_PROVIDERS)
170+
.build());
171+
172+
RewrapManyDataKeyOptions rewrapManyDataKeyOptions = new RewrapManyDataKeyOptions().masterKey(BsonDocument.parse("{}"));
173+
174+
//when
175+
Executable executable = () -> clientEncryption.rewrapManyDataKey(new BsonDocument(), rewrapManyDataKeyOptions);
176+
177+
//then
178+
MongoClientException mongoClientException = assertThrows(MongoClientException.class, executable);
179+
180+
assertEquals("Missing the provider but supplied a master key in the RewrapManyDataKeyOptions",
181+
mongoClientException.getMessage());
182+
}
150183
}

0 commit comments

Comments
 (0)