Browse Source

Fix an issue where custom Auth config would cause errors.

When the params key is omitted from the AuthComponent config a fatal
error would happen.
mark_story 11 years ago
parent
commit
b01ef90b54

+ 5 - 1
src/Controller/Component/AuthComponent.php

@@ -775,7 +775,11 @@ class AuthComponent extends Component {
 		}
 		$flashConfig = $this->_config['flash'];
 		$key = $flashConfig['key'];
-		$this->session->flash($message, 'error', $flashConfig['params'] + compact('key'));
+		$params = [];
+		if (isset($flashConfig['params'])) {
+			$params = $flashConfig['params'];
+		}
+		$this->session->flash($message, 'error', $params + compact('key'));
 	}
 
 }

+ 10 - 1
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -1141,15 +1141,24 @@ class AuthComponentTest extends TestCase {
  */
 	public function testFlashSettings() {
 		$this->Auth->session = $this->getMock('Cake\Network\Session');
-		$this->Auth->session->expects($this->once())
+		$this->Auth->session->expects($this->at(0))
 			->method('flash')
 			->with('Auth failure', 'error', array('key' => 'auth-key', 'element' => 'custom'));
 
+		$this->Auth->session->expects($this->at(1))
+			->method('flash')
+			->with('Auth failure', 'error', array('key' => 'auth-key'));
+
 		$this->Auth->config('flash', [
 			'params' => array('element' => 'custom'),
 			'key' => 'auth-key'
 		]);
 		$this->Auth->flash('Auth failure');
+
+		$this->Auth->config('flash', [
+			'key' => 'auth-key'
+		], false);
+		$this->Auth->flash('Auth failure');
 	}
 
 /**