Skip to content

Commit 81e8b79

Browse files
authored
PHPLIB-1031: Test mongocryptd is not spawned when shared library is loaded (#1067)
* PHPLIB-1031: Test mongocryptd is not spawned when shared library is loaded * Update libmongocrypt checks * Remove obsolete auth database URI option * Allow different server selection errors
1 parent b70b2e3 commit 81e8b79

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

tests/SpecTests/ClientSideEncryptionSpecTest.php

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,44 @@ static function (self $test, ClientEncryption $clientEncryption, ClientEncryptio
10291029
];
10301030
}
10311031

1032+
/**
1033+
* Prose test 8: Bypass Spawning mongocryptd (via loading shared library)
1034+
*
1035+
* @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/#via-loading-shared-library
1036+
*/
1037+
public function testBypassSpawningMongocryptdViaLoadingSharedLibrary(): void
1038+
{
1039+
if (! static::isCryptSharedLibAvailable()) {
1040+
$this->markTestSkipped('Bypass spawning of mongocryptd cannot be tested when crypt_shared is not available');
1041+
}
1042+
1043+
$autoEncryptionOpts = [
1044+
'keyVaultNamespace' => 'keyvault.datakeys',
1045+
'kmsProviders' => [
1046+
'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)],
1047+
],
1048+
'schemaMap' => [
1049+
'db.coll' => $this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/external/external-schema.json')),
1050+
],
1051+
'extraOptions' => [
1052+
'mongocryptdBypassSpawn' => true,
1053+
'mongocryptdURI' => 'mongodb://localhost:27021/?serverSelectionTimeoutMS=1000',
1054+
'mongocryptdSpawnArgs' => ['--pidfilepath=bypass-spawning-mongocryptd.pid', '--port=27021'],
1055+
'cryptSharedLibRequired' => true,
1056+
],
1057+
];
1058+
1059+
$clientEncrypted = static::createTestClient(null, [], ['autoEncryption' => $autoEncryptionOpts]);
1060+
1061+
$clientEncrypted->selectCollection('db', 'coll')->insertOne(['unencrypted' => 'test']);
1062+
1063+
$clientMongocryptd = static::createTestClient('mongodb://localhost:27021/?serverSelectionTimeoutMS=1000');
1064+
1065+
$this->expectException(ConnectionTimeoutException::class);
1066+
$this->expectExceptionMessageMatches('#(No suitable servers found)|(No servers yet eligible for rescan)#');
1067+
$clientMongocryptd->getManager()->selectServer();
1068+
}
1069+
10321070
/**
10331071
* Prose test 8: Bypass Spawning mongocryptd (via mongocryptdBypassSpawn)
10341072
*
@@ -1054,7 +1092,7 @@ public function testBypassSpawningMongocryptdViaBypassSpawn(): void
10541092
],
10551093
'extraOptions' => [
10561094
'mongocryptdBypassSpawn' => true,
1057-
'mongocryptdURI' => 'mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000',
1095+
'mongocryptdURI' => 'mongodb://localhost:27021/?serverSelectionTimeoutMS=1000',
10581096
'mongocryptdSpawnArgs' => ['--pidfilepath=bypass-spawning-mongocryptd.pid', '--port=27021'],
10591097
],
10601098
];
@@ -1100,10 +1138,11 @@ public function testBypassSpawningMongocryptdViaBypassAutoEncryption(): void
11001138

11011139
$clientEncrypted->selectCollection('db', 'coll')->insertOne(['unencrypted' => 'test']);
11021140

1103-
$clientMongocryptd = static::createTestClient('mongodb://localhost:27021');
1141+
$clientMongocryptd = static::createTestClient('mongodb://localhost:27021/?serverSelectionTimeoutMS=1000');
11041142

11051143
$this->expectException(ConnectionTimeoutException::class);
1106-
$clientMongocryptd->selectDatabase('db')->command(['ping' => 1]);
1144+
$this->expectExceptionMessageMatches('#(No suitable servers found)|(No servers yet eligible for rescan)#');
1145+
$clientMongocryptd->getManager()->selectServer();
11071146
}
11081147

11091148
/**
@@ -1133,10 +1172,11 @@ public function testBypassSpawningMongocryptdViaBypassQueryAnalysis(): void
11331172

11341173
$clientEncrypted->selectCollection('db', 'coll')->insertOne(['unencrypted' => 'test']);
11351174

1136-
$clientMongocryptd = static::createTestClient('mongodb://localhost:27021');
1175+
$clientMongocryptd = static::createTestClient('mongodb://localhost:27021/?serverSelectionTimeoutMS=1000');
11371176

11381177
$this->expectException(ConnectionTimeoutException::class);
1139-
$clientMongocryptd->selectDatabase('db')->command(['ping' => 1]);
1178+
$this->expectExceptionMessageMatches('#(No suitable servers found)|(No servers yet eligible for rescan)#');
1179+
$clientMongocryptd->getManager()->selectServer();
11401180
}
11411181

11421182
/**

0 commit comments

Comments
 (0)