TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
BulkUpdateTaskTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Saltedpasswords\Tests\Functional\Task;
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 
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 
55  protected function setUp()
56  {
57  parent::setUp();
58  foreach ($this->xmlDatabaseFixtures as $fixture) {
59  $this->importDataSet($fixture);
60  }
61  $this->subject = GeneralUtility::makeInstance(BulkUpdateTask::class);
62  }
63 
70  {
71  $expectedOutput = [
72  [
73  'uid' => 1,
74  'password' => '$P$CDmA2Juu2h9/9MNaKaxtgzZgIVmjkh/'
75  ],
76  [
77  'uid' => 2,
78  'password' => 'M$v2AultVYItaCpb.tpdx2aGAue8eL3/'
79  ],
80  [
81  'uid' => 3,
82  'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
83  ],
84  [
85  'uid' => 4,
86  'password' => ''
87  ],
88  [
89  'uid' => 5,
90  'password' => '819b0643d6b89dc9b579fdfc9094f28e'
91  ],
92  [
93  'uid' => 6,
94  'password' => '34cc93ece0ba9e3f6f235d4af979b16c'
95  ]
96  ];
97 
98  $this->assertEquals($expectedOutput, $this->callInaccessibleMethod($this->subject, 'findUsersToUpdate', 'BE'));
99  }
100 
107  {
108  $expectedOutput = [
109  [
110  'uid' => 1,
111  'password' => '$P$CDmA2Juu2h9/9MNaKaxtgzZgIVmjkh/'
112  ],
113  [
114  'uid' => 2,
115  'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
116  ]
117  ];
118 
119  $this->assertEquals($expectedOutput, $this->callInaccessibleMethod($this->subject, 'findUsersToUpdate', 'FE'));
120  }
121 
128  {
129  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users');
130  $usersToBeUpdated = $queryBuilder
131  ->select('uid', 'password')
132  ->from('fe_users')
133  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)))
134  ->execute()
135  ->fetchAll();
136 
137  $originalMd5Password = $usersToBeUpdated[0]['password'];
138 
139  $this->callInaccessibleMethod($this->subject, 'updatePasswords', 'FE', $usersToBeUpdated);
140 
141  $saltedPassword = $queryBuilder
142  ->select('password')
143  ->from('fe_users')
144  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)))
145  ->execute()
146  ->fetchColumn();
147 
148  $this->assertNotEquals($originalMd5Password, $saltedPassword);
149 
150  $saltedPasswordsInstance = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance(substr($saltedPassword, 1));
151  $this->assertTrue($saltedPasswordsInstance->checkPassword($originalMd5Password, substr($saltedPassword, 1)));
152  }
153 }
callInaccessibleMethod($object, $name,...$arguments)
static getSaltingInstance($saltedHash= '', $mode=TYPO3_MODE)
Definition: SaltFactory.php:83
static makeInstance($className,...$constructorArguments)