Browse Source

Merge pull request #8575 from justinyost/b/correct-exception-on-post-validate

Change Exception Throw When SecurityComponent ValidatePost Fails to match documentation.

Fixes #8574
Mark Story 10 years ago
parent
commit
80b9050c57

+ 2 - 2
src/Controller/Component/SecurityComponent.php

@@ -313,7 +313,7 @@ class SecurityComponent extends Component
      * Validate submitted form
      *
      * @param \Cake\Controller\Controller $controller Instantiating controller
-     * @throws \Cake\Controller\Exception\SecurityException
+     * @throws \Cake\Controller\Exception\AuthSecurityException
      * @return bool true if submitted form is valid
      */
     protected function _validatePost(Controller $controller)
@@ -334,7 +334,7 @@ class SecurityComponent extends Component
             $msg = $this->_debugPostTokenNotMatching($controller, $hashParts);
         }
 
-        throw new SecurityException($msg);
+        throw new AuthSecurityException($msg);
     }
 
     /**

+ 3 - 3
tests/TestCase/Controller/Component/SecurityComponentTest.php

@@ -477,7 +477,7 @@ class SecurityComponentTest extends TestCase
             'Model' => ['username' => 'nate', 'password' => 'foo', 'valid' => '0'],
             '_Token' => compact('fields', 'unlocked', 'debug')
         ];
-        $this->assertFalse($this->validatePost('SecurityException', 'Unexpected field \'Model.password\' in POST data, Unexpected field \'Model.username\' in POST data'));
+        $this->assertFalse($this->validatePost('AuthSecurityException', 'Unexpected field \'Model.password\' in POST data, Unexpected field \'Model.username\' in POST data'));
     }
 
     /**
@@ -498,7 +498,7 @@ class SecurityComponentTest extends TestCase
             'Model' => ['username' => 'nate', 'password' => 'foo', 'valid' => '0'],
             '_Token' => compact('fields')
         ];
-        $this->assertFalse($this->validatePost('SecurityException', '\'_Token.unlocked\' was not found in request data.'));
+        $this->assertFalse($this->validatePost('AuthSecurityException', '\'_Token.unlocked\' was not found in request data.'));
     }
 
     /**
@@ -517,7 +517,7 @@ class SecurityComponentTest extends TestCase
             'Model' => ['username' => 'nate', 'password' => 'foo', 'valid' => '0'],
             '_Token' => compact('unlocked')
         ];
-        $result = $this->validatePost('SecurityException', '\'_Token.fields\' was not found in request data.');
+        $result = $this->validatePost('AuthSecurityException', '\'_Token.fields\' was not found in request data.');
         $this->assertFalse($result, 'validatePost passed when fields were missing. %s');
     }