class OneTimeAuthenticationTest
Same name and namespace in other branches
- 11.x core/modules/user/tests/src/Kernel/OneTimeAuthenticationTest.php \Drupal\Tests\user\Kernel\OneTimeAuthenticationTest
Tests OneTimeAuthentication service.
Attributes
#[Group('user')]
#[RunTestsInSeparateProcesses]
#[CoversClass(OneTimeAuthentication::class)]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\user\Kernel\OneTimeAuthenticationTest uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of OneTimeAuthenticationTest
File
-
core/
modules/ user/ tests/ src/ Kernel/ OneTimeAuthenticationTest.php, line 17
Namespace
Drupal\Tests\user\KernelView source
class OneTimeAuthenticationTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'user',
];
/**
* Tests uniqueness of hashes when no password is set.
*/
public function testUniqueHashNoPasswordValue() : void {
$this->installEntitySchema('user');
$timestamp = \Drupal::time()->getRequestTime();
$user_a = $this->createUser([], NULL, FALSE, [
'uid' => 12,
'mail' => '3user@example.com',
'login' => $timestamp - 1000,
]);
$user_b = $this->createUser([], NULL, FALSE, [
'uid' => 123,
'mail' => 'user@example.com',
'login' => $timestamp - 1000,
]);
// Unset passwords after the users are created in order to avoid
// (different) password hashes being generated for the empty strings.
$user_a->setPassword('');
$user_b->setPassword('');
$oneTimeAuthentication = \Drupal::service(OneTimeAuthentication::class);
$hash_a = $oneTimeAuthentication->generateHmac($user_a, $timestamp);
$hash_b = $oneTimeAuthentication->generateHmac($user_b, $timestamp);
$this->assertNotEquals($hash_a, $hash_b);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.