1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Badcow DNS Library. |
7
|
|
|
* |
8
|
|
|
* (c) Samuel Williams <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Tests\Rdata; |
15
|
|
|
|
16
|
|
|
use Badcow\DNS\Rdata\DecodeException; |
17
|
|
|
use Badcow\DNS\Rdata\Factory; |
18
|
|
|
use Badcow\DNS\Rdata\IPSECKEY; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
class IpseckeyTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function getDataProvider(): array |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
|
|
// Text, Precedence, GatewayType, Algorithm, Gateway, PublicKey |
27
|
|
|
['10 1 2 192.0.2.38 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==', 10, 1, 2, '192.0.2.38', base64_decode('AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==')], |
28
|
|
|
['10 0 2 . AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==', 10, 0, 2, null, base64_decode('AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==')], |
29
|
|
|
['10 1 2 192.0.2.3 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==', 10, 1, 2, '192.0.2.3', base64_decode('AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==')], |
30
|
|
|
['10 3 2 mygateway.example.com. AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==', 10, 3, 2, 'mygateway.example.com.', base64_decode('AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==')], |
31
|
|
|
['10 3 0 mygateway.example.com.', 10, 3, 0, 'mygateway.example.com.', null], |
32
|
|
|
['10 2 2 2001:db8:0:8002::2000:1 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==', 10, 2, 2, '2001:db8:0:8002::2000:1', base64_decode('AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==')], |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testGetType(): void |
37
|
|
|
{ |
38
|
|
|
$ipseckey = new IPSECKEY(); |
39
|
|
|
$this->assertEquals('IPSECKEY', $ipseckey->getType()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testGetTypeCode(): void |
43
|
|
|
{ |
44
|
|
|
$ipseckey = new IPSECKEY(); |
45
|
|
|
$this->assertEquals(45, $ipseckey->getTypeCode()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider getDataProvider |
50
|
|
|
*/ |
51
|
|
|
public function testToText(string $text, int $precedence, int $gatewayType, int $algorithm, ?string $gateway, ?string $publicKey): void |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$ipseckey = new IPSECKEY(); |
54
|
|
|
$ipseckey->setPrecedence($precedence); |
55
|
|
|
$ipseckey->setGateway($gateway); |
56
|
|
|
$ipseckey->setPublicKey($algorithm, $publicKey); |
57
|
|
|
|
58
|
|
|
$this->assertEquals($text, $ipseckey->toText()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @dataProvider getDataProvider |
63
|
|
|
* |
64
|
|
|
* @throws DecodeException |
65
|
|
|
*/ |
66
|
|
|
public function testToFromWire(string $text, int $precedence, int $gatewayType, int $algorithm, ?string $gateway, ?string $publicKey): void |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$ipseckey = new IPSECKEY(); |
69
|
|
|
$ipseckey->setPrecedence($precedence); |
70
|
|
|
$ipseckey->setGateway($gateway); |
71
|
|
|
$ipseckey->setPublicKey($algorithm, $publicKey); |
72
|
|
|
|
73
|
|
|
$wireFormat = $ipseckey->toWire(); |
74
|
|
|
$rdLength = strlen($wireFormat); |
75
|
|
|
$wireFormat = 'abc'.$wireFormat; |
76
|
|
|
$offset = 3; |
77
|
|
|
|
78
|
|
|
$fromWire = new IPSECKEY(); |
79
|
|
|
$fromWire->fromWire($wireFormat, $offset, $rdLength); |
80
|
|
|
|
81
|
|
|
$this->assertEquals($ipseckey, $fromWire); |
82
|
|
|
$this->assertEquals(3 + $rdLength, $offset); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @dataProvider getDataProvider |
87
|
|
|
*/ |
88
|
|
|
public function testFromText(string $text, int $precedence, int $gatewayType, int $algorithm, ?string $gateway, ?string $publicKey): void |
89
|
|
|
{ |
90
|
|
|
$ipseckey = new IPSECKEY(); |
91
|
|
|
$ipseckey->fromText($text); |
92
|
|
|
|
93
|
|
|
$this->assertEquals($precedence, $ipseckey->getPrecedence()); |
94
|
|
|
$this->assertEquals($gatewayType, $ipseckey->getGatewayType()); |
95
|
|
|
$this->assertEquals($algorithm, $ipseckey->getAlgorithm()); |
96
|
|
|
$this->assertEquals($gateway, $ipseckey->getGateway()); |
97
|
|
|
$this->assertEquals($publicKey, $ipseckey->getPublicKey()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @dataProvider getDataProvider |
102
|
|
|
*/ |
103
|
|
|
public function testFactory(string $text, int $precedence, int $gatewayType, int $algorithm, ?string $gateway, ?string $publicKey): void |
104
|
|
|
{ |
105
|
|
|
$ipseckey = Factory::IPSECKEY($precedence, $gateway, $algorithm, $publicKey); |
106
|
|
|
|
107
|
|
|
$this->assertEquals($text, $ipseckey->toText()); |
108
|
|
|
$this->assertEquals($precedence, $ipseckey->getPrecedence()); |
109
|
|
|
$this->assertEquals($gatewayType, $ipseckey->getGatewayType()); |
110
|
|
|
$this->assertEquals($algorithm, $ipseckey->getAlgorithm()); |
111
|
|
|
$this->assertEquals($gateway, $ipseckey->getGateway()); |
112
|
|
|
$this->assertEquals($publicKey, $ipseckey->getPublicKey()); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.