Search in sources :

Example 16 with TestCommandListener

use of com.mongodb.internal.connection.TestCommandListener in project mongo-java-driver by mongodb.

the class ClientEncryptionDataKeyAndDoubleEncryptionTest method setUp.

@Before
public void setUp() {
    assumeTrue(serverVersionAtLeast(4, 2));
    assumeTrue("Has encryption tests", hasEncryptionTestsEnabled());
    // Step 1: create unencrypted client
    commandListener = new TestCommandListener();
    client = new SyncMongoClient(MongoClients.create(getMongoClientSettingsBuilder().addCommandListener(commandListener).build()));
    client.getDatabase("keyvault").getCollection("datakeys").drop();
    client.getDatabase("db").getCollection("coll").drop();
    // Step 2: Create encrypted client and client encryption
    Map<String, Map<String, Object>> kmsProviders = new HashMap<String, Map<String, Object>>() {

        {
            put("aws", new HashMap<String, Object>() {

                {
                    put("accessKeyId", System.getProperty("org.mongodb.test.awsAccessKeyId"));
                    put("secretAccessKey", System.getProperty("org.mongodb.test.awsSecretAccessKey"));
                }
            });
            put("azure", new HashMap<String, Object>() {

                {
                    put("tenantId", System.getProperty("org.mongodb.test.azureTenantId"));
                    put("clientId", System.getProperty("org.mongodb.test.azureClientId"));
                    put("clientSecret", System.getProperty("org.mongodb.test.azureClientSecret"));
                }
            });
            put("gcp", new HashMap<String, Object>() {

                {
                    put("email", System.getProperty("org.mongodb.test.gcpEmail"));
                    put("privateKey", System.getProperty("org.mongodb.test.gcpPrivateKey"));
                }
            });
            put("local", new HashMap<String, Object>() {

                {
                    put("key", "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBM" + "UN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk");
                }
            });
        }
    };
    HashMap<String, BsonDocument> schemaMap = new HashMap<String, BsonDocument>() {

        {
            put("db.coll", BsonDocument.parse("{" + "  \"bsonType\": \"object\"," + "  \"properties\": {" + "    \"encrypted_placeholder\": {" + "      \"encrypt\": {" + "        \"keyId\": \"/placeholder\"," + "        \"bsonType\": \"string\"," + "        \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\"" + "      }" + "    }" + "  }" + "}"));
        }
    };
    String keyVaultNamespace = "keyvault.datakeys";
    clientEncrypted = new SyncMongoClient(MongoClients.create(getMongoClientSettingsBuilder().autoEncryptionSettings(AutoEncryptionSettings.builder().keyVaultNamespace(keyVaultNamespace).kmsProviders(kmsProviders).schemaMap(schemaMap).build()).build()));
    clientEncryption = ClientEncryptions.create(ClientEncryptionSettings.builder().keyVaultMongoClientSettings(getMongoClientSettingsBuilder().addCommandListener(commandListener).build()).keyVaultNamespace(keyVaultNamespace).kmsProviders(kmsProviders).build());
}
Also used : SyncMongoClient(com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient) BsonDocument(org.bson.BsonDocument) HashMap(java.util.HashMap) TestCommandListener(com.mongodb.internal.connection.TestCommandListener) BsonString(org.bson.BsonString) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Aggregations

TestCommandListener (com.mongodb.internal.connection.TestCommandListener)16 BsonDocument (org.bson.BsonDocument)11 BsonString (org.bson.BsonString)10 Before (org.junit.Before)9 MongoClientSettings (com.mongodb.MongoClientSettings)5 HashMap (java.util.HashMap)5 BsonArray (org.bson.BsonArray)5 TestConnectionPoolListener (com.mongodb.internal.connection.TestConnectionPoolListener)4 Map (java.util.Map)4 BsonInt32 (org.bson.BsonInt32)4 BsonValue (org.bson.BsonValue)4 Fixture.getMongoClientSettingsBuilder (com.mongodb.client.Fixture.getMongoClientSettingsBuilder)3 ArrayList (java.util.ArrayList)3 BsonBoolean (org.bson.BsonBoolean)3 ClusterFixture.getMultiMongosConnectionString (com.mongodb.ClusterFixture.getMultiMongosConnectionString)2 ClusterFixture.isSharded (com.mongodb.ClusterFixture.isSharded)2 MongoNamespace (com.mongodb.MongoNamespace)2 CreateCollectionOptions (com.mongodb.client.model.CreateCollectionOptions)2 ValidationOptions (com.mongodb.client.model.ValidationOptions)2 ConnectionCheckOutFailedEvent (com.mongodb.event.ConnectionCheckOutFailedEvent)2