@@ -12,7 +12,7 @@ function extractUri(string $env): ?string
12
12
return getenv ($ env ) ?: null ;
13
13
}
14
14
15
- function extractUriWithCertificate (string $ env ): ?string
15
+ function extractUriWithCertificate (string $ env ): ?array
16
16
{
17
17
$ uri = getenv ($ env );
18
18
if (! is_string ($ uri )) {
@@ -24,10 +24,19 @@ function extractUriWithCertificate(string $env): ?string
24
24
return null ;
25
25
}
26
26
27
- $ certPath = '/tmp/cert.pem ' ;
28
- file_put_contents ($ certPath , base64_decode ($ cert ));
27
+ $ certPath = tempnam (sys_get_temp_dir (), 'cert_ ' );
28
+ $ certContents = base64_decode ($ cert );
29
+ if (! $ certPath || ! $ certContents ) {
30
+ return null ;
31
+ }
29
32
30
- return $ uri . '&tlsCertificateKeyFile= ' . $ certPath ;
33
+ file_put_contents ($ certPath , $ certContents );
34
+ chmod ($ certPath , 0600 );
35
+
36
+ return [
37
+ 'uri ' => $ uri . '&tlsCertificateKeyFile= ' . $ certPath ,
38
+ 'certPath ' => $ certPath ,
39
+ ];
31
40
}
32
41
33
42
function testConnection (string $ uri ): void
@@ -81,14 +90,20 @@ foreach ($envs as $env) {
81
90
82
91
foreach ($ x509Envs as $ env ) {
83
92
echo $ env , ': ' ;
84
- $ uri = extractUriWithCertificate ($ env );
93
+ $ uriWithCertificate = extractUriWithCertificate ($ env );
85
94
86
- if (! is_string ( $ uri )) {
95
+ if (! is_array ( $ uriWithCertificate )) {
87
96
echo "FAIL: env var is undefined \n" ;
88
97
continue ;
89
98
}
90
99
91
- testConnection ($ uri );
100
+ ['uri ' => $ uri , 'certPath ' => $ certPath ] = $ uriWithCertificate ;
101
+
102
+ try {
103
+ testConnection ($ uri );
104
+ } finally {
105
+ @unlink ($ certPath );
106
+ }
92
107
}
93
108
94
109
?>
0 commit comments