mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API: add SecurityToken::reset() as a shortcut for regenerating a secure token.
See http://open.silverstripe.org/ticket/6303
This commit is contained in:
parent
23ed5335e6
commit
f9ea5430bb
@ -147,6 +147,13 @@ class SecurityToken extends Object implements TemplateGlobalProvider {
|
|||||||
Session::set($this->getName(), $val);
|
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.
|
* Checks for an existing CSRF token in the current users session.
|
||||||
* This check is automatically performed in {@link Form->httpSubmission()}
|
* This check is automatically performed in {@link Form->httpSubmission()}
|
||||||
@ -291,6 +298,5 @@ class NullSecurityToken extends SecurityToken {
|
|||||||
*/
|
*/
|
||||||
function generate() {
|
function generate() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -65,6 +65,14 @@ class SecurityTokenTest extends SapphireTest {
|
|||||||
$t->setValue('mytoken');
|
$t->setValue('mytoken');
|
||||||
$this->assertTrue($t->check('mytoken'), 'Valid token returns true');
|
$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() {
|
function testCheckRequest() {
|
||||||
$t = new SecurityToken();
|
$t = new SecurityToken();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user