Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test cleanup to prevent conflicts between tests. #1608

Merged
merged 7 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import com.mongodb.ClientEncryptionSettings;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCredential;
import com.mongodb.MongoNamespace;
import com.mongodb.MongoSecurityException;
import com.mongodb.WriteConcern;
import com.mongodb.client.model.vault.EncryptOptions;
import com.mongodb.client.test.CollectionHelper;
import com.mongodb.client.vault.ClientEncryption;
import com.mongodb.client.vault.ClientEncryptions;
import org.bson.BsonBinary;
Expand Down Expand Up @@ -57,6 +59,7 @@ public class ClientSideEncryptionExternalKeyVaultTest {
private MongoClient client, clientEncrypted;
private ClientEncryption clientEncryption;
private final boolean withExternalKeyVault;
private static final MongoNamespace NAMESPACE = new MongoNamespace("db", ClientSideEncryptionExternalKeyVaultTest.class.getName());
jyemin marked this conversation as resolved.
Show resolved Hide resolved

public ClientSideEncryptionExternalKeyVaultTest(final boolean withExternalKeyVault) {
this.withExternalKeyVault = withExternalKeyVault;
Expand Down Expand Up @@ -84,7 +87,7 @@ public void setUp() throws IOException, URISyntaxException {
+ "UN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk");
localMasterkey.put("key", localMasterkeyBytes);
kmsProviders.put("local", localMasterkey);
schemaMap.put("db.coll", bsonDocumentFromPath("external-schema.json"));
schemaMap.put(NAMESPACE.getFullName(), bsonDocumentFromPath("external-schema.json"));

AutoEncryptionSettings.Builder autoEncryptionSettingsBuilder = AutoEncryptionSettings.builder()
.keyVaultNamespace("keyvault.datakeys")
Expand Down Expand Up @@ -123,8 +126,8 @@ public void setUp() throws IOException, URISyntaxException {
public void testExternal() {
boolean authExceptionThrown = false;
MongoCollection<BsonDocument> coll = clientEncrypted
.getDatabase("db")
.getCollection("coll", BsonDocument.class);
.getDatabase(NAMESPACE.getDatabaseName())
.getCollection(NAMESPACE.getCollectionName(), BsonDocument.class);
try {
coll.insertOne(new BsonDocument().append("encrypted", new BsonString("test")));
} catch (MongoSecurityException mse) {
Expand Down Expand Up @@ -169,5 +172,7 @@ public void after() {
// ignore
}
}

CollectionHelper.drop(NAMESPACE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.mongodb.client.model.bulk.ClientBulkWriteOptions;
import com.mongodb.client.model.bulk.ClientBulkWriteResult;
import com.mongodb.client.model.bulk.ClientNamespacedWriteModel;
import com.mongodb.client.test.CollectionHelper;
import com.mongodb.event.CommandStartedEvent;
import com.mongodb.internal.connection.TestCommandListener;
import org.bson.BsonArray;
Expand All @@ -47,6 +48,7 @@
import org.bson.RawBsonDocument;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.codecs.pojo.PojoCodecProvider;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -613,4 +615,9 @@ private static ClientBulkWriteResult runInTransaction(final ClientSession sessio
throw throwable;
}
}

@AfterAll
public static void cleanUp() {
CollectionHelper.drop(NAMESPACE);
}
}