Skip to content
This repository
Browse code

Fixing camel cased methods in checks for allowedActions in AuthCompon…

…ent under PHP5. Normalizes to lowercase method name. Fixes #6142

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8205 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 8c7883fe3efa87941b239e377b59933299e641a7 1 parent 6a34c9e
Mark Story authored June 30, 2009
6  cake/libs/controller/components/auth.php
@@ -263,6 +263,8 @@ function initialize(&$controller) {
263 263
  */
264 264
 	function startup(&$controller) {
265 265
 		$methods = array_flip($controller->methods);
  266
+		$controllerAction = strtolower($controller->params['action']);
  267
+
266 268
 		$isErrorOrTests = (
267 269
 			strtolower($controller->name) == 'cakeerror' ||
268 270
 			(strtolower($controller->name) == 'tests' && Configure::read() > 0)
@@ -273,7 +275,7 @@ function startup(&$controller) {
273 275
 
274 276
 		$isMissingAction = (
275 277
 			$controller->scaffold === false &&
276  
-			!isset($methods[strtolower($controller->params['action'])])
  278
+			!isset($methods[$controllerAction])
277 279
 		);
278 280
 
279 281
 		if ($isMissingAction) {
@@ -295,7 +297,7 @@ function startup(&$controller) {
295 297
 
296 298
 		$isAllowed = (
297 299
 			$this->allowedActions == array('*') ||
298  
-			in_array($controller->params['action'], $this->allowedActions)
  300
+			isset($methods[$controllerAction])
299 301
 		);
300 302
 
301 303
 		if ($loginAction != $url && $isAllowed) {
25  cake/tests/cases/libs/controller/components/auth.test.php
@@ -728,7 +728,32 @@ function testAllowDenyAll() {
728 728
 		$this->Controller->params['action'] = 'Add';
729 729
 		$this->assertFalse($this->Controller->Auth->startup($this->Controller));
730 730
 	}
  731
+/**
  732
+ * test that allow() and allowedActions work with camelCase method names.
  733
+ *
  734
+ * @return void
  735
+ **/
  736
+	function testAllowedActionsWithCamelCaseMethods() {
  737
+		$url = '/auth_test/camelCase';
  738
+		$this->Controller->params = Router::parse($url);
  739
+		$this->Controller->params['url']['url'] = Router::normalize($url);
  740
+		$this->Controller->Auth->initialize($this->Controller);
  741
+		$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
  742
+		$this->Controller->Auth->userModel = 'AuthUser';
  743
+		$this->Controller->Auth->allow('*');
  744
+		$result = $this->Controller->Auth->startup($this->Controller);
  745
+		$this->assertTrue($result, 'startup() should return true, as action is allowed. %s');
731 746
 
  747
+		$url = '/auth_test/camelCase';
  748
+		$this->Controller->params = Router::parse($url);
  749
+		$this->Controller->params['url']['url'] = Router::normalize($url);
  750
+		$this->Controller->Auth->initialize($this->Controller);
  751
+		$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
  752
+		$this->Controller->Auth->userModel = 'AuthUser';
  753
+		$this->Controller->Auth->allowedActions = array('delete', 'camelCase', 'add');
  754
+		$result = $this->Controller->Auth->startup($this->Controller);
  755
+		$this->assertTrue($result, 'startup() should return true, as action is allowed. %s');
  756
+	}
732 757
 /**
733 758
  * testLoginRedirect method
734 759
  *

0 notes on commit 8c7883f

Please sign in to comment.
Something went wrong with that request. Please try again.