diff --git a/.travis.yml b/.travis.yml index 8fe9574..1a7918c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ php: - 7.4 install: - - composer install + - travis_retry composer install script: - vendor/bin/phpunit diff --git a/src/IPv6.php b/src/IPv6.php index 110edfd..9a64983 100644 --- a/src/IPv6.php +++ b/src/IPv6.php @@ -42,7 +42,8 @@ public function anonymize($byteCount) 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 'ffff:ffff:ffff:ffff::', 'ffff:ffff:ffff:0000::', - 'ffff:ff00:0000:0000::' + 'ffff:ff00:0000:0000::', + '0000::' ); $newBinaryIp = $newBinaryIp & pack('a16', inet_pton($masks[$byteCount])); diff --git a/tests/IPv6Test.php b/tests/IPv6Test.php index 7f0ce61..9146736 100644 --- a/tests/IPv6Test.php +++ b/tests/IPv6Test.php @@ -70,13 +70,15 @@ public function getAddressesToAnonymize() "\x20\x01\x0d\xb8\x00\x00\x08\xd3\x00\x00\x8a\x2e\x00\x70\x73\x44", "\x20\x01\x0d\xb8\x00\x00\x08\xd3\x00\x00\x00\x00\x00\x00\x00\x00", // mask 64 bits "\x20\x01\x0d\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", // mask 80 bits - "\x20\x01\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" // mask 104 bits + "\x20\x01\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", // mask 104 bits + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" // mask all bits )), array('2001:6f8:900:724::2', array( "\x20\x01\x06\xf8\x09\x00\x07\x24\x00\x00\x00\x00\x00\x00\x00\x02", "\x20\x01\x06\xf8\x09\x00\x07\x24\x00\x00\x00\x00\x00\x00\x00\x00", "\x20\x01\x06\xf8\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "\x20\x01\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", )) ); } @@ -91,7 +93,7 @@ public function testAnonymize($ipString, $expected) $this->assertInstanceOf('Matomo\Network\IPv6', $ip); // each IP is tested with 0 to 4 octets masked - for ($byteCount = 0; $byteCount < 4; $byteCount++) { + for ($byteCount = 0; $byteCount <= 4; $byteCount++) { $result = $ip->anonymize($byteCount); $this->assertEquals($expected[$byteCount], $result->toBinary(), "Got $result, Expected " . bin2hex($expected[$byteCount]) . ", Mask: " . $byteCount); }