ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractDigestTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV\Auth\Backend;
4 
5 use Sabre\HTTP;
6 
8 
9  function testCheckNoHeaders() {
10 
11  $request = new HTTP\Request();
12  $response = new HTTP\Response();
13 
14  $backend = new AbstractDigestMock();
15  $this->assertFalse(
16  $backend->check($request, $response)[0]
17  );
18 
19  }
20 
22 
23  $header = 'username=null, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
25  'PHP_AUTH_DIGEST' => $header,
26  ]);
27  $response = new HTTP\Response();
28 
29  $backend = new AbstractDigestMock();
30  $this->assertFalse(
31  $backend->check($request, $response)[0]
32  );
33 
34  }
35 
40 
41  $header = 'username=array, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
43  'PHP_AUTH_DIGEST' => $header,
44  ]);
45 
46  $response = new HTTP\Response();
47 
48  $backend = new AbstractDigestMock();
49  $backend->check($request, $response);
50 
51  }
52 
53  function testCheckUnknownUser() {
54 
55  $header = 'username=false, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
57  'PHP_AUTH_DIGEST' => $header,
58  ]);
59 
60  $response = new HTTP\Response();
61 
62  $backend = new AbstractDigestMock();
63  $this->assertFalse(
64  $backend->check($request, $response)[0]
65  );
66 
67  }
68 
69  function testCheckBadPassword() {
70 
71  $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
73  'PHP_AUTH_DIGEST' => $header,
74  'REQUEST_METHOD' => 'PUT',
75  ]);
76 
77  $response = new HTTP\Response();
78 
79  $backend = new AbstractDigestMock();
80  $this->assertFalse(
81  $backend->check($request, $response)[0]
82  );
83 
84  }
85 
86  function testCheck() {
87 
88  $digestHash = md5('HELLO:12345:1:1:auth:' . md5('GET:/'));
89  $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=' . $digestHash . ', opaque=1, qop=auth, nc=1, cnonce=1';
91  'REQUEST_METHOD' => 'GET',
92  'PHP_AUTH_DIGEST' => $header,
93  'REQUEST_URI' => '/',
94  ]);
95 
96  $response = new HTTP\Response();
97 
98  $backend = new AbstractDigestMock();
99  $this->assertEquals(
100  [true, 'principals/user'],
101  $backend->check($request, $response)
102  );
103 
104  }
105 
106  function testRequireAuth() {
107 
108  $request = new HTTP\Request();
109  $response = new HTTP\Response();
110 
111  $backend = new AbstractDigestMock();
112  $backend->setRealm('writing unittests on a saturday night');
113  $backend->challenge($request, $response);
114 
115  $this->assertStringStartsWith(
116  'Digest realm="writing unittests on a saturday night"',
117  $response->getHeader('WWW-Authenticate')
118  );
119 
120  }
121 
122 }
123 
124 
126 
127  function getDigestHash($realm, $userName) {
128 
129  switch ($userName) {
130  case 'null' : return null;
131  case 'false' : return false;
132  case 'array' : return [];
133  case 'user' : return 'HELLO';
134  }
135 
136  }
137 
138 }
foreach($paths as $path) $request
Definition: asyncclient.php:32
HTTP Digest authentication backend class.
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$response