‪TYPO3CMS  ‪main
IpLockerTest.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;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 final class ‪IpLockerTest extends UnitTestCase
30 {
31  public static function ‪getSessionIpLockDataProvider(): array
32  {
33  return [
34  'basic IPv4-locks, part-count 0' => [
35  '192.168.0.1',
36  0,
37  8,
38  '[DISABLED]',
39  ],
40  'basic IPv4-locks, part-count 1' => [
41  '192.168.0.1',
42  1,
43  8,
44  '192.0.0.0',
45  ],
46  'basic IPv4-locks, part-count 2' => [
47  '192.168.0.1',
48  2,
49  8,
50  '192.168.0.0',
51  ],
52  'basic IPv4-locks, part-count 3' => [
53  '192.168.0.1',
54  3,
55  8,
56  '192.168.0.0',
57  ],
58  'basic IPv4-locks, part-count 4' => [
59  '192.168.0.1',
60  4,
61  8,
62  '192.168.0.1',
63  ],
64  'basic IPv6-locks, part-count 0' => [
65  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
66  4,
67  0,
68  '[DISABLED]',
69  ],
70  'basic IPv6-locks, part-count 1' => [
71  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
72  4,
73  1,
74  '2001:0000:0000:0000:0000:0000:0000:0000',
75  ],
76  'basic IPv6-locks, part-count 2' => [
77  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
78  4,
79  2,
80  '2001:0db8:0000:0000:0000:0000:0000:0000',
81  ],
82  'basic IPv6-locks, part-count 3' => [
83  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
84  4,
85  3,
86  '2001:0db8:85a3:0000:0000:0000:0000:0000',
87  ],
88  'basic IPv6-locks, part-count 4' => [
89  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
90  4,
91  4,
92  '2001:0db8:85a3:08d3:0000:0000:0000:0000',
93  ],
94  'basic IPv6-locks, part-count 5' => [
95  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
96  4,
97  5,
98  '2001:0db8:85a3:08d3:1319:0000:0000:0000',
99  ],
100  'basic IPv6-locks, part-count 6' => [
101  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
102  4,
103  6,
104  '2001:0db8:85a3:08d3:1319:8a2e:0000:0000',
105  ],
106  'basic IPv6-locks, part-count 7' => [
107  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
108  4,
109  7,
110  '2001:0db8:85a3:08d3:1319:8a2e:0370:0000',
111  ],
112  'basic IPv6-locks, part-count 8' => [
113  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
114  4,
115  8,
116  '2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
117  ],
118  'compressed IPv6-lock, IP ::1, part-count 8' => [
119  '::1',
120  4,
121  8,
122  '0000:0000:0000:0000:0000:0000:0000:0001',
123  ],
124  'compressed IPv6-lock, IP 2001:db8:0:200::7, part-count 8' => [
125  '2001:db8:0:200::7',
126  4,
127  8,
128  '2001:0db8:0000:0200:0000:0000:0000:0007',
129  ],
130  'compressed IPv6-lock, IPv4-mapped IP ::ffff:127.0.0.1, part-count 8' => [
131  '::ffff:127.0.0.1',
132  4,
133  8,
134  '0000:0000:0000:0000:0000:ffff:7f00:0001',
135  ],
136  ];
137  }
138 
139  #[DataProvider('getSessionIpLockDataProvider')]
140  #[Test]
141  public function ‪getSessionIpLock(string $ipAddress, int $lockIPv4PartCount, int $lockIPv6PartCount, string $expectedLock): void
142  {
143  $ipLocker = GeneralUtility::makeInstance(IpLocker::class, $lockIPv4PartCount, $lockIPv6PartCount);
144  $lock = $ipLocker->getSessionIpLock($ipAddress);
145 
146  self::assertEquals($expectedLock, $lock);
147  }
148 }
‪TYPO3\CMS\Core\Tests\Unit\Authentication
Definition: AuthenticationServiceTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Authentication\IpLockerTest\getSessionIpLockDataProvider
‪static getSessionIpLockDataProvider()
Definition: IpLockerTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Authentication\IpLockerTest
Definition: IpLockerTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Authentication\IpLockerTest\getSessionIpLock
‪getSessionIpLock(string $ipAddress, int $lockIPv4PartCount, int $lockIPv6PartCount, string $expectedLock)
Definition: IpLockerTest.php:141
‪TYPO3\CMS\Core\Authentication\IpLocker
Definition: IpLocker.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52