TYPO3 CMS  TYPO3_8-7
BulkUpdateTaskTest.php
Go to the documentation of this file.
1 <?php
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 
20 
24 class BulkUpdateTaskTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
25 {
31  protected $xmlDatabaseFixtures = [
32  'typo3/sysext/saltedpasswords/Tests/Functional/Fixtures/be_users.xml',
33  'typo3/sysext/saltedpasswords/Tests/Functional/Fixtures/fe_users.xml'
34  ];
35 
41  protected $testExtensionsToLoad = [
42  'typo3/sysext/scheduler'
43  ];
44 
48  protected $subject;
49 
53  protected function setUp()
54  {
55  parent::setUp();
56  foreach ($this->xmlDatabaseFixtures as $fixture) {
57  $this->importDataSet($fixture);
58  }
59  $this->subject = GeneralUtility::makeInstance(BulkUpdateTask::class);
60  }
61 
68  {
69  $expectedOutput = [
70  [
71  'uid' => 1,
72  'password' => '$P$CDmA2Juu2h9/9MNaKaxtgzZgIVmjkh/'
73  ],
74  [
75  'uid' => 2,
76  'password' => 'M$v2AultVYItaCpb.tpdx2aGAue8eL3/'
77  ],
78  [
79  'uid' => 3,
80  'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
81  ],
82  [
83  'uid' => 4,
84  'password' => ''
85  ],
86  [
87  'uid' => 5,
88  'password' => '819b0643d6b89dc9b579fdfc9094f28e'
89  ],
90  [
91  'uid' => 6,
92  'password' => '34cc93ece0ba9e3f6f235d4af979b16c'
93  ]
94  ];
95 
96  $this->assertEquals($expectedOutput, $this->callInaccessibleMethod($this->subject, 'findUsersToUpdate', 'BE'));
97  }
98 
105  {
106  $expectedOutput = [
107  [
108  'uid' => 1,
109  'password' => '$P$CDmA2Juu2h9/9MNaKaxtgzZgIVmjkh/'
110  ],
111  [
112  'uid' => 2,
113  'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
114  ]
115  ];
116 
117  $this->assertEquals($expectedOutput, $this->callInaccessibleMethod($this->subject, 'findUsersToUpdate', 'FE'));
118  }
119 
126  {
127  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users');
128  $usersToBeUpdated = $queryBuilder
129  ->select('uid', 'password')
130  ->from('fe_users')
131  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)))
132  ->execute()
133  ->fetchAll();
134 
135  $originalMd5Password = $usersToBeUpdated[0]['password'];
136 
137  $this->callInaccessibleMethod($this->subject, 'updatePasswords', 'FE', $usersToBeUpdated);
138 
139  $saltedPassword = $queryBuilder
140  ->select('password')
141  ->from('fe_users')
142  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)))
143  ->execute()
144  ->fetchColumn();
145 
146  $this->assertNotEquals($originalMd5Password, $saltedPassword);
147 
148  $saltedPasswordsInstance = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance(substr($saltedPassword, 1));
149  $this->assertTrue($saltedPasswordsInstance->checkPassword($originalMd5Password, substr($saltedPassword, 1)));
150  }
151 }
static getSaltingInstance($saltedHash='', $mode=TYPO3_MODE)
Definition: SaltFactory.php:83
static makeInstance($className,... $constructorArguments)