Skip to content

Commit

Permalink
Making the various SecurityComponent::requireXX methods accept a sing…
Browse files Browse the repository at this point in the history
…le array or a list of strings as their arguments. Unifies the use of these functions with AuthComponent. Fixes #354
  • Loading branch information
markstory committed Dec 2, 2009
1 parent 0b13e3d commit 16f6d4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cake/libs/controller/components/security.php
Expand Up @@ -429,6 +429,9 @@ function blackHole(&$controller, $error = '') {
* @access protected
*/
function _requireMethod($method, $actions = array()) {
if (isset($actions[0]) && is_array($actions[0])) {
$actions = $actions[0];
}
$this->{'require' . $method} = (empty($actions)) ? array('*'): $actions;
}

Expand Down
14 changes: 7 additions & 7 deletions cake/tests/cases/libs/controller/components/security.test.php
Expand Up @@ -190,7 +190,7 @@ function testStartup() {
function testRequirePostFail() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->Controller->action = 'posted';
$this->Controller->Security->requirePost('posted');
$this->Controller->Security->requirePost(array('posted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ function testRequireSecureFail() {
$_SERVER['HTTPS'] = 'off';
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->action = 'posted';
$this->Controller->Security->requireSecure('posted');
$this->Controller->Security->requireSecure(array('posted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ function testRequireAuthFail() {
$_SERVER['REQUEST_METHOD'] = 'AUTH';
$this->Controller->action = 'posted';
$this->Controller->data = array('username' => 'willy', 'password' => 'somePass');
$this->Controller->Security->requireAuth('posted');
$this->Controller->Security->requireAuth(array('posted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);

Expand Down Expand Up @@ -321,7 +321,7 @@ function testRequirePostSucceedWrongMethod() {
function testRequireGetFail() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->action = 'getted';
$this->Controller->Security->requireGet('getted');
$this->Controller->Security->requireGet(array('getted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
Expand Down Expand Up @@ -360,7 +360,7 @@ function testRequireLogin() {

$this->Controller->action = 'posted';
$this->Controller->Security->requireLogin(
'posted',
array('posted'),
array('type' => 'basic', 'users' => array('admin' => 'password'))
);
$_SERVER['PHP_AUTH_USER'] = 'admin2';
Expand Down Expand Up @@ -437,7 +437,7 @@ function testRequireGetSucceedWrongMethod() {
function testRequirePutFail() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->action = 'putted';
$this->Controller->Security->requirePut('putted');
$this->Controller->Security->requirePut(array('putted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
Expand Down Expand Up @@ -479,7 +479,7 @@ function testRequirePutSucceedWrongMethod() {
function testRequireDeleteFail() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->action = 'deleted';
$this->Controller->Security->requireDelete('deleted');
$this->Controller->Security->requireDelete(array('deleted', 'other_method'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
Expand Down

0 comments on commit 16f6d4d

Please sign in to comment.