/
IpAddressAnonymizerTest.php
81 lines (63 loc) · 2.04 KB
/
IpAddressAnonymizerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
//namespace unit\models;
namespace ls\tests;
use LimeSurvey\Models\Services\IpAddressAnonymizer;
use PHPUnit\Framework\TestCase;
class IpAddressAnonymizerTest extends TestCase
{
/**
* Test it is ipv4
*/
public function testIsIpV4()
{
$ipToBeTested = '192.168.3.1';
$ipAnonymizer = new IpAddressAnonymizer($ipToBeTested);
$this->assertTrue($ipAnonymizer->isIpv4());
}
/**
* Test not ipv4
*/
public function testIsNotIpv4(){
$ipToBeTested = '192.168.3.';
$ipAnonymizer = new IpAddressAnonymizer($ipToBeTested);
$this->assertFalse($ipAnonymizer->isIpv4());
}
/**
* Test it is ipv6
*/
public function testIsIpV6(){
$ipToBeTested = '2a03:2880:2117:df07:face:b00c:5:1';
$ipToBeTested2 = '2a03:2880:2117:df07::5:1';
$ipAnonymizer = new IpAddressAnonymizer($ipToBeTested);
$this->assertTrue($ipAnonymizer->isIpv6());
$ipAnonymizer = new IpAddressAnonymizer($ipToBeTested2);
$this->assertTrue($ipAnonymizer->isIpv6());
}
/**
* Test not ipv6
*/
public function testIsNotIpv6(){
$ipToBeTested = '192.3.4.5';
$ipAnonymizer = new IpAddressAnonymizer($ipToBeTested);
$this->assertFalse($ipAnonymizer->isIpv6());
}
/**
* Test ip anonymization with ipv4
* 192.168.3.4 is anomymized to 192.168.3.4
*/
public function testIpAnonymizeIpv4(){
$ipToBeTested = '192.168.3.4';
$ipAnonymizer = new IpAddressAnonymizer($ipToBeTested);
$this->assertEquals('192.168.3.0', $ipAnonymizer->anonymizeIpAddress());
}
/**
* Test ip anonymization with ipv6
*
* 2a03:2880:2117:df07:face:b00c:5:1 is anonymized to 2a03:2880:2117:0:0:0:0:0
*/
public function testIpAnonymizeIpv6(){
$ipToBeTested = '2a03:2880:2117:df07:face:b00c:5:1';
$ipAnonymizer = new IpAddressAnonymizer($ipToBeTested);
$this->assertEquals('2a03:2880:2117:0:0:0:0:0', $ipAnonymizer->anonymizeIpAddress());
}
}