|
20 | 20 | import com.mongodb.ClientEncryptionSettings; |
21 | 21 | import com.mongodb.MongoClientSettings; |
22 | 22 | import com.mongodb.MongoCredential; |
| 23 | +import com.mongodb.MongoNamespace; |
23 | 24 | import com.mongodb.MongoSecurityException; |
24 | 25 | import com.mongodb.WriteConcern; |
25 | 26 | import com.mongodb.client.model.vault.EncryptOptions; |
| 27 | +import com.mongodb.client.test.CollectionHelper; |
26 | 28 | import com.mongodb.client.vault.ClientEncryption; |
27 | 29 | import com.mongodb.client.vault.ClientEncryptions; |
28 | 30 | import org.bson.BsonBinary; |
@@ -57,6 +59,7 @@ public class ClientSideEncryptionExternalKeyVaultTest { |
57 | 59 | private MongoClient client, clientEncrypted; |
58 | 60 | private ClientEncryption clientEncryption; |
59 | 61 | private final boolean withExternalKeyVault; |
| 62 | + private static final MongoNamespace NAMESPACE = new MongoNamespace("db", ClientSideEncryptionExternalKeyVaultTest.class.getName()); |
60 | 63 |
|
61 | 64 | public ClientSideEncryptionExternalKeyVaultTest(final boolean withExternalKeyVault) { |
62 | 65 | this.withExternalKeyVault = withExternalKeyVault; |
@@ -84,7 +87,7 @@ public void setUp() throws IOException, URISyntaxException { |
84 | 87 | + "UN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk"); |
85 | 88 | localMasterkey.put("key", localMasterkeyBytes); |
86 | 89 | kmsProviders.put("local", localMasterkey); |
87 | | - schemaMap.put("db.coll", bsonDocumentFromPath("external-schema.json")); |
| 90 | + schemaMap.put(NAMESPACE.getFullName(), bsonDocumentFromPath("external-schema.json")); |
88 | 91 |
|
89 | 92 | AutoEncryptionSettings.Builder autoEncryptionSettingsBuilder = AutoEncryptionSettings.builder() |
90 | 93 | .keyVaultNamespace("keyvault.datakeys") |
@@ -123,8 +126,8 @@ public void setUp() throws IOException, URISyntaxException { |
123 | 126 | public void testExternal() { |
124 | 127 | boolean authExceptionThrown = false; |
125 | 128 | MongoCollection<BsonDocument> coll = clientEncrypted |
126 | | - .getDatabase("db") |
127 | | - .getCollection("coll", BsonDocument.class); |
| 129 | + .getDatabase(NAMESPACE.getDatabaseName()) |
| 130 | + .getCollection(NAMESPACE.getCollectionName(), BsonDocument.class); |
128 | 131 | try { |
129 | 132 | coll.insertOne(new BsonDocument().append("encrypted", new BsonString("test"))); |
130 | 133 | } catch (MongoSecurityException mse) { |
@@ -169,5 +172,7 @@ public void after() { |
169 | 172 | // ignore |
170 | 173 | } |
171 | 174 | } |
| 175 | + |
| 176 | + CollectionHelper.drop(NAMESPACE); |
172 | 177 | } |
173 | 178 | } |
0 commit comments