gitlab-net-dns 0.9.1

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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.gitlab-ci.yml +20 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +3 -0
  6. data/.rubocop_defaults.yml +359 -0
  7. data/.rubocop_todo.yml +207 -0
  8. data/.travis.yml +13 -0
  9. data/CHANGELOG.md +113 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE.txt +56 -0
  12. data/README.md +172 -0
  13. data/Rakefile +38 -0
  14. data/THANKS.rdoc +24 -0
  15. data/bin/console +14 -0
  16. data/demo/check_soa.rb +104 -0
  17. data/demo/threads.rb +18 -0
  18. data/gitlab-net-dns.gemspec +24 -0
  19. data/lib/net/dns.rb +104 -0
  20. data/lib/net/dns/header.rb +705 -0
  21. data/lib/net/dns/names.rb +120 -0
  22. data/lib/net/dns/packet.rb +560 -0
  23. data/lib/net/dns/question.rb +185 -0
  24. data/lib/net/dns/resolver.rb +1214 -0
  25. data/lib/net/dns/resolver/socks.rb +148 -0
  26. data/lib/net/dns/resolver/timeouts.rb +70 -0
  27. data/lib/net/dns/rr.rb +356 -0
  28. data/lib/net/dns/rr/a.rb +114 -0
  29. data/lib/net/dns/rr/aaaa.rb +94 -0
  30. data/lib/net/dns/rr/classes.rb +130 -0
  31. data/lib/net/dns/rr/cname.rb +74 -0
  32. data/lib/net/dns/rr/hinfo.rb +96 -0
  33. data/lib/net/dns/rr/mr.rb +70 -0
  34. data/lib/net/dns/rr/mx.rb +82 -0
  35. data/lib/net/dns/rr/ns.rb +70 -0
  36. data/lib/net/dns/rr/null.rb +50 -0
  37. data/lib/net/dns/rr/ptr.rb +77 -0
  38. data/lib/net/dns/rr/soa.rb +75 -0
  39. data/lib/net/dns/rr/srv.rb +41 -0
  40. data/lib/net/dns/rr/txt.rb +58 -0
  41. data/lib/net/dns/rr/types.rb +191 -0
  42. data/lib/net/dns/version.rb +8 -0
  43. data/spec/fixtures/resolv.conf +4 -0
  44. data/spec/spec_helper.rb +14 -0
  45. data/spec/unit/resolver/dns_timeout_spec.rb +36 -0
  46. data/spec/unit/resolver/tcp_timeout_spec.rb +46 -0
  47. data/spec/unit/resolver/udp_timeout_spec.rb +46 -0
  48. data/test/test_helper.rb +13 -0
  49. data/test/unit/header_test.rb +164 -0
  50. data/test/unit/names_test.rb +21 -0
  51. data/test/unit/packet_test.rb +47 -0
  52. data/test/unit/question_test.rb +81 -0
  53. data/test/unit/resolver_test.rb +114 -0
  54. data/test/unit/rr/a_test.rb +106 -0
  55. data/test/unit/rr/aaaa_test.rb +102 -0
  56. data/test/unit/rr/classes_test.rb +83 -0
  57. data/test/unit/rr/cname_test.rb +90 -0
  58. data/test/unit/rr/hinfo_test.rb +111 -0
  59. data/test/unit/rr/mr_test.rb +99 -0
  60. data/test/unit/rr/mx_test.rb +106 -0
  61. data/test/unit/rr/ns_test.rb +80 -0
  62. data/test/unit/rr/types_test.rb +71 -0
  63. data/test/unit/rr_test.rb +127 -0
  64. metadata +172 -0
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+ require 'net/dns/rr'
3
+
4
+ class RRNSTest < Minitest::Test
5
+ def setup
6
+ @rr_name = "google.com."
7
+ @rr_type = "NS"
8
+ @rr_cls = "IN"
9
+ @rr_ttl = 10_800
10
+ @rr_nsdname = "ns1.google.com."
11
+
12
+ @rr_output = "google.com. 10800 IN NS ns1.google.com."
13
+
14
+ @rr = Net::DNS::RR::NS.new(name: "google.com.", nsdname: "ns1.google.com.", ttl: @rr_ttl)
15
+ end
16
+
17
+ def test_initialize_from_hash
18
+ @record = Net::DNS::RR::NS.new(name: "google.com.", nsdname: "ns1.google.com.")
19
+ assert_equal @rr_output, @record.inspect
20
+ assert_equal @rr_name, @record.name
21
+ assert_equal @rr_type, @record.type
22
+ assert_equal @rr_cls, @record.cls
23
+ assert_equal @rr_ttl, @record.ttl
24
+ assert_equal @rr_nsdname, @record.nsdname
25
+ end
26
+
27
+ def test_initialize_from_string
28
+ @record = Net::DNS::RR::NS.new("google.com. 10800 IN NS ns1.google.com.")
29
+ assert_equal @rr_output, @record.inspect
30
+ assert_equal @rr_name, @record.name
31
+ assert_equal @rr_type, @record.type
32
+ assert_equal @rr_cls, @record.cls
33
+ assert_equal @rr_ttl, @record.ttl
34
+ assert_equal @rr_nsdname, @record.nsdname
35
+ end
36
+
37
+ def test_parse
38
+ data = "\006google\003com\000\000\002\000\001\000\000*0\000\020\003ns1\006google\003com\000"
39
+ @record = Net::DNS::RR.parse(data)
40
+ assert_equal @rr_output, @record.inspect
41
+ assert_equal @rr_name, @record.name
42
+ assert_equal @rr_type, @record.type
43
+ assert_equal @rr_cls, @record.cls
44
+ assert_equal @rr_ttl, @record.ttl
45
+ assert_equal @rr_nsdname, @record.nsdname
46
+ end
47
+
48
+ InvalidArguments = [
49
+ { name: "google.com", nsdname: "255.256" },
50
+ { name: "google.com" },
51
+ Object.new,
52
+ Array.new(7),
53
+ "10800 IN A",
54
+ ].freeze
55
+
56
+ InvalidArguments.each_with_index do |arguments, index|
57
+ define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
58
+ assert_raises(ArgumentError) { Net::DNS::RR::NS.new(arguments) }
59
+ end
60
+ end
61
+
62
+ def test_value
63
+ assert_equal "ns1.google.com.", @rr.value
64
+ end
65
+
66
+ def test_inspect
67
+ assert_equal "google.com. 10800 IN NS ns1.google.com.",
68
+ @rr.inspect
69
+ end
70
+
71
+ def test_to_s
72
+ assert_equal "google.com. 10800 IN NS ns1.google.com.",
73
+ @rr.to_s
74
+ end
75
+
76
+ def test_to_a
77
+ assert_equal ["google.com.", 10_800, "IN", "NS", "ns1.google.com."],
78
+ @rr.to_a
79
+ end
80
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+ require 'net/dns/rr'
3
+
4
+ class RRTypesTest < Minitest::Test
5
+ def setup
6
+ end
7
+
8
+ def test_default
9
+ @_default = Net::DNS::RR::Types.default
10
+
11
+ # Default type should be ANY => 255
12
+ instance = Net::DNS::RR::Types.new(nil)
13
+ assert_equal("1", instance.to_str)
14
+ assert_equal("A", instance.to_s)
15
+
16
+ # Let's change default behaviour
17
+ Net::DNS::RR::Types.default = "A"
18
+ instance = Net::DNS::RR::Types.new(nil)
19
+ assert_equal("1", instance.to_str)
20
+ assert_equal("A", instance.to_s)
21
+
22
+ Net::DNS::RR::Types.default = "ANY"
23
+ instance = Net::DNS::RR::Types.new(nil)
24
+ assert_equal("255", instance.to_str)
25
+ assert_equal("ANY", instance.to_s)
26
+ ensure
27
+ Net::DNS::RR::Types.default = Net::DNS::RR::Types::TYPES.invert[@_default]
28
+ end
29
+
30
+ def test_types
31
+ Net::DNS::RR::Types::TYPES.each do |key, num|
32
+ instance_from_string = Net::DNS::RR::Types.new(key)
33
+ instance_from_num = Net::DNS::RR::Types.new(num)
34
+ assert_equal(key, instance_from_string.to_s)
35
+ assert_equal(num.to_s, instance_from_string.to_str)
36
+ assert_equal(key, instance_from_num.to_s)
37
+ assert_equal(num.to_s, instance_from_num.to_str)
38
+ end
39
+ assert_raises(ArgumentError) do
40
+ Net::DNS::RR::Types.new({})
41
+ end
42
+ end
43
+
44
+ def test_regexp
45
+ pattern = Net::DNS::RR::Types.regexp
46
+ assert_instance_of String, pattern
47
+ Net::DNS::RR::Types::TYPES.each do |key, num|
48
+ assert_match /\|?#{key}\|?/, pattern
49
+ end
50
+ end
51
+
52
+ def test_valid?
53
+ assert_equal(true, Net::DNS::RR::Types.valid?("A"))
54
+ assert_equal(true, Net::DNS::RR::Types.valid?(1))
55
+ assert_equal(false, Net::DNS::RR::Types.valid?("Q"))
56
+ assert_equal(false, Net::DNS::RR::Types.valid?(256))
57
+ assert_raises(ArgumentError) do
58
+ Net::DNS::RR::Types.valid?({})
59
+ end
60
+ end
61
+
62
+ def test_to_str
63
+ assert_equal("A", Net::DNS::RR::Types.to_str(1))
64
+ assert_raises(ArgumentError) do
65
+ Net::DNS::RR::Types.to_str(256)
66
+ end
67
+ assert_raises(ArgumentError) do
68
+ Net::DNS::RR::Types.to_str("string")
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,127 @@
1
+ require 'test_helper'
2
+ require 'net/dns/rr'
3
+
4
+ class RRTest < Minitest::Test
5
+ def setup
6
+ @rr_name = "example.com."
7
+ @type = "A"
8
+ @cls = "IN"
9
+ @ttl = 10_800
10
+ @rdata = "64.233.187.99"
11
+
12
+ @defaults = Net::DNS::RR.new(name: @rr_name,
13
+ rdata: @rdata)
14
+
15
+ @a_hash = Net::DNS::RR.new(name: @rr_name,
16
+ ttl: @ttl,
17
+ cls: @cls,
18
+ type: @type,
19
+ address: @rdata)
20
+
21
+ @a_string = Net::DNS::RR::A.new("example.com. 10800 IN A 64.233.187.99")
22
+
23
+ @str = "example.com. 10800 IN A 64.233.187.99"
24
+
25
+ @a = Net::DNS::RR.new("foo.example.com. 86400 A 10.1.2.3")
26
+ @mx = Net::DNS::RR.new("example.com. 7200 MX 10 mailhost.example.com.")
27
+ @cname = Net::DNS::RR.new("www.example.com IN CNAME www1.example.com")
28
+ @txt = Net::DNS::RR.new('baz.example.com 3600 HS TXT "text record"')
29
+
30
+ @a_data = @a.data
31
+ @a_binary = Net::DNS::RR.parse(@a_data)
32
+ @mx_data = @mx.data
33
+ @mx_binary = Net::DNS::RR.parse(@mx_data)
34
+
35
+ @array = [@rr_name, @ttl, @cls, @type, @rdata]
36
+ end
37
+
38
+ def test_classes
39
+ assert_instance_of Net::DNS::RR::A, @a
40
+ assert_instance_of Net::DNS::RR::MX, @mx
41
+ assert_instance_of Net::DNS::RR::CNAME, @cname
42
+ assert_instance_of Net::DNS::RR::TXT, @txt
43
+ assert_instance_of Net::DNS::RR::A, @a_binary
44
+ assert_instance_of Net::DNS::RR::MX, @mx_binary
45
+ end
46
+
47
+ def test_ttl
48
+ assert_equal @a.ttl, 86_400
49
+ assert_equal @mx.ttl, 7200
50
+ assert_equal @cname.ttl, 10_800
51
+ assert_equal @txt.ttl, 3600
52
+ assert_equal @a_binary.ttl, 86_400
53
+ assert_equal @mx_binary.ttl, 7200
54
+ end
55
+
56
+ def test_types
57
+ assert_equal @a.type, "A"
58
+ assert_equal @mx.type, "MX"
59
+ assert_equal @cname.type, "CNAME"
60
+ assert_equal @txt.type, "TXT"
61
+ assert_equal @a_binary.type, "A"
62
+ assert_equal @mx_binary.type, "MX"
63
+ end
64
+
65
+ def test_cls
66
+ assert_equal @a.cls, "IN"
67
+ assert_equal @mx.cls, "IN"
68
+ assert_equal @cname.cls, "IN"
69
+ assert_equal @txt.cls, "HS"
70
+ assert_equal @a_binary.cls, "IN"
71
+ assert_equal @mx_binary.cls, "IN"
72
+ end
73
+
74
+ def test_name
75
+ assert_equal @a.name, "foo.example.com."
76
+ assert_equal @mx.name, "example.com."
77
+ assert_equal @cname.name, "www.example.com"
78
+ assert_equal @txt.name, "baz.example.com"
79
+ assert_equal @a_binary.name, "foo.example.com."
80
+ assert_equal @mx_binary.name, "example.com."
81
+ end
82
+
83
+ def test_rdata
84
+ assert_equal @a.address.to_s, "10.1.2.3"
85
+ assert_equal @mx.preference, 10
86
+ assert_equal @mx.exchange, "mailhost.example.com."
87
+ assert_equal @cname.cname, "www1.example.com"
88
+ assert_equal @txt.txt, '"text record"'
89
+ assert_equal @a_binary.address.to_s, "10.1.2.3"
90
+ assert_equal @mx_binary.preference, 10
91
+ assert_equal @mx_binary.exchange, "mailhost.example.com."
92
+ end
93
+
94
+ def test_simple
95
+ assert_equal @rr_name, @defaults.name
96
+ assert_equal @type, @defaults.type
97
+ assert_equal @cls, @defaults.cls
98
+ assert_equal @ttl, @defaults.ttl
99
+ assert_equal @rdata, @defaults.rdata.to_s
100
+
101
+ assert_equal(@str, @a_hash.inspect)
102
+ assert_equal(@rr_name, @a_hash.name)
103
+ assert_equal(@type, @a_hash.type)
104
+ assert_equal(@cls, @a_hash.cls)
105
+ assert_equal(@ttl, @a_hash.ttl)
106
+ assert_equal(@rdata, @a_hash.address.to_s)
107
+
108
+ assert_equal(@str, @a_string.inspect)
109
+ assert_equal(@rr_name, @a_string.name)
110
+ assert_equal(@type, @a_string.type)
111
+ assert_equal(@cls, @a_string.cls)
112
+ assert_equal(@ttl, @a_string.ttl)
113
+ assert_equal(@rdata, @a_string.address.to_s)
114
+
115
+ assert_equal(@a_data, @a_binary.data)
116
+ assert_equal(@mx_data, @mx_binary.data)
117
+
118
+ assert_equal(@str, @a_hash.to_s)
119
+ assert_equal(@array, @a_hash.to_a)
120
+ end
121
+
122
+ def test_range
123
+ assert_raises(ArgumentError) do
124
+ Net::DNS::RR.new("google.com. 10800 IM A")
125
+ end
126
+ end
127
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab-net-dns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ platform: ruby
6
+ authors:
7
+ - Marco Ceresa
8
+ - Simone Carletti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-10-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mocha
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: yard
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Net::DNS is a pure Ruby DNS library, with a clean OO interface and an
57
+ extensible API.
58
+ email:
59
+ - ceresa@gmail.com
60
+ - weppos@weppos.net
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ files:
66
+ - ".gitignore"
67
+ - ".gitlab-ci.yml"
68
+ - ".rspec"
69
+ - ".rubocop.yml"
70
+ - ".rubocop_defaults.yml"
71
+ - ".rubocop_todo.yml"
72
+ - ".travis.yml"
73
+ - CHANGELOG.md
74
+ - Gemfile
75
+ - LICENSE.txt
76
+ - README.md
77
+ - Rakefile
78
+ - THANKS.rdoc
79
+ - bin/console
80
+ - demo/check_soa.rb
81
+ - demo/threads.rb
82
+ - gitlab-net-dns.gemspec
83
+ - lib/net/dns.rb
84
+ - lib/net/dns/header.rb
85
+ - lib/net/dns/names.rb
86
+ - lib/net/dns/packet.rb
87
+ - lib/net/dns/question.rb
88
+ - lib/net/dns/resolver.rb
89
+ - lib/net/dns/resolver/socks.rb
90
+ - lib/net/dns/resolver/timeouts.rb
91
+ - lib/net/dns/rr.rb
92
+ - lib/net/dns/rr/a.rb
93
+ - lib/net/dns/rr/aaaa.rb
94
+ - lib/net/dns/rr/classes.rb
95
+ - lib/net/dns/rr/cname.rb
96
+ - lib/net/dns/rr/hinfo.rb
97
+ - lib/net/dns/rr/mr.rb
98
+ - lib/net/dns/rr/mx.rb
99
+ - lib/net/dns/rr/ns.rb
100
+ - lib/net/dns/rr/null.rb
101
+ - lib/net/dns/rr/ptr.rb
102
+ - lib/net/dns/rr/soa.rb
103
+ - lib/net/dns/rr/srv.rb
104
+ - lib/net/dns/rr/txt.rb
105
+ - lib/net/dns/rr/types.rb
106
+ - lib/net/dns/version.rb
107
+ - spec/fixtures/resolv.conf
108
+ - spec/spec_helper.rb
109
+ - spec/unit/resolver/dns_timeout_spec.rb
110
+ - spec/unit/resolver/tcp_timeout_spec.rb
111
+ - spec/unit/resolver/udp_timeout_spec.rb
112
+ - test/test_helper.rb
113
+ - test/unit/header_test.rb
114
+ - test/unit/names_test.rb
115
+ - test/unit/packet_test.rb
116
+ - test/unit/question_test.rb
117
+ - test/unit/resolver_test.rb
118
+ - test/unit/rr/a_test.rb
119
+ - test/unit/rr/aaaa_test.rb
120
+ - test/unit/rr/classes_test.rb
121
+ - test/unit/rr/cname_test.rb
122
+ - test/unit/rr/hinfo_test.rb
123
+ - test/unit/rr/mr_test.rb
124
+ - test/unit/rr/mx_test.rb
125
+ - test/unit/rr/ns_test.rb
126
+ - test/unit/rr/types_test.rb
127
+ - test/unit/rr_test.rb
128
+ homepage: https://gitlab.com/gitlab-org/gitlab-net-dns
129
+ licenses:
130
+ - Ruby
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '2.1'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.0.3
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Pure Ruby DNS library.
151
+ test_files:
152
+ - spec/fixtures/resolv.conf
153
+ - spec/spec_helper.rb
154
+ - spec/unit/resolver/dns_timeout_spec.rb
155
+ - spec/unit/resolver/tcp_timeout_spec.rb
156
+ - spec/unit/resolver/udp_timeout_spec.rb
157
+ - test/test_helper.rb
158
+ - test/unit/header_test.rb
159
+ - test/unit/names_test.rb
160
+ - test/unit/packet_test.rb
161
+ - test/unit/question_test.rb
162
+ - test/unit/resolver_test.rb
163
+ - test/unit/rr/a_test.rb
164
+ - test/unit/rr/aaaa_test.rb
165
+ - test/unit/rr/classes_test.rb
166
+ - test/unit/rr/cname_test.rb
167
+ - test/unit/rr/hinfo_test.rb
168
+ - test/unit/rr/mr_test.rb
169
+ - test/unit/rr/mx_test.rb
170
+ - test/unit/rr/ns_test.rb
171
+ - test/unit/rr/types_test.rb
172
+ - test/unit/rr_test.rb