Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5406

Test Failure: ClientSideEncryptionTest

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • None
    • Java Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The test fails to timeout - showing there is an issue with the code or the test is incorrect.

      Local prose test derrived from timeout.yml to help debug "timeoutMS applied to listCollections to get collection schema"

          @Tag("setsFailPoint")
          @Test
          public void testCSFLE() {
      
              // This would have to be the same master key as was used to create the encryption key
              byte[] localMasterKey = new byte[96];
              new SecureRandom().nextBytes(localMasterKey);
      
              Map<String, Map<String, Object>> kmsProviders = new HashMap<String, Map<String, Object>>() {{
                  put("local", new HashMap<String, Object>() {{
                      put("key", localMasterKey);
                  }});
              }};
              MongoClientSettings commonClientSettings = getMongoClientSettings();
              String keyVaultNamespace = "encryption.__keyVault";
              ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()
                      .keyVaultMongoClientSettings(commonClientSettings)
                      .keyVaultNamespace(keyVaultNamespace)
                      .kmsProviders(kmsProviders)
                      .build();
      
              ClientEncryption clientEncryption = ClientEncryptions.create(clientEncryptionSettings);
              BsonBinary dataKeyId = clientEncryption.createDataKey("local", new DataKeyOptions());
              String base64DataKeyId = Base64.getEncoder().encodeToString(dataKeyId.getData());
      
              final String dbName = "test";
              final String collName = "coll";
              AutoEncryptionSettings autoEncryptionSettings = AutoEncryptionSettings.builder()
                      .keyVaultNamespace(keyVaultNamespace)
                      .kmsProviders(kmsProviders)
                      .schemaMap(new HashMap<String, BsonDocument>() {{
                          put(dbName + "." + collName,
                                  // Need a schema that references the new data key
                                  BsonDocument.parse("{"
                                          + "  properties: {"
                                          + "    encryptedField: {"
                                          + "      encrypt: {"
                                          + "        keyId: [{"
                                          + "          \"$binary\": {"
                                          + "            \"base64\": \"" + base64DataKeyId + "\","
                                          + "            \"subType\": \"04\""
                                          + "          }"
                                          + "        }],"
                                          + "        bsonType: \"string\","
                                          + "        algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\""
                                          + "      }"
                                          + "    }"
                                          + "  },"
                                          + "  \"bsonType\": \"object\""
                                          + "}"));
                      }}).build();
      
      
              collectionHelper.runAdminCommand("{" +
                      "        \"configureFailPoint\": \"failCommand\"," +
                      "        \"mode\": {" +
                      "          \"times\": 3" +
                      "        }," +
                      "        \"data\": {" +
                      "          \"failCommands\": [" +
                      "            \"listCollections\"," +
                      "            \"find\"" +
                      "          ]," +
                      "          \"blockConnection\": true," +
                      "          \"blockTimeMS\": 200" +
                      "        }" +
                      "      }");
      
              try (MongoClient mongoClient = createMongoClient(getMongoClientSettingsBuilder()
                      .autoEncryptionSettings(autoEncryptionSettings)
                      .timeout(500, TimeUnit.MILLISECONDS))) {
                  MongoCollection<Document> collection = mongoClient.getDatabase(namespace.getDatabaseName())
                          .getCollection(namespace.getCollectionName());
                  assertThrows(MongoOperationTimeoutException.class, () -> 
                      collection.insertOne(new Document("encryptedField", "123456789"))
                  );
              }
          }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: