2017-04-12 14:32:48 -04:00
|
|
|
<?php
|
2021-04-19 09:50:30 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-04-12 14:32:48 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-04-12 14:32:48 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Test\Security\Normalizer;
|
|
|
|
|
|
|
|
|
|
use OC\Security\Normalizer\IpAddress;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class IpAddressTest extends TestCase {
|
2025-05-13 02:49:30 -04:00
|
|
|
public static function subnetDataProvider(): array {
|
2017-04-12 14:32:48 -04:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'64.233.191.254',
|
|
|
|
|
'64.233.191.254/32',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'192.168.0.123',
|
|
|
|
|
'192.168.0.123/32',
|
|
|
|
|
],
|
2021-11-22 08:01:41 -05:00
|
|
|
[
|
|
|
|
|
'::ffff:192.168.0.123',
|
2021-11-22 09:53:41 -05:00
|
|
|
'192.168.0.123/32',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'0:0:0:0:0:ffff:192.168.0.123',
|
|
|
|
|
'192.168.0.123/32',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'0:0:0:0:0:ffff:c0a8:7b',
|
|
|
|
|
'192.168.0.123/32',
|
2021-11-22 08:01:41 -05:00
|
|
|
],
|
2017-04-12 14:32:48 -04:00
|
|
|
[
|
2025-04-08 03:34:43 -04:00
|
|
|
'2001:0db8:0000:0000:0000:8a2e:0370:7334',
|
2025-04-16 09:47:50 -04:00
|
|
|
'2001:db8::/56',
|
2021-04-07 08:07:08 -04:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'2001:db8:3333:4444:5555:6666:7777:8888',
|
2025-04-16 09:47:50 -04:00
|
|
|
'2001:db8:3333:4400::/56',
|
2021-04-07 08:07:08 -04:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'::1234:5678',
|
2025-04-16 09:47:50 -04:00
|
|
|
'::/56',
|
2017-04-12 14:32:48 -04:00
|
|
|
],
|
2019-01-03 04:03:46 -05:00
|
|
|
[
|
|
|
|
|
'[::1]',
|
2025-04-16 09:47:50 -04:00
|
|
|
'::/56',
|
2019-01-03 04:03:46 -05:00
|
|
|
],
|
2017-04-12 14:32:48 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param string $input
|
|
|
|
|
* @param string $expected
|
|
|
|
|
*/
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('subnetDataProvider')]
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetSubnet($input, $expected): void {
|
2017-04-12 14:32:48 -04:00
|
|
|
$this->assertSame($expected, (new IpAddress($input))->getSubnet());
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testToString(): void {
|
2017-04-12 14:32:48 -04:00
|
|
|
$this->assertSame('127.0.0.1', (string)(new IpAddress('127.0.0.1')));
|
|
|
|
|
}
|
|
|
|
|
}
|