Skip to content

Commit

Permalink
Fix usage of addParams() across the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 1, 2017
1 parent 4f22837 commit 5f923ff
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 195 deletions.
14 changes: 8 additions & 6 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -383,7 +383,7 @@ protected function _unauthenticated(Controller $controller)
if ($auth === false) {
throw new Exception('At least one authenticate object must be available.');
}
$result = $auth->unauthenticated($this->request, $response);
$result = $auth->unauthenticated($controller->request, $response);
if ($result !== null) {
return $result;
}
Expand Down Expand Up @@ -535,7 +535,7 @@ public function isAuthorized($user = null, ServerRequest $request = null)
$user = $this->user();
}
if (empty($request)) {
$request = $this->request;
$request = $this->getController()->getRequest();
}
if (empty($this->_authorizeObjects)) {
$this->constructAuthorize();
Expand Down Expand Up @@ -749,7 +749,7 @@ protected function _getUser()
$this->constructAuthenticate();
}
foreach ($this->_authenticateObjects as $auth) {
$result = $auth->getUser($this->request);
$result = $auth->getUser($this->getController()->getRequest());
if (!empty($result) && is_array($result)) {
$this->_authenticationProvider = $auth;
$event = $this->dispatchEvent('Auth.afterIdentify', [$result, $auth]);
Expand Down Expand Up @@ -785,7 +785,7 @@ protected function _getUser()
*/
public function redirectUrl($url = null)
{
$redirectUrl = $this->request->getQuery(static::QUERY_STRING_REDIRECT);
$redirectUrl = $this->getController()->getRequest()->getQuery(static::QUERY_STRING_REDIRECT);
if ($redirectUrl && (substr($redirectUrl, 0, 1) !== '/' || substr($redirectUrl, 0, 2) === '//')) {
$redirectUrl = null;
}
Expand Down Expand Up @@ -825,7 +825,7 @@ public function identify()
$this->constructAuthenticate();
}
foreach ($this->_authenticateObjects as $auth) {
$result = $auth->authenticate($this->request, $this->response);
$result = $auth->authenticate($this->getController()->getRequest(), $this->response);
if (!empty($result)) {
$this->_authenticationProvider = $auth;
$event = $this->dispatchEvent('Auth.afterIdentify', [$result, $auth]);
Expand Down Expand Up @@ -911,7 +911,9 @@ public function storage(StorageInterface $storage = null)
if (!class_exists($className)) {
throw new Exception(sprintf('Auth storage adapter "%s" was not found.', $class));
}
$this->_storage = new $className($this->request, $this->response, $config);
$request = $this->getController()->getRequest();
$response = $this->getController()->getResponse();
$this->_storage = new $className($request, $response, $config);

return $this->_storage;
}
Expand Down
9 changes: 4 additions & 5 deletions src/Controller/Component/PaginatorComponent.php
Expand Up @@ -266,12 +266,11 @@ public function getPaginator()
*/
protected function _setPagingParams()
{
$request = $this->_registry->getController()->request;
$controller = $this->getController();
$request = $controller->getRequest();
$paging = $this->_paginator->getPagingParams() + (array)$request->getParam('paging');

$request->addParams([
'paging' => $this->_paginator->getPagingParams()
+ (array)$request->getParam('paging')
]);
$controller->setRequest($request->withParam('paging', $paging));
}

/**
Expand Down
6 changes: 1 addition & 5 deletions tests/TestCase/Auth/BasicAuthenticateTest.php
Expand Up @@ -129,9 +129,8 @@ public function testAuthenticateInjection()
'environment' => [
'PHP_AUTH_USER' => '> 1',
'PHP_AUTH_PW' => "' OR 1 = 1"
]
],
]);
$request->addParams(['pass' => []]);

$this->assertFalse($this->auth->getUser($request));
$this->assertFalse($this->auth->authenticate($request, $this->response));
Expand Down Expand Up @@ -172,7 +171,6 @@ public function testAuthenticateUsernameZero()
public function testAuthenticateChallenge()
{
$request = new ServerRequest('posts/index');
$request->addParams(['pass' => []]);

try {
$this->auth->unauthenticated($request, $this->response);
Expand All @@ -199,7 +197,6 @@ public function testAuthenticateSuccess()
'PHP_AUTH_PW' => 'password'
]
]);
$request->addParams(['pass' => []]);

$result = $this->auth->authenticate($request, $this->response);
$expected = [
Expand Down Expand Up @@ -228,7 +225,6 @@ public function testAuthenticateFailReChallenge()
'PHP_AUTH_PW' => 'password'
]
]);
$request->addParams(['pass' => []]);

$this->auth->unauthenticated($request, $this->response);
}
Expand Down
11 changes: 1 addition & 10 deletions tests/TestCase/Auth/DigestAuthenticateTest.php
Expand Up @@ -113,8 +113,7 @@ public function testAuthenticateWrongUsername()
{
$this->expectException(\Cake\Http\Exception\UnauthorizedException::class);
$this->expectExceptionCode(401);
$request = new ServerRequest('posts/index');
$request->addParams(['pass' => []]);
$request = new ServerRequest(['url' => 'posts/index']);

$data = [
'username' => 'incorrect_user',
Expand Down Expand Up @@ -142,7 +141,6 @@ public function testAuthenticateChallenge()
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);

try {
$this->auth->unauthenticated($request, $this->response);
Expand All @@ -169,7 +167,6 @@ public function testAuthenticateChallengeIncludesStaleAttributeOnStaleNonce()
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);
$data = [
'uri' => '/dir/index.html',
'nonce' => $this->generateNonce(null, 5, strtotime('-10 minutes')),
Expand Down Expand Up @@ -201,7 +198,6 @@ public function testAuthenticateFailsOnStaleNonce()
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);

$data = [
'uri' => '/dir/index.html',
Expand All @@ -227,7 +223,6 @@ public function testAuthenticateValidUsernamePasswordNoNonce()
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);

$data = [
'username' => 'mariano',
Expand Down Expand Up @@ -255,7 +250,6 @@ public function testAuthenticateSuccess()
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);

$data = [
'uri' => '/dir/index.html',
Expand Down Expand Up @@ -291,7 +285,6 @@ public function testAuthenticateSuccessHiddenPasswordField()
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);

$data = [
'uri' => '/dir/index.html',
Expand Down Expand Up @@ -325,7 +318,6 @@ public function testAuthenticateSuccessSimulatedRequestMethod()
'post' => ['_method' => 'PUT'],
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);

$data = [
'username' => 'mariano',
Expand Down Expand Up @@ -362,7 +354,6 @@ public function testAuthenticateFailReChallenge()
'url' => 'posts/index',
'environment' => ['REQUEST_METHOD' => 'GET']
]);
$request->addParams(['pass' => []]);

$data = [
'username' => 'invalid',
Expand Down

0 comments on commit 5f923ff

Please sign in to comment.