summaryrefslogtreecommitdiffstats
path: root/tests/Inc/IpUtilTest.php
diff options
context:
space:
mode:
authorSimon Rettberg2026-04-28 14:42:07 +0200
committerSimon Rettberg2026-04-28 14:42:07 +0200
commitf1e35d43695f914677fcf8b2b4550a3c58cdcf10 (patch)
tree99b9ca7ba24cbaed033963c20ff41e9303d28a21 /tests/Inc/IpUtilTest.php
parentAdd README.md (diff)
downloadslx-admin-f1e35d43695f914677fcf8b2b4550a3c58cdcf10.tar.gz
slx-admin-f1e35d43695f914677fcf8b2b4550a3c58cdcf10.tar.xz
slx-admin-f1e35d43695f914677fcf8b2b4550a3c58cdcf10.zip
Add IP address normalization, add support for X-Forwarded-For
Tests written by Junie AI
Diffstat (limited to 'tests/Inc/IpUtilTest.php')
-rw-r--r--tests/Inc/IpUtilTest.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/Inc/IpUtilTest.php b/tests/Inc/IpUtilTest.php
index 8c65a0c3..11f30a5c 100644
--- a/tests/Inc/IpUtilTest.php
+++ b/tests/Inc/IpUtilTest.php
@@ -57,4 +57,31 @@ class IpUtilTest extends TestCase
IpUtil::rangeToCidr($start, $end)
);
}
+
+ public function testNormalizeIp(): void
+ {
+ $this->assertSame('1.0.0.1', IpUtil::normalizeIp('1.1'));
+ $this->assertSame('1.2.2.88', IpUtil::normalizeIp('1.2.600'));
+ $this->assertSame('1.219.1.1', IpUtil::normalizeIp('1.0333.1.1'));
+ $this->assertSame('127.0.0.1', IpUtil::normalizeIp('::ffff:127.0.0.1'));
+ $this->assertSame('127.0.0.1', IpUtil::normalizeIp('0x7f.0.0.1'));
+ $this->assertSame('127.0.0.1', IpUtil::normalizeIp('0177.0.0.1'));
+ $this->assertSame('127.0.0.1', IpUtil::normalizeIp('2130706433'));
+ $this->assertSame('127.0.0.1', IpUtil::normalizeIp('0x7f000001'));
+ $this->assertSame('::1', IpUtil::normalizeIp('::1'));
+ $this->assertNull(IpUtil::normalizeIp('256.1.1.1'));
+ $this->assertNull(IpUtil::normalizeIp('1.2.3.4.5'));
+ $this->assertNull(IpUtil::normalizeIp('0x100000000'));
+ $this->assertNull(IpUtil::normalizeIp('not an ip'));
+ $this->assertNull(IpUtil::normalizeIp('::ffff:256.1.1.1'));
+ }
+
+ public function testIsValidIp(): void
+ {
+ $this->assertTrue(IpUtil::isValidIp('1.1'));
+ $this->assertTrue(IpUtil::isValidIp('127.0.0.1'));
+ $this->assertTrue(IpUtil::isValidIp('::1'));
+ $this->assertFalse(IpUtil::isValidIp('256.1.1.1'));
+ $this->assertFalse(IpUtil::isValidIp('not an ip'));
+ }
}