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\Algorithms; |
17
|
|
|
use Badcow\DNS\Rdata\Factory; |
18
|
|
|
use Badcow\DNS\Rdata\NSEC3PARAM; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
class Nsec3paramTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testGetType(): void |
24
|
|
|
{ |
25
|
|
|
$nsec3param = new NSEC3PARAM(); |
26
|
|
|
$this->assertEquals('NSEC3PARAM', $nsec3param->getType()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetTypeCode(): void |
30
|
|
|
{ |
31
|
|
|
$nsec3param = new NSEC3PARAM(); |
32
|
|
|
$this->assertEquals(51, $nsec3param->getTypeCode()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testToText(): void |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$nsec3param = new NSEC3PARAM(); |
38
|
|
|
$nsec3param->setHashAlgorithm(Algorithms::RSAMD5); |
39
|
|
|
$nsec3param->setSalt('d9143ec07c5977ae'); |
40
|
|
|
$nsec3param->setIterations(55); |
41
|
|
|
$nsec3param->setFlags(0); |
42
|
|
|
|
43
|
|
|
$expectation = '1 0 55 d9143ec07c5977ae'; |
44
|
|
|
$this->assertEquals($expectation, $nsec3param->toText()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testToWire(): void |
48
|
|
|
{ |
49
|
|
|
$nsec3param = new NSEC3PARAM(); |
50
|
|
|
$nsec3param->setHashAlgorithm(Algorithms::RSAMD5); |
51
|
|
|
$nsec3param->setSalt('d9143ec07c5977ae'); |
52
|
|
|
$nsec3param->setIterations(55); |
53
|
|
|
$nsec3param->setFlags(0); |
54
|
|
|
|
55
|
|
|
$expectation = chr(1).chr(0).pack('n', 55).chr(8).hex2bin('d9143ec07c5977ae'); |
56
|
|
|
|
57
|
|
|
$this->assertEquals($expectation, $nsec3param->toWire()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function testFromText(): void |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$expectation = new NSEC3PARAM(); |
63
|
|
|
$expectation->setHashAlgorithm(Algorithms::RSAMD5); |
64
|
|
|
$expectation->setSalt('d9143ec07c5977ae'); |
65
|
|
|
$expectation->setIterations(55); |
66
|
|
|
$expectation->setFlags(0); |
67
|
|
|
|
68
|
|
|
$fromText = new NSEC3PARAM(); |
69
|
|
|
$fromText->fromText('1 0 55 d9143ec07c5977ae'); |
70
|
|
|
$this->assertEquals($expectation, $fromText); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testFromWire(): void |
74
|
|
|
{ |
75
|
|
|
$expectation = new NSEC3PARAM(); |
76
|
|
|
$expectation->setHashAlgorithm(Algorithms::RSAMD5); |
77
|
|
|
$expectation->setSalt('d9143ec07c5977ae'); |
78
|
|
|
$expectation->setIterations(55); |
79
|
|
|
$expectation->setFlags(0); |
80
|
|
|
|
81
|
|
|
$wireFormat = chr(1).chr(0).pack('n', 55).chr(8).hex2bin('d9143ec07c5977ae'); |
82
|
|
|
|
83
|
|
|
$fromWire = new NSEC3PARAM(); |
84
|
|
|
$fromWire->fromWire($wireFormat); |
85
|
|
|
$this->assertEquals($expectation, $fromWire); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testFactory(): void |
89
|
|
|
{ |
90
|
|
|
$nsec3param = Factory::NSEC3PARAM(Algorithms::RSAMD5, 0, 55, 'd9143ec07c5977ae'); |
91
|
|
|
|
92
|
|
|
$this->assertEquals(1, $nsec3param->getHashAlgorithm()); |
93
|
|
|
$this->assertEquals(0, $nsec3param->getFlags()); |
94
|
|
|
$this->assertEquals(55, $nsec3param->getIterations()); |
95
|
|
|
$this->assertEquals('d9143ec07c5977ae', $nsec3param->getSalt()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.