Skip to content

Commit

Permalink
Solve failing unittest CloudFront\SignerTest::testBadPrivateKeyPath()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Zombaya committed Jun 7, 2022
1 parent 6ce0cb6 commit b0ab727
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/CloudFront/Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ public function __construct($keyPairId, $privateKey, $passphrase = "")
if (!$this->pkHandle = openssl_pkey_get_private($privateKey, $passphrase)) {
if (!file_exists($privateKey)) {
throw new \InvalidArgumentException("PK file not found: $privateKey");
} else {
$this->pkHandle = openssl_pkey_get_private("file://$privateKey", $passphrase);
if (!$this->pkHandle) {
throw new \InvalidArgumentException(openssl_error_string());
}

$this->pkHandle = openssl_pkey_get_private("file://$privateKey", $passphrase);
if (!$this->pkHandle) {
$errorMessages = [];
while(($newMessage = openssl_error_string()) !== false){
$errorMessages[] = $newMessage;
}
throw new \InvalidArgumentException(implode("\n",$errorMessages));
}
}
}
Expand Down

0 comments on commit b0ab727

Please sign in to comment.