‪TYPO3CMS  9.5
InstallToolFormProtectionTest.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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪InstallToolFormProtectionTest extends UnitTestCase
23 {
27  protected ‪$subject;
28 
32  protected function ‪setUp()
33  {
34  $this->subject = $this->getAccessibleMock(
35  \‪TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class,
36  ['dummy']
37  );
38  }
39 
41  // Tests concerning the reading and saving of the tokens
43 
48  {
49  $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
50  $formName = 'foo';
51  $action = 'edit';
52  $formInstanceName = '42';
53 
54  $tokenId = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($formName . $action . $formInstanceName . $sessionToken);
55 
56  $_SESSION['installToolFormToken'] = $sessionToken;
57 
58  $this->subject->_call('retrieveSessionToken');
59 
60  $this->assertTrue(
61  $this->subject->validateToken($tokenId, $formName, $action, $formInstanceName)
62  );
63  }
64 
69  {
70  $_SESSION['installToolFormToken'] = 'foo';
71 
72  $this->subject->_set('sessionToken', '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd');
73 
74  $this->subject->persistSessionToken();
75 
76  $this->assertEquals(
77  '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
78  $_SESSION['installToolFormToken']
79  );
80  }
81 }
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\setUp
‪setUp()
Definition: InstallToolFormProtectionTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\persistSessionTokenWritesTokensToSession
‪persistSessionTokenWritesTokensToSession()
Definition: InstallToolFormProtectionTest.php:67
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\tokenFromSessionDataIsAvailableForValidateToken
‪tokenFromSessionDataIsAvailableForValidateToken()
Definition: InstallToolFormProtectionTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\$subject
‪TYPO3 CMS Core FormProtection InstallToolFormProtection PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $subject
Definition: InstallToolFormProtectionTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\FormProtection
Definition: AbstractFormProtectionTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest
Definition: InstallToolFormProtectionTest.php:23