25 const REALM =
'SabreDAV unittest';
31 $this->auth =
new AWS(self::REALM, $this->request, $this->response);
37 $this->request->setMethod(
'GET');
40 $this->assertFalse(
$result,
'No AWS Authorization header was supplied, so we should have gotten false');
47 $accessKey =
'accessKey';
48 $secretKey =
'secretKey';
50 $this->request->setMethod(
'GET');
51 $this->request->setHeaders([
52 'Authorization' =>
"AWS $accessKey:sig",
53 'Content-MD5' =>
'garbage',
55 $this->request->setUrl(
'/');
58 $result = $this->auth->validate($secretKey);
67 $accessKey =
'accessKey';
68 $secretKey =
'secretKey';
69 $content =
'thisisthebody';
70 $contentMD5 = base64_encode(md5($content,
true));
72 $this->request->setMethod(
'POST');
73 $this->request->setHeaders([
74 'Authorization' =>
"AWS $accessKey:sig",
75 'Content-MD5' => $contentMD5,
77 $this->request->setUrl(
'/');
78 $this->request->setBody($content);
81 $result = $this->auth->validate($secretKey);
90 $accessKey =
'accessKey';
91 $secretKey =
'secretKey';
92 $content =
'thisisthebody';
93 $contentMD5 = base64_encode(md5($content,
true));
95 $date = new \DateTime(
'@' . (time() + (60 * 20)));
97 $date = $date->format(
'D, d M Y H:i:s \\G\\M\\T');
99 $this->request->setMethod(
'POST');
100 $this->request->setHeaders([
101 'Authorization' =>
"AWS $accessKey:sig",
102 'Content-MD5' => $contentMD5,
106 $this->request->setBody($content);
109 $result = $this->auth->validate($secretKey);
118 $accessKey =
'accessKey';
119 $secretKey =
'secretKey';
120 $content =
'thisisthebody';
121 $contentMD5 = base64_encode(md5($content,
true));
123 $date = new \DateTime(
'@' . (time() - (60 * 20)));
125 $date = $date->format(
'D, d M Y H:i:s \\G\\M\\T');
127 $this->request->setMethod(
'POST');
128 $this->request->setHeaders([
129 'Authorization' =>
"AWS $accessKey:sig",
130 'Content-MD5' => $contentMD5,
134 $this->request->setBody($content);
137 $result = $this->auth->validate($secretKey);
146 $accessKey =
'accessKey';
147 $secretKey =
'secretKey';
148 $content =
'thisisthebody';
150 $contentMD5 = base64_encode(md5($content,
true));
152 $date = new \DateTime(
'now');
154 $date = $date->format(
'D, d M Y H:i:s \\G\\M\\T');
156 $this->request->setUrl(
'/');
157 $this->request->setMethod(
'POST');
158 $this->request->setHeaders([
159 'Authorization' =>
"AWS $accessKey:sig",
160 'Content-MD5' => $contentMD5,
161 'X-amz-date' => $date,
163 $this->request->setBody($content);
166 $result = $this->auth->validate($secretKey);
175 $accessKey =
'accessKey';
176 $secretKey =
'secretKey';
177 $content =
'thisisthebody';
178 $contentMD5 = base64_encode(md5($content,
true));
180 $date = new \DateTime(
'now');
182 $date = $date->format(
'D, d M Y H:i:s \\G\\M\\T');
185 $sig = base64_encode($this->
hmacsha1($secretKey,
186 "POST\n$contentMD5\n\n$date\nx-amz-date:$date\n/evert" 189 $this->request->setUrl(
'/evert');
190 $this->request->setMethod(
'POST');
191 $this->request->setHeaders([
192 'Authorization' =>
"AWS $accessKey:$sig",
193 'Content-MD5' => $contentMD5,
194 'X-amz-date' => $date,
197 $this->request->setBody($content);
200 $result = $this->auth->validate($secretKey);
202 $this->assertTrue(
$result,
'Signature did not validate, got errorcode ' . $this->auth->errorCode);
203 $this->assertEquals($accessKey, $this->auth->getAccessKey());
209 $this->auth->requireLogin();
210 $test = preg_match(
'/^AWS$/', $this->response->getHeader(
'WWW-Authenticate'), $matches);
211 $this->assertTrue(
$test ==
true,
'The WWW-Authenticate response didn\'t match our pattern');
225 if (strlen(
$key) > $blocksize)
227 $key = str_pad(
$key, $blocksize, chr(0x00));
228 $ipad = str_repeat(chr(0x36), $blocksize);
229 $opad = str_repeat(chr(0x5c), $blocksize);
230 $hmac = pack(
'H*', sha1((
$key ^ $opad) . pack(
'H*', sha1((
$key ^ $ipad) .
$message))));
HTTP AWS Authentication handler.
const ERR_INVALIDSIGNATURE
The Request class represents a single HTTP request.
testIncorrectContentMD5()
catch(Exception $e) $message
const ERR_INVALIDDATEFORMAT
This class represents a single HTTP response.
const ERR_REQUESTTIMESKEWED
const ERR_MD5CHECKSUMWRONG
hmacsha1($key, $message)
Generates an HMAC-SHA1 signature.