Permalink
Browse files

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

  • Loading branch information...
1 parent 23ed533 commit f9ea5430bbe25511dcccd7e0d5f4a31f951f329c @wilr wilr committed Jul 1, 2012
Showing with 17 additions and 3 deletions.
  1. +9 −3 security/SecurityToken.php
  2. +8 −0 tests/security/SecurityTokenTest.php
View
@@ -148,6 +148,13 @@ function setValue($val) {
}
/**
+ * Reset the token to a new value.
+ */
+ public function reset() {
+ $this->setValue($this->generate());
+ }
+
+ /**
* Checks for an existing CSRF token in the current users session.
* This check is automatically performed in {@link Form->httpSubmission()}
* if a form has security tokens enabled.
@@ -291,6 +298,5 @@ function setValue($val) {
*/
function generate() {
return null;
- }
-
-}
+ }
+}
@@ -65,6 +65,14 @@ function testCheck() {
$t->setValue('mytoken');
$this->assertTrue($t->check('mytoken'), 'Valid token returns true');
}
+
+ function testReset() {
+ $t = new SecurityToken();
+ $initialValue = $t->getValue();
+ $t->reset();
+
+ $this->assertNotEquals($t->getValue(), $initialValue);
+ }
function testCheckRequest() {
$t = new SecurityToken();

0 comments on commit f9ea543

Please sign in to comment.