Skip to content

Commit

Permalink
Rewrite error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tt1991 committed Nov 16, 2015
1 parent b84f9ef commit cb6d3f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/Escher.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static function parseFromHeaders(array $headerList, $authHeaderKey, $date
try {
$dateTime = new DateTime($headerList[strtolower($dateHeaderKey)], new DateTimeZone('GMT'));
} catch (Exception $ex) {
throw new EscherException('Invalid date header, expected format is: Wed, 04 Nov 2015 09:20:22 GMT');
throw new EscherException('Date header is invalid, the expected format is Wed, 04 Nov 2015 09:20:22 GMT');
}
}
return new EscherAuthElements($elementParts, $accessKeyId, $shortDate, $credentialScope, $dateTime, $host, true);
Expand All @@ -511,7 +511,7 @@ public static function parseAuthHeader($headerContent, $algoPrefix)
'Signature=([0-9a-f]+)$/';

if (!preg_match($pattern, $headerContent, $matches)) {
throw new EscherException('Could not parse auth header');
throw new EscherException('Auth header format is invalid');
}
return array(
'Algorithm' => $matches[1],
Expand Down Expand Up @@ -564,7 +564,7 @@ private static function checkParam($queryParams, $vendorKey, $paramId)
{
$paramKey = 'X-' . $vendorKey . '-' . $paramId;
if (!isset($queryParams[$paramKey])) {
throw new EscherException('Query key is missing: ' . $paramKey);
throw new EscherException('Query key: ' . $paramKey . ' is missing');
}
return $paramKey;
}
Expand All @@ -581,7 +581,7 @@ public function validateDates(EscherRequestHelper $helper, $clockSkew)
{
$shortDate = $this->dateTime->format('Ymd');
if ($shortDate !== $this->getShortDate()) {
throw new EscherException('Invalid date in authorization header, it should equal with header');
throw new EscherException('Date in the authorization header is invalid. It must be the same as the date header');
}

if (!$this->isInAcceptableInterval($helper->getTimeStamp(), EscherUtils::getTimeStampOfDateTime($this->dateTime), $clockSkew)) {
Expand All @@ -592,7 +592,7 @@ public function validateDates(EscherRequestHelper $helper, $clockSkew)
public function validateCredentials($credentialScope)
{
if (!$this->checkCredentials($credentialScope)) {
throw new EscherException('Invalid Credential Scope');
throw new EscherException('Credential scope is invalid');
}
}

Expand Down Expand Up @@ -634,7 +634,7 @@ public function validateHashAlgo()
{
if(!in_array(strtoupper($this->getAlgorithm()), array('SHA256','SHA512')))
{
throw new EscherException('Invalid hash algorithm, only SHA256 and SHA512 are allowed');
throw new EscherException('Hash algorithm is invalid. Only SHA256 and SHA512 are allowed');
}
}

Expand Down Expand Up @@ -892,7 +892,7 @@ class EscherUtils
public static function parseLongDate($dateString)
{
if (!preg_match('/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/', $dateString)) {
throw new EscherException('Invalid date header, expected format is: 20151104T092022Z');
throw new EscherException('Date header is invalid, the expected format is 20151104T092022Z');
}
if (!self::advancedDateTimeFunctionsAvailable()) {
return new DateTime($dateString, new DateTimeZone('GMT'));
Expand Down
8 changes: 4 additions & 4 deletions test/unit/AuthenticateRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ public function itShouldFailToValidateInvalidRequests($tamperedKey, $tamperedVal
public function requestTamperingProvider()
{
return array(
'wrong date' => array('HTTP_X_EMS_DATE', 'INVALIDDATE', 'Invalid date header, expected format is: 20151104T092022Z'),
'wrong date' => array('HTTP_X_EMS_DATE', 'INVALIDDATE', 'Date header is invalid, the expected format is 20151104T092022Z'),
'wrong request time' => array('REQUEST_TIME', '20110909T113600Z', 'The request date is not within the accepted time range'),
'wrong auth header' => array('HTTP_X_EMS_AUTH', 'Malformed auth header', 'Could not parse auth header'),
'wrong auth header' => array('HTTP_X_EMS_AUTH', 'Malformed auth header', 'Auth header format is invalid'),
'tampered signature' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-ems-date, Signature=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'The signatures do not match'),
'wrong hash algo' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA123 Credential=AKIDEXAMPLE/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-ems-date, Signature=f36c21c6e16a71a6e8dc56673ad6354aeef49c577a22fd58a190b5fcf8891dbd', 'Invalid hash algorithm, only SHA256 and SHA512 are allowed'),
'wrong hash algo' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA123 Credential=AKIDEXAMPLE/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-ems-date, Signature=f36c21c6e16a71a6e8dc56673ad6354aeef49c577a22fd58a190b5fcf8891dbd', 'Hash algorithm is invalid. Only SHA256 and SHA512 are allowed'),
'host not signed' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA123 Credential=AKIDEXAMPLE/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-type;x-ems-date, Signature=f36c21c6e16a71a6e8dc56673ad6354aeef49c577a22fd58a190b5fcf8891dbd', 'The host header is not signed'),
'date not signed' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA123 Credential=AKIDEXAMPLE/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-type;host, Signature=f36c21c6e16a71a6e8dc56673ad6354aeef49c577a22fd58a190b5fcf8891dbd', 'The x-ems-date header is not signed'),
'invalid credential' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-2/iam/aws4_request, SignedHeaders=content-type;host;x-ems-date, Signature=f36c21c6e16a71a6e8dc56673ad6354aeef49c577a22fd58a190b5fcf8891dbd', 'Invalid Credential Scope'),
'invalid credential' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-2/iam/aws4_request, SignedHeaders=content-type;host;x-ems-date, Signature=f36c21c6e16a71a6e8dc56673ad6354aeef49c577a22fd58a190b5fcf8891dbd', 'Credential scope is invalid'),
'invalid Escher key' => array('HTTP_X_EMS_AUTH', 'EMS-HMAC-SHA256 Credential=FOOBAR/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-ems-date, Signature=f36c21c6e16a71a6e8dc56673ad6354aeef49c577a22fd58a190b5fcf8891dbd', 'Invalid Escher key'),
);
}
Expand Down

0 comments on commit cb6d3f7

Please sign in to comment.