|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Badcow DNS Library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Samuel Williams <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Badcow\DNS\Tests\Ip; |
|
13
|
|
|
|
|
14
|
|
|
use Badcow\DNS\Ip\Toolbox; |
|
15
|
|
|
|
|
16
|
|
|
class ToolboxTest extends \PHPUnit\Framework\TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function provider_expandIPv6(): array |
|
19
|
|
|
{ |
|
20
|
|
|
return [ |
|
21
|
|
|
['0000:0000:0000:0000:0000:0000:0000:0001', '::1'], |
|
22
|
|
|
['2001:0db8:0000:0000:0000:ff00:0042:8329', '2001:db8::ff00:42:8329'], |
|
23
|
|
|
['2001:0000:0000:acad:0000:0000:0000:0001', '2001:0:0:acad::1'], |
|
24
|
|
|
['0000:0000:0000:0000:0000:0000:0000:0000', '::'], |
|
25
|
|
|
['2001:0000:0000:ab80:2390:0000:0000:000a', '2001::ab80:2390:0:0:a'], |
|
26
|
|
|
['0000:0000:aaaa:0000:0000:aaaa:0000:0000', '::aaaa:0:0:aaaa:0:0'], |
|
27
|
|
|
['0001:0000:0000:0000:0000:0000:0000:0000', '1::'], |
|
28
|
|
|
]; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function provider_contractIPv6(): array |
|
32
|
|
|
{ |
|
33
|
|
|
return array_merge($this->provider_expandIPv6(), [ |
|
34
|
|
|
['2001:db8:0:0:f:0:0:0', '2001:db8:0:0:f::'], |
|
35
|
|
|
['2001:db8::ff00:42:8329', '2001:db8::ff00:42:8329'], |
|
36
|
|
|
['2001:db8:a:bac:8099:d:f:9', '2001:db8:a:bac:8099:d:f:9'], |
|
37
|
|
|
]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $expectation |
|
42
|
|
|
* @param string $ip |
|
43
|
|
|
* |
|
44
|
|
|
* @dataProvider provider_expandIPv6 |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testExpandIpv6(string $expectation, string $ip) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->assertEquals($expectation, Toolbox::expandIpv6($ip)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $ip |
|
53
|
|
|
* @param string $expectation |
|
54
|
|
|
* |
|
55
|
|
|
* @dataProvider provider_contractIPv6 |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testContractIpv6(string $ip, string $expectation) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertEquals($expectation, Toolbox::contractIpv6($ip)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testReverseIpv4() |
|
63
|
|
|
{ |
|
64
|
|
|
$case_1 = '192.168.1.213'; |
|
65
|
|
|
$exp_1 = '213.1.168.192.in-addr.arpa.'; |
|
66
|
|
|
|
|
67
|
|
|
$this->assertEquals($exp_1, Toolbox::reverseIpv4($case_1)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testReverseIpv6() |
|
71
|
|
|
{ |
|
72
|
|
|
$case_1 = '2001:db8::567:89ab'; |
|
73
|
|
|
$case_2 = '8007:ea:19'; |
|
74
|
|
|
|
|
75
|
|
|
$exp_1 = 'b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.'; |
|
76
|
|
|
$exp_2 = '9.1.0.0.a.e.0.0.7.0.0.8.ip6.arpa.'; |
|
77
|
|
|
|
|
78
|
|
|
$this->assertEquals($exp_1, Toolbox::reverseIpv6($case_1)); |
|
79
|
|
|
$this->assertEquals($exp_2, Toolbox::reverseIpv6($case_2)); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|