Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b6ed52c

Browse files
Merge v2.1 into v2.x (#1859)
2 parents fb444c9 + ec936b9 commit b6ed52c

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

‎tests/atlas.phpt‎

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,50 @@ Atlas Connectivity Tests
77
<?php
88
require_once __DIR__ . "/utils/basic.inc";
99

10+
function extractUriWithCertificate(string $env): ?array
11+
{
12+
$uri = getenv($env);
13+
if (! is_string($uri)) {
14+
return null;
15+
}
16+
17+
$cert = getenv($env . '_CERT_BASE64');
18+
if (! is_string($cert)) {
19+
return null;
20+
}
21+
22+
$certPath = tempnam(sys_get_temp_dir(), 'cert_');
23+
$certContents = base64_decode($cert);
24+
if (! $certPath || ! $certContents) {
25+
return null;
26+
}
27+
28+
file_put_contents($certPath, $certContents);
29+
30+
return [
31+
'uri' => $uri . '&tlsCertificateKeyFile=' . $certPath,
32+
'certPath' => $certPath,
33+
];
34+
}
35+
36+
function testConnection(string $uri): void
37+
{
38+
try {
39+
$m = new \MongoDB\Driver\Manager($uri);
40+
$m->executeCommand(
41+
'admin',
42+
new \MongoDB\Driver\Command(['ping' => 1]),
43+
);
44+
iterator_to_array($m->executeQuery(
45+
'test.test',
46+
new \MongoDB\Driver\Query([]),
47+
));
48+
echo "PASS\n";
49+
} catch(Exception $e) {
50+
echo "FAIL: ", $e->getMessage(), "\n";
51+
}
52+
}
53+
1054
$envs = [
1155
'ATLAS_SERVERLESS',
1256
'ATLAS_SRV_SERVERLESS',
@@ -21,9 +65,10 @@ $envs = [
2165
'ATLAS_TLS12',
2266
'ATLAS_SRV_TLS12',
2367
];
24-
25-
$command = new \MongoDB\Driver\Command(['ping' => 1]);
26-
$query = new \MongoDB\Driver\Query([]);
68+
$x509Envs = [
69+
'ATLAS_X509',
70+
'ATLAS_X509_DEV',
71+
];
2772

2873
foreach ($envs as $env) {
2974
echo $env, ': ';
@@ -34,15 +79,27 @@ foreach ($envs as $env) {
3479
continue;
3580
}
3681

82+
testConnection($uri);
83+
}
84+
85+
foreach ($x509Envs as $env) {
86+
echo $env, ': ';
87+
$uriWithCertificate = extractUriWithCertificate($env);
88+
89+
if (! is_array($uriWithCertificate)) {
90+
echo "FAIL: env var is undefined\n";
91+
continue;
92+
}
93+
94+
['uri' => $uri, 'certPath' => $certPath] = $uriWithCertificate;
95+
3796
try {
38-
$m = new \MongoDB\Driver\Manager($uri);
39-
$m->executeCommand('admin', $command);
40-
iterator_to_array($m->executeQuery('test.test', $query));
41-
echo "PASS\n";
42-
} catch(Exception $e) {
43-
echo "FAIL: ", $e->getMessage(), "\n";
97+
testConnection($uri);
98+
} finally {
99+
@unlink($certPath);
44100
}
45101
}
102+
46103
?>
47104
===DONE===
48105
<?php exit(0); ?>
@@ -59,4 +116,6 @@ ATLAS_TLS11: PASS
59116
ATLAS_SRV_TLS11: PASS
60117
ATLAS_TLS12: PASS
61118
ATLAS_SRV_TLS12: PASS
119+
ATLAS_X509: PASS
120+
ATLAS_X509_DEV: PASS
62121
===DONE===

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /