|
|
@@ -103,6 +103,8 @@ class DigestAuthenticateTest extends CakeTestCase {
|
|
|
/**
|
|
|
* test the authenticate method
|
|
|
*
|
|
|
+ * @expectedException UnauthorizedException
|
|
|
+ * @expectedExceptionCode 401
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testAuthenticateWrongUsername() {
|
|
|
@@ -121,18 +123,7 @@ response="6629fae49393a05397450978507c4ef1",
|
|
|
opaque="123abc"
|
|
|
DIGEST;
|
|
|
|
|
|
- $this->response->expects($this->at(0))
|
|
|
- ->method('header')
|
|
|
- ->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
|
|
-
|
|
|
- $this->response->expects($this->at(1))
|
|
|
- ->method('statusCode')
|
|
|
- ->with(401);
|
|
|
-
|
|
|
- $this->response->expects($this->at(2))
|
|
|
- ->method('send');
|
|
|
-
|
|
|
- $this->assertTrue($this->auth->unauthenticated($request, $this->response));
|
|
|
+ $this->auth->unauthenticated($request, $this->response);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -144,19 +135,14 @@ DIGEST;
|
|
|
$request = new CakeRequest('posts/index', false);
|
|
|
$request->addParams(array('pass' => array(), 'named' => array()));
|
|
|
|
|
|
- $this->response->expects($this->at(0))
|
|
|
- ->method('header')
|
|
|
- ->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
|
|
-
|
|
|
- $this->response->expects($this->at(1))
|
|
|
- ->method('statusCode')
|
|
|
- ->with(401);
|
|
|
+ try {
|
|
|
+ $this->auth->unauthenticated($request, $this->response);
|
|
|
+ } catch (UnauthorizedException $e) {}
|
|
|
|
|
|
- $this->response->expects($this->at(2))
|
|
|
- ->method('send');
|
|
|
+ $this->assertNotEmpty($e);
|
|
|
|
|
|
- $result = $this->auth->unauthenticated($request, $this->response);
|
|
|
- $this->assertTrue($result);
|
|
|
+ $expected = array('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
|
|
+ $this->assertEquals($expected, $e->responseHeader());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -193,6 +179,8 @@ DIGEST;
|
|
|
/**
|
|
|
* test scope failure.
|
|
|
*
|
|
|
+ * @expectedException UnauthorizedException
|
|
|
+ * @expectedExceptionCode 401
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testAuthenticateFailReChallenge() {
|
|
|
@@ -212,18 +200,7 @@ response="6629fae49393a05397450978507c4ef1",
|
|
|
opaque="123abc"
|
|
|
DIGEST;
|
|
|
|
|
|
- $this->response->expects($this->at(0))
|
|
|
- ->method('header')
|
|
|
- ->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
|
|
-
|
|
|
- $this->response->expects($this->at(1))
|
|
|
- ->method('statusCode')
|
|
|
- ->with(401);
|
|
|
-
|
|
|
- $this->response->expects($this->at(2))
|
|
|
- ->method('send');
|
|
|
-
|
|
|
- $this->assertTrue($this->auth->unauthenticated($request, $this->response));
|
|
|
+ $this->auth->unauthenticated($request, $this->response);
|
|
|
}
|
|
|
|
|
|
/**
|