Metadata collections not dropped when an encrypted collection is dropped

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Client Side Encryption
    • None
    • None
    • PHP Drivers
    • Not Needed
    • 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?
    • None
    • None
    • None
    • None
    • None
    • None

       

      use MongoDB\BSON\Binary;
      use MongoDB\Client;
      
      class TestDropEncryptedCollection extends TestCase
      {
          public function testDropEncryptedCollection(): void
          {
              $collectionName = $this->getCollectionName();
              $encryptedClient = new Client(
                  $this->getUri(),
                  [],
                  [
                      'autoEncryption' => $autoEncryptionOptions = [
                          'keyVaultNamespace' => 'encryption.datakeys',
                          'kmsProviders' => [
                              'local' => [
                                  'key' => new Binary(random_bytes(96)),
                              ],
                          ],
                          //'encryptedFieldsMap' => [],
                       ],
                  ],
              );
              $clientEncryption = $encryptedClient->createClientEncryption($autoEncryptionOptions);
              $database = $encryptedClient->getDatabase($this->getDatabaseName());
              $database->drop();
              $database->createEncryptedCollection($collectionName, $clientEncryption, 'local', null, [
                  'encryptedFields' => [
                      'fields' => [
                          [
                              'keyId' => null,
                              'path' => 'ssn',
                              'bsonType' => 'string',
                          ],
                      ],
                  ],
              ]);
              $collectionNames = iterator_to_array($database->listCollectionNames());
              self::assertCount(3, $collectionNames);
              $database->dropCollection($collectionName);
              //$database->dropCollection($collectionName, ['encryptedFields' => []]);
              $collectionNames = iterator_to_array($database->listCollectionNames());
              self::assertCount(0, $collectionNames);
          }
      } 

       

       

      When an encrypted collection is dropped, and autoEncryption is enabled, the metadata collections (.esc and .ecoc) must be automatically dropped.

      https://github.com/mongodb/mongo-php-library/blob/888d383b6cf5ea25eba8adce4ad6474fe703dbb6/src/Collection.php#L514-L517

      They are removed only in one of the conditions:

      • The autoEncryption.encryptedFieldsMap is set in the client driver options. With any value (even an empty array)
      • The option encryptedFields is set drop options

      $database->dropCollection($collectionName, ['encryptedFields' => []]);

       

       

              Assignee:
              Jeremy Mikola
              Reporter:
              Jérôme Tamarelle
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: