@@ -7,6 +7,50 @@ Atlas Connectivity Tests
7
7
<?php
8
8
require_once __DIR__ . "/utils/basic.inc " ;
9
9
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
+
10
54
$ envs = [
11
55
'ATLAS_SERVERLESS ' ,
12
56
'ATLAS_SRV_SERVERLESS ' ,
@@ -21,9 +65,10 @@ $envs = [
21
65
'ATLAS_TLS12 ' ,
22
66
'ATLAS_SRV_TLS12 ' ,
23
67
];
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
+ ];
27
72
28
73
foreach ($ envs as $ env ) {
29
74
echo $ env , ': ' ;
@@ -34,15 +79,27 @@ foreach ($envs as $env) {
34
79
continue ;
35
80
}
36
81
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
+
37
96
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 );
44
100
}
45
101
}
102
+
46
103
?>
47
104
===DONE===
48
105
<?php exit (0 ); ?>
@@ -59,4 +116,6 @@ ATLAS_TLS11: PASS
59
116
ATLAS_SRV_TLS11: PASS
60
117
ATLAS_TLS12: PASS
61
118
ATLAS_SRV_TLS12: PASS
119
+ ATLAS_X509: PASS
120
+ ATLAS_X509_DEV: PASS
62
121
===DONE===
0 commit comments