ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\HTTP\Auth\AWSTest Class Reference
+ Inheritance diagram for Sabre\HTTP\Auth\AWSTest:
+ Collaboration diagram for Sabre\HTTP\Auth\AWSTest:

Public Member Functions

 setUp ()
 
 testNoHeader ()
 
 testIncorrectContentMD5 ()
 
 testNoDate ()
 
 testFutureDate ()
 
 testPastDate ()
 
 testIncorrectSignature ()
 
 testValidRequest ()
 
 test401 ()
 

Data Fields

const REALM = 'SabreDAV unittest'
 

Private Member Functions

 hmacsha1 ($key, $message)
 Generates an HMAC-SHA1 signature. More...
 

Private Attributes

 $response
 
 $request
 
 $auth
 

Detailed Description

Definition at line 8 of file AWSTest.php.

Member Function Documentation

◆ hmacsha1()

Sabre\HTTP\Auth\AWSTest::hmacsha1 (   $key,
  $message 
)
private

Generates an HMAC-SHA1 signature.

Parameters
string$key
string$message
Returns
string

Definition at line 222 of file AWSTest.php.

References $key, and $message.

Referenced by Sabre\HTTP\Auth\AWSTest\testValidRequest().

222  {
223 
224  $blocksize = 64;
225  if (strlen($key) > $blocksize)
226  $key = pack('H*', sha1($key));
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))));
231  return $hmac;
232 
233  }
catch(Exception $e) $message
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ setUp()

Sabre\HTTP\Auth\AWSTest::setUp ( )

Definition at line 27 of file AWSTest.php.

27  {
28 
29  $this->response = new Response();
30  $this->request = new Request();
31  $this->auth = new AWS(self::REALM, $this->request, $this->response);
32 
33  }

◆ test401()

Sabre\HTTP\Auth\AWSTest::test401 ( )

Definition at line 207 of file AWSTest.php.

References $test.

207  {
208 
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');
212 
213  }
$test
Definition: Utf8Test.php:84

◆ testFutureDate()

Sabre\HTTP\Auth\AWSTest::testFutureDate ( )

Definition at line 88 of file AWSTest.php.

References $result, and Sabre\HTTP\Auth\AWS\ERR_REQUESTTIMESKEWED.

88  {
89 
90  $accessKey = 'accessKey';
91  $secretKey = 'secretKey';
92  $content = 'thisisthebody';
93  $contentMD5 = base64_encode(md5($content, true));
94 
95  $date = new \DateTime('@' . (time() + (60 * 20)));
96  $date->setTimeZone(new \DateTimeZone('GMT'));
97  $date = $date->format('D, d M Y H:i:s \\G\\M\\T');
98 
99  $this->request->setMethod('POST');
100  $this->request->setHeaders([
101  'Authorization' => "AWS $accessKey:sig",
102  'Content-MD5' => $contentMD5,
103  'Date' => $date,
104  ]);
105 
106  $this->request->setBody($content);
107 
108  $this->auth->init();
109  $result = $this->auth->validate($secretKey);
110 
111  $this->assertFalse($result);
112  $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode);
113 
114  }
$result
const ERR_REQUESTTIMESKEWED
Definition: AWS.php:44

◆ testIncorrectContentMD5()

Sabre\HTTP\Auth\AWSTest::testIncorrectContentMD5 ( )

Definition at line 45 of file AWSTest.php.

References $result, and Sabre\HTTP\Auth\AWS\ERR_MD5CHECKSUMWRONG.

45  {
46 
47  $accessKey = 'accessKey';
48  $secretKey = 'secretKey';
49 
50  $this->request->setMethod('GET');
51  $this->request->setHeaders([
52  'Authorization' => "AWS $accessKey:sig",
53  'Content-MD5' => 'garbage',
54  ]);
55  $this->request->setUrl('/');
56 
57  $this->auth->init();
58  $result = $this->auth->validate($secretKey);
59 
60  $this->assertFalse($result);
61  $this->assertEquals(AWS::ERR_MD5CHECKSUMWRONG, $this->auth->errorCode);
62 
63  }
$result
const ERR_MD5CHECKSUMWRONG
Definition: AWS.php:42

◆ testIncorrectSignature()

Sabre\HTTP\Auth\AWSTest::testIncorrectSignature ( )

Definition at line 144 of file AWSTest.php.

References $result, and Sabre\HTTP\Auth\AWS\ERR_INVALIDSIGNATURE.

144  {
145 
146  $accessKey = 'accessKey';
147  $secretKey = 'secretKey';
148  $content = 'thisisthebody';
149 
150  $contentMD5 = base64_encode(md5($content, true));
151 
152  $date = new \DateTime('now');
153  $date->setTimeZone(new \DateTimeZone('GMT'));
154  $date = $date->format('D, d M Y H:i:s \\G\\M\\T');
155 
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,
162  ]);
163  $this->request->setBody($content);
164 
165  $this->auth->init();
166  $result = $this->auth->validate($secretKey);
167 
168  $this->assertFalse($result);
169  $this->assertEquals(AWS::ERR_INVALIDSIGNATURE, $this->auth->errorCode);
170 
171  }
const ERR_INVALIDSIGNATURE
Definition: AWS.php:45
$result

◆ testNoDate()

Sabre\HTTP\Auth\AWSTest::testNoDate ( )

Definition at line 65 of file AWSTest.php.

References $result, and Sabre\HTTP\Auth\AWS\ERR_INVALIDDATEFORMAT.

65  {
66 
67  $accessKey = 'accessKey';
68  $secretKey = 'secretKey';
69  $content = 'thisisthebody';
70  $contentMD5 = base64_encode(md5($content, true));
71 
72  $this->request->setMethod('POST');
73  $this->request->setHeaders([
74  'Authorization' => "AWS $accessKey:sig",
75  'Content-MD5' => $contentMD5,
76  ]);
77  $this->request->setUrl('/');
78  $this->request->setBody($content);
79 
80  $this->auth->init();
81  $result = $this->auth->validate($secretKey);
82 
83  $this->assertFalse($result);
84  $this->assertEquals(AWS::ERR_INVALIDDATEFORMAT, $this->auth->errorCode);
85 
86  }
$result
const ERR_INVALIDDATEFORMAT
Definition: AWS.php:43

◆ testNoHeader()

Sabre\HTTP\Auth\AWSTest::testNoHeader ( )

Definition at line 35 of file AWSTest.php.

References $result, and Sabre\HTTP\Auth\AWS\ERR_NOAWSHEADER.

35  {
36 
37  $this->request->setMethod('GET');
38  $result = $this->auth->init();
39 
40  $this->assertFalse($result, 'No AWS Authorization header was supplied, so we should have gotten false');
41  $this->assertEquals(AWS::ERR_NOAWSHEADER, $this->auth->errorCode);
42 
43  }
$result
const ERR_NOAWSHEADER
Definition: AWS.php:41

◆ testPastDate()

Sabre\HTTP\Auth\AWSTest::testPastDate ( )

Definition at line 116 of file AWSTest.php.

References $result, and Sabre\HTTP\Auth\AWS\ERR_REQUESTTIMESKEWED.

116  {
117 
118  $accessKey = 'accessKey';
119  $secretKey = 'secretKey';
120  $content = 'thisisthebody';
121  $contentMD5 = base64_encode(md5($content, true));
122 
123  $date = new \DateTime('@' . (time() - (60 * 20)));
124  $date->setTimeZone(new \DateTimeZone('GMT'));
125  $date = $date->format('D, d M Y H:i:s \\G\\M\\T');
126 
127  $this->request->setMethod('POST');
128  $this->request->setHeaders([
129  'Authorization' => "AWS $accessKey:sig",
130  'Content-MD5' => $contentMD5,
131  'Date' => $date,
132  ]);
133 
134  $this->request->setBody($content);
135 
136  $this->auth->init();
137  $result = $this->auth->validate($secretKey);
138 
139  $this->assertFalse($result);
140  $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode);
141 
142  }
$result
const ERR_REQUESTTIMESKEWED
Definition: AWS.php:44

◆ testValidRequest()

Sabre\HTTP\Auth\AWSTest::testValidRequest ( )

Definition at line 173 of file AWSTest.php.

References $result, and Sabre\HTTP\Auth\AWSTest\hmacsha1().

173  {
174 
175  $accessKey = 'accessKey';
176  $secretKey = 'secretKey';
177  $content = 'thisisthebody';
178  $contentMD5 = base64_encode(md5($content, true));
179 
180  $date = new \DateTime('now');
181  $date->setTimeZone(new \DateTimeZone('GMT'));
182  $date = $date->format('D, d M Y H:i:s \\G\\M\\T');
183 
184 
185  $sig = base64_encode($this->hmacsha1($secretKey,
186  "POST\n$contentMD5\n\n$date\nx-amz-date:$date\n/evert"
187  ));
188 
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,
195  ]);
196 
197  $this->request->setBody($content);
198 
199  $this->auth->init();
200  $result = $this->auth->validate($secretKey);
201 
202  $this->assertTrue($result, 'Signature did not validate, got errorcode ' . $this->auth->errorCode);
203  $this->assertEquals($accessKey, $this->auth->getAccessKey());
204 
205  }
$result
hmacsha1($key, $message)
Generates an HMAC-SHA1 signature.
Definition: AWSTest.php:222
+ Here is the call graph for this function:

Field Documentation

◆ $auth

Sabre\HTTP\Auth\AWSTest::$auth
private

Definition at line 23 of file AWSTest.php.

◆ $request

Sabre\HTTP\Auth\AWSTest::$request
private

Definition at line 18 of file AWSTest.php.

◆ $response

Sabre\HTTP\Auth\AWSTest::$response
private

Definition at line 13 of file AWSTest.php.

◆ REALM

const Sabre\HTTP\Auth\AWSTest::REALM = 'SabreDAV unittest'

Definition at line 25 of file AWSTest.php.


The documentation for this class was generated from the following file: