|
6 | 6 | use MongoDB\Driver\ClientEncryption;
|
7 | 7 | use MongoDB\Driver\Exception\BulkWriteException;
|
8 | 8 | use MongoDB\Driver\Exception\CommandException;
|
| 9 | +use MongoDB\Exception\CreateEncryptedCollectionException; |
9 | 10 | use MongoDB\Exception\InvalidArgumentException;
|
10 | 11 |
|
11 | 12 | use function base64_decode;
|
@@ -121,17 +122,23 @@ public function testCase2_MissingEncryptedFields(string $kmsProvider, ?array $ma
|
121 | 122 | */
|
122 | 123 | public function testCase3_InvalidKeyId(string $kmsProvider, ?array $masterKey): void
|
123 | 124 | {
|
124 |
| - $this->expectException(CommandException::class); |
125 |
| - $this->expectExceptionCode(self::SERVER_ERROR_TYPEMISMATCH); |
126 |
| - $this->expectExceptionMessage('keyId'); |
127 |
| - |
128 |
| - $this->database->createEncryptedCollection( |
129 |
| - $this->getCollectionName(), |
130 |
| - $this->clientEncryption, |
131 |
| - $kmsProvider, |
132 |
| - $masterKey, |
133 |
| - ['encryptedFields' => ['fields' => [['path' => 'ssn', 'bsonType' => 'string', 'keyId' => false]]]] |
134 |
| - ); |
| 125 | + try { |
| 126 | + $this->database->createEncryptedCollection( |
| 127 | + $this->getCollectionName(), |
| 128 | + $this->clientEncryption, |
| 129 | + $kmsProvider, |
| 130 | + $masterKey, |
| 131 | + ['encryptedFields' => ['fields' => [['path' => 'ssn', 'bsonType' => 'string', 'keyId' => false]]]] |
| 132 | + ); |
| 133 | + $this->fail('CreateEncryptedCollectionException was not thrown'); |
| 134 | + } catch (CreateEncryptedCollectionException $e) { |
| 135 | + $this->assertFalse($e->getEncryptedFields()['fields'][0]['keyId'], 'Invalid keyId should not be modified'); |
| 136 | + |
| 137 | + $previous = $e->getPrevious(); |
| 138 | + $this->assertInstanceOf(CommandException::class, $previous); |
| 139 | + $this->assertSame(self::SERVER_ERROR_TYPEMISMATCH, $previous->getCode()); |
| 140 | + $this->assertStringContainsString('keyId', $previous->getMessage()); |
| 141 | + } |
135 | 142 | }
|
136 | 143 |
|
137 | 144 | /**
|
|
0 commit comments