Skip to content

Commit ced0b55

Browse files
committed
Fix Ip tests
We no longer use the old regexp based config, so the tests failed.
1 parent d5dd5d1 commit ced0b55

File tree

3 files changed

+4
-44
lines changed

3 files changed

+4
-44
lines changed

_test/tests/inc/Ip.test.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ public function test_ip_matches(string $ip, string $ipOrRange, bool $expected):
147147
*/
148148
public function proxy_is_trusted_provider(): array
149149
{
150-
// The default value that shipped with the config.
151-
$legacyDefault = '^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)';
152-
153150
// The new default configuration value.
154151
$default = ['::1', 'fe80::/10', '127.0.0.0/8', '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'];
155152

@@ -160,20 +157,6 @@ public function proxy_is_trusted_provider(): array
160157
// Empty configuration.
161158
['', '127.0.0.1', false],
162159

163-
// Legacy configuration with a regular expression.
164-
[$legacyDefault, '127.0.0.1', true],
165-
[$legacyDefault, '127.1.2.3', true],
166-
[$legacyDefault, '10.1.2.3', true],
167-
[$legacyDefault, '11.1.2.3', false],
168-
[$legacyDefault, '172.16.0.1', true],
169-
[$legacyDefault, '172.160.0.1', false],
170-
[$legacyDefault, '172.31.255.255', true],
171-
[$legacyDefault, '172.32.0.0', false],
172-
[$legacyDefault, '172.200.0.0', false],
173-
[$legacyDefault, '192.168.2.3', true],
174-
[$legacyDefault, '192.169.1.2', false],
175-
[$legacyDefault, '::1', true],
176-
177160
// Configuration with an array of IPs/CIDRs.
178161
[$default, '127.0.0.1', true],
179162
[$default, '127.1.2.3', true],
@@ -230,9 +213,6 @@ public function test_proxy_is_trusted($config, string $ip, bool $expected): void
230213
*/
231214
public function forwarded_for_provider(): array
232215
{
233-
// The default value that shipped with the config.
234-
$legacyDefault = '^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)';
235-
236216
// The new default configuration value.
237217
$default = ['::1', 'fe80::/10', '127.0.0.0/8', '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'];
238218

@@ -241,27 +221,9 @@ public function forwarded_for_provider(): array
241221

242222
$tests = [
243223
// Empty config value should always return empty array.
244-
['', '', '127.0.0.1', []],
245-
['', '127.0.0.1', '127.0.0.1', []],
246224
[[], '', '127.0.0.1', []],
247225
[[], '127.0.0.1', '127.0.0.1', []],
248226

249-
// The old default configuration.
250-
[$legacyDefault, '', '127.0.0.1', []],
251-
[$legacyDefault, '1.2.3.4', '127.0.0.1', ['1.2.3.4', '127.0.0.1']],
252-
[$legacyDefault, '1.2.3.4', '192.168.1.1', ['1.2.3.4', '192.168.1.1']],
253-
[$legacyDefault, '1.2.3.4,172.16.0.1', '192.168.1.1', ['1.2.3.4', '172.16.0.1', '192.168.1.1']],
254-
[$legacyDefault, '1.2.3.4,172.16.0.1', '::1', ['1.2.3.4', '172.16.0.1', '::1']],
255-
256-
// Directly from an untrusted proxy.
257-
[$legacyDefault, '', '127.0.0.1', []],
258-
[$legacyDefault, '1.2.3.4', '11.22.33.44', []],
259-
[$legacyDefault, '::1', '11.22.33.44', []],
260-
261-
// From a trusted proxy, but via an untrusted proxy.
262-
[$legacyDefault, '1.2.3.4,11.22.33.44,172.16.0.1', '192.168.1.1', []],
263-
[$legacyDefault, '1.2.3.4,::2,172.16.0.1', '::1', []],
264-
265227
// The new default configuration.
266228
[$default, '', '127.0.0.1', []],
267229
[$default, '1.2.3.4', '127.0.0.1', ['1.2.3.4', '127.0.0.1']],

_test/tests/inc/common_clientip.test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class common_clientIP_test extends DokuWikiTest {
66
* @var mixed[] $configs Possible values for $conf['trustedproxies'].
77
*/
88
private $configs = [
9-
'^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)',
109
['::1', 'fe80::/10', '127.0.0.0/8', '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'],
1110
];
1211

inc/Ip.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,13 @@ public static function proxyIsTrusted(string $ip): bool
151151
return false;
152152
}
153153

154-
foreach ((array) $conf['trustedproxies'] as $trusted) {
154+
foreach ((array)$conf['trustedproxies'] as $trusted) {
155155
if (Ip::ipMatches($ip, $trusted)) {
156-
return true;
156+
return true; // The given IP matches one of the trusted proxies.
157157
}
158158
}
159159

160-
Logger::error('Invalid value for $conf[trustedproxies]');
161-
return false;
160+
return false; // none of the proxies matched
162161
}
163162

164163
/**
@@ -184,7 +183,7 @@ public static function forwardedFor(): array
184183

185184
$forwardedFor = $INPUT->server->str('HTTP_X_FORWARDED_FOR');
186185

187-
if (empty($conf['trustedproxy']) || !$forwardedFor) {
186+
if (empty($conf['trustedproxies']) || !$forwardedFor) {
188187
return [];
189188
}
190189

0 commit comments

Comments
 (0)