Permalink
Browse files

fix failing tests

  • Loading branch information...
ceeram committed Mar 18, 2013
1 parent b28ea65 commit 89ecd95e55c16259f9222ea3e00dd1c6eeaa7293
@@ -114,13 +114,13 @@ public function getUser(CakeRequest $request) {
*
* @param CakeRequest $request A request object.
* @param CakeResponse $response A response object.
- * @return boolean True
+ * @return void
+ * @throws UnauthorizedException
*/
public function unauthenticated(CakeRequest $request, CakeResponse $response) {
$Exception = new UnauthorizedException();
- $Exception->responseHeader($this->loginHeaders());
+ $Exception->responseHeader(array($this->loginHeaders()));
throw $Exception;
- return true;
}
/**
@@ -137,15 +137,14 @@ public function testAuthenticateChallenge() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
- $this->response->expects($this->at(0))
- ->method('header')
- ->with('WWW-Authenticate: Basic realm="localhost"');
+ try {
+ $this->auth->unauthenticated($request, $this->response);
+ } catch (UnauthorizedException $e) {}
- $this->response->expects($this->at(1))
- ->method('send');
+ $this->assertNotEmpty($e);
- $result = $this->auth->unauthenticated($request, $this->response);
- $this->assertTrue($result);
+ $expected = array('WWW-Authenticate: Basic realm="localhost"');
+ $this->assertEquals($expected, $e->responseHeader());
}
/**
@@ -173,6 +172,8 @@ public function testAuthenticateSuccess() {
/**
* test scope failure.
*
+ * @expectedException UnauthorizedException
+ * @expectedExceptionCode 401
* @return void
*/
public function testAuthenticateFailReChallenge() {
@@ -183,18 +184,7 @@ public function testAuthenticateFailReChallenge() {
$_SERVER['PHP_AUTH_USER'] = 'mariano';
$_SERVER['PHP_AUTH_PW'] = 'password';
- $this->response->expects($this->at(0))
- ->method('header')
- ->with('WWW-Authenticate: Basic realm="localhost"');
-
- $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);
}
}
@@ -103,6 +103,8 @@ public function testAuthenticateNoData() {
/**
* test the authenticate method
*
+ * @expectedException UnauthorizedException
+ * @expectedExceptionCode 401
* @return void
*/
public function testAuthenticateWrongUsername() {
@@ -121,18 +123,7 @@ public function testAuthenticateWrongUsername() {
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 @@ public function testAuthenticateChallenge() {
$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 @@ public function testAuthenticateSuccess() {
/**
* test scope failure.
*
+ * @expectedException UnauthorizedException
+ * @expectedExceptionCode 401
* @return void
*/
public function testAuthenticateFailReChallenge() {
@@ -212,18 +200,7 @@ public function testAuthenticateFailReChallenge() {
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);
}
/**
@@ -1359,6 +1359,8 @@ public function testUser() {
/**
* testStatelessAuthNoRedirect method
*
+ * @expectedException UnauthorizedException
+ * @expectedExceptionCode 401
* @return void
*/
public function testStatelessAuthNoRedirect() {
@@ -1372,18 +1374,7 @@ public function testStatelessAuthNoRedirect() {
$this->Auth->authenticate = array('Basic');
$this->Controller->request['action'] = 'admin_add';
- $this->Auth->response->expects($this->once())
- ->method('statusCode')
- ->with(401);
-
- $this->Auth->response->expects($this->once())
- ->method('send');
-
- $result = $this->Auth->startup($this->Controller);
- $this->assertFalse($result);
-
- $this->assertNull($this->Controller->testUrl);
- $this->assertNull(CakeSession::id());
+ $this->Auth->startup($this->Controller);
}
/**

0 comments on commit 89ecd95

Please sign in to comment.