‪TYPO3CMS  ‪main
AbstractUserAuthenticationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
28 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
29 
30 final class ‪AbstractUserAuthenticationTest extends FunctionalTestCase
31 {
32  private string ‪$sessionId;
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '12345';
40  $this->sessionId = bin2hex(random_bytes(20));
41  $this->userSession = ‪UserSession::createNonFixated($this->sessionId);
42  $this->subject = new ‪AnyUserAuthentication($this->userSession);
43  }
44 
45  protected function ‪tearDown(): void
46  {
47  unset($this->sessionId, $this->userSession, $this->subject);
48  unset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
49  parent::tearDown();
50  }
51 
52  #[Test]
54  {
55  $this->subject->pushModuleData(self::class, true);
56  self::assertNotContains($this->sessionId, $this->subject->uc['moduleSessionID']);
57  }
58 
59  #[Test]
61  {
62  $this->subject->pushModuleData(self::class, true);
63  self::assertTrue($this->subject->getModuleData(self::class));
64  }
65 
66  #[Test]
68  {
69  $this->subject->uc['moduleData'][self::class] = true;
70  $this->subject->uc['moduleSessionID'][self::class] = ‪$this->sessionId;
71  self::assertTrue($this->subject->getModuleData(self::class));
72  }
73 
75  {
76  return [
77  ['', ''],
78  [null, ''],
79  [0, '0'],
80  ['0', '0'],
81  ['12,31', '12, 31'],
82  ];
83  }
84 
85  #[DataProvider('getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGivenDataProvider')]
86  #[Test]
88  int|null|string $checkPid_value,
89  string $expectedPids
90  ): void {
91  $this->subject->user_table = 'be_users';
92  $this->subject->checkPid_value = $checkPid_value;
93 
94  $authInfoArray = $this->subject->getAuthInfoArray(new ‪ServerRequest('https://example.com'));
95 
96  $enableClause = $authInfoArray['db_user']['enable_clause'];
97  self::assertInstanceOf(CompositeExpression::class, $enableClause);
98 
99  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('be_users');
100 
101  $expectedEnableClause = '';
102 
103  if ($expectedPids !== '') {
104  $expectedEnableClause = $connection->quoteIdentifier('be_users.pid') . ' IN (' . $expectedPids . ')';
105  }
106 
107  self::assertSame($expectedEnableClause, (string)$enableClause);
108  }
109 }
‪TYPO3\CMS\Core\Tests\Functional\Authentication\Fixtures\AnyUserAuthentication
Definition: AnyUserAuthentication.php:24
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGivenDataProvider
‪static getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGivenDataProvider()
Definition: AbstractUserAuthenticationTest.php:74
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\$sessionId
‪string $sessionId
Definition: AbstractUserAuthenticationTest.php:32
‪TYPO3\CMS\Core\Session\UserSession\createNonFixated
‪static createNonFixated(string $identifier)
Definition: UserSession.php:243
‪TYPO3\CMS\Core\Session\UserSession
Definition: UserSession.php:45
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\getModuleDataResolvesHashedSessionId
‪getModuleDataResolvesHashedSessionId()
Definition: AbstractUserAuthenticationTest.php:60
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest
Definition: AbstractUserAuthenticationTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\setUp
‪setUp()
Definition: AbstractUserAuthenticationTest.php:36
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\getModuleDataFallsBackToPlainSessionId
‪getModuleDataFallsBackToPlainSessionId()
Definition: AbstractUserAuthenticationTest.php:67
‪TYPO3\CMS\Core\Tests\Functional\Authentication
Definition: AbstractUserAuthenticationTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\$userSession
‪UserSession $userSession
Definition: AbstractUserAuthenticationTest.php:34
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\pushModuleDataDoesNotRevealPlainSessionId
‪pushModuleDataDoesNotRevealPlainSessionId()
Definition: AbstractUserAuthenticationTest.php:53
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\getAuthInfoArrayReturnsCorrectPidConstraintForGivenCheckPidValue
‪getAuthInfoArrayReturnsCorrectPidConstraintForGivenCheckPidValue(int|null|string $checkPid_value, string $expectedPids)
Definition: AbstractUserAuthenticationTest.php:87
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\tearDown
‪tearDown()
Definition: AbstractUserAuthenticationTest.php:45
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\$subject
‪AnyUserAuthentication $subject
Definition: AbstractUserAuthenticationTest.php:33