[TASK] Replace assertion method to use dedicated method
[Packages/TYPO3.CMS.git] / typo3 / sysext / saltedpasswords / Tests / Unit / Evaluation / EvaluatorTest.php
1 <?php
2 namespace TYPO3\CMS\Saltedpasswords\Tests\Unit\Evaluation;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Saltedpasswords\Evaluation\Evaluator;
19
20 /**
21 * Testcase for SaltedPasswordsUtility
22 */
23 class EvaluatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
24 {
25 /**
26 * @var Evaluator
27 */
28 protected $subject;
29
30 /**
31 * Set up the a test
32 */
33 protected function setUp()
34 {
35 $this->subject = $this->getMock(Evaluator::class, array('dummy'));
36
37 // Make sure SaltedPasswordsUtility::isUsageEnabled() returns TRUE
38 unset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords']);
39 $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] = 'rsa';
40 }
41
42 /**
43 * @test
44 */
45 public function passwordIsTurnedIntoSaltedString()
46 {
47 $isSet = null;
48 $originalPassword = 'password';
49 $saltedPassword = $this->subject->evaluateFieldValue($originalPassword, '', $isSet);
50 $this->assertTrue($isSet);
51 $this->assertNotEquals($originalPassword, $saltedPassword);
52 $this->assertTrue(GeneralUtility::inList('$1$,$2$,$2a,$P$', substr($saltedPassword, 0, 3)));
53 }
54
55 /**
56 * @test
57 */
58 public function md5HashIsUpdatedToTemporarySaltedString()
59 {
60 $isSet = null;
61 $originalPassword = '5f4dcc3b5aa765d61d8327deb882cf99';
62 $saltedPassword = $this->subject->evaluateFieldValue($originalPassword, '', $isSet);
63 $this->assertTrue($isSet);
64 $this->assertNotEquals($originalPassword, $saltedPassword);
65 $this->assertTrue(GeneralUtility::isFirstPartOfStr($saltedPassword, 'M$'));
66 }
67
68 /**
69 * @test
70 */
71 public function temporarySaltedStringIsNotTouched()
72 {
73 $isSet = null;
74 $originalPassword = 'M$P$CibIRipvLfaPlaaeH8ifu9g21BrPjp.';
75 $saltedPassword = $this->subject->evaluateFieldValue($originalPassword, '', $isSet);
76 $this->assertNull($isSet);
77 $this->assertSame($originalPassword, $saltedPassword);
78 }
79 }