‪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;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 final class ‪AbstractUserAuthenticationTest extends FunctionalTestCase
30 {
31  #[Test]
33  {
34  $sessionId = bin2hex(random_bytes(20));
35  $userSession = ‪UserSession::createNonFixated($sessionId);
36  $subject = new ‪AnyUserAuthentication($userSession);
37  $subject->pushModuleData(self::class, true);
38  self::assertNotContains($sessionId, $subject->uc['moduleSessionID']);
39  }
40 
41  #[Test]
43  {
44  $sessionId = bin2hex(random_bytes(20));
45  $userSession = ‪UserSession::createNonFixated($sessionId);
46  $subject = new ‪AnyUserAuthentication($userSession);
47  $subject->pushModuleData(self::class, true);
48  self::assertTrue($subject->getModuleData(self::class));
49  }
50 
51  #[Test]
53  {
54  $sessionId = bin2hex(random_bytes(20));
55  $userSession = ‪UserSession::createNonFixated($sessionId);
56  $subject = new ‪AnyUserAuthentication($userSession);
57  $subject->uc['moduleData'][self::class] = true;
58  $subject->uc['moduleSessionID'][self::class] = $sessionId;
59  self::assertTrue($subject->getModuleData(self::class));
60  }
61 
63  {
64  return [
65  ['', ''],
66  [null, ''],
67  [0, '0'],
68  ['0', '0'],
69  ['12,31', '12, 31'],
70  ];
71  }
72 
73  #[DataProvider('getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGivenDataProvider')]
74  #[Test]
76  int|null|string $checkPid_value,
77  string $expectedPids
78  ): void {
79  $sessionId = bin2hex(random_bytes(20));
80  $userSession = ‪UserSession::createNonFixated($sessionId);
81  $subject = new ‪AnyUserAuthentication($userSession);
82  $subject->user_table = 'be_users';
83  $subject->checkPid_value = $checkPid_value;
84  $authInfoArray = $subject->getAuthInfoArray(new ‪ServerRequest('https://example.com'));
85  $enableClause = $authInfoArray['db_user']['enable_clause'];
86  self::assertInstanceOf(CompositeExpression::class, $enableClause);
87  $connection = $this->get(ConnectionPool::class)->getConnectionForTable('be_users');
88  $expectedEnableClause = '';
89  if ($expectedPids !== '') {
90  $expectedEnableClause = $connection->quoteIdentifier('be_users.pid') . ' IN (' . $expectedPids . ')';
91  }
92  self::assertSame($expectedEnableClause, (string)$enableClause);
93  }
94 }
‪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:62
‪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:42
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest
Definition: AbstractUserAuthenticationTest.php:30
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\getModuleDataFallsBackToPlainSessionId
‪getModuleDataFallsBackToPlainSessionId()
Definition: AbstractUserAuthenticationTest.php:52
‪TYPO3\CMS\Core\Tests\Functional\Authentication
Definition: AbstractUserAuthenticationTest.php:18
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\pushModuleDataDoesNotRevealPlainSessionId
‪pushModuleDataDoesNotRevealPlainSessionId()
Definition: AbstractUserAuthenticationTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\Authentication\AbstractUserAuthenticationTest\getAuthInfoArrayReturnsCorrectPidConstraintForGivenCheckPidValue
‪getAuthInfoArrayReturnsCorrectPidConstraintForGivenCheckPidValue(int|null|string $checkPid_value, string $expectedPids)
Definition: AbstractUserAuthenticationTest.php:75
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46