Skip to content

Commit 988c53d

Browse files
committed
Apply review feedback from Copilot
1 parent 0e55a07 commit 988c53d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

tests/atlas.phpt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function extractUri(string $env): ?string
1212
return getenv($env) ?: null;
1313
}
1414

15-
function extractUriWithCertificate(string $env): ?string
15+
function extractUriWithCertificate(string $env): ?array
1616
{
1717
$uri = getenv($env);
1818
if (! is_string($uri)) {
@@ -24,10 +24,19 @@ function extractUriWithCertificate(string $env): ?string
2424
return null;
2525
}
2626

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+
}
2932

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+
];
3140
}
3241

3342
function testConnection(string $uri): void
@@ -81,14 +90,20 @@ foreach ($envs as $env) {
8190

8291
foreach ($x509Envs as $env) {
8392
echo $env, ': ';
84-
$uri = extractUriWithCertificate($env);
93+
$uriWithCertificate = extractUriWithCertificate($env);
8594

86-
if (! is_string($uri)) {
95+
if (! is_array($uriWithCertificate)) {
8796
echo "FAIL: env var is undefined\n";
8897
continue;
8998
}
9099

91-
testConnection($uri);
100+
['uri' => $uri, 'certPath' => $certPath] = $uriWithCertificate;
101+
102+
try {
103+
testConnection($uri);
104+
} finally {
105+
@unlink($certPath);
106+
}
92107
}
93108

94109
?>

0 commit comments

Comments
 (0)