Skip to content
This repository
Browse code

API: add SecurityToken::reset() as a shortcut for regenerating a secu…

  • Loading branch information...
commit f9ea5430bbe25511dcccd7e0d5f4a31f951f329c 1 parent 23ed533
Will Rossiter authored July 01, 2012
12  security/SecurityToken.php
@@ -148,6 +148,13 @@ function setValue($val) {
148 148
 	}
149 149
 	
150 150
 	/**
  151
+	 * Reset the token to a new value.
  152
+	 */
  153
+	public function reset() {
  154
+		$this->setValue($this->generate());
  155
+	}
  156
+	
  157
+	/**
151 158
 	 * Checks for an existing CSRF token in the current users session.
152 159
 	 * This check is automatically performed in {@link Form->httpSubmission()}
153 160
 	 * if a form has security tokens enabled.
@@ -291,6 +298,5 @@ function setValue($val) {
291 298
 	 */
292 299
 	function generate() {
293 300
 		return null;
294  
-	}
295  
-	
296  
-}
  301
+	}	
  302
+}
8  tests/security/SecurityTokenTest.php
@@ -65,6 +65,14 @@ function testCheck() {
65 65
 		$t->setValue('mytoken');
66 66
 		$this->assertTrue($t->check('mytoken'), 'Valid token returns true');
67 67
 	}
  68
+
  69
+	function testReset() {
  70
+		$t = new SecurityToken();
  71
+		$initialValue = $t->getValue();
  72
+		$t->reset(); 
  73
+
  74
+		$this->assertNotEquals($t->getValue(), $initialValue);
  75
+	}
68 76
 	
69 77
 	function testCheckRequest() {
70 78
 		$t = new SecurityToken();

0 notes on commit f9ea543

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