@@ -19,105 +19,105 @@ |
||
19 | 19 | use Test\TestCase; |
20 | 20 | |
21 | 21 | class RemoteHostValidatorIntegrationTest extends TestCase { |
22 | - /** @var IConfig|IConfig&MockObject|MockObject */ |
|
23 | - private IConfig $config; |
|
24 | - private RemoteHostValidator $validator; |
|
25 | - |
|
26 | - protected function setUp(): void { |
|
27 | - parent::setUp(); |
|
28 | - |
|
29 | - // Mock config to avoid any side effects |
|
30 | - $this->config = $this->createMock(IConfig::class); |
|
31 | - |
|
32 | - $this->validator = new RemoteHostValidator( |
|
33 | - $this->config, |
|
34 | - Server::get(HostnameClassifier::class), |
|
35 | - Server::get(IpAddressClassifier::class), |
|
36 | - new NullLogger(), |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - public static function localHostsData(): array { |
|
41 | - return [ |
|
42 | - ['[::1]'], |
|
43 | - ['[::]'], |
|
44 | - ['192.168.0.1'], |
|
45 | - ['127.0.0.1'], |
|
46 | - ['127.0.0.13'], // all 127.0.0.0/8 network is loopback address |
|
47 | - ['172.16.42.1'], |
|
48 | - ['[fdf8:f53b:82e4::53]'], |
|
49 | - ['[fe80::200:5aee:feaa:20a2]'], |
|
50 | - ['[0:0:0:0:0:ffff:10.0.0.1]'], |
|
51 | - ['[0:0:0:0:0:ffff:127.0.0.0]'], |
|
52 | - ['10.0.0.1'], |
|
53 | - ['!@#$'], // test invalid url |
|
54 | - ['100.100.100.200'], |
|
55 | - ['192.0.0.1'], |
|
56 | - ['0177.0.0.9'], |
|
57 | - ['⑯⑨。②⑤④。⑯⑨。②⑤④'], |
|
58 | - ['127。②⑤④。⑯⑨.②⑤④'], |
|
59 | - ['127.0.00000000000000000000000000000000001'], |
|
60 | - ['127.1'], |
|
61 | - ['127.000.001'], |
|
62 | - ['0177.0.0.01'], |
|
63 | - ['0x7f.0x0.0x0.0x1'], |
|
64 | - ['0x7f000001'], |
|
65 | - ['2130706433'], |
|
66 | - ['00000000000000000000000000000000000000000000000000177.1'], |
|
67 | - ['0x7f.1'], |
|
68 | - ['127.0x1'], |
|
69 | - ['[0000:0000:0000:0000:0000:0000:0000:0001]'], |
|
70 | - ['[0:0:0:0:0:0:0:1]'], |
|
71 | - ['[0:0:0:0::0:0:1]'], |
|
72 | - ['%31%32%37%2E%30%2E%30%2E%31'], |
|
73 | - ['%31%32%37%2E%30%2E%30.%31'], |
|
74 | - ['[%3A%3A%31]'], |
|
75 | - ]; |
|
76 | - } |
|
77 | - |
|
78 | - #[\PHPUnit\Framework\Attributes\DataProvider('localHostsData')] |
|
79 | - public function testLocalHostsWhenNotAllowed(string $host): void { |
|
80 | - $this->config |
|
81 | - ->method('getSystemValueBool') |
|
82 | - ->with('allow_local_remote_servers', false) |
|
83 | - ->willReturn(false); |
|
84 | - |
|
85 | - $isValid = $this->validator->isValid($host); |
|
86 | - |
|
87 | - self::assertFalse($isValid); |
|
88 | - } |
|
89 | - |
|
90 | - #[\PHPUnit\Framework\Attributes\DataProvider('localHostsData')] |
|
91 | - public function testLocalHostsWhenAllowed(string $host): void { |
|
92 | - $this->config |
|
93 | - ->method('getSystemValueBool') |
|
94 | - ->with('allow_local_remote_servers', false) |
|
95 | - ->willReturn(true); |
|
96 | - |
|
97 | - $isValid = $this->validator->isValid($host); |
|
98 | - |
|
99 | - self::assertTrue($isValid); |
|
100 | - } |
|
101 | - |
|
102 | - public static function externalAddressesData():array { |
|
103 | - return [ |
|
104 | - ['8.8.8.8'], |
|
105 | - ['8.8.4.4'], |
|
106 | - ['8.8.8.8'], |
|
107 | - ['8.8.4.4'], |
|
108 | - ['[2001:4860:4860::8888]'], |
|
109 | - ]; |
|
110 | - } |
|
111 | - |
|
112 | - #[\PHPUnit\Framework\Attributes\DataProvider('externalAddressesData')] |
|
113 | - public function testExternalHost(string $host): void { |
|
114 | - $this->config |
|
115 | - ->method('getSystemValueBool') |
|
116 | - ->with('allow_local_remote_servers', false) |
|
117 | - ->willReturn(false); |
|
118 | - |
|
119 | - $isValid = $this->validator->isValid($host); |
|
120 | - |
|
121 | - self::assertTrue($isValid); |
|
122 | - } |
|
22 | + /** @var IConfig|IConfig&MockObject|MockObject */ |
|
23 | + private IConfig $config; |
|
24 | + private RemoteHostValidator $validator; |
|
25 | + |
|
26 | + protected function setUp(): void { |
|
27 | + parent::setUp(); |
|
28 | + |
|
29 | + // Mock config to avoid any side effects |
|
30 | + $this->config = $this->createMock(IConfig::class); |
|
31 | + |
|
32 | + $this->validator = new RemoteHostValidator( |
|
33 | + $this->config, |
|
34 | + Server::get(HostnameClassifier::class), |
|
35 | + Server::get(IpAddressClassifier::class), |
|
36 | + new NullLogger(), |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + public static function localHostsData(): array { |
|
41 | + return [ |
|
42 | + ['[::1]'], |
|
43 | + ['[::]'], |
|
44 | + ['192.168.0.1'], |
|
45 | + ['127.0.0.1'], |
|
46 | + ['127.0.0.13'], // all 127.0.0.0/8 network is loopback address |
|
47 | + ['172.16.42.1'], |
|
48 | + ['[fdf8:f53b:82e4::53]'], |
|
49 | + ['[fe80::200:5aee:feaa:20a2]'], |
|
50 | + ['[0:0:0:0:0:ffff:10.0.0.1]'], |
|
51 | + ['[0:0:0:0:0:ffff:127.0.0.0]'], |
|
52 | + ['10.0.0.1'], |
|
53 | + ['!@#$'], // test invalid url |
|
54 | + ['100.100.100.200'], |
|
55 | + ['192.0.0.1'], |
|
56 | + ['0177.0.0.9'], |
|
57 | + ['⑯⑨。②⑤④。⑯⑨。②⑤④'], |
|
58 | + ['127。②⑤④。⑯⑨.②⑤④'], |
|
59 | + ['127.0.00000000000000000000000000000000001'], |
|
60 | + ['127.1'], |
|
61 | + ['127.000.001'], |
|
62 | + ['0177.0.0.01'], |
|
63 | + ['0x7f.0x0.0x0.0x1'], |
|
64 | + ['0x7f000001'], |
|
65 | + ['2130706433'], |
|
66 | + ['00000000000000000000000000000000000000000000000000177.1'], |
|
67 | + ['0x7f.1'], |
|
68 | + ['127.0x1'], |
|
69 | + ['[0000:0000:0000:0000:0000:0000:0000:0001]'], |
|
70 | + ['[0:0:0:0:0:0:0:1]'], |
|
71 | + ['[0:0:0:0::0:0:1]'], |
|
72 | + ['%31%32%37%2E%30%2E%30%2E%31'], |
|
73 | + ['%31%32%37%2E%30%2E%30.%31'], |
|
74 | + ['[%3A%3A%31]'], |
|
75 | + ]; |
|
76 | + } |
|
77 | + |
|
78 | + #[\PHPUnit\Framework\Attributes\DataProvider('localHostsData')] |
|
79 | + public function testLocalHostsWhenNotAllowed(string $host): void { |
|
80 | + $this->config |
|
81 | + ->method('getSystemValueBool') |
|
82 | + ->with('allow_local_remote_servers', false) |
|
83 | + ->willReturn(false); |
|
84 | + |
|
85 | + $isValid = $this->validator->isValid($host); |
|
86 | + |
|
87 | + self::assertFalse($isValid); |
|
88 | + } |
|
89 | + |
|
90 | + #[\PHPUnit\Framework\Attributes\DataProvider('localHostsData')] |
|
91 | + public function testLocalHostsWhenAllowed(string $host): void { |
|
92 | + $this->config |
|
93 | + ->method('getSystemValueBool') |
|
94 | + ->with('allow_local_remote_servers', false) |
|
95 | + ->willReturn(true); |
|
96 | + |
|
97 | + $isValid = $this->validator->isValid($host); |
|
98 | + |
|
99 | + self::assertTrue($isValid); |
|
100 | + } |
|
101 | + |
|
102 | + public static function externalAddressesData():array { |
|
103 | + return [ |
|
104 | + ['8.8.8.8'], |
|
105 | + ['8.8.4.4'], |
|
106 | + ['8.8.8.8'], |
|
107 | + ['8.8.4.4'], |
|
108 | + ['[2001:4860:4860::8888]'], |
|
109 | + ]; |
|
110 | + } |
|
111 | + |
|
112 | + #[\PHPUnit\Framework\Attributes\DataProvider('externalAddressesData')] |
|
113 | + public function testExternalHost(string $host): void { |
|
114 | + $this->config |
|
115 | + ->method('getSystemValueBool') |
|
116 | + ->with('allow_local_remote_servers', false) |
|
117 | + ->willReturn(false); |
|
118 | + |
|
119 | + $isValid = $this->validator->isValid($host); |
|
120 | + |
|
121 | + self::assertTrue($isValid); |
|
122 | + } |
|
123 | 123 | } |
@@ -13,51 +13,51 @@ |
||
13 | 13 | use Test\TestCase; |
14 | 14 | |
15 | 15 | class IpAddressClassifierTest extends TestCase { |
16 | - private IpAddressClassifier $classifier; |
|
17 | - |
|
18 | - protected function setUp(): void { |
|
19 | - parent::setUp(); |
|
20 | - |
|
21 | - $this->classifier = new IpAddressClassifier(); |
|
22 | - } |
|
23 | - |
|
24 | - public static function publicIpAddressData(): array { |
|
25 | - return [ |
|
26 | - ['8.8.8.8'], |
|
27 | - ['8.8.4.4'], |
|
28 | - ['2001:4860:4860::8888'], |
|
29 | - ['2001:4860:4860::8844'], |
|
30 | - ]; |
|
31 | - } |
|
32 | - |
|
33 | - #[\PHPUnit\Framework\Attributes\DataProvider('publicIpAddressData')] |
|
34 | - public function testPublicAddress(string $ip): void { |
|
35 | - $isLocal = $this->classifier->isLocalAddress($ip); |
|
36 | - |
|
37 | - self::assertFalse($isLocal); |
|
38 | - } |
|
39 | - |
|
40 | - public static function localIpAddressData(): array { |
|
41 | - return [ |
|
42 | - ['127.0.0.1'], |
|
43 | - ['127.0.0.13'], // all 127.0.0.0/8 network is loopback address |
|
44 | - ['192.168.0.1'], |
|
45 | - ['fe80::200:5aee:feaa:20a2'], |
|
46 | - ['fe80::1fc4:15d8:78db:2319%enp4s0'], // v6 zone ID |
|
47 | - ['0:0:0:0:0:ffff:10.0.0.1'], |
|
48 | - ['0:0:0:0:0:ffff:127.0.0.0'], |
|
49 | - ['10.0.0.1'], |
|
50 | - ['::'], |
|
51 | - ['::1'], |
|
52 | - ['100.100.100.200'], |
|
53 | - ['192.0.0.1'], |
|
54 | - ]; |
|
55 | - } |
|
56 | - |
|
57 | - #[\PHPUnit\Framework\Attributes\DataProvider('localIpAddressData')] |
|
58 | - public function testLocalAddress(string $ip): void { |
|
59 | - $isLocal = $this->classifier->isLocalAddress($ip); |
|
60 | - |
|
61 | - self::assertTrue($isLocal); |
|
62 | - } |
|
16 | + private IpAddressClassifier $classifier; |
|
17 | + |
|
18 | + protected function setUp(): void { |
|
19 | + parent::setUp(); |
|
20 | + |
|
21 | + $this->classifier = new IpAddressClassifier(); |
|
22 | + } |
|
23 | + |
|
24 | + public static function publicIpAddressData(): array { |
|
25 | + return [ |
|
26 | + ['8.8.8.8'], |
|
27 | + ['8.8.4.4'], |
|
28 | + ['2001:4860:4860::8888'], |
|
29 | + ['2001:4860:4860::8844'], |
|
30 | + ]; |
|
31 | + } |
|
32 | + |
|
33 | + #[\PHPUnit\Framework\Attributes\DataProvider('publicIpAddressData')] |
|
34 | + public function testPublicAddress(string $ip): void { |
|
35 | + $isLocal = $this->classifier->isLocalAddress($ip); |
|
36 | + |
|
37 | + self::assertFalse($isLocal); |
|
38 | + } |
|
39 | + |
|
40 | + public static function localIpAddressData(): array { |
|
41 | + return [ |
|
42 | + ['127.0.0.1'], |
|
43 | + ['127.0.0.13'], // all 127.0.0.0/8 network is loopback address |
|
44 | + ['192.168.0.1'], |
|
45 | + ['fe80::200:5aee:feaa:20a2'], |
|
46 | + ['fe80::1fc4:15d8:78db:2319%enp4s0'], // v6 zone ID |
|
47 | + ['0:0:0:0:0:ffff:10.0.0.1'], |
|
48 | + ['0:0:0:0:0:ffff:127.0.0.0'], |
|
49 | + ['10.0.0.1'], |
|
50 | + ['::'], |
|
51 | + ['::1'], |
|
52 | + ['100.100.100.200'], |
|
53 | + ['192.0.0.1'], |
|
54 | + ]; |
|
55 | + } |
|
56 | + |
|
57 | + #[\PHPUnit\Framework\Attributes\DataProvider('localIpAddressData')] |
|
58 | + public function testLocalAddress(string $ip): void { |
|
59 | + $isLocal = $this->classifier->isLocalAddress($ip); |
|
60 | + |
|
61 | + self::assertTrue($isLocal); |
|
62 | + } |
|
63 | 63 | } |