[TASK] Use name-resolution instead of strings where possible: 9
[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 /**
18 * Testcase for SaltedPasswordsUtility
19 *
20 * @author Marcus Krause <marcus#exp2009@t3sec.info>
21 */
22 class EvaluatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Saltedpasswords\Evaluation\Evaluator
26 */
27 protected $fixture;
28
29 public function setUp() {
30 $this->fixture = $this->getMock(\TYPO3\CMS\Saltedpasswords\Evaluation\Evaluator::class, array('dummy'));
31
32 // Make sure SaltedPasswordsUtility::isUsageEnabled() returns TRUE
33 unset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords']);
34 $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] = 'rsa';
35 }
36
37 /**
38 * @test
39 */
40 public function passwordIsTurnedIntoSaltedString() {
41 $isSet = NULL;
42 $originalPassword = 'password';
43 $saltedPassword = $this->fixture->evaluateFieldValue($originalPassword, '', $isSet);
44 $this->assertTrue($isSet);
45 $this->assertNotEquals($originalPassword, $saltedPassword);
46 $this->assertTrue(\TYPO3\CMS\Core\Utility\GeneralUtility::inList('$1$,$2$,$2a,$P$', substr($saltedPassword, 0, 3)));
47 }
48
49 /**
50 * @test
51 */
52 public function md5HashIsUpdatedToTemporarySaltedString() {
53 $isSet = NULL;
54 $originalPassword = '5f4dcc3b5aa765d61d8327deb882cf99';
55 $saltedPassword = $this->fixture->evaluateFieldValue($originalPassword, '', $isSet);
56 $this->assertTrue($isSet);
57 $this->assertNotEquals($originalPassword, $saltedPassword);
58 $this->assertTrue(\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($saltedPassword, 'M$'));
59 }
60
61 /**
62 * @test
63 */
64 public function temporarySaltedStringIsNotTouched() {
65 $isSet = NULL;
66 $originalPassword = 'M$P$CibIRipvLfaPlaaeH8ifu9g21BrPjp.';
67 $saltedPassword = $this->fixture->evaluateFieldValue($originalPassword, '', $isSet);
68 $this->assertFalse($isSet);
69 $this->assertSame($originalPassword, $saltedPassword);
70 }
71 }