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\A; |
17
|
|
|
use Badcow\DNS\Rdata\Factory; |
18
|
|
|
use Badcow\DNS\Rdata\MX; |
19
|
|
|
use Badcow\DNS\Rdata\NS; |
20
|
|
|
use Badcow\DNS\Rdata\NSEC; |
21
|
|
|
use Badcow\DNS\Rdata\PTR; |
22
|
|
|
use Badcow\DNS\Rdata\RRSIG; |
23
|
|
|
use PHPUnit\Framework\TestCase; |
24
|
|
|
|
25
|
|
|
class NsecTest extends TestCase |
26
|
|
|
{ |
27
|
|
View Code Duplication |
public function testOutput(): void |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$expectation = 'host.example.com. A MX RRSIG NSEC'; |
30
|
|
|
|
31
|
|
|
$nsec = new NSEC(); |
32
|
|
|
$nsec->setNextDomainName('host.example.com.'); |
33
|
|
|
$nsec->addType(A::TYPE); |
34
|
|
|
$nsec->addType(MX::TYPE); |
35
|
|
|
$nsec->addType(RRSIG::TYPE); |
36
|
|
|
$nsec->addType(NSEC::TYPE); |
37
|
|
|
|
38
|
|
|
$this->assertEquals($expectation, $nsec->toText()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testFactory(): void |
42
|
|
|
{ |
43
|
|
|
$nextDomain = 'host.example.com.'; |
44
|
|
|
$bitMaps = [A::TYPE, MX::TYPE, RRSIG::TYPE, NSEC::TYPE]; |
45
|
|
|
$nsec = Factory::NSEC($nextDomain, $bitMaps); |
46
|
|
|
|
47
|
|
|
$this->assertEquals($nextDomain, $nsec->getNextDomainName()); |
48
|
|
|
$this->assertEquals($bitMaps, $nsec->getTypes()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testClearTypeMap(): void |
52
|
|
|
{ |
53
|
|
|
$nsec = new NSEC(); |
54
|
|
|
$nsec->addType(NS::TYPE); |
55
|
|
|
$nsec->addType(PTR::TYPE); |
56
|
|
|
|
57
|
|
|
$this->assertEquals([NS::TYPE, PTR::TYPE], $nsec->getTypes()); |
58
|
|
|
$nsec->clearTypes(); |
59
|
|
|
$this->assertEquals([], $nsec->getTypes()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testFromText(): void |
63
|
|
|
{ |
64
|
|
|
$text = 'host.example.com. A MX RRSIG NSEC TYPE1234'; |
65
|
|
|
/** @var NSEC $nsec */ |
66
|
|
|
$nsec = new NSEC(); |
67
|
|
|
$nsec->fromText($text); |
68
|
|
|
|
69
|
|
|
$this->assertEquals('host.example.com.', $nsec->getNextDomainName()); |
70
|
|
|
$this->assertEquals(['A', 'MX', 'RRSIG', 'NSEC', 'TYPE1234'], $nsec->getTypes()); |
71
|
|
|
$this->assertEquals($text, $nsec->toText()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testWire(): void |
75
|
|
|
{ |
76
|
|
|
$hexMatrix = [ |
77
|
|
|
0x04, ord('h'), ord('o'), ord('s'), ord('t'), |
78
|
|
|
0x07, ord('e'), ord('x'), ord('a'), ord('m'), ord('p'), ord('l'), ord('e'), |
79
|
|
|
0x03, ord('c'), ord('o'), ord('m'), 0x00, |
80
|
|
|
0x00, 0x06, 0x40, 0x01, 0x00, 0x00, 0x00, 0x03, |
81
|
|
|
0x01, 0x01, 0x40, |
82
|
|
|
0x80, 0x01, 0x40, |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
$expectation = pack('C*', ...$hexMatrix); |
86
|
|
|
|
87
|
|
|
$text = 'host.example.com. A MX RRSIG NSEC CAA DLV'; |
88
|
|
|
/** @var NSEC $nsec */ |
89
|
|
|
$nsec = new NSEC(); |
90
|
|
|
$nsec->fromText($text); |
91
|
|
|
|
92
|
|
|
$this->assertEquals($expectation, $nsec->toWire()); |
93
|
|
|
$fromWire = new NSEC(); |
94
|
|
|
$fromWire->fromWire($expectation); |
95
|
|
|
$this->assertEquals($nsec, $fromWire); |
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.