mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #606 from willrossi/trac6303
API: add SecurityToken::reset() as a shortcut for regenerating a token.
This commit is contained in:
commit
95e4057e21
@ -147,6 +147,13 @@ class SecurityToken extends Object implements TemplateGlobalProvider {
|
||||
Session::set($this->getName(), $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()}
|
||||
@ -292,5 +299,4 @@ class NullSecurityToken extends SecurityToken {
|
||||
function generate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -66,6 +66,14 @@ class SecurityTokenTest extends SapphireTest {
|
||||
$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();
|
||||
$n = $t->getName();
|
||||
|
Loading…
Reference in New Issue
Block a user