Browse Source

SecurityComponent::requireSecure() should accept empty argument

spiliot 11 years ago
parent
commit
cf84947d09

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

@@ -147,7 +147,7 @@ class SecurityComponent extends Component {
  * @return void
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requireSecure
  */
-	public function requireSecure($actions) {
+	public function requireSecure($actions = null) {
 		$this->_requireMethod('Secure', (array)$actions);
 	}
 

+ 32 - 2
tests/TestCase/Controller/Component/SecurityComponentTest.php

@@ -236,8 +236,8 @@ class SecurityComponentTest extends TestCase {
 	public function testRequireSecureFail() {
 		$_SERVER['HTTPS'] = 'off';
 		$_SERVER['REQUEST_METHOD'] = 'POST';
-		$event = new Event('Controller.startup', $this->Controller);
 		$this->Controller->request['action'] = 'posted';
+		$event = new Event('Controller.startup', $this->Controller);
 		$this->Controller->Security->requireSecure(array('posted'));
 		$this->Controller->Security->startup($event);
 		$this->assertTrue($this->Controller->failed);
@@ -249,9 +249,9 @@ class SecurityComponentTest extends TestCase {
  * @return void
  */
 	public function testRequireSecureSucceed() {
+		$_SERVER['HTTPS'] = 'on';
 		$_SERVER['REQUEST_METHOD'] = 'Secure';
 		$this->Controller->request['action'] = 'posted';
-		$_SERVER['HTTPS'] = 'on';
 		$event = new Event('Controller.startup', $this->Controller);
 		$this->Controller->Security->requireSecure('posted');
 		$this->Controller->Security->startup($event);
@@ -259,6 +259,36 @@ class SecurityComponentTest extends TestCase {
 	}
 
 /**
+ * testRequireSecureEmptyFail method
+ *
+ * @return void
+ */
+	public function testRequireSecureEmptyFail() {
+		$_SERVER['HTTPS'] = 'off';
+		$_SERVER['REQUEST_METHOD'] = 'POST';
+		$this->Controller->request['action'] = 'posted';
+		$event = new Event('Controller.startup', $this->Controller);
+		$this->Controller->Security->requireSecure();
+		$this->Controller->Security->startup($event);
+		$this->assertTrue($this->Controller->failed);
+	}
+
+/**
+ * testRequireSecureEmptySucceed method
+ *
+ * @return void
+ */
+	public function testRequireSecureEmptySucceed() {
+		$_SERVER['HTTPS'] = 'on';
+		$_SERVER['REQUEST_METHOD'] = 'Secure';
+		$this->Controller->request['action'] = 'posted';
+		$event = new Event('Controller.startup', $this->Controller);
+		$this->Controller->Security->requireSecure();
+		$this->Controller->Security->startup($event);
+		$this->assertFalse($this->Controller->failed);
+	}
+
+/**
  * testRequireAuthFail method
  *
  * @return void