bluemonk-net-dns 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ require 'test/unit'
2
+ require 'net/dns/resolver/timeouts.rb'
3
+
4
+ class Test_DnsTimeout < Test::Unit::TestCase
5
+
6
+ def test_tcp
7
+ assert_equal(TcpTimeout.new(0).to_s,"infinite")
8
+ assert_equal(TcpTimeout.new(30).to_s, "30")
9
+ assert_equal(TcpTimeout.new(30).pretty_to_s, "30 seconds")
10
+ assert_equal(TcpTimeout.new(90).pretty_to_s,
11
+ "1 minutes and 30 seconds")
12
+ assert_equal(TcpTimeout.new(3690).pretty_to_s,
13
+ "1 hours, 1 minutes and 30 seconds")
14
+ assert_equal(TcpTimeout.new(1).timeout {1+1}, 2)
15
+ end
16
+
17
+ def test_udp
18
+ assert_equal(UdpTimeout.new(0).to_s,"not defined")
19
+ assert_equal(UdpTimeout.new(30).to_s, "30")
20
+ assert_equal(UdpTimeout.new(30).pretty_to_s, "30 seconds")
21
+ assert_equal(UdpTimeout.new(90).pretty_to_s,
22
+ "1 minutes and 30 seconds")
23
+ assert_equal(UdpTimeout.new(3690).pretty_to_s,
24
+ "1 hours, 1 minutes and 30 seconds")
25
+ assert_equal(UdpTimeout.new(1).timeout {1+1}, 2)
26
+ end
27
+
28
+ def test_range_tcp
29
+ assert_raise(DnsTimeoutArgumentError) do
30
+ TcpTimeout.new("a")
31
+ end
32
+ assert_raise(DnsTimeoutArgumentError) do
33
+ TcpTimeout.new(-1)
34
+ end
35
+ assert_raise(DnsTimeoutArgumentError) do
36
+ TcpTimeout.new(1).timeout
37
+ end
38
+ assert_raise(TimeoutError) do
39
+ TcpTimeout.new(0.1).timeout {sleep 2}
40
+ end
41
+ end
42
+
43
+ def test_range_udp
44
+ assert_raise(DnsTimeoutArgumentError) do
45
+ UdpTimeout.new("a")
46
+ end
47
+ assert_raise(DnsTimeoutArgumentError) do
48
+ UdpTimeout.new(-1)
49
+ end
50
+ assert_raise(DnsTimeoutArgumentError) do
51
+ UdpTimeout.new(1).timeout
52
+ end
53
+ assert_raise(TimeoutError) do
54
+ UdpTimeout.new(0.1).timeout {sleep 2}
55
+ end
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,72 @@
1
+ require 'test/unit'
2
+ require 'net/dns/rr'
3
+
4
+ class Test_A < Test::Unit::TestCase
5
+ def setup
6
+
7
+ @name = "google.com."
8
+ @type = "A"
9
+ @cls = "IN"
10
+ @ttl = 10800
11
+ @address = "64.233.187.99"
12
+
13
+
14
+ @hash = Net::DNS::RR::A.new(:name => @name,
15
+ :address => @address)
16
+
17
+ @string = Net::DNS::RR::A.new("google.com. 10800 IN A 64.233.187.99")
18
+
19
+ @arr = Net::DNS::RR.parse(@string.data)
20
+
21
+ @str = "google.com. 10800 IN A 64.233.187.99"
22
+ end
23
+
24
+ def test_simple
25
+ assert_equal(@str,@hash.inspect)
26
+ assert_equal(@name, @hash.name)
27
+ assert_equal(@type, @hash.type)
28
+ assert_equal(@cls, @hash.cls)
29
+ assert_equal(@ttl, @hash.ttl)
30
+ assert_equal(@address, @hash.address.to_s)
31
+
32
+ assert_equal(@str, @string.inspect)
33
+ assert_equal(@name, @string.name)
34
+ assert_equal(@type, @string.type)
35
+ assert_equal(@cls, @string.cls)
36
+ assert_equal(@ttl, @string.ttl)
37
+ assert_equal(@address, @string.address.to_s)
38
+
39
+ assert_equal(@str, @arr.inspect)
40
+ assert_equal(@name, @arr.name)
41
+ assert_equal(@type, @arr.type)
42
+ assert_equal(@cls, @arr.cls)
43
+ assert_equal(@ttl, @arr.ttl)
44
+ assert_equal(@address, @arr.address.to_s)
45
+ end
46
+
47
+ def test_range
48
+ assert_raise(RRArgumentError) do
49
+ Net::DNS::RR::A.new(:name => "google.com",
50
+ :address => "255.256")
51
+ end
52
+ assert_raise(RRArgumentError) do
53
+ Net::DNS::RR::A.new(:name => "google.com")
54
+ end
55
+ assert_raise(RRArgumentError) do
56
+ Net::DNS::RR::A.new(Object.new)
57
+ end
58
+ assert_raise(RRArgumentError) do
59
+ Net::DNS::RR::A.new(Array.new(7))
60
+ end
61
+ assert_raise(RRArgumentError) do
62
+ Net::DNS::RR::A.new("10800 IN A")
63
+ end
64
+ assert_raise(RRArgumentError) do
65
+ Net::DNS::RR::A.new("google.com. 10800 IN B")
66
+ end
67
+ assert_raise(RRArgumentError) do
68
+ Net::DNS::RR::A.new("google.com. 10800 IM A")
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,73 @@
1
+ require 'test/unit'
2
+ require 'net/dns/rr/classes'
3
+
4
+ class Test_Classes < Test::Unit::TestCase
5
+ def setup
6
+ @classes = {
7
+ 'IN' => 1, # RFC 1035
8
+ 'CH' => 3, # RFC 1035
9
+ 'HS' => 4, # RFC 1035
10
+ 'NONE' => 254, # RFC 2136
11
+ 'ANY' => 255, # RFC 1035
12
+ }
13
+ @regexp_string = "HS|ANY|NONE|CH|IN"
14
+ end
15
+
16
+ def test_default
17
+ # Default type should be ANY => 255
18
+ instance = Net::DNS::RR::Classes.new(nil)
19
+ assert_equal("1", instance.to_str)
20
+ assert_equal("IN", instance.to_s)
21
+
22
+ # Let's change default behaviour
23
+ Net::DNS::RR::Classes.default = "CH"
24
+ instance = Net::DNS::RR::Classes.new(nil)
25
+ assert_equal("3", instance.to_str)
26
+ assert_equal("CH", instance.to_s)
27
+
28
+ Net::DNS::RR::Classes.default = "IN"
29
+ instance = Net::DNS::RR::Classes.new(nil)
30
+ assert_equal("1", instance.to_str)
31
+ assert_equal("IN", instance.to_s)
32
+
33
+ end
34
+
35
+ def test_classes
36
+ @classes.each do |key,num|
37
+ instance_from_string = Net::DNS::RR::Classes.new(key)
38
+ instance_from_num = Net::DNS::RR::Classes.new(num)
39
+ assert_equal(key, instance_from_string.to_s)
40
+ assert_equal(num.to_s, instance_from_string.to_str)
41
+ assert_equal(key, instance_from_num.to_s)
42
+ assert_equal(num.to_s, instance_from_num.to_str)
43
+ end
44
+ assert_raise(ClassArgumentError) do
45
+ Net::DNS::RR::Classes.new(Hash.new)
46
+ end
47
+ end
48
+
49
+ def test_regexp
50
+ assert_equal(@regexp_string, Net::DNS::RR::Classes.regexp)
51
+ end
52
+
53
+ def test_valid
54
+ assert_equal(true, Net::DNS::RR::Classes.valid?("IN"))
55
+ assert_equal(true, Net::DNS::RR::Classes.valid?(1))
56
+ assert_equal(false, Net::DNS::RR::Classes.valid?("Q"))
57
+ assert_equal(false, Net::DNS::RR::Classes.valid?(256))
58
+ assert_raise(ClassArgumentError) do
59
+ Net::DNS::RR::Classes.valid? Hash.new
60
+ end
61
+ end
62
+
63
+ def test_to_str
64
+ assert_equal("IN", Net::DNS::RR::Classes.to_str(1))
65
+ assert_raise(ClassArgumentError) do
66
+ Net::DNS::RR::Classes.to_str(256)
67
+ end
68
+ assert_raise(ClassArgumentError) do
69
+ Net::DNS::RR::Classes.to_str("string")
70
+ end
71
+ end
72
+
73
+ end
@@ -0,0 +1,66 @@
1
+ require 'test/unit'
2
+ require 'net/dns/rr'
3
+
4
+ class Test_NS < Test::Unit::TestCase
5
+ def setup
6
+
7
+ @name = "google.com."
8
+ @type = "NS"
9
+ @cls = "IN"
10
+ @ttl = 10800
11
+ @nsdname = "ns1.google.com."
12
+
13
+
14
+ @hash = Net::DNS::RR::NS.new(:name => @name,
15
+ :nsdname => @nsdname)
16
+
17
+ @string = Net::DNS::RR::NS.new("google.com. 10800 IN NS ns1.google.com.")
18
+
19
+ @arr = Net::DNS::RR.parse(@string.data)
20
+
21
+ @str = "google.com. 10800 IN NS ns1.google.com."
22
+ end
23
+
24
+ def test_simple
25
+ assert_equal(@str,@hash.inspect)
26
+ assert_equal(@name, @hash.name)
27
+ assert_equal(@type, @hash.type)
28
+ assert_equal(@cls, @hash.cls)
29
+ assert_equal(@ttl, @hash.ttl)
30
+ assert_equal(@nsdname, @hash.nsdname)
31
+
32
+ assert_equal(@str, @string.inspect)
33
+ assert_equal(@name, @string.name)
34
+ assert_equal(@type, @string.type)
35
+ assert_equal(@cls, @string.cls)
36
+ assert_equal(@ttl, @string.ttl)
37
+ assert_equal(@nsdname, @string.nsdname)
38
+
39
+ assert_equal(@str, @arr.inspect)
40
+ assert_equal(@name, @arr.name)
41
+ assert_equal(@type, @arr.type)
42
+ assert_equal(@cls, @arr.cls)
43
+ assert_equal(@ttl, @arr.ttl)
44
+ assert_equal(@nsdname, @arr.nsdname)
45
+ end
46
+
47
+ def test_range
48
+ assert_raise(RRArgumentError) do
49
+ Net::DNS::RR::NS.new(:name => "google.com",
50
+ :nsdname => "255.256")
51
+ end
52
+ assert_raise(RRArgumentError) do
53
+ Net::DNS::RR::NS.new(:name => "google.com")
54
+ end
55
+ assert_raise(ArgumentError) do
56
+ Net::DNS::RR::NS.new(Range.new)
57
+ end
58
+ assert_raise(RRArgumentError) do
59
+ Net::DNS::RR::NS.new(Array.new(7))
60
+ end
61
+ assert_raise(RRArgumentError) do
62
+ Net::DNS::RR::NS.new("10800 IN A")
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,127 @@
1
+ require 'test/unit'
2
+ require 'net/dns/rr/types'
3
+
4
+ class Test_Types < Test::Unit::TestCase
5
+ def setup
6
+ @types = {
7
+ 'SIGZERO' => 0,
8
+ 'A' => 1,
9
+ 'NS' => 2,
10
+ 'MD' => 3,
11
+ 'MF' => 4,
12
+ 'CNAME' => 5,
13
+ 'SOA' => 6,
14
+ 'MB' => 7,
15
+ 'MG' => 8,
16
+ 'MR' => 9,
17
+ 'NULL' => 10,
18
+ 'WKS' => 11,
19
+ 'PTR' => 12,
20
+ 'HINFO' => 13,
21
+ 'MINFO' => 14,
22
+ 'MX' => 15,
23
+ 'TXT' => 16,
24
+ 'RP' => 17,
25
+ 'AFSDB' => 18,
26
+ 'X25' => 19,
27
+ 'ISDN' => 20,
28
+ 'RT' => 21,
29
+ 'NSAP' => 22,
30
+ 'NSAP_PTR' => 23,
31
+ 'SIG' => 24,
32
+ 'KEY' => 25,
33
+ 'PX' => 26,
34
+ 'GPOS' => 27,
35
+ 'AAAA' => 28,
36
+ 'LOC' => 29,
37
+ 'NXT' => 30,
38
+ 'EID' => 31,
39
+ 'NIMLOC' => 32,
40
+ 'SRV' => 33,
41
+ 'ATMA' => 34,
42
+ 'NAPTR' => 35,
43
+ 'KX' => 36,
44
+ 'CERT' => 37,
45
+ 'DNAME' => 39,
46
+ 'OPT' => 41,
47
+ 'DS' => 43,
48
+ 'SSHFP' => 44,
49
+ 'RRSIG' => 46,
50
+ 'NSEC' => 47,
51
+ 'DNSKEY' => 48,
52
+ 'UINFO' => 100,
53
+ 'UID' => 101,
54
+ 'GID' => 102,
55
+ 'UNSPEC' => 103,
56
+ 'TKEY' => 249,
57
+ 'TSIG' => 250,
58
+ 'IXFR' => 251,
59
+ 'AXFR' => 252,
60
+ 'MAILB' => 253,
61
+ 'MAILA' => 254,
62
+ 'ANY' => 255,
63
+ }
64
+
65
+ @regexp_string = "UNSPEC|ATMA|EID|LOC|NSAP|ISDN|MX|ANY|MAILA|SRV|AFSDB|MD|" +
66
+ "A|MAILB|TKEY|GID|KX|GPOS|RT|HINFO|PTR|CNAME|MF|SIGZERO|DNSKEY|DS|AAAA|" +
67
+ "MG|UID|NSEC|NIMLOC|NSAP_PTR|X25|TXT|MR|SOA|NS|DNAME|CERT|SIG|AXFR|IXFR|" +
68
+ "UINFO|NAPTR|OPT|PX|RP|TSIG|SSHFP|KEY|MINFO|WKS|NULL|RRSIG|NXT|MB"
69
+ end
70
+
71
+ def test_default
72
+ # Default type should be ANY => 255
73
+ instance = Net::DNS::RR::Types.new(nil)
74
+ assert_equal("1", instance.to_str)
75
+ assert_equal("A", instance.to_s)
76
+
77
+ # Let's change default behaviour
78
+ Net::DNS::RR::Types.default = "A"
79
+ instance = Net::DNS::RR::Types.new(nil)
80
+ assert_equal("1", instance.to_str)
81
+ assert_equal("A", instance.to_s)
82
+
83
+ Net::DNS::RR::Types.default = "ANY"
84
+ instance = Net::DNS::RR::Types.new(nil)
85
+ assert_equal("255", instance.to_str)
86
+ assert_equal("ANY", instance.to_s)
87
+ end
88
+
89
+ def test_types
90
+ @types.each do |key,num|
91
+ instance_from_string = Net::DNS::RR::Types.new(key)
92
+ instance_from_num = Net::DNS::RR::Types.new(num)
93
+ assert_equal(key, instance_from_string.to_s)
94
+ assert_equal(num.to_s, instance_from_string.to_str)
95
+ assert_equal(key, instance_from_num.to_s)
96
+ assert_equal(num.to_s, instance_from_num.to_str)
97
+ end
98
+ assert_raise(TypeArgumentError) do
99
+ Net::DNS::RR::Types.new(Hash.new)
100
+ end
101
+ end
102
+
103
+ def test_regexp
104
+ assert_equal(@regexp_string, Net::DNS::RR::Types.regexp)
105
+ end
106
+
107
+ def test_valid
108
+ assert_equal(true, Net::DNS::RR::Types.valid?("A"))
109
+ assert_equal(true, Net::DNS::RR::Types.valid?(1))
110
+ assert_equal(false, Net::DNS::RR::Types.valid?("Q"))
111
+ assert_equal(false, Net::DNS::RR::Types.valid?(256))
112
+ assert_raise(TypeArgumentError) do
113
+ Net::DNS::RR::Types.valid? Hash.new
114
+ end
115
+ end
116
+
117
+ def test_to_str
118
+ assert_equal("A", Net::DNS::RR::Types.to_str(1))
119
+ assert_raise(TypeArgumentError) do
120
+ Net::DNS::RR::Types.to_str(256)
121
+ end
122
+ assert_raise(TypeArgumentError) do
123
+ Net::DNS::RR::Types.to_str("string")
124
+ end
125
+ end
126
+
127
+ end
@@ -0,0 +1,170 @@
1
+ require 'test/unit'
2
+ require 'net/dns/header'
3
+
4
+ class Test_Header < Test::Unit::TestCase
5
+ include Net::DNS
6
+
7
+ def setup
8
+
9
+ @default = Header.new
10
+ @hash = Header.new(:id => 441,
11
+ :qr => 1,
12
+ :opCode => Header::IQUERY,
13
+ :aa => 1,
14
+ :tc => 1,
15
+ :rd => 0,
16
+ :cd => 0,
17
+ :ad => 0,
18
+ :ra => 1,
19
+ :rCode => Header::RCode::FORMAT,
20
+ :qdCount => 1,
21
+ :anCount => 2,
22
+ :nsCount => 3,
23
+ :arCount => 3)
24
+
25
+ @modified = Header.new
26
+ @modified.id = 442
27
+ @modified.qr = true
28
+ @modified.opCode = Header::IQUERY
29
+ @modified.aa = true
30
+ @modified.tc = true
31
+ @modified.rd = false
32
+ @modified.cd = false
33
+ @modified.ra = true
34
+ @modified.rCode = Header::RCode::FORMAT
35
+ @modified.qdCount = 1
36
+ @modified.anCount = 2
37
+ @modified.nsCount = 3
38
+ @modified.arCount = 3
39
+
40
+ @data = @modified.data
41
+ num = [(@data.unpack("n")[0]+1)].pack("n")
42
+ @data[0],@data[1] = num[0], num[1]
43
+ @binary = Header.parse(@data)
44
+
45
+ end
46
+
47
+ def test_simple
48
+ assert_equal(@default.query?, true)
49
+ assert_equal(@default.response?, false)
50
+ assert_equal(@default.opCode, Header::QUERY)
51
+ assert_equal(@default.auth?, false)
52
+ assert_equal(@default.truncated?, false)
53
+ assert_equal(@default.recursive?, true)
54
+ assert_equal(@default.checking?, true)
55
+ assert_equal(@default.verified?, false)
56
+ assert_equal(@default.r_available?, false)
57
+ assert_equal(@default.rCode.code, Header::RCode::NOERROR)
58
+ assert_equal(@default.qdCount, 1)
59
+ assert_equal(@default.anCount, 0)
60
+ assert_equal(@default.nsCount, 0)
61
+ assert_equal(@default.arCount, 0)
62
+
63
+ assert_equal(@hash.id, 441)
64
+ assert_equal(@hash.query?, false)
65
+ assert_equal(@hash.response?, true)
66
+ assert_equal(@hash.opCode, Header::IQUERY)
67
+ assert_equal(@hash.auth?, true)
68
+ assert_equal(@hash.truncated?, true)
69
+ assert_equal(@hash.recursive?, false)
70
+ assert_equal(@hash.checking?, true)
71
+ assert_equal(@hash.verified?, false)
72
+ assert_equal(@hash.r_available?, true)
73
+ assert_equal(@hash.rCode.code, Header::RCode::FORMAT)
74
+ assert_equal(@hash.qdCount, 1)
75
+ assert_equal(@hash.anCount, 2)
76
+ assert_equal(@hash.nsCount, 3)
77
+ assert_equal(@hash.arCount, 3)
78
+
79
+ assert_equal(@modified.id, 442)
80
+ assert_equal(@modified.query?, false)
81
+ assert_equal(@modified.response?, true)
82
+ assert_equal(@modified.opCode, Header::IQUERY)
83
+ assert_equal(@modified.auth?, true)
84
+ assert_equal(@modified.truncated?, true)
85
+ assert_equal(@modified.recursive?, false)
86
+ assert_equal(@modified.checking?, true)
87
+ assert_equal(@modified.verified?, false)
88
+ assert_equal(@modified.r_available?, true)
89
+ assert_equal(@modified.rCode.code, Header::RCode::FORMAT)
90
+ assert_equal(@modified.qdCount, 1)
91
+ assert_equal(@modified.anCount, 2)
92
+ assert_equal(@modified.nsCount, 3)
93
+ assert_equal(@modified.arCount, 3)
94
+
95
+ assert_equal(@binary.data, @data)
96
+
97
+ assert_equal(@binary.id, 443)
98
+ assert_equal(@binary.query?, false)
99
+ assert_equal(@binary.response?, true)
100
+ assert_equal(@binary.opCode, Header::IQUERY)
101
+ assert_equal(@binary.auth?, true)
102
+ assert_equal(@binary.truncated?, true)
103
+ assert_equal(@binary.recursive?, false)
104
+ assert_equal(@binary.checking?, true)
105
+ assert_equal(@binary.verified?, false)
106
+ assert_equal(@binary.r_available?, true)
107
+ assert_equal(@binary.rCode.code, Header::RCode::FORMAT)
108
+ assert_equal(@binary.qdCount, 1)
109
+ assert_equal(@binary.anCount, 2)
110
+ assert_equal(@binary.nsCount, 3)
111
+ assert_equal(@binary.arCount, 3)
112
+
113
+ assert_raise(HeaderArgumentError) do
114
+ Header.new(Array.new)
115
+ end
116
+ assert_raise(HeaderArgumentError) do
117
+ Header.parse(Array.new)
118
+ end
119
+ assert_raise(HeaderArgumentError) do
120
+ Header.parse("aa")
121
+ end
122
+ assert_raise(HeaderDuplicateID) do
123
+ @default.id = 441
124
+ end
125
+ assert_raise(HeaderArgumentError) do
126
+ @default.id = 1000000
127
+ end
128
+ assert_raise(HeaderArgumentError) do
129
+ @default.qr=2
130
+ end
131
+ assert_raise(HeaderWrongOpcode) do
132
+ @default.opCode=4
133
+ end
134
+ assert_raise(HeaderArgumentError) do
135
+ @default.aa=2
136
+ end
137
+ assert_raise(HeaderArgumentError) do
138
+ @default.tc=2
139
+ end
140
+ assert_raise(HeaderWrongRecursive) do
141
+ @default.recursive=2
142
+ end
143
+ assert_raise(HeaderArgumentError) do
144
+ @default.ra=2
145
+ end
146
+ assert_raise(HeaderArgumentError) do
147
+ @default.cd=2
148
+ end
149
+ assert_raise(HeaderArgumentError) do
150
+ @default.ad=2
151
+ end
152
+ assert_raise(HeaderArgumentError) do
153
+ @default.rCode=46
154
+ end
155
+ assert_raise(HeaderWrongCount) do
156
+ @default.qdCount=100000
157
+ end
158
+ assert_raise(HeaderWrongCount) do
159
+ @default.anCount=100000
160
+ end
161
+ assert_raise(HeaderWrongCount) do
162
+ @default.nsCount=100000
163
+ end
164
+ assert_raise(HeaderWrongCount) do
165
+ @default.arCount=100000
166
+ end
167
+ end
168
+
169
+ end
170
+
@@ -0,0 +1,42 @@
1
+ require 'test/unit'
2
+ require 'net/dns/packet'
3
+
4
+ class Test_Packet < Test::Unit::TestCase
5
+ include Net::DNS
6
+
7
+ def setup
8
+ @domain = 'example.com'
9
+ @type = 'MX'
10
+ @cls = 'HS'
11
+
12
+ @default = Packet.new(@domain)
13
+ @string = Packet.new(@domain, MX, HS)
14
+
15
+ packet = "\337M\201\200\000\001\000\003\000\004\000\004\006google\003com\000\000\001\000\001\300\f\000\001\000\001\000\000\001,\000\004@\351\273c\300\f\000\001\000\001\000\000\001,\000\004H\016\317c\300\f\000\001\000\001\000\000\001,\000\004@\351\247c\300\f\000\002\000\001\000\003\364\200\000\006\003ns1\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns2\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns3\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns4\300\f\300X\000\001\000\001\000\003\307\273\000\004\330\357 \n\300j\000\001\000\001\000\003\307\273\000\004\330\357\"\n\300|\000\001\000\001\000\003\307\273\000\004\330\357$\n\300\216\000\001\000\001\000\003\307\273\000\004\330\357&\n"
16
+
17
+ @binary = Packet.parse(packet)
18
+
19
+ end
20
+
21
+ def test_instances
22
+ assert_instance_of(Net::DNS::Packet, @string)
23
+ assert_instance_of(Net::DNS::Header, @string.header)
24
+ assert_instance_of(Array, @string.question)
25
+ assert_instance_of(Net::DNS::Question, @string.question[0])
26
+ assert_instance_of(Array, @string.answer)
27
+ assert_instance_of(Array, @string.authority)
28
+ assert_instance_of(Array, @string.additional)
29
+
30
+ assert_instance_of(Net::DNS::Packet, @binary)
31
+ assert_instance_of(Net::DNS::Header, @binary.header)
32
+ assert_instance_of(Array, @binary.question)
33
+ assert_instance_of(Net::DNS::Question, @binary.question[0])
34
+ assert_instance_of(Array, @binary.answer)
35
+ assert_instance_of(Net::DNS::RR::A, @binary.answer[0])
36
+ assert_instance_of(Array, @binary.authority)
37
+ assert_instance_of(Net::DNS::RR::NS, @binary.authority[0])
38
+ assert_instance_of(Array, @binary.additional)
39
+ assert_instance_of(Net::DNS::RR::A, @binary.additional[0])
40
+ end
41
+
42
+ end
@@ -0,0 +1,54 @@
1
+ require 'test/unit'
2
+ require 'net/dns/question'
3
+
4
+ class Test_Question < Test::Unit::TestCase
5
+ include Net::DNS
6
+
7
+ def setup
8
+ @domain = 'example.com.'
9
+ @type = 'MX'
10
+ @cls = 'HS'
11
+ @data = "\006google\003com\000\000\001\000\001"
12
+
13
+ @default = Question.new(@domain)
14
+ @string = Question.new(@domain,@type,@cls)
15
+ @binary = Question.parse(@data)
16
+ @binary2 = Question.parse(@string.data)
17
+ end
18
+
19
+ def test_simple
20
+ assert_equal(@default.qName, @domain)
21
+ assert_equal(@default.qType.to_s, "A")
22
+ assert_equal(@default.qClass.to_s, "IN")
23
+
24
+ assert_equal(@string.qName, @domain)
25
+ assert_equal(@string.qType.to_s, "MX")
26
+ assert_equal(@string.qClass.to_s, "HS")
27
+
28
+ assert_equal(@binary.qName, "google.com.")
29
+ assert_equal(@binary.qType.to_s, "A")
30
+ assert_equal(@binary.qClass.to_s, "IN")
31
+
32
+ assert_equal(@binary2.qName, @domain)
33
+ assert_equal(@binary2.qType.to_s, "MX")
34
+ assert_equal(@binary2.qClass.to_s, "HS")
35
+ end
36
+
37
+ def test_raise
38
+ assert_raise(QuestionNameError) do
39
+ Question.new(1)
40
+ end
41
+ assert_raise(QuestionNameError) do
42
+ Question.new("test{")
43
+ end
44
+ assert_raise(QuestionArgumentError) do
45
+ Question.parse(Array.new)
46
+ end
47
+ assert_raise(QuestionArgumentError) do
48
+ Question.parse("test")
49
+ end
50
+
51
+ end
52
+
53
+
54
+ end