mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
fix failing tests
This commit is contained in:
parent
b28ea65b24
commit
89ecd95e55
4 changed files with 27 additions and 69 deletions
|
@ -114,13 +114,13 @@ class BasicAuthenticate extends BaseAuthenticate {
|
||||||
*
|
*
|
||||||
* @param CakeRequest $request A request object.
|
* @param CakeRequest $request A request object.
|
||||||
* @param CakeResponse $response A response object.
|
* @param CakeResponse $response A response object.
|
||||||
* @return boolean True
|
* @return void
|
||||||
|
* @throws UnauthorizedException
|
||||||
*/
|
*/
|
||||||
public function unauthenticated(CakeRequest $request, CakeResponse $response) {
|
public function unauthenticated(CakeRequest $request, CakeResponse $response) {
|
||||||
$Exception = new UnauthorizedException();
|
$Exception = new UnauthorizedException();
|
||||||
$Exception->responseHeader($this->loginHeaders());
|
$Exception->responseHeader(array($this->loginHeaders()));
|
||||||
throw $Exception;
|
throw $Exception;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -137,15 +137,14 @@ class BasicAuthenticateTest extends CakeTestCase {
|
||||||
$request = new CakeRequest('posts/index', false);
|
$request = new CakeRequest('posts/index', false);
|
||||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||||
|
|
||||||
$this->response->expects($this->at(0))
|
try {
|
||||||
->method('header')
|
$this->auth->unauthenticated($request, $this->response);
|
||||||
->with('WWW-Authenticate: Basic realm="localhost"');
|
} catch (UnauthorizedException $e) {}
|
||||||
|
|
||||||
$this->response->expects($this->at(1))
|
$this->assertNotEmpty($e);
|
||||||
->method('send');
|
|
||||||
|
|
||||||
$result = $this->auth->unauthenticated($request, $this->response);
|
$expected = array('WWW-Authenticate: Basic realm="localhost"');
|
||||||
$this->assertTrue($result);
|
$this->assertEquals($expected, $e->responseHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,6 +172,8 @@ class BasicAuthenticateTest extends CakeTestCase {
|
||||||
/**
|
/**
|
||||||
* test scope failure.
|
* test scope failure.
|
||||||
*
|
*
|
||||||
|
* @expectedException UnauthorizedException
|
||||||
|
* @expectedExceptionCode 401
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testAuthenticateFailReChallenge() {
|
public function testAuthenticateFailReChallenge() {
|
||||||
|
@ -183,18 +184,7 @@ class BasicAuthenticateTest extends CakeTestCase {
|
||||||
$_SERVER['PHP_AUTH_USER'] = 'mariano';
|
$_SERVER['PHP_AUTH_USER'] = 'mariano';
|
||||||
$_SERVER['PHP_AUTH_PW'] = 'password';
|
$_SERVER['PHP_AUTH_PW'] = 'password';
|
||||||
|
|
||||||
$this->response->expects($this->at(0))
|
$this->auth->unauthenticated($request, $this->response);
|
||||||
->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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,8 @@ class DigestAuthenticateTest extends CakeTestCase {
|
||||||
/**
|
/**
|
||||||
* test the authenticate method
|
* test the authenticate method
|
||||||
*
|
*
|
||||||
|
* @expectedException UnauthorizedException
|
||||||
|
* @expectedExceptionCode 401
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testAuthenticateWrongUsername() {
|
public function testAuthenticateWrongUsername() {
|
||||||
|
@ -121,18 +123,7 @@ response="6629fae49393a05397450978507c4ef1",
|
||||||
opaque="123abc"
|
opaque="123abc"
|
||||||
DIGEST;
|
DIGEST;
|
||||||
|
|
||||||
$this->response->expects($this->at(0))
|
$this->auth->unauthenticated($request, $this->response);
|
||||||
->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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,19 +135,14 @@ DIGEST;
|
||||||
$request = new CakeRequest('posts/index', false);
|
$request = new CakeRequest('posts/index', false);
|
||||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||||
|
|
||||||
$this->response->expects($this->at(0))
|
try {
|
||||||
->method('header')
|
$this->auth->unauthenticated($request, $this->response);
|
||||||
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
} catch (UnauthorizedException $e) {}
|
||||||
|
|
||||||
$this->response->expects($this->at(1))
|
$this->assertNotEmpty($e);
|
||||||
->method('statusCode')
|
|
||||||
->with(401);
|
|
||||||
|
|
||||||
$this->response->expects($this->at(2))
|
$expected = array('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
||||||
->method('send');
|
$this->assertEquals($expected, $e->responseHeader());
|
||||||
|
|
||||||
$result = $this->auth->unauthenticated($request, $this->response);
|
|
||||||
$this->assertTrue($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,6 +179,8 @@ DIGEST;
|
||||||
/**
|
/**
|
||||||
* test scope failure.
|
* test scope failure.
|
||||||
*
|
*
|
||||||
|
* @expectedException UnauthorizedException
|
||||||
|
* @expectedExceptionCode 401
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testAuthenticateFailReChallenge() {
|
public function testAuthenticateFailReChallenge() {
|
||||||
|
@ -212,18 +200,7 @@ response="6629fae49393a05397450978507c4ef1",
|
||||||
opaque="123abc"
|
opaque="123abc"
|
||||||
DIGEST;
|
DIGEST;
|
||||||
|
|
||||||
$this->response->expects($this->at(0))
|
$this->auth->unauthenticated($request, $this->response);
|
||||||
->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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1359,6 +1359,8 @@ class AuthComponentTest extends CakeTestCase {
|
||||||
/**
|
/**
|
||||||
* testStatelessAuthNoRedirect method
|
* testStatelessAuthNoRedirect method
|
||||||
*
|
*
|
||||||
|
* @expectedException UnauthorizedException
|
||||||
|
* @expectedExceptionCode 401
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testStatelessAuthNoRedirect() {
|
public function testStatelessAuthNoRedirect() {
|
||||||
|
@ -1372,18 +1374,7 @@ class AuthComponentTest extends CakeTestCase {
|
||||||
$this->Auth->authenticate = array('Basic');
|
$this->Auth->authenticate = array('Basic');
|
||||||
$this->Controller->request['action'] = 'admin_add';
|
$this->Controller->request['action'] = 'admin_add';
|
||||||
|
|
||||||
$this->Auth->response->expects($this->once())
|
$this->Auth->startup($this->Controller);
|
||||||
->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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue