net-dns2 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +20 -0
  4. data/CHANGELOG.md +105 -0
  5. data/Gemfile +4 -0
  6. data/README.md +155 -0
  7. data/Rakefile +94 -0
  8. data/THANKS.rdoc +24 -0
  9. data/demo/check_soa.rb +115 -0
  10. data/demo/threads.rb +22 -0
  11. data/lib/net/dns.rb +112 -0
  12. data/lib/net/dns/core_ext.rb +52 -0
  13. data/lib/net/dns/header.rb +713 -0
  14. data/lib/net/dns/names.rb +118 -0
  15. data/lib/net/dns/packet.rb +563 -0
  16. data/lib/net/dns/question.rb +188 -0
  17. data/lib/net/dns/resolver.rb +1313 -0
  18. data/lib/net/dns/resolver/socks.rb +154 -0
  19. data/lib/net/dns/resolver/timeouts.rb +75 -0
  20. data/lib/net/dns/rr.rb +366 -0
  21. data/lib/net/dns/rr/a.rb +124 -0
  22. data/lib/net/dns/rr/aaaa.rb +103 -0
  23. data/lib/net/dns/rr/classes.rb +133 -0
  24. data/lib/net/dns/rr/cname.rb +82 -0
  25. data/lib/net/dns/rr/hinfo.rb +108 -0
  26. data/lib/net/dns/rr/mr.rb +79 -0
  27. data/lib/net/dns/rr/mx.rb +92 -0
  28. data/lib/net/dns/rr/ns.rb +78 -0
  29. data/lib/net/dns/rr/null.rb +53 -0
  30. data/lib/net/dns/rr/ptr.rb +83 -0
  31. data/lib/net/dns/rr/soa.rb +78 -0
  32. data/lib/net/dns/rr/srv.rb +45 -0
  33. data/lib/net/dns/rr/txt.rb +61 -0
  34. data/lib/net/dns/rr/types.rb +193 -0
  35. data/lib/net/dns/version.rb +16 -0
  36. data/net-dns.gemspec +37 -0
  37. data/test/header_test.rb +167 -0
  38. data/test/names_test.rb +21 -0
  39. data/test/packet_test.rb +49 -0
  40. data/test/question_test.rb +83 -0
  41. data/test/resolver_test.rb +117 -0
  42. data/test/rr/a_test.rb +113 -0
  43. data/test/rr/aaaa_test.rb +109 -0
  44. data/test/rr/classes_test.rb +85 -0
  45. data/test/rr/cname_test.rb +97 -0
  46. data/test/rr/hinfo_test.rb +117 -0
  47. data/test/rr/mr_test.rb +105 -0
  48. data/test/rr/mx_test.rb +112 -0
  49. data/test/rr/ns_test.rb +86 -0
  50. data/test/rr/types_test.rb +69 -0
  51. data/test/rr_test.rb +131 -0
  52. data/test/test_helper.rb +4 -0
  53. metadata +158 -0
@@ -0,0 +1,86 @@
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
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,131 @@
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
+
@@ -0,0 +1,4 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'test/unit'
4
+ require 'net/dns'
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: net-dns2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.1
5
+ platform: ruby
6
+ authors:
7
+ - Marco Ceresa
8
+ - Simone Carletti
9
+ - Christopher Carpenter
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-05-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '10.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '10.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: yard
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: packetfu
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ description: Net::DNS is a pure Ruby DNS library, with a clean OO interface and an
58
+ extensible API.
59
+ email:
60
+ - ceresa@gmail.com
61
+ - weppos@weppos.net
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .travis.yml
68
+ - CHANGELOG.md
69
+ - Gemfile
70
+ - README.md
71
+ - Rakefile
72
+ - THANKS.rdoc
73
+ - demo/check_soa.rb
74
+ - demo/threads.rb
75
+ - lib/net/dns.rb
76
+ - lib/net/dns/core_ext.rb
77
+ - lib/net/dns/header.rb
78
+ - lib/net/dns/names.rb
79
+ - lib/net/dns/packet.rb
80
+ - lib/net/dns/question.rb
81
+ - lib/net/dns/resolver.rb
82
+ - lib/net/dns/resolver/socks.rb
83
+ - lib/net/dns/resolver/timeouts.rb
84
+ - lib/net/dns/rr.rb
85
+ - lib/net/dns/rr/a.rb
86
+ - lib/net/dns/rr/aaaa.rb
87
+ - lib/net/dns/rr/classes.rb
88
+ - lib/net/dns/rr/cname.rb
89
+ - lib/net/dns/rr/hinfo.rb
90
+ - lib/net/dns/rr/mr.rb
91
+ - lib/net/dns/rr/mx.rb
92
+ - lib/net/dns/rr/ns.rb
93
+ - lib/net/dns/rr/null.rb
94
+ - lib/net/dns/rr/ptr.rb
95
+ - lib/net/dns/rr/soa.rb
96
+ - lib/net/dns/rr/srv.rb
97
+ - lib/net/dns/rr/txt.rb
98
+ - lib/net/dns/rr/types.rb
99
+ - lib/net/dns/version.rb
100
+ - net-dns.gemspec
101
+ - test/header_test.rb
102
+ - test/names_test.rb
103
+ - test/packet_test.rb
104
+ - test/question_test.rb
105
+ - test/resolver_test.rb
106
+ - test/rr/a_test.rb
107
+ - test/rr/aaaa_test.rb
108
+ - test/rr/classes_test.rb
109
+ - test/rr/cname_test.rb
110
+ - test/rr/hinfo_test.rb
111
+ - test/rr/mr_test.rb
112
+ - test/rr/mx_test.rb
113
+ - test/rr/ns_test.rb
114
+ - test/rr/types_test.rb
115
+ - test/rr_test.rb
116
+ - test/test_helper.rb
117
+ homepage: http://github.com/mordocai/net-dns
118
+ licenses:
119
+ - Ruby
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: 1.8.7
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.14
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Pure Ruby DNS library, fork with fixes.
141
+ test_files:
142
+ - test/header_test.rb
143
+ - test/names_test.rb
144
+ - test/packet_test.rb
145
+ - test/question_test.rb
146
+ - test/resolver_test.rb
147
+ - test/rr/a_test.rb
148
+ - test/rr/aaaa_test.rb
149
+ - test/rr/classes_test.rb
150
+ - test/rr/cname_test.rb
151
+ - test/rr/hinfo_test.rb
152
+ - test/rr/mr_test.rb
153
+ - test/rr/mx_test.rb
154
+ - test/rr/ns_test.rb
155
+ - test/rr/types_test.rb
156
+ - test/rr_test.rb
157
+ - test/test_helper.rb
158
+ has_rdoc: