HipTest::testToText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Factory;
17
use Badcow\DNS\Rdata\HIP;
18
use PHPUnit\Framework\TestCase;
19
20
class HipTest extends TestCase
21
{
22
    private $publicKey;
23
    private $hit;
24
    private $rvs = [
25
        'rvs0.example.com.',
26
        'rvs1.example.com.',
27
        'rvs2.example.com.',
28
    ];
29
30
    public function setUp(): void
31
    {
32
        $this->publicKey = base64_decode('AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cI
33
            vM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ry
34
            ra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXd
35
            XF5D'
36
        );
37
38
        $this->hit = hex2bin('200100107B1A74DF365639CC39F1D578');
39
    }
40
41
    public function testGetType(): void
42
    {
43
        $hip = new HIP();
44
        $this->assertEquals('HIP', $hip->getType());
45
    }
46
47
    public function testGetTypeCode(): void
48
    {
49
        $hip = new HIP();
50
        $this->assertEquals(55, $hip->getTypeCode());
51
    }
52
53
    public function testToText(): void
54
    {
55
        $hip = new HIP();
56
        $hip->setPublicKeyAlgorithm(2);
57
        $hip->setPublicKey($this->publicKey);
58
        $hip->setHostIdentityTag($this->hit);
59
        array_map([$hip, 'addRendezvousServer'], $this->rvs);
60
        $expectation = '2 200100107b1a74df365639cc39f1d578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs0.example.com. rvs1.example.com. rvs2.example.com.';
61
62
        $this->assertEquals($expectation, $hip->toText());
63
    }
64
65 View Code Duplication
    public function testWire(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
66
    {
67
        $hip = new HIP();
68
        $hip->setPublicKeyAlgorithm(2);
69
        $hip->setPublicKey($this->publicKey);
70
        $hip->setHostIdentityTag($this->hit);
71
        array_map([$hip, 'addRendezvousServer'], $this->rvs);
72
        $wireFormat = $hip->toWire();
73
74
        $fromWire = new HIP();
75
        $fromWire->fromWire($wireFormat);
76
77
        $this->assertEquals($hip, $fromWire);
78
    }
79
80 View Code Duplication
    public function testFromText(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
81
    {
82
        $expectation = new HIP();
83
        $expectation->setPublicKeyAlgorithm(2);
84
        $expectation->setPublicKey($this->publicKey);
85
        $expectation->setHostIdentityTag($this->hit);
86
        array_map([$expectation, 'addRendezvousServer'], $this->rvs);
87
        $text = '2 200100107b1a74df365639cc39f1d578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs0.example.com. rvs1.example.com. rvs2.example.com.';
88
89
        $fromText = new HIP();
90
        $fromText->fromText($text);
91
        $this->assertEquals($expectation, $fromText);
92
    }
93
94
    public function testFactory(): void
95
    {
96
        $hip = Factory::HIP(2, $this->hit, $this->publicKey, $this->rvs);
97
98
        $this->assertEquals(2, $hip->getPublicKeyAlgorithm());
99
        $this->assertEquals($this->publicKey, $hip->getPublicKey());
100
        $this->assertEquals($this->hit, $hip->getHostIdentityTag());
101
        $this->assertEquals($this->rvs, $hip->getRendezvousServers());
102
    }
103
}
104