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