Skip to content

Commit b0ab727

Browse files
committed
Solve failing unittest CloudFront\SignerTest::testBadPrivateKeyPath()
There were remaining error-messages in the openssl-error-stack, resulting in an unexpected result in the unittest. This was solved by outputting all error-messages in Aws\CloudFront\Signer::__construct(). Another option would be to clear all error-messages in Aws\Test\CloudFront\SignerTest::_tearDown(), so tests would no longer interfer with eachother. The first solution was chosen since it would output all openssl-error-messages to the user, not only the first one, making it more complete.
1 parent 6ce0cb6 commit b0ab727

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/CloudFront/Signer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ public function __construct($keyPairId, $privateKey, $passphrase = "")
3434
if (!$this->pkHandle = openssl_pkey_get_private($privateKey, $passphrase)) {
3535
if (!file_exists($privateKey)) {
3636
throw new \InvalidArgumentException("PK file not found: $privateKey");
37-
} else {
38-
$this->pkHandle = openssl_pkey_get_private("file://$privateKey", $passphrase);
39-
if (!$this->pkHandle) {
40-
throw new \InvalidArgumentException(openssl_error_string());
37+
}
38+
39+
$this->pkHandle = openssl_pkey_get_private("file://$privateKey", $passphrase);
40+
if (!$this->pkHandle) {
41+
$errorMessages = [];
42+
while(($newMessage = openssl_error_string()) !== false){
43+
$errorMessages[] = $newMessage;
4144
}
45+
throw new \InvalidArgumentException(implode("\n",$errorMessages));
4246
}
4347
}
4448
}

0 commit comments

Comments
 (0)