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
data/test/rr/mx_test.rb DELETED
@@ -1,112 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRMXTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @rr_name = "example.com."
8
- @rr_type = "MX"
9
- @rr_cls = "IN"
10
- @rr_ttl = 10000
11
- @rr_preference = 10
12
- @rr_exchange = "mail.example.com."
13
- @rr_value = "#{@rr_preference} #{@rr_exchange}"
14
-
15
- @rr_output = "example.com. 10000 IN MX 10 mail.example.com."
16
-
17
- @rr = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 10, :exchange => "mail.example.com.", :ttl => 10000)
18
- end
19
-
20
-
21
- def test_initialize_from_hash
22
- @record = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 10, :exchange => "mail.example.com.", :ttl => 10000)
23
- assert_equal @rr_output, @record.to_s
24
- assert_equal @rr_name, @record.name
25
- assert_equal @rr_type, @record.type
26
- assert_equal @rr_cls, @record.cls
27
- assert_equal @rr_ttl, @record.ttl
28
- assert_equal @rr_preference, @record.preference
29
- assert_equal @rr_exchange, @record.exchange
30
- end
31
-
32
- def test_initialize_from_string
33
- @record = Net::DNS::RR::MX.new("example.com. 10000 IN MX 10 mail.example.com.")
34
- assert_equal @rr_output, @record.to_s
35
- assert_equal @rr_name, @record.name
36
- assert_equal @rr_type, @record.type
37
- assert_equal @rr_cls, @record.cls
38
- assert_equal @rr_ttl, @record.ttl
39
- assert_equal @rr_preference, @record.preference
40
- assert_equal @rr_exchange, @record.exchange
41
- end
42
-
43
- # FIXME: can't get it working with canned data
44
- # def test_parse
45
- # data = "\001\220\006google\003com\004s9b2\005psmtp\003com\000"
46
- # @record = Net::DNS::RR.parse(data)
47
- # assert_equal @rr_output, @record.to_s
48
- # assert_equal @rr_name, @record.name
49
- # assert_equal @rr_type, @record.type
50
- # assert_equal @rr_cls, @record.cls
51
- # assert_equal @rr_ttl, @record.ttl
52
- # assert_equal @rr_preference, @record.preference
53
- # assert_equal @rr_exchange, @record.exchange
54
- # end
55
-
56
-
57
- InvalidArguments = [
58
- { :name => "google.com" },
59
- Object.new,
60
- Array.new(7),
61
- "10800 IN NS",
62
- "google.com. 10800 IN NS",
63
- ]
64
-
65
- InvalidArguments.each_with_index do |arguments, index|
66
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
67
- assert_raises(ArgumentError) { p Net::DNS::RR::MX.new(arguments) }
68
- end
69
- end
70
-
71
-
72
- def test_preference
73
- @rr = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 10, :exchange => "mail.example.com.")
74
- assert_equal 10, @rr.preference
75
-
76
- @rr = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 100, :exchange => "mail.example.com.")
77
- assert_equal 100, @rr.preference
78
- end
79
-
80
- def test_exchange
81
- @rr = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 10, :exchange => "mail.example.com.")
82
- assert_equal "mail.example.com.", @rr.exchange
83
-
84
- @rr = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 10, :exchange => "mail2.example.com.")
85
- assert_equal "mail2.example.com.", @rr.exchange
86
- end
87
-
88
- def test_value
89
- @rr = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 10, :exchange => "mail.example.com.")
90
- assert_equal "10 mail.example.com.", @rr.value
91
-
92
- @rr = Net::DNS::RR::MX.new(:name => "example.com.", :preference => 100, :exchange => "mail2.example.com.")
93
- assert_equal "100 mail2.example.com.", @rr.value
94
- end
95
-
96
-
97
- def test_inspect
98
- assert_equal "example.com. 10000 IN MX 10 mail.example.com.",
99
- @rr.inspect
100
- end
101
-
102
- def test_to_s
103
- assert_equal "example.com. 10000 IN MX 10 mail.example.com.",
104
- @rr.to_s
105
- end
106
-
107
- def test_to_a
108
- assert_equal ["example.com.", 10000, "IN", "MX", "10 mail.example.com."],
109
- @rr.to_a
110
- end
111
-
112
- end
data/test/rr/ns_test.rb DELETED
@@ -1,86 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRNSTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @rr_name = "google.com."
8
- @rr_type = "NS"
9
- @rr_cls = "IN"
10
- @rr_ttl = 10800
11
- @rr_nsdname = "ns1.google.com."
12
-
13
- @rr_output = "google.com. 10800 IN NS ns1.google.com."
14
-
15
- @rr = Net::DNS::RR::NS.new(:name => "google.com.", :nsdname => "ns1.google.com.", :ttl => @rr_ttl)
16
- end
17
-
18
-
19
- def test_initialize_from_hash
20
- @record = Net::DNS::RR::NS.new(:name => "google.com.", :nsdname => "ns1.google.com.")
21
- assert_equal @rr_output, @record.inspect
22
- assert_equal @rr_name, @record.name
23
- assert_equal @rr_type, @record.type
24
- assert_equal @rr_cls, @record.cls
25
- assert_equal @rr_ttl, @record.ttl
26
- assert_equal @rr_nsdname, @record.nsdname
27
- end
28
-
29
- def test_initialize_from_string
30
- @record = Net::DNS::RR::NS.new("google.com. 10800 IN NS ns1.google.com.")
31
- assert_equal @rr_output, @record.inspect
32
- assert_equal @rr_name, @record.name
33
- assert_equal @rr_type, @record.type
34
- assert_equal @rr_cls, @record.cls
35
- assert_equal @rr_ttl, @record.ttl
36
- assert_equal @rr_nsdname, @record.nsdname
37
- end
38
-
39
- def test_parse
40
- data = "\006google\003com\000\000\002\000\001\000\000*0\000\020\003ns1\006google\003com\000"
41
- @record = Net::DNS::RR.parse(data)
42
- assert_equal @rr_output, @record.inspect
43
- assert_equal @rr_name, @record.name
44
- assert_equal @rr_type, @record.type
45
- assert_equal @rr_cls, @record.cls
46
- assert_equal @rr_ttl, @record.ttl
47
- assert_equal @rr_nsdname, @record.nsdname
48
- end
49
-
50
-
51
- InvalidArguments = [
52
- { :name => "google.com", :nsdname => "255.256" },
53
- { :name => "google.com" },
54
- Object.new,
55
- Array.new(7),
56
- "10800 IN A",
57
- ]
58
-
59
- InvalidArguments.each_with_index do |arguments, index|
60
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
61
- assert_raises(ArgumentError) { Net::DNS::RR::NS.new(arguments) }
62
- end
63
- end
64
-
65
-
66
- def test_value
67
- assert_equal "ns1.google.com.", @rr.value
68
- end
69
-
70
-
71
- def test_inspect
72
- assert_equal "google.com. 10800 IN NS ns1.google.com.",
73
- @rr.inspect
74
- end
75
-
76
- def test_to_s
77
- assert_equal "google.com. 10800 IN NS ns1.google.com.",
78
- @rr.to_s
79
- end
80
-
81
- def test_to_a
82
- assert_equal ["google.com.", 10800, "IN", "NS", "ns1.google.com."],
83
- @rr.to_a
84
- end
85
-
86
- end
@@ -1,69 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRTypesTest < Test::Unit::TestCase
5
-
6
- def setup
7
- end
8
-
9
- def test_default
10
- # Default type should be ANY => 255
11
- instance = Net::DNS::RR::Types.new(nil)
12
- assert_equal("1", instance.to_str)
13
- assert_equal("A", instance.to_s)
14
-
15
- # Let's change default behaviour
16
- Net::DNS::RR::Types.default = "A"
17
- instance = Net::DNS::RR::Types.new(nil)
18
- assert_equal("1", instance.to_str)
19
- assert_equal("A", instance.to_s)
20
-
21
- Net::DNS::RR::Types.default = "ANY"
22
- instance = Net::DNS::RR::Types.new(nil)
23
- assert_equal("255", instance.to_str)
24
- assert_equal("ANY", instance.to_s)
25
- end
26
-
27
- def test_types
28
- Net::DNS::RR::Types::TYPES.each do |key, num|
29
- instance_from_string = Net::DNS::RR::Types.new(key)
30
- instance_from_num = Net::DNS::RR::Types.new(num)
31
- assert_equal(key, instance_from_string.to_s)
32
- assert_equal(num.to_s, instance_from_string.to_str)
33
- assert_equal(key, instance_from_num.to_s)
34
- assert_equal(num.to_s, instance_from_num.to_str)
35
- end
36
- assert_raises(ArgumentError) do
37
- Net::DNS::RR::Types.new(Hash.new)
38
- end
39
- end
40
-
41
- def test_regexp
42
- pattern = Net::DNS::RR::Types.regexp
43
- assert_instance_of String, pattern
44
- Net::DNS::RR::Types::TYPES.each do |key, num|
45
- assert_match /\|?#{key}\|?/, pattern
46
- end
47
- end
48
-
49
- def test_valid?
50
- assert_equal(true, Net::DNS::RR::Types.valid?("A"))
51
- assert_equal(true, Net::DNS::RR::Types.valid?(1))
52
- assert_equal(false, Net::DNS::RR::Types.valid?("Q"))
53
- assert_equal(false, Net::DNS::RR::Types.valid?(256))
54
- assert_raises(ArgumentError) do
55
- Net::DNS::RR::Types.valid? Hash.new
56
- end
57
- end
58
-
59
- def test_to_str
60
- assert_equal("A", Net::DNS::RR::Types.to_str(1))
61
- assert_raises(ArgumentError) do
62
- Net::DNS::RR::Types.to_str(256)
63
- end
64
- assert_raises(ArgumentError) do
65
- Net::DNS::RR::Types.to_str("string")
66
- end
67
- end
68
-
69
- end
data/test/rr_test.rb DELETED
@@ -1,131 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @rr_name = "example.com."
8
- @type = "A"
9
- @cls = "IN"
10
- @ttl = 10800
11
- @rdata = "64.233.187.99"
12
-
13
- @defaults = Net::DNS::RR.new(:name => @rr_name,
14
- :rdata => @rdata)
15
-
16
-
17
- @a_hash = Net::DNS::RR.new(:name => @rr_name,
18
- :ttl => @ttl,
19
- :cls => @cls,
20
- :type => @type,
21
- :address => @rdata)
22
-
23
- @a_string = Net::DNS::RR::A.new("example.com. 10800 IN A 64.233.187.99")
24
-
25
- @str = "example.com. 10800 IN A 64.233.187.99"
26
-
27
- @a = Net::DNS::RR.new("foo.example.com. 86400 A 10.1.2.3")
28
- @mx = Net::DNS::RR.new("example.com. 7200 MX 10 mailhost.example.com.")
29
- @cname = Net::DNS::RR.new("www.example.com IN CNAME www1.example.com")
30
- @txt = Net::DNS::RR.new('baz.example.com 3600 HS TXT "text record"')
31
-
32
- @a_data = @a.data
33
- @a_binary = Net::DNS::RR.parse(@a_data)
34
- @mx_data = @mx.data
35
- @mx_binary = Net::DNS::RR.parse(@mx_data)
36
-
37
- @array = [@rr_name,@ttl,@cls,@type,@rdata]
38
- end
39
-
40
- def test_classes
41
- assert_instance_of Net::DNS::RR::A, @a
42
- assert_instance_of Net::DNS::RR::MX, @mx
43
- assert_instance_of Net::DNS::RR::CNAME, @cname
44
- assert_instance_of Net::DNS::RR::TXT, @txt
45
- assert_instance_of Net::DNS::RR::A, @a_binary
46
- assert_instance_of Net::DNS::RR::MX, @mx_binary
47
- end
48
-
49
- def test_ttl
50
- assert_equal @a.ttl, 86400
51
- assert_equal @mx.ttl, 7200
52
- assert_equal @cname.ttl, 10800
53
- assert_equal @txt.ttl, 3600
54
- assert_equal @a_binary.ttl, 86400
55
- assert_equal @mx_binary.ttl, 7200
56
- end
57
-
58
- def test_types
59
- assert_equal @a.type, "A"
60
- assert_equal @mx.type, "MX"
61
- assert_equal @cname.type, "CNAME"
62
- assert_equal @txt.type, "TXT"
63
- assert_equal @a_binary.type, "A"
64
- assert_equal @mx_binary.type, "MX"
65
- end
66
-
67
- def test_cls
68
- assert_equal @a.cls, "IN"
69
- assert_equal @mx.cls, "IN"
70
- assert_equal @cname.cls, "IN"
71
- assert_equal @txt.cls, "HS"
72
- assert_equal @a_binary.cls, "IN"
73
- assert_equal @mx_binary.cls, "IN"
74
- end
75
-
76
- def test_name
77
- assert_equal @a.name, "foo.example.com."
78
- assert_equal @mx.name, "example.com."
79
- assert_equal @cname.name, "www.example.com"
80
- assert_equal @txt.name, "baz.example.com"
81
- assert_equal @a_binary.name, "foo.example.com."
82
- assert_equal @mx_binary.name, "example.com."
83
- end
84
-
85
- def test_rdata
86
- assert_equal @a.address.to_s, "10.1.2.3"
87
- assert_equal @mx.preference, 10
88
- assert_equal @mx.exchange, "mailhost.example.com."
89
- assert_equal @cname.cname, "www1.example.com"
90
- assert_equal @txt.txt, '"text record"'
91
- assert_equal @a_binary.address.to_s, "10.1.2.3"
92
- assert_equal @mx_binary.preference, 10
93
- assert_equal @mx_binary.exchange, "mailhost.example.com."
94
- end
95
-
96
- def test_simple
97
- assert_equal @rr_name, @defaults.name
98
- assert_equal @type, @defaults.type
99
- assert_equal @cls, @defaults.cls
100
- assert_equal @ttl, @defaults.ttl
101
- assert_equal @rdata, @defaults.rdata.to_s
102
-
103
- assert_equal(@str,@a_hash.inspect)
104
- assert_equal(@rr_name, @a_hash.name)
105
- assert_equal(@type, @a_hash.type)
106
- assert_equal(@cls, @a_hash.cls)
107
- assert_equal(@ttl, @a_hash.ttl)
108
- assert_equal(@rdata, @a_hash.address.to_s)
109
-
110
- assert_equal(@str, @a_string.inspect)
111
- assert_equal(@rr_name, @a_string.name)
112
- assert_equal(@type, @a_string.type)
113
- assert_equal(@cls, @a_string.cls)
114
- assert_equal(@ttl, @a_string.ttl)
115
- assert_equal(@rdata, @a_string.address.to_s)
116
-
117
- assert_equal(@a_data, @a_binary.data)
118
- assert_equal(@mx_data, @mx_binary.data)
119
-
120
- assert_equal(@str, @a_hash.to_s)
121
- assert_equal(@array, @a_hash.to_a)
122
- end
123
-
124
- def test_range
125
- assert_raises(ArgumentError) do
126
- Net::DNS::RR.new("google.com. 10800 IM A")
127
- end
128
- end
129
-
130
- end
131
-
data/test/test_helper.rb DELETED
@@ -1,4 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
- require 'test/unit'
4
- require 'net/dns'