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