1# $Id: 07-misc.t 625 2007-01-24 14:35:58Z olaf $ -*-perl-*-
2
3use Test::More tests => 37;
4use strict;
5
6BEGIN { use_ok('Net::DNS'); 
7}
8
9
10
11# test to make sure that wildcarding works.
12#
13my $rr;
14eval { $rr = Net::DNS::RR->new('*.t.net-dns.org 60 IN A 10.0.0.1'); };
15
16ok($rr, 'RR got made');
17
18is($rr->name,    '*.t.net-dns.org', 'Name is correct'   );
19is($rr->ttl,      60,               'TTL is correct'    );
20is($rr->class,   'IN',              'CLASS is correct'  );
21is($rr->type,    'A',               'TYPE is correct'   );
22is($rr->address, '10.0.0.1',        'Address is correct');
23
24#
25# Make sure the underscore in SRV hostnames work.
26#
27my $srv;
28eval { $srv = Net::DNS::RR->new('_rvp._tcp.t.net-dns.org. 60 IN SRV 0 0 80 im.bastardsinc.biz'); };
29
30ok(!$@,  'No errors');
31ok($srv, 'SRV got made');
32
33
34
35#
36# Test that the 5.005 Use of uninitialized value at
37# /usr/local/lib/perl5/site_perl/5.005/Net/DNS/RR.pm line 639. bug is gone
38#
39my $warning = 0;
40{
41	
42	local $^W = 1;
43	local $SIG{__WARN__} = sub { $warning++ };
44	
45	my $rr = Net::DNS::RR->new('mx.t.net-dns.org 60 IN MX 10 a.t.net-dns.org');
46	ok($rr, 'RR created');
47
48	is($rr->preference, 10, 'Preference works');
49}
50
51is($warning, 0, 'No evil warning');
52
53
54{
55	my $mx = Net::DNS::RR->new('mx.t.net-dns.org 60 IN MX 0 mail.net-dns.org');
56	
57	like($mx->string, '/0 mail.net-dns.org/');
58	is($mx->preference, 0);
59	is($mx->exchange, 'mail.net-dns.org');
60}
61
62{
63	my $srv = Net::DNS::RR->new('srv.t.net-dns.org 60 IN SRV 0 2 3 target.net-dns.org');
64	
65	like($srv->string, '/0 2 3 target.net-dns.org\./');
66	is($srv->rdatastr, '0 2 3 target.net-dns.org.');
67}
68
69
70
71
72
73#
74#
75# Below are some thests that have to do with TXT RRs 
76#
77#
78
79
80#;; QUESTION SECTION:
81#;txt2.t.net-dns.org.		IN	TXT
82
83#;; ANSWER SECTION:
84#txt2.t.net-dns.org.	60	IN	TXT	"Net-DNS\; complicated $tuff" "sort of \" text\; and binary \000 data"
85
86#;; AUTHORITY SECTION:
87#net-dns.org.		3600	IN	NS	ns1.net-dns.org.
88#net-dns.org.		3600	IN	NS	ns.ripe.net.
89#net-dns.org.		3600	IN	NS	ns.hactrn.net.
90
91#;; ADDITIONAL SECTION:
92#ns1.net-dns.org.	3600	IN	A	193.0.4.49
93#ns1.net-dns.org.	3600	IN	AAAA
94
95my $UUencodedPacket='
9611 99 85 00 00 01
9700 01 00 03 00 02 04 74  78 74 32 01 74 07 6e 65
9874 2d 64 6e 73 03 6f 72  67 00 00 10 00 01 c0 0c
9900 10 00 01 00 00 00 3c  00 3d 1a 4e 65 74 2d 44
1004e 53 3b 20 63 6f 6d 70  6c 69 63 61 74 65 64 20
10124 74 75 66 66 21 73 6f  72 74 20 6f 66 20 22 20
10274 65 78 74 3b 20 61 6e  64 20 62 69 6e 61 72 79
10320 00 20 64 61 74 61 c0  13 00 02 00 01 00 00 0e
10410 00 06 03 6e 73 31 c0  13 c0 13 00 02 00 01 00
10500 0e 10 00 0d 02 6e 73  04 72 69 70 65 03 6e 65
10674 00 c0 13 00 02 00 01  00 00 0e 10 00 0c 02 6e
10773 06 68 61 63 74 72 6e  c0 93 c0 79 00 01 00 01
10800 00 0e 10 00 04 c1 00  04 31 c0 79 00 1c 00 01
10900 00 0e 10 00 10 20 01  06 10 02 40 00 03 00 00
11012 34 be 21 e3 1e                               
111';
112
113
114
115
116$UUencodedPacket =~ s/\s*//g;
117my $packetdata = pack('H*',$UUencodedPacket);
118my $packet     = Net::DNS::Packet->new(\$packetdata);
119my $TXTrr=($packet->answer)[0];
120is(($TXTrr->char_str_list())[0],'Net-DNS; complicated $tuff',"First Char string in TXT RR read from wireformat");
121
122# Compare the second char_str this contains a NULL byte (space NULL
123# space=200020 in hex)
124
125is(unpack('H*',($TXTrr->char_str_list())[1]),"736f7274206f66202220746578743b20616e642062696e61727920002064617461", "Second Char string in TXT RR read from wireformat");
126
127
128my $TXTrr2=Net::DNS::RR->new('txt2.t.net-dns.org.	60	IN	TXT  "Test1 \" \; more stuff"  "Test2"');
129
130is(($TXTrr2->char_str_list())[0],'Test1 " ; more stuff', "First arg string in TXT RR read from zonefileformat");
131is(($TXTrr2->char_str_list())[1],'Test2',"Second Char string in TXT RR read from zonefileformat");
132
133
134my $TXTrr3   = Net::DNS::RR->new("baz.example.com 3600 HS TXT '\"' 'Char Str2'");
135
136is( ($TXTrr3->char_str_list())[0],'"',"Escaped \" between the  single quotes");
137
138
139
140
141
142
143ok(Net::DNS::Resolver::Base::_ip_is_ipv4("10.0.0.9"),"_ip_is_ipv4, test 1");
144
145ok(Net::DNS::Resolver::Base::_ip_is_ipv4("1"),"_ip_is_ipv4, test 2");
146
147# remember 1.1 expands to 1.0.0.1 and is legal.
148ok( Net::DNS::Resolver::Base::_ip_is_ipv4("1.1"),"_ip_is_ipv4, test 3");
149
150ok( ! Net::DNS::Resolver::Base::_ip_is_ipv4("256.1.0.9"),"_ip_is_ipv4, test 4");
151
152ok( ! Net::DNS::Resolver::Base::_ip_is_ipv4("10.11.12.13.14"),"_ip_is_ipv4, test 5");
153
154ok(Net::DNS::Resolver::Base::_ip_is_ipv6("::1"),"_ip_is_ipv6, test 1");
155ok(Net::DNS::Resolver::Base::_ip_is_ipv6("1::1"),"_ip_is_ipv6, test 2");
156ok(Net::DNS::Resolver::Base::_ip_is_ipv6("1::1:1"),"_ip_is_ipv6, test 3");
157ok(! Net::DNS::Resolver::Base::_ip_is_ipv6("1::1:1::1"),"_ip_is_ipv6, test 4");
158ok(Net::DNS::Resolver::Base::_ip_is_ipv6("1:2:3:4:4:6:7:8"),"_ip_is_ipv6, test 5");
159ok(! Net::DNS::Resolver::Base::_ip_is_ipv6("1:2:3:4:4:6:7:8:9"),"_ip_is_ipv6, test 6");
160
161
162ok( Net::DNS::Resolver::Base::_ip_is_ipv6("0001:0002:0003:0004:0004:0006:0007:0008"),"_ip_is_ipv6, test 7");
163
164ok( Net::DNS::Resolver::Base::_ip_is_ipv6("abcd:ef01:2345:6789::"),"_ip_is_ipv6, test 8");
165
166ok(! Net::DNS::Resolver::Base::_ip_is_ipv6("abcd:efgh:2345:6789::"),"_ip_is_ipv6, test 9");
167
168ok( Net::DNS::Resolver::Base::_ip_is_ipv6("0001:0002:0003:0004:0004:0006:0007:10.0.0.1"),"_ip_is_ipv6, test 10");
169
170