|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Badcow DNS Library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Samuel Williams <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Badcow\DNS\Tests; |
|
13
|
|
|
|
|
14
|
|
|
use Badcow\DNS\AlignedBuilder; |
|
15
|
|
|
use Badcow\DNS\Classes; |
|
16
|
|
|
use Badcow\DNS\ResourceRecord; |
|
17
|
|
|
use Badcow\DNS\Rdata\Factory; |
|
18
|
|
|
use Badcow\DNS\Tests\Rdata\DummyRdata; |
|
19
|
|
|
|
|
20
|
|
|
class AlignedBuilderTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
protected $expected = <<< 'DNS' |
|
23
|
|
|
$ORIGIN example.com. |
|
24
|
|
|
$TTL 3600 |
|
25
|
|
|
@ IN SOA ( |
|
26
|
|
|
example.com. ; MNAME |
|
27
|
|
|
postmaster.example.com. ; RNAME |
|
28
|
|
|
2015050801 ; SERIAL |
|
29
|
|
|
3600 ; REFRESH |
|
30
|
|
|
14400 ; RETRY |
|
31
|
|
|
604800 ; EXPIRE |
|
32
|
|
|
3600 ; MINIMUM |
|
33
|
|
|
) |
|
34
|
|
|
|
|
35
|
|
|
; NS RECORDS |
|
36
|
|
|
@ 14400 IN NS ns1.example.net.au. |
|
37
|
|
|
@ 14400 IN NS ns2.example.net.au. |
|
38
|
|
|
|
|
39
|
|
|
; A RECORDS |
|
40
|
|
|
subdomain.au A 192.168.1.2; This is a local ip. |
|
41
|
|
|
|
|
42
|
|
|
; AAAA RECORDS |
|
43
|
|
|
ipv6domain 3600 IN AAAA ::1; This is an IPv6 domain. |
|
44
|
|
|
|
|
45
|
|
|
; CNAME RECORDS |
|
46
|
|
|
alias CNAME subdomain.au.example.com. |
|
47
|
|
|
|
|
48
|
|
|
; DNAME RECORDS |
|
49
|
|
|
bar.example.com. IN DNAME foo.example.com. |
|
50
|
|
|
|
|
51
|
|
|
; MX RECORDS |
|
52
|
|
|
@ MX 10 mail-gw1.example.net. |
|
53
|
|
|
@ MX 20 mail-gw2.example.net. |
|
54
|
|
|
@ MX 30 mail-gw3.example.net. |
|
55
|
|
|
|
|
56
|
|
|
; LOC RECORDS |
|
57
|
|
|
canberra IN LOC ( |
|
58
|
|
|
35 18 27.000 S ; LATITUDE |
|
59
|
|
|
149 7 27.840 E ; LONGITUDE |
|
60
|
|
|
500.00m ; ALTITUDE |
|
61
|
|
|
20.12m ; SIZE |
|
62
|
|
|
200.30m ; HORIZONTAL PRECISION |
|
63
|
|
|
300.10m ; VERTICAL PRECISION |
|
64
|
|
|
); This is Canberra |
|
65
|
|
|
|
|
66
|
|
|
; HINFO RECORDS |
|
67
|
|
|
@ IN HINFO "2.7GHz" "Ubuntu 12.04" |
|
68
|
|
|
|
|
69
|
|
|
; TXT RECORDS |
|
70
|
|
|
example.net. IN TXT "v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all" |
|
71
|
|
|
|
|
72
|
|
|
DNS; |
|
73
|
|
|
|
|
74
|
|
|
public function testCompareResourceRecords() |
|
75
|
|
|
{ |
|
76
|
|
|
$soa = new ResourceRecord(); |
|
77
|
|
|
$soa->setClass('IN'); |
|
78
|
|
|
$soa->setName('@'); |
|
79
|
|
|
$soa->setRdata(Factory::Soa( |
|
80
|
|
|
'example.com.', |
|
81
|
|
|
'postmaster.example.com.', |
|
82
|
|
|
2015050801, |
|
83
|
|
|
3600, |
|
84
|
|
|
14400, |
|
85
|
|
|
604800, |
|
86
|
|
|
3600 |
|
87
|
|
|
)); |
|
88
|
|
|
|
|
89
|
|
|
$ns1 = new ResourceRecord(); |
|
90
|
|
|
$ns1->setClass(Classes::INTERNET); |
|
91
|
|
|
$ns1->setName('@'); |
|
92
|
|
|
$ns1->setTtl(14400); |
|
93
|
|
|
$ns1->setRdata(Factory::Ns('ns1.example.net.au.')); |
|
94
|
|
|
|
|
95
|
|
|
$ns2 = new ResourceRecord(); |
|
96
|
|
|
$ns2->setClass('IN'); |
|
97
|
|
|
$ns2->setName('@'); |
|
98
|
|
|
$ns2->setTtl(14400); |
|
99
|
|
|
$ns2->setRdata(Factory::Ns('ns2.example.net.au.')); |
|
100
|
|
|
|
|
101
|
|
|
$a = new ResourceRecord(); |
|
102
|
|
|
$a->setName('subdomain.au'); |
|
103
|
|
|
$a->setRdata(Factory::A('192.168.1.2')); |
|
104
|
|
|
$a->setComment('This is a local ip.'); |
|
105
|
|
|
|
|
106
|
|
|
$cname = new ResourceRecord(); |
|
107
|
|
|
$cname->setName('alias'); |
|
108
|
|
|
$cname->setRdata(Factory::Cname('subdomain.au.example.com.')); |
|
109
|
|
|
$cname->setClass(Classes::INTERNET); |
|
110
|
|
|
|
|
111
|
|
|
$aaaa = new ResourceRecord('ipv6domain', Factory::Aaaa('::1'), 3600); |
|
112
|
|
|
|
|
113
|
|
|
$mx1 = new ResourceRecord(); |
|
114
|
|
|
$mx1->setName('@'); |
|
115
|
|
|
$mx1->setRdata(Factory::Mx(10, 'mailgw01.example.net.')); |
|
116
|
|
|
|
|
117
|
|
|
$mx2 = new ResourceRecord(); |
|
118
|
|
|
$mx2->setName('@'); |
|
119
|
|
|
$mx2->setRdata(Factory::Mx(20, 'mailgw02.example.net.')); |
|
120
|
|
|
|
|
121
|
|
|
$txt = new ResourceRecord(); |
|
122
|
|
|
$txt->setName('example.net.'); |
|
123
|
|
|
$txt->setRdata(Factory::txt('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all')); |
|
124
|
|
|
|
|
125
|
|
|
$dummy = new ResourceRecord(); |
|
126
|
|
|
$dummy->setName('example.com.'); |
|
127
|
|
|
$dummy->setRdata(new DummyRdata()); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($soa, $ns1) < 0); |
|
130
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($aaaa, $cname) < 0); |
|
131
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $mx2) < 0); |
|
132
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $mx2) < 0); |
|
133
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $dummy) < 0); |
|
134
|
|
|
|
|
135
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($mx1, $a) > 0); |
|
136
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($ns2, $ns1) > 0); |
|
137
|
|
|
$this->assertTrue(AlignedBuilder::compareResourceRecords($dummy, $txt) > 0); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function testBuild() |
|
141
|
|
|
{ |
|
142
|
|
|
$zone = $this->buildTestZone(); |
|
143
|
|
|
$zone->addResourceRecord(new ResourceRecord('null')); |
|
144
|
|
|
|
|
145
|
|
|
$builder = new AlignedBuilder(); |
|
146
|
|
|
$output = $builder->build($zone); |
|
147
|
|
|
|
|
148
|
|
|
$this->assertEquals($this->expected, $output); |
|
149
|
|
|
|
|
150
|
|
|
if (true == $this->getEnvVariable(self::PHP_ENV_PRINT_TEST_ZONE)) { |
|
151
|
|
|
$this->printBlock($output, 'ALIGNED TEST ZONE'); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|