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\TA; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
class TaTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
private static $digest = '2BB183AF5F22588179A53B0A98631FAD1A292118'; |
24
|
|
|
|
25
|
|
View Code Duplication |
public function testOutput(): void |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$expectation = '60485 5 1 '.self::$digest; |
28
|
|
|
|
29
|
|
|
$ta = new TA(); |
30
|
|
|
$ta->setKeyTag(60485); |
31
|
|
|
$ta->setAlgorithm(Algorithms::RSASHA1); |
32
|
|
|
$ta->setDigestType(TA::DIGEST_SHA1); |
33
|
|
|
$ta->setDigest(hex2bin(self::$digest)); |
34
|
|
|
|
35
|
|
|
$this->assertEquals($expectation, $ta->toText()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testFactory(): void |
39
|
|
|
{ |
40
|
|
|
$keyTag = 60485; |
41
|
|
|
$ta = Factory::TA($keyTag, Algorithms::RSASHA1, self::$digest, TA::DIGEST_SHA1); |
42
|
|
|
|
43
|
|
|
$this->assertEquals($keyTag, $ta->getKeyTag()); |
44
|
|
|
$this->assertEquals(Algorithms::RSASHA1, $ta->getAlgorithm()); |
45
|
|
|
$this->assertEquals(self::$digest, $ta->getDigest()); |
46
|
|
|
$this->assertEquals(TA::DIGEST_SHA1, $ta->getDigestType()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function testFromText(): void |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$expectation = new TA(); |
52
|
|
|
$expectation->setKeyTag(60485); |
53
|
|
|
$expectation->setAlgorithm(Algorithms::RSASHA1); |
54
|
|
|
$expectation->setDigestType(TA::DIGEST_SHA1); |
55
|
|
|
$expectation->setDigest(hex2bin(self::$digest)); |
56
|
|
|
|
57
|
|
|
$fromText = new TA(); |
58
|
|
|
$fromText->fromText('60485 5 1 '.self::$digest); |
59
|
|
|
$this->assertEquals($expectation, $fromText); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testWire(): void |
63
|
|
|
{ |
64
|
|
|
$ta = new TA(); |
65
|
|
|
$ta->setKeyTag(60485); |
66
|
|
|
$ta->setAlgorithm(Algorithms::RSASHA1); |
67
|
|
|
$ta->setDigestType(TA::DIGEST_SHA1); |
68
|
|
|
$ta->setDigest(hex2bin(self::$digest)); |
69
|
|
|
$wireFormat = $ta->toWire(); |
70
|
|
|
|
71
|
|
|
$fromWire = new TA(); |
72
|
|
|
$fromWire->fromWire($wireFormat); |
73
|
|
|
$this->assertEquals($ta, $fromWire); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.