‪TYPO3CMS  ‪main
NotCurrentPasswordValidatorTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪NotCurrentPasswordValidatorTest extends FunctionalTestCase
29 {
33  protected bool ‪$initializeDatabase = false;
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  ‪$GLOBALS['LANG'] = $this->getMockBuilder(LanguageService::class)
39  ->disableOriginalConstructor()
40  ->onlyMethods(['sL'])
41  ->getMock();
42  }
43 
44  #[Test]
46  {
47  $knownPasswordHash = GeneralUtility::makeInstance(PasswordHashFactory::class)
48  ->getDefaultHashInstance('BE')
49  ->getHashedPassword('password');
50 
52 
53  $contextData = new ‪ContextData(loginMode: 'BE', currentPasswordHash: $knownPasswordHash);
54  self::assertFalse(‪$validator->validate('password', $contextData));
55  }
56 
57  #[Test]
59  {
60  $this->expectException(\RuntimeException::class);
61  $this->expectExceptionCode(1649846004);
62 
64  $contextData = new ‪ContextData(loginMode: 'INVALID');
65  ‪$validator->validate('password', $contextData);
66  }
67 
68  #[Test]
70  {
71  $knownPasswordHash = GeneralUtility::makeInstance(PasswordHashFactory::class)
72  ->getDefaultHashInstance('FE')
73  ->getHashedPassword('password');
74 
76  $contextData = new ‪ContextData(loginMode: 'FE', currentPasswordHash: $knownPasswordHash);
77 
78  self::assertFalse(‪$validator->validate('password', $contextData));
79  }
80 }
‪TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory
Definition: PasswordHashFactory.php:27
‪TYPO3\CMS\Core\Tests\Functional\PasswordPolicy\Validator\NotCurrentPasswordValidatorTest\validatorReturnsFalseIfPasswordIsEqualToCurrentPasswordForBackendUser
‪validatorReturnsFalseIfPasswordIsEqualToCurrentPasswordForBackendUser()
Definition: NotCurrentPasswordValidatorTest.php:45
‪TYPO3\CMS\Core\Tests\Functional\PasswordPolicy\Validator\NotCurrentPasswordValidatorTest\validatorReturnsFalseIfPasswordIsEqualToCurrentPasswordForFrontendUser
‪validatorReturnsFalseIfPasswordIsEqualToCurrentPasswordForFrontendUser()
Definition: NotCurrentPasswordValidatorTest.php:69
‪TYPO3\CMS\Core\PasswordPolicy\Validator\NotCurrentPasswordValidator
Definition: NotCurrentPasswordValidator.php:31
‪TYPO3\CMS\Core\Tests\Functional\PasswordPolicy\Validator\NotCurrentPasswordValidatorTest
Definition: NotCurrentPasswordValidatorTest.php:29
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:262
‪TYPO3\CMS\Core\Tests\Functional\PasswordPolicy\Validator\NotCurrentPasswordValidatorTest\$initializeDatabase
‪bool $initializeDatabase
Definition: NotCurrentPasswordValidatorTest.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Tests\Functional\PasswordPolicy\Validator\NotCurrentPasswordValidatorTest\setUp
‪setUp()
Definition: NotCurrentPasswordValidatorTest.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\PasswordPolicy\Validator\NotCurrentPasswordValidatorTest\validatorThrowsExpectedExceptionIfNoUnsupportedLoginMode
‪validatorThrowsExpectedExceptionIfNoUnsupportedLoginMode()
Definition: NotCurrentPasswordValidatorTest.php:58
‪TYPO3\CMS\Core\PasswordPolicy\Validator\Dto\ContextData
Definition: ContextData.php:28
‪TYPO3\CMS\Core\Tests\Functional\PasswordPolicy\Validator
Definition: NotCurrentPasswordValidatorTest.php:18