27 const REALM =
'SabreDAV unittest';
33 $this->auth =
new Digest(self::REALM, $this->request, $this->response);
48 md5($username .
':' . self::REALM .
':' .
$password) .
':' .
53 md5(
'GET' .
':' .
'/')
56 $this->request->setMethod(
'GET');
57 $this->request->setHeader(
'Authorization',
'Digest username="' . $username .
'", realm="' . self::REALM .
'", nonce="' . $nonce .
'", uri="/", response="' . $digestHash .
'", opaque="' . $opaque .
'", qop=auth,nc=' . $nc .
',cnonce="' . $cnonce .
'"');
61 $this->assertEquals($username, $this->auth->getUsername());
62 $this->assertEquals(self::REALM, $this->auth->getRealm());
63 $this->assertTrue($this->auth->validateA1(md5($username .
':' . self::REALM .
':' . $password)),
'Authentication is deemed invalid through validateA1');
64 $this->assertTrue($this->auth->validatePassword($password),
'Authentication is deemed invalid through validatePassword');
78 md5($username .
':' . self::REALM .
':' .
$password) .
':' .
83 md5(
'GET' .
':' .
'/')
86 $this->request->setMethod(
'GET');
87 $this->request->setHeader(
'Authorization',
'Digest username="' . $username .
'", realm="' . self::REALM .
'", nonce="' . $nonce .
'", uri="/", response="' . $digestHash .
'", opaque="' . $opaque .
'", qop=auth,nc=' . $nc .
',cnonce="' . $cnonce .
'"');
91 $this->assertFalse($this->auth->validateA1(md5($username .
':' . self::REALM .
':' . ($password .
'randomness'))),
'Authentication is deemed invalid through validateA1');
97 $this->request->setMethod(
'GET');
98 $this->request->setHeader(
'Authorization',
'basic blablabla');
101 $this->assertFalse($this->auth->validateA1(md5(
'user:realm:password')));
117 md5($username .
':' . self::REALM .
':' .
$password) .
':' .
122 md5(
'POST' .
':' .
'/' .
':' . md5(
'body'))
125 $this->request->setMethod(
'POST');
126 $this->request->setHeader(
'Authorization',
'Digest username="' . $username .
'", realm="' . self::REALM .
'", nonce="' . $nonce .
'", uri="/", response="' . $digestHash .
'", opaque="' . $opaque .
'", qop=auth-int,nc=' . $nc .
',cnonce="' . $cnonce .
'"');
127 $this->request->setBody(
'body');
131 $this->assertTrue($this->auth->validateA1(md5($username .
':' . self::REALM .
':' . $password)),
'Authentication is deemed invalid through validateA1');
146 md5($username .
':' . self::REALM .
':' .
$password) .
':' .
151 md5(
'POST' .
':' .
'/' .
':' . md5(
'body'))
154 $this->request->setMethod(
'POST');
155 $this->request->setHeader(
'Authorization',
'Digest username="' . $username .
'", realm="' . self::REALM .
'", nonce="' . $nonce .
'", uri="/", response="' . $digestHash .
'", opaque="' . $opaque .
'", qop=auth-int,nc=' . $nc .
',cnonce="' . $cnonce .
'"');
156 $this->request->setBody(
'body');
160 $this->assertTrue($this->auth->validateA1(md5($username .
':' . self::REALM .
':' . $password)),
'Authentication is deemed invalid through validateA1');
167 $this->auth->requireLogin();
172 default : $qopstr =
'auth,auth-int';
break;
175 $test = preg_match(
'/Digest realm="' . self::REALM .
'",qop="' . $qopstr .
'",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/',
176 $this->response->getHeader(
'WWW-Authenticate'), $matches);
178 $this->assertTrue(
$test ==
true,
'The WWW-Authenticate response didn\'t match our pattern. We received: ' . $this->response->getHeader(
'WWW-Authenticate'));
180 $nonce = $matches[1];
181 $opaque = $matches[2];
185 $this->auth->setQOP($qop);
187 return [$nonce,$opaque];
The Request class represents a single HTTP request.
const QOP_AUTH
These constants are used in setQOP();.
This class represents a single HTTP response.
getServerTokens($qop=Digest::QOP_AUTH)
HTTP Digest Authentication handler.