diff --git a/core/includes/common.inc b/core/includes/common.inc index eb1a51c..5ad4dbc 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3056,7 +3056,7 @@ function drupal_get_private_key() { * @deprecated as of Drupal 8.0. Use the csrf_token service instead. */ function drupal_get_token($value = '') { - return \Drupal::csrfToken()->getToken($value); + return \Drupal::csrfToken()->get($value); } /** @@ -3078,7 +3078,7 @@ function drupal_get_token($value = '') { * @deprecated as of Drupal 8.0. Use the csrf_token service instead. */ function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) { - return \Drupal::csrfToken()->validateToken($token, $value, $skip_anonymous); + return \Drupal::csrfToken()->validate($token, $value, $skip_anonymous); } /** diff --git a/core/lib/Drupal/Core/Access/CsrfTokenManager.php b/core/lib/Drupal/Core/Access/CsrfTokenManager.php index efb4575..5adf613 100644 --- a/core/lib/Drupal/Core/Access/CsrfTokenManager.php +++ b/core/lib/Drupal/Core/Access/CsrfTokenManager.php @@ -86,7 +86,7 @@ public function setPrivateKey($key) { * @return string * The private key. */ - public function createPrivateKey() { + protected function createPrivateKey() { return Crypt::randomStringHashed(55); } @@ -103,7 +103,7 @@ public function createPrivateKey() { * * @see drupal_get_hash_salt() */ - public function getToken($value = '') { + public function get($value = '') { return Crypt::hmacBase64($value, session_id() . $this->getPrivateKey() . drupal_get_hash_salt()); } @@ -121,10 +121,10 @@ public function getToken($value = '') { * TRUE for a valid token, FALSE for an invalid token. When $skip_anonymous * is TRUE, the return value will always be TRUE for anonymous users. */ - public function validateToken($token, $value = '', $skip_anonymous = FALSE) { + public function validate($token, $value = '', $skip_anonymous = FALSE) { $user = $this->request->attributes->get('account'); - return ($skip_anonymous && $user->id() == 0) || ($token == $this->getToken($value)); + return ($skip_anonymous && $user->id() == 0) || ($token == $this->get($value)); } } diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenManagerTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenManagerTest.php index a3d7e5a..506a63c 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenManagerTest.php @@ -35,7 +35,7 @@ function setUp() { $this->state = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface'); - $this->manager = new CsrfTokenManager($this->state, new Request()); + $this->manager = new CsrfTokenManager($this->state); $this->manager->setRequest(new Request()); } @@ -66,38 +66,31 @@ public function testSetPrivateKey() { } /** - * Tests CsrfTokenManager::createPrivateKey(). - */ - public function testCreatePrivateKey() { - $this->assertInternalType('string', $this->manager->createPrivateKey()); - } - - /** * Tests CsrfTokenManager::getToken(). * * @depends testGetPrivateKey */ - public function testGetToken() { + public function testGet() { $this->mockAllStateMethods(); - $this->assertInternalType('string', $this->manager->getToken()); - $this->assertNotSame($this->manager->getToken(), $this->manager->getToken($this->randomName())); + $this->assertInternalType('string', $this->manager->get()); + $this->assertNotSame($this->manager->get(), $this->manager->get($this->randomName())); } /** * Tests CsrfTokenManager::validateToken(). * - * @depends testGetToken + * @depends testGet */ - public function testValidateToken() { + public function testValidate() { $this->mockAllStateMethods(); - $token = $this->manager->getToken(); - $this->assertTrue($this->manager->validateToken($token)); - $this->assertFalse($this->manager->validateToken($token, 'foo')); + $token = $this->manager->get(); + $this->assertTrue($this->manager->validate($token)); + $this->assertFalse($this->manager->validate($token, 'foo')); - $token = $this->manager->getToken('bar'); - $this->assertTrue($this->manager->validateToken($token, 'bar')); + $token = $this->manager->get('bar'); + $this->assertTrue($this->manager->validate($token, 'bar')); } /**