|
3 | 3 | namespace MongoDB\Tests;
|
4 | 4 |
|
5 | 5 | use MongoDB\Client;
|
| 6 | +use MongoDB\Driver\ClientEncryption; |
6 | 7 | use MongoDB\Driver\ReadConcern;
|
7 | 8 | use MongoDB\Driver\ReadPreference;
|
8 | 9 | use MongoDB\Driver\WriteConcern;
|
@@ -173,4 +174,55 @@ public function testSelectDatabasePassesOptions()
|
173 | 174 | $this->assertInstanceOf(WriteConcern::class, $debug['writeConcern']);
|
174 | 175 | $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
|
175 | 176 | }
|
| 177 | + |
| 178 | + public function testCreateClientEncryption() |
| 179 | + { |
| 180 | + $client = new Client(static::getUri()); |
| 181 | + |
| 182 | + $options = [ |
| 183 | + 'keyVaultNamespace' => 'default.keys', |
| 184 | + 'kmsProviders' => ['aws' => ['accessKeyId' => 'abc', 'secretAccessKey' => 'def']], |
| 185 | + ]; |
| 186 | + |
| 187 | + $clientEncryption = $client->createClientEncryption($options); |
| 188 | + $this->assertInstanceOf(ClientEncryption::class, $clientEncryption); |
| 189 | + } |
| 190 | + |
| 191 | + public function testCreateClientEncryptionWithKeyVaultClient() |
| 192 | + { |
| 193 | + $client = new Client(static::getUri()); |
| 194 | + |
| 195 | + $options = [ |
| 196 | + 'keyVaultClient' => $client, |
| 197 | + 'keyVaultNamespace' => 'default.keys', |
| 198 | + 'kmsProviders' => ['aws' => ['accessKeyId' => 'abc', 'secretAccessKey' => 'def']], |
| 199 | + ]; |
| 200 | + |
| 201 | + $clientEncryption = $client->createClientEncryption($options); |
| 202 | + $this->assertInstanceOf(ClientEncryption::class, $clientEncryption); |
| 203 | + } |
| 204 | + |
| 205 | + public function testCreateClientEncryptionWithManager() |
| 206 | + { |
| 207 | + $client = new Client(static::getUri()); |
| 208 | + |
| 209 | + $options = [ |
| 210 | + 'keyVaultClient' => $client->getManager(), |
| 211 | + 'keyVaultNamespace' => 'default.keys', |
| 212 | + 'kmsProviders' => ['aws' => ['accessKeyId' => 'abc', 'secretAccessKey' => 'def']], |
| 213 | + ]; |
| 214 | + |
| 215 | + $clientEncryption = $client->createClientEncryption($options); |
| 216 | + $this->assertInstanceOf(ClientEncryption::class, $clientEncryption); |
| 217 | + } |
| 218 | + |
| 219 | + public function testCreateClientEncryptionWithInvalidKeyVaultClient() |
| 220 | + { |
| 221 | + $client = new Client(static::getUri()); |
| 222 | + |
| 223 | + $this->expectException(InvalidArgumentException::class); |
| 224 | + $this->expectExceptionMessage('Expected "keyVaultClient" option to have type "MongoDB\Client" or "MongoDB\Driver\Manager" but found "string"'); |
| 225 | + |
| 226 | + $client->createClientEncryption(['keyVaultClient' => 'foo']); |
| 227 | + } |
176 | 228 | }
|
0 commit comments