From 1febaa253ab02f374245541bacb43f8b72eac582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 12 Aug 2025 21:33:38 +0200 Subject: [PATCH] Cast KMS provider to object to support AWS empty config --- lib/Doctrine/ODM/MongoDB/Configuration.php | 3 ++- .../ODM/MongoDB/Tests/ConfigurationTest.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Configuration.php b/lib/Doctrine/ODM/MongoDB/Configuration.php index b4b0b4adf8..760caed968 100644 --- a/lib/Doctrine/ODM/MongoDB/Configuration.php +++ b/lib/Doctrine/ODM/MongoDB/Configuration.php @@ -793,7 +793,8 @@ private static function getVersion(): string private function getAutoEncryptionOptions(): array { return [ - 'kmsProviders' => [$this->attributes['kmsProvider']['type'] => array_diff_key($this->attributes['kmsProvider'], ['type' => 0])], + // Each kmsProvider must be an object, it can be empty + 'kmsProviders' => [$this->attributes['kmsProvider']['type'] => (object) array_diff_key($this->attributes['kmsProvider'], ['type' => 0])], 'keyVaultNamespace' => $this->getDefaultDB() . '.datakeys', ...$this->attributes['autoEncryption'] ?? [], ]; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/ConfigurationTest.php b/tests/Doctrine/ODM/MongoDB/Tests/ConfigurationTest.php index f5c3affe72..45d9f25370 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/ConfigurationTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/ConfigurationTest.php @@ -55,7 +55,7 @@ public function testLocalKmsProvider(): void self::assertNull($c->getDefaultMasterKey()); self::assertEquals([ 'kmsProviders' => [ - 'local' => ['key' => '1234567890123456789012345678901234567890123456789012345678901234'], + 'local' => (object) ['key' => '1234567890123456789012345678901234567890123456789012345678901234'], ], 'extraOptions' => ['mongocryptdURI' => 'mongodb://localhost:27020'], // Default key vault namespace @@ -74,7 +74,7 @@ public function testKmsProvider(): void self::assertSame($masterKey, $c->getDefaultMasterKey()); self::assertEquals([ 'kmsProviders' => [ - 'aws' => ['accessKeyId' => 'AKIA', 'secretAccessKey' => 'SECRET'], + 'aws' => (object) ['accessKeyId' => 'AKIA', 'secretAccessKey' => 'SECRET'], ], // Key vault namespace from the configuration 'keyVaultNamespace' => 'keyvault.datakeys', @@ -88,27 +88,27 @@ public function testAutoEncryptionOptions(): void 'keyVaultClient' => $keyVaultClient = new Manager(), 'keyVaultNamespace' => 'keyvault.datakeys', 'extraOptions' => ['mongocryptdURI' => 'mongodb://localhost:27020'], - 'tlsOptions' => ['tlsDisableOCSPEndpointCheck' => true], + 'tlsOptions' => ['local' => ['tlsDisableOCSPEndpointCheck' => true]], ]); $c->setKmsProvider(['type' => 'local', 'key' => '1234567890123456789012345678901234567890123456789012345678901234']); - self::assertSame([ + self::assertEquals([ 'kmsProviders' => [ - 'local' => ['key' => '1234567890123456789012345678901234567890123456789012345678901234'], + 'local' => (object) ['key' => '1234567890123456789012345678901234567890123456789012345678901234'], ], 'keyVaultNamespace' => 'keyvault.datakeys', 'keyVaultClient' => $keyVaultClient, 'extraOptions' => ['mongocryptdURI' => 'mongodb://localhost:27020'], - 'tlsOptions' => ['tlsDisableOCSPEndpointCheck' => true], + 'tlsOptions' => ['local' => ['tlsDisableOCSPEndpointCheck' => true]], ], $c->getDriverOptions()['autoEncryption']); - self::assertSame([ + self::assertEquals([ 'kmsProviders' => [ - 'local' => ['key' => '1234567890123456789012345678901234567890123456789012345678901234'], + 'local' => (object) ['key' => '1234567890123456789012345678901234567890123456789012345678901234'], ], 'keyVaultNamespace' => 'keyvault.datakeys', 'keyVaultClient' => $keyVaultClient, - 'tlsOptions' => ['tlsDisableOCSPEndpointCheck' => true], + 'tlsOptions' => ['local' => ['tlsDisableOCSPEndpointCheck' => true]], ], $c->getClientEncryptionOptions()); }