net-dns 0.8.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +6 -14
  2. data/.rspec +1 -0
  3. data/.travis.yml +9 -16
  4. data/CHANGELOG.md +37 -13
  5. data/LICENSE.txt +56 -0
  6. data/README.md +94 -77
  7. data/demo/check_soa.rb +27 -38
  8. data/demo/threads.rb +3 -7
  9. data/lib/net/dns/header.rb +86 -110
  10. data/lib/net/dns/names.rb +31 -31
  11. data/lib/net/dns/packet.rb +148 -158
  12. data/lib/net/dns/question.rb +41 -42
  13. data/lib/net/dns/resolver/socks.rb +47 -55
  14. data/lib/net/dns/resolver/timeouts.rb +19 -30
  15. data/lib/net/dns/resolver.rb +151 -176
  16. data/lib/net/dns/rr/a.rb +45 -55
  17. data/lib/net/dns/rr/aaaa.rb +39 -50
  18. data/lib/net/dns/rr/classes.rb +32 -37
  19. data/lib/net/dns/rr/cname.rb +31 -41
  20. data/lib/net/dns/rr/hinfo.rb +40 -56
  21. data/lib/net/dns/rr/mr.rb +31 -42
  22. data/lib/net/dns/rr/mx.rb +35 -47
  23. data/lib/net/dns/rr/ns.rb +31 -41
  24. data/lib/net/dns/rr/null.rb +10 -15
  25. data/lib/net/dns/rr/ptr.rb +16 -24
  26. data/lib/net/dns/rr/soa.rb +36 -35
  27. data/lib/net/dns/rr/srv.rb +18 -19
  28. data/lib/net/dns/rr/txt.rb +11 -16
  29. data/lib/net/dns/rr/types.rb +118 -109
  30. data/lib/net/dns/rr.rb +107 -117
  31. data/lib/net/dns/version.rb +5 -13
  32. data/lib/net/dns.rb +6 -11
  33. metadata +18 -83
  34. data/.gitignore +0 -8
  35. data/Gemfile +0 -4
  36. data/Rakefile +0 -71
  37. data/fixtures/resolv.conf +0 -4
  38. data/lib/net/dns/core_ext.rb +0 -52
  39. data/net-dns.gemspec +0 -35
  40. data/test/header_test.rb +0 -167
  41. data/test/names_test.rb +0 -21
  42. data/test/packet_test.rb +0 -49
  43. data/test/question_test.rb +0 -83
  44. data/test/resolver/timeouts_test.rb +0 -109
  45. data/test/resolver_test.rb +0 -117
  46. data/test/rr/a_test.rb +0 -113
  47. data/test/rr/aaaa_test.rb +0 -109
  48. data/test/rr/classes_test.rb +0 -85
  49. data/test/rr/cname_test.rb +0 -97
  50. data/test/rr/hinfo_test.rb +0 -117
  51. data/test/rr/mr_test.rb +0 -105
  52. data/test/rr/mx_test.rb +0 -112
  53. data/test/rr/ns_test.rb +0 -86
  54. data/test/rr/types_test.rb +0 -69
  55. data/test/rr_test.rb +0 -131
  56. data/test/test_helper.rb +0 -4
@@ -1,52 +0,0 @@
1
- module Net # :nodoc:
2
- module DNS
3
-
4
- module HashKeys # :nodoc:
5
-
6
- # Returns an hash with all the
7
- # keys turned into downcase
8
- #
9
- # hsh = {"Test" => 1, "FooBar" => 2}
10
- # hsh.downcase_keys!
11
- # #=> {"test"=>1,"foobar"=>2}
12
- #
13
- def downcase_keys!
14
- hsh = Hash.new
15
- self.each do |key,val|
16
- hsh[key.downcase] = val
17
- end
18
- self.replace(hsh)
19
- end
20
-
21
- end
22
-
23
- module HashOperators # :nodoc:
24
-
25
- # Performs a sort of group difference
26
- # operation on hashes or arrays
27
- #
28
- # a = {:a=>1,:b=>2,:c=>3}
29
- # b = {:a=>1,:b=>2}
30
- # c = [:a,:c]
31
- # a-b #=> {:c=>3}
32
- # a-c #=> {:b=>2}
33
- #
34
- def -(other)
35
- case other
36
- when Hash
37
- delete_if { |k,v| other.has_key?(k) }
38
- when Array
39
- delete_if { |k,v| other.include?(k) }
40
- end
41
- end
42
-
43
- end
44
-
45
- end
46
- end
47
-
48
-
49
- class Hash # :nodoc:
50
- include Net::DNS::HashKeys
51
- include Net::DNS::HashOperators
52
- end
data/net-dns.gemspec DELETED
@@ -1,35 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = "net-dns"
5
- s.version = "0.8.0"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Marco Ceresa", "Simone Carletti"]
9
- s.date = "2013-05-08"
10
- s.description = "Net::DNS is a pure Ruby DNS library, with a clean OO interface and an extensible API."
11
- s.email = ["ceresa@gmail.com", "weppos@weppos.net"]
12
- s.files = [".gitignore", ".travis.yml", "CHANGELOG.md", "Gemfile", "README.md", "Rakefile", "THANKS.rdoc", "demo/check_soa.rb", "demo/threads.rb", "fixtures/resolv.conf", "lib/net/dns.rb", "lib/net/dns/core_ext.rb", "lib/net/dns/header.rb", "lib/net/dns/names.rb", "lib/net/dns/packet.rb", "lib/net/dns/question.rb", "lib/net/dns/resolver.rb", "lib/net/dns/resolver/socks.rb", "lib/net/dns/resolver/timeouts.rb", "lib/net/dns/rr.rb", "lib/net/dns/rr/a.rb", "lib/net/dns/rr/aaaa.rb", "lib/net/dns/rr/classes.rb", "lib/net/dns/rr/cname.rb", "lib/net/dns/rr/hinfo.rb", "lib/net/dns/rr/mr.rb", "lib/net/dns/rr/mx.rb", "lib/net/dns/rr/ns.rb", "lib/net/dns/rr/null.rb", "lib/net/dns/rr/ptr.rb", "lib/net/dns/rr/soa.rb", "lib/net/dns/rr/srv.rb", "lib/net/dns/rr/txt.rb", "lib/net/dns/rr/types.rb", "lib/net/dns/version.rb", "net-dns.gemspec", "test/header_test.rb", "test/names_test.rb", "test/packet_test.rb", "test/question_test.rb", "test/resolver/timeouts_test.rb", "test/resolver_test.rb", "test/rr/a_test.rb", "test/rr/aaaa_test.rb", "test/rr/classes_test.rb", "test/rr/cname_test.rb", "test/rr/hinfo_test.rb", "test/rr/mr_test.rb", "test/rr/mx_test.rb", "test/rr/ns_test.rb", "test/rr/types_test.rb", "test/rr_test.rb", "test/test_helper.rb"]
13
- s.homepage = "http://github.com/bluemonk/net-dns"
14
- s.require_paths = ["lib"]
15
- s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
16
- s.rubyforge_project = "net-dns"
17
- s.rubygems_version = "2.0.3"
18
- s.summary = "Pure Ruby DNS library."
19
- s.test_files = ["test/header_test.rb", "test/names_test.rb", "test/packet_test.rb", "test/question_test.rb", "test/resolver/timeouts_test.rb", "test/resolver_test.rb", "test/rr/a_test.rb", "test/rr/aaaa_test.rb", "test/rr/classes_test.rb", "test/rr/cname_test.rb", "test/rr/hinfo_test.rb", "test/rr/mr_test.rb", "test/rr/mx_test.rb", "test/rr/ns_test.rb", "test/rr/types_test.rb", "test/rr_test.rb", "test/test_helper.rb"]
20
-
21
- if s.respond_to? :specification_version then
22
- s.specification_version = 4
23
-
24
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- s.add_development_dependency(%q<rake>, ["~> 10.0"])
26
- s.add_development_dependency(%q<yard>, [">= 0"])
27
- else
28
- s.add_dependency(%q<rake>, ["~> 10.0"])
29
- s.add_dependency(%q<yard>, [">= 0"])
30
- end
31
- else
32
- s.add_dependency(%q<rake>, ["~> 10.0"])
33
- s.add_dependency(%q<yard>, [">= 0"])
34
- end
35
- end
data/test/header_test.rb DELETED
@@ -1,167 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/header'
3
-
4
- class HeaderTest < 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_raises(ArgumentError) do
114
- Header.new(Array.new)
115
- end
116
- assert_raises(ArgumentError) do
117
- Header.parse(Array.new)
118
- end
119
- assert_raises(ArgumentError) do
120
- Header.parse("aa")
121
- end
122
- assert_raises(ArgumentError) do
123
- @default.id = 1000000
124
- end
125
- assert_raises(ArgumentError) do
126
- @default.qr=2
127
- end
128
- assert_raises(Header::WrongOpcodeError) do
129
- @default.opCode=4
130
- end
131
- assert_raises(ArgumentError) do
132
- @default.aa=2
133
- end
134
- assert_raises(ArgumentError) do
135
- @default.tc=2
136
- end
137
- assert_raises(Header::WrongRecursiveError) do
138
- @default.recursive=2
139
- end
140
- assert_raises(ArgumentError) do
141
- @default.ra=2
142
- end
143
- assert_raises(ArgumentError) do
144
- @default.cd=2
145
- end
146
- assert_raises(ArgumentError) do
147
- @default.ad=2
148
- end
149
- assert_raises(ArgumentError) do
150
- @default.rCode=46
151
- end
152
- assert_raises(Header::WrongCountError) do
153
- @default.qdCount=100000
154
- end
155
- assert_raises(Header::WrongCountError) do
156
- @default.anCount=100000
157
- end
158
- assert_raises(Header::WrongCountError) do
159
- @default.nsCount=100000
160
- end
161
- assert_raises(Header::WrongCountError) do
162
- @default.arCount=100000
163
- end
164
- end
165
-
166
- end
167
-
data/test/names_test.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/names'
3
-
4
- class NamesTest < Test::Unit::TestCase
5
- include Net::DNS::Names
6
-
7
- def test_long_names
8
- assert_nothing_raised do
9
- pack_name('a' * 63)
10
- end
11
- assert_raises ArgumentError do
12
- pack_name('a' * 64)
13
- end
14
- assert_nothing_raised do
15
- pack_name(['a' * 63, 'b' * 63, 'c' * 63, 'd' * 63].join('.'))
16
- end
17
- assert_raises ArgumentError do
18
- pack_name(['a' * 63, 'b' * 63, 'c' * 63, 'd' * 63, 'e'].join('.'))
19
- end
20
- end
21
- end
data/test/packet_test.rb DELETED
@@ -1,49 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/packet'
3
-
4
- class PacketTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @klass = Net::DNS::Packet
8
- @domain = 'example.com'
9
- end
10
-
11
- def test_initialize
12
- @record = @klass.new(@domain, Net::DNS::MX, Net::DNS::HS)
13
- assert_instance_of @klass, @record
14
- assert_instance_of Net::DNS::Header, @record.header
15
- assert_instance_of Array, @record.question
16
- assert_instance_of Net::DNS::Question, @record.question.first
17
- assert_instance_of Array, @record.answer
18
- assert_instance_of Array, @record.authority
19
- assert_instance_of Array, @record.additional
20
- end
21
-
22
- def test_initialize_should_set_question
23
- @question = @klass.new(@domain).question.first
24
- assert_equal @domain, @question.qName
25
- assert_equal Net::DNS::RR::Types.new(Net::DNS::A).to_s, @question.qType.to_s
26
- assert_equal Net::DNS::RR::Classes.new(Net::DNS::IN).to_s, @question.qClass.to_s
27
-
28
- @question = @klass.new(@domain, Net::DNS::MX, Net::DNS::HS).question.first
29
- assert_equal @domain, @question.qName
30
- assert_equal Net::DNS::RR::Types.new(Net::DNS::MX).to_s, @question.qType.to_s
31
- assert_equal Net::DNS::RR::Classes.new(Net::DNS::HS).to_s, @question.qClass.to_s
32
- end
33
-
34
- def test_self_parse
35
- 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"
36
- @record = @klass.parse(packet)
37
- assert_instance_of @klass, @record
38
- assert_instance_of Net::DNS::Header, @record.header
39
- assert_instance_of Array, @record.question
40
- assert_instance_of Net::DNS::Question, @record.question.first
41
- assert_instance_of Array, @record.answer
42
- assert_instance_of Net::DNS::RR::A, @record.answer.first
43
- assert_instance_of Array, @record.authority
44
- assert_instance_of Net::DNS::RR::NS, @record.authority.first
45
- assert_instance_of Array, @record.additional
46
- assert_instance_of Net::DNS::RR::A, @record.additional.first
47
- end
48
-
49
- end
@@ -1,83 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/question'
3
-
4
- class QuestionTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @domain = 'example.com.'
8
- @type = 'MX'
9
- @cls = 'HS'
10
- @data = "\006google\003com\000\000\001\000\001"
11
-
12
- @default = Net::DNS::Question.new(@domain)
13
- @string = Net::DNS::Question.new(@domain,@type,@cls)
14
- @binary = Net::DNS::Question.parse(@data)
15
- @binary2 = Net::DNS::Question.parse(@string.data)
16
- end
17
-
18
- def test_simple
19
- assert_equal(@default.qName, @domain)
20
- assert_equal(@default.qType.to_s, "A")
21
- assert_equal(@default.qClass.to_s, "IN")
22
-
23
- assert_equal(@string.qName, @domain)
24
- assert_equal(@string.qType.to_s, "MX")
25
- assert_equal(@string.qClass.to_s, "HS")
26
-
27
- assert_equal(@binary.qName, "google.com.")
28
- assert_equal(@binary.qType.to_s, "A")
29
- assert_equal(@binary.qClass.to_s, "IN")
30
-
31
- assert_equal(@binary2.qName, @domain)
32
- assert_equal(@binary2.qType.to_s, "MX")
33
- assert_equal(@binary2.qClass.to_s, "HS")
34
- end
35
-
36
- def test_raise
37
- # assert_raises(Net::DNS::Question::NameInvalid) do
38
- # Net::DNS::Question.new(1)
39
- # end
40
- assert_raises(Net::DNS::Question::NameInvalid) do
41
- Net::DNS::Question.new("test{")
42
- end
43
- assert_raises(ArgumentError) do
44
- Net::DNS::Question.parse(Array.new)
45
- end
46
- assert_raises(ArgumentError) do
47
- Net::DNS::Question.parse("test")
48
- end
49
- end
50
-
51
- def test_inspect
52
- assert_equal "google.com. IN A ",
53
- Net::DNS::Question.new("google.com.").inspect
54
- assert_equal "google.com. IN A ",
55
- Net::DNS::Question.new("google.com.", Net::DNS::A).inspect
56
- assert_equal "google.com. IN NS ",
57
- Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
58
- assert_equal "google.com. IN NS ",
59
- Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
60
- end
61
-
62
- def test_inspect_with_name_longer_than_29_chrs
63
- assert_equal "supercalifragilistichespiralidoso.com IN A ",
64
- Net::DNS::Question.new("supercalifragilistichespiralidoso.com").inspect
65
- end
66
-
67
- def test_to_s
68
- assert_equal "google.com. IN A ",
69
- Net::DNS::Question.new("google.com.").to_s
70
- assert_equal "google.com. IN A ",
71
- Net::DNS::Question.new("google.com.", Net::DNS::A).to_s
72
- assert_equal "google.com. IN NS ",
73
- Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
74
- assert_equal "google.com. IN NS ",
75
- Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
76
- end
77
-
78
- def test_to_s_with_name_longer_than_29_chrs
79
- assert_equal "supercalifragilistichespiralidoso.com IN A ",
80
- Net::DNS::Question.new("supercalifragilistichespiralidoso.com").to_s
81
- end
82
-
83
- end
@@ -1,109 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/resolver/timeouts'
3
-
4
- class DnsTimeoutTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @klass = Net::DNS::Resolver::DnsTimeout
8
- end
9
-
10
- def test_initialize
11
- timeout = @klass.new(0)
12
- assert_instance_of @klass, timeout
13
- end
14
-
15
- def test_initialize_should_set_timeout
16
- assert_equal 0, @klass.new(0).seconds
17
- assert_equal 10, @klass.new(10).seconds
18
- end
19
-
20
- def test_initialize_should_set_raise_with_invalid_timeout
21
- assert_raises(ArgumentError) { @klass.new(nil) }
22
- assert_raises(ArgumentError) { @klass.new("") }
23
- assert_raises(ArgumentError) { @klass.new("foo") }
24
- assert_raises(ArgumentError) { @klass.new(-1) }
25
- end
26
-
27
-
28
- def test_to_s
29
- assert_equal "", @klass.new(0).to_s
30
- assert_equal "1", @klass.new(1).to_s
31
- assert_equal "10", @klass.new(10).to_s
32
- end
33
-
34
-
35
- def test_timeout_should_raise_localjumperror_without_block
36
- assert_raises(LocalJumpError) { @klass.new(1).timeout }
37
- end
38
-
39
- end
40
-
41
- class TcpTimeoutTest < Test::Unit::TestCase
42
-
43
- def test_initialize
44
- assert_raises(ArgumentError) do
45
- Net::DNS::Resolver::TcpTimeout.new("a")
46
- end
47
- assert_raises(ArgumentError) do
48
- Net::DNS::Resolver::TcpTimeout.new(-1)
49
- end
50
- assert_raises(TimeoutError) do
51
- Net::DNS::Resolver::TcpTimeout.new(0.1).timeout { sleep 2 }
52
- end
53
- end
54
-
55
- def test_to_s
56
- assert_equal "infinite", Net::DNS::Resolver::TcpTimeout.new(0).to_s
57
- assert_equal "30", Net::DNS::Resolver::TcpTimeout.new(30).to_s
58
- end
59
-
60
- def test_pretty_to_s
61
- assert_equal "30 seconds", Net::DNS::Resolver::TcpTimeout.new(30).pretty_to_s
62
- assert_equal "1 minutes and 30 seconds", Net::DNS::Resolver::TcpTimeout.new(90).pretty_to_s
63
- assert_equal "1 hours, 1 minutes and 30 seconds", Net::DNS::Resolver::TcpTimeout.new(3690).pretty_to_s
64
- end
65
-
66
- def test_timeout
67
- assert_equal 2, Net::DNS::Resolver::TcpTimeout.new(1).timeout { 1 + 1 }
68
- end
69
-
70
- def test_timeout_should_raise_localjumperror_without_block
71
- assert_raises(LocalJumpError) { Net::DNS::Resolver::TcpTimeout.new(1).timeout }
72
- end
73
-
74
- end
75
-
76
- class UdpTimeoutTest < Test::Unit::TestCase
77
-
78
- def test_initialize
79
- assert_raises(ArgumentError) do
80
- Net::DNS::Resolver::UdpTimeout.new("a")
81
- end
82
- assert_raises(ArgumentError) do
83
- Net::DNS::Resolver::UdpTimeout.new(-1)
84
- end
85
- assert_raises(TimeoutError) do
86
- Net::DNS::Resolver::UdpTimeout.new(0.1).timeout {sleep 2}
87
- end
88
- end
89
-
90
- def test_to_s
91
- assert_equal "not defined", Net::DNS::Resolver::UdpTimeout.new(0).to_s
92
- assert_equal "30", Net::DNS::Resolver::UdpTimeout.new(30).to_s
93
- end
94
-
95
- def test_pretty_to_s
96
- assert_equal "30 seconds", Net::DNS::Resolver::UdpTimeout.new(30).pretty_to_s
97
- assert_equal "1 minutes and 30 seconds", Net::DNS::Resolver::UdpTimeout.new(90).pretty_to_s
98
- assert_equal "1 hours, 1 minutes and 30 seconds", Net::DNS::Resolver::UdpTimeout.new(3690).pretty_to_s
99
- end
100
-
101
- def test_timeout
102
- assert_equal 2, Net::DNS::Resolver::UdpTimeout.new(1).timeout { 1 + 1 }
103
- end
104
-
105
- def test_timeout_should_raise_localjumperror_without_block
106
- assert_raises(LocalJumpError) { Net::DNS::Resolver::UdpTimeout.new(1).timeout }
107
- end
108
-
109
- end
@@ -1,117 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/resolver'
3
-
4
- class Net::DNS::Resolver
5
- attr_reader :config
6
- end
7
-
8
-
9
- class ResolverTest < Test::Unit::TestCase
10
-
11
- def test_initialize
12
- assert_nothing_raised { Net::DNS::Resolver.new }
13
- end
14
-
15
- def test_initialize_with_config
16
- assert_nothing_raised { Net::DNS::Resolver.new({}) }
17
- end
18
-
19
- def test_initialize_with_multi_name_servers
20
- resolver = Net::DNS::Resolver.new({:config_file => 'fixtures/resolv.conf'})
21
- assert_equal ['192.168.1.1', '192.168.1.2', '192.168.1.3', '192.168.1.4'], resolver.nameservers
22
- end
23
-
24
- def test_initialize_with_invalid_config_should_raise_argumenterror
25
- assert_raises(ArgumentError) { Net::DNS::Resolver.new("") }
26
- assert_raises(ArgumentError) { Net::DNS::Resolver.new(0) }
27
- assert_raises(ArgumentError) { Net::DNS::Resolver.new(:foo) }
28
- end
29
-
30
- def test_query_with_no_nameservers_should_raise_resolvererror
31
- assert_raises(Net::DNS::Resolver::Error) { Net::DNS::Resolver.new(:nameservers => []).query("example.com") }
32
- end
33
-
34
- # def test_send_to_ipv6_nameserver_should_not_raise_einval
35
- # assert_nothing_raised { Net::DNS::Resolver.new(:nameservers => ['2001:4860:4860::8888', '2001:4860:4860::8844']).send('example.com')}
36
- # end
37
-
38
- # I know private methods are supposed to not be tested directly
39
- # but since this library lacks unit tests, for now let me test them in this way.
40
-
41
- def _make_query_packet(*args)
42
- Net::DNS::Resolver.new.send(:make_query_packet, *args)
43
- end
44
-
45
- def test_make_query_packet_from_ipaddr
46
- packet = _make_query_packet(IPAddr.new("192.168.1.1"), Net::DNS::A, cls = Net::DNS::IN)
47
- assert_equal "1.1.168.192.in-addr.arpa", packet.question.first.qName
48
- assert_equal Net::DNS::PTR.to_i, packet.question.first.qType.to_i
49
- assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
50
- end
51
-
52
- def test_make_query_packet_from_string_like_ipv4
53
- packet = _make_query_packet("192.168.1.1", Net::DNS::A, cls = Net::DNS::IN)
54
- assert_equal "1.1.168.192.in-addr.arpa", packet.question.first.qName
55
- assert_equal Net::DNS::PTR.to_i, packet.question.first.qType.to_i
56
- assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
57
- end
58
-
59
- def test_make_query_packet_from_string_like_ipv6
60
- packet = _make_query_packet("2001:1ac0::200:0:a5d1:6004:2", Net::DNS::A, cls = Net::DNS::IN)
61
- assert_equal "2.0.0.0.4.0.0.6.1.d.5.a.0.0.0.0.0.0.2.0.0.0.0.0.0.c.a.1.1.0.0.2.ip6.arpa", packet.question.first.qName
62
- assert_equal Net::DNS::PTR.to_i, packet.question.first.qType.to_i
63
- assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
64
- end
65
-
66
- def test_make_query_packet_from_string_like_hostname
67
- packet = _make_query_packet("ns2.google.com", Net::DNS::A, cls = Net::DNS::IN)
68
- assert_equal "ns2.google.com", packet.question.first.qName
69
- assert_equal Net::DNS::A.to_i, packet.question.first.qType.to_i
70
- assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
71
- end
72
-
73
- def test_make_query_packet_from_string_like_hostname_with_number
74
- packet = _make_query_packet("ns.google.com", Net::DNS::A, cls = Net::DNS::IN)
75
- assert_equal "ns.google.com", packet.question.first.qName
76
- assert_equal Net::DNS::A.to_i, packet.question.first.qType.to_i
77
- assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
78
- end
79
-
80
- def test_should_return_state_without_exception
81
- res = Net::DNS::Resolver.new
82
- assert_nothing_raised {res.state}
83
- end
84
-
85
- RubyPlatforms = [
86
- ["darwin9.0", false], # Mac OS X
87
- ["darwin", false], # JRuby on Mac OS X
88
- ["linux-gnu", false],
89
- ["mingw32", true], # ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-mingw32]
90
- ["mswin32", true], # ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-mswin32]
91
- ["mswin32", true], # ruby 1.8.6 (2008-04-22 rev 6555) [x86-jruby1.1.1]
92
- ]
93
-
94
- C = Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG
95
-
96
- def test_self_platform_windows_question
97
- RubyPlatforms.each do |platform, is_windows|
98
- assert_equal is_windows,
99
- override_platform(platform) { Net::DNS::Resolver.platform_windows? },
100
- "Expected `#{is_windows}' with platform `#{platform}'"
101
- end
102
- end
103
-
104
-
105
- private
106
-
107
- def override_platform(new_platform, &block)
108
- raise LocalJumpError, "no block given" unless block_given?
109
- old_platform = C["host_os"]
110
- C["host_os"] = new_platform
111
- result = yield
112
- ensure
113
- C["host_os"] = old_platform
114
- result
115
- end
116
-
117
- end