|
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\Parser; |
|
15
|
|
|
|
|
16
|
|
|
use Badcow\DNS\Parser\Comments; |
|
17
|
|
|
use Badcow\DNS\Parser\Parser; |
|
18
|
|
|
use Badcow\DNS\Rdata\A; |
|
19
|
|
|
use Badcow\DNS\Rdata\AAAA; |
|
20
|
|
|
use Badcow\DNS\Rdata\NS; |
|
21
|
|
|
use Badcow\DNS\Rdata\SOA; |
|
22
|
|
|
use Badcow\DNS\Rdata\TXT; |
|
23
|
|
|
use PHPUnit\Framework\TestCase; |
|
24
|
|
|
|
|
25
|
|
|
class ParseZoneWithCommentsTest extends TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @throws \Exception |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testParseZoneWithComments(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$zoneFile = NormaliserTest::readFile(__DIR__.'/Resources/testCollapseMultilines_sample.txt'); |
|
33
|
|
|
$zone = Parser::parse('example.com.', $zoneFile, Comments::ALL); |
|
34
|
|
|
|
|
35
|
|
|
$nsRecords = ParserTest::findRecord('@', $zone, NS::TYPE); |
|
36
|
|
|
$this->assertCount(2, $nsRecords); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$mailTxtRecords = ParserTest::findRecord('mail', $zone, TXT::TYPE); |
|
39
|
|
|
$this->assertCount(1, $mailTxtRecords); |
|
|
|
|
|
|
40
|
|
|
$this->assertNull($mailTxtRecords[0]->getComment()); |
|
41
|
|
|
|
|
42
|
|
|
$sub_domainRecords = ParserTest::findRecord('sub.domain', $zone, A::TYPE); |
|
43
|
|
|
$this->assertCount(1, $sub_domainRecords); |
|
|
|
|
|
|
44
|
|
|
$this->assertEquals('This is a local ip.', $sub_domainRecords[0]->getComment()); |
|
45
|
|
|
|
|
46
|
|
|
$ipv6_domainRecords = ParserTest::findRecord('ipv6.domain', $zone, AAAA::TYPE); |
|
47
|
|
|
$this->assertCount(1, $ipv6_domainRecords); |
|
|
|
|
|
|
48
|
|
|
$this->assertEquals('This is an IPv6 domain.', $ipv6_domainRecords[0]->getComment()); |
|
49
|
|
|
|
|
50
|
|
|
$soaRecords = ParserTest::findRecord('@', $zone, SOA::TYPE); |
|
51
|
|
|
$this->assertCount(1, $soaRecords); |
|
|
|
|
|
|
52
|
|
|
$this->assertEquals('MNAME RNAME SERIAL REFRESH RETRY EXPIRE MINIMUM This is my Start of Authority Record; AKA SOA.', $soaRecords[0]->getComment()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @throws \Exception |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testCommentOnlyLinesParse(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$zoneFile = NormaliserTest::readFile(__DIR__.'/Resources/testCollapseMultilines_sample.txt'); |
|
61
|
|
|
$zone = Parser::parse('example.com.', $zoneFile, Comments::ALL); |
|
62
|
|
|
|
|
63
|
|
|
$nullEntries = ParserTest::findRecord(null, $zone, null); |
|
64
|
|
|
$this->assertCount(4, $nullEntries); |
|
|
|
|
|
|
65
|
|
|
$this->assertEquals('NS RECORDS', $nullEntries[0]->getComment()); |
|
66
|
|
|
$this->assertEquals('A RECORDS', $nullEntries[1]->getComment()); |
|
67
|
|
|
$this->assertEquals('AAAA RECORDS', $nullEntries[2]->getComment()); |
|
68
|
|
|
$this->assertEquals('MX RECORDS', $nullEntries[3]->getComment()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @throws \Exception |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testMultilineTxtRecords(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$zoneFile = NormaliserTest::readFile(__DIR__.'/Resources/testMultilineTxtRecords_sample.txt'); |
|
77
|
|
|
$zone = Parser::parse('acme.com.', $zoneFile, Comments::ALL); |
|
78
|
|
|
|
|
79
|
|
|
$txtRecords = ParserTest::findRecord('test', $zone, TXT::TYPE); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertCount(1, $txtRecords); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$test = $txtRecords[0]; |
|
84
|
|
|
$this->assertEquals('test', $test->getName()); |
|
85
|
|
|
$this->assertEquals(7230, $test->getTtl()); |
|
86
|
|
|
$this->assertEquals('TXT', $test->getType()); |
|
87
|
|
|
$this->assertEquals('This is a comment.', $test->getComment()); |
|
88
|
|
|
$this->assertEquals('This is an example of a multiline TXT record.', $test->getRdata()->getText()); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: