diff --git a/src/Escher.php b/src/Escher.php index 7ab4f31..986ef2a 100644 --- a/src/Escher.php +++ b/src/Escher.php @@ -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); @@ -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], @@ -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; } @@ -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)) { @@ -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'); } } @@ -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'); } } @@ -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')); diff --git a/test/unit/AuthenticateRequestTest.php b/test/unit/AuthenticateRequestTest.php index cbcf9be..8a4c650 100644 --- a/test/unit/AuthenticateRequestTest.php +++ b/test/unit/AuthenticateRequestTest.php @@ -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'), ); }