net-dns 0.9.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -16
  3. data/README.md +1 -1
  4. data/lib/net/dns/header.rb +48 -64
  5. data/lib/net/dns/names.rb +8 -10
  6. data/lib/net/dns/packet.rb +46 -53
  7. data/lib/net/dns/question.rb +5 -3
  8. data/lib/net/dns/resolver/socks.rb +5 -7
  9. data/lib/net/dns/resolver/timeouts.rb +3 -5
  10. data/lib/net/dns/resolver.rb +54 -69
  11. data/lib/net/dns/rr/a.rb +3 -4
  12. data/lib/net/dns/rr/aaaa.rb +3 -5
  13. data/lib/net/dns/rr/classes.rb +6 -8
  14. data/lib/net/dns/rr/cname.rb +3 -5
  15. data/lib/net/dns/rr/hinfo.rb +9 -13
  16. data/lib/net/dns/rr/mr.rb +3 -5
  17. data/lib/net/dns/rr/mx.rb +5 -7
  18. data/lib/net/dns/rr/ns.rb +3 -5
  19. data/lib/net/dns/rr/null.rb +3 -5
  20. data/lib/net/dns/rr/ptr.rb +3 -5
  21. data/lib/net/dns/rr/soa.rb +11 -7
  22. data/lib/net/dns/rr/srv.rb +5 -2
  23. data/lib/net/dns/rr/txt.rb +4 -6
  24. data/lib/net/dns/rr/types.rb +90 -79
  25. data/lib/net/dns/rr.rb +2 -2
  26. data/lib/net/dns/version.rb +1 -1
  27. data/lib/net/dns.rb +3 -1
  28. metadata +11 -104
  29. data/.gitignore +0 -8
  30. data/.rubocop.yml +0 -3
  31. data/.rubocop_defaults.yml +0 -364
  32. data/.rubocop_todo.yml +0 -207
  33. data/Gemfile +0 -8
  34. data/Rakefile +0 -38
  35. data/bin/console +0 -14
  36. data/lib/net/dns/core_ext.rb +0 -45
  37. data/net-dns.gemspec +0 -23
  38. data/spec/fixtures/resolv.conf +0 -4
  39. data/spec/spec_helper.rb +0 -14
  40. data/spec/unit/resolver/dns_timeout_spec.rb +0 -36
  41. data/spec/unit/resolver/tcp_timeout_spec.rb +0 -46
  42. data/spec/unit/resolver/udp_timeout_spec.rb +0 -46
  43. data/test/test_helper.rb +0 -13
  44. data/test/unit/header_test.rb +0 -164
  45. data/test/unit/names_test.rb +0 -21
  46. data/test/unit/packet_test.rb +0 -47
  47. data/test/unit/question_test.rb +0 -81
  48. data/test/unit/resolver_test.rb +0 -114
  49. data/test/unit/rr/a_test.rb +0 -106
  50. data/test/unit/rr/aaaa_test.rb +0 -102
  51. data/test/unit/rr/classes_test.rb +0 -83
  52. data/test/unit/rr/cname_test.rb +0 -90
  53. data/test/unit/rr/hinfo_test.rb +0 -111
  54. data/test/unit/rr/mr_test.rb +0 -99
  55. data/test/unit/rr/mx_test.rb +0 -106
  56. data/test/unit/rr/ns_test.rb +0 -80
  57. data/test/unit/rr/types_test.rb +0 -71
  58. data/test/unit/rr_test.rb +0 -127
@@ -1,106 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRATest < Minitest::Test
5
- def setup
6
- @rr_name = "google.com."
7
- @rr_type = "A"
8
- @rr_cls = "IN"
9
- @rr_ttl = 10_000
10
- @rr_value = "64.233.187.99"
11
- @rr_address = IPAddr.new(@rr_value)
12
-
13
- @rr_output = "google.com. 10000 IN A 64.233.187.99"
14
-
15
- @rr = Net::DNS::RR::A.new(name: @rr_name, address: @rr_address, ttl: @rr_ttl)
16
- end
17
-
18
- def test_initialize_from_hash
19
- @record = Net::DNS::RR::A.new(name: @rr_name, address: @rr_value, ttl: @rr_ttl)
20
- assert_equal @rr_output, @record.to_s
21
- assert_equal @rr_name, @record.name
22
- assert_equal @rr_type, @record.type
23
- assert_equal @rr_cls, @record.cls
24
- assert_equal @rr_ttl, @record.ttl
25
- assert_equal @rr_address, @record.address
26
- assert_equal @rr_value, @record.value
27
- end
28
-
29
- def test_initialize_from_string
30
- @record = Net::DNS::RR::A.new("#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} #{@rr_value}")
31
- assert_equal @rr_output, @record.to_s
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_address, @record.address
37
- assert_equal @rr_value, @record.value
38
- end
39
-
40
- def test_parse
41
- data = "\006google\003com\000\000\001\000\001\000\000'\020\000\004@\351\273c"
42
- @record = Net::DNS::RR.parse(data)
43
- assert_equal @rr_output, @record.to_s
44
- assert_equal @rr_name, @record.name
45
- assert_equal @rr_type, @record.type
46
- assert_equal @rr_cls, @record.cls
47
- assert_equal @rr_ttl, @record.ttl
48
- assert_equal @rr_address, @record.address
49
- assert_equal @rr_value, @record.value
50
- end
51
-
52
- InvalidArguments = [
53
- { name: "google.com", address: "255.256" },
54
- { name: "google.com" },
55
- Object.new,
56
- Array.new(7),
57
- "10800 IN A",
58
- "google.com. 10800 IN B",
59
- "google.com. 10800 IM A",
60
- ].freeze
61
-
62
- InvalidArguments.each_with_index do |arguments, index|
63
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
64
- assert_raises(ArgumentError) { Net::DNS::RR::A.new(arguments) }
65
- end
66
- end
67
-
68
- def test_address_getter
69
- assert_equal @rr_address, @rr.address
70
- end
71
-
72
- def test_address_setter
73
- assert_raises(ArgumentError) { @rr.address = nil }
74
-
75
- expected = IPAddr.new("64.233.187.99")
76
- assert_equal expected, @rr.address = "64.233.187.99"
77
- assert_equal expected, @rr.address
78
-
79
- expected = IPAddr.new("64.233.187.90")
80
- assert_equal expected, @rr.address = 1_089_059_674
81
- assert_equal expected, @rr.address
82
-
83
- expected = IPAddr.new("64.233.187.80")
84
- assert_equal expected, @rr.address = IPAddr.new("64.233.187.80")
85
- assert_equal expected, @rr.address
86
- end
87
-
88
- def test_value
89
- assert_equal @rr_value, @rr.value
90
- end
91
-
92
- def test_inspect
93
- assert_equal "google.com. 10000 IN A 64.233.187.99",
94
- @rr.inspect
95
- end
96
-
97
- def test_to_s
98
- assert_equal "google.com. 10000 IN A 64.233.187.99",
99
- @rr.to_s
100
- end
101
-
102
- def test_to_a
103
- assert_equal ["google.com.", 10_000, "IN", "A", "64.233.187.99"],
104
- @rr.to_a
105
- end
106
- end
@@ -1,102 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRAAAATest < Minitest::Test
5
- def setup
6
- @rr_name = "www.nic.it."
7
- @rr_type = "AAAA"
8
- @rr_cls = "IN"
9
- @rr_ttl = 60
10
- @rr_value = "2a00:d40:1:1::239"
11
- @rr_address = IPAddr.new(@rr_value)
12
-
13
- @rr_output = "www.nic.it. 60 IN AAAA 2a00:d40:1:1::239"
14
-
15
- @rr = Net::DNS::RR::AAAA.new(name: @rr_name, address: @rr_address, ttl: @rr_ttl)
16
- end
17
-
18
- def test_initialize_from_hash
19
- @record = Net::DNS::RR::AAAA.new(name: @rr_name, address: @rr_value, ttl: @rr_ttl)
20
- assert_equal @rr_output, @record.to_s
21
- assert_equal @rr_name, @record.name
22
- assert_equal @rr_type, @record.type
23
- assert_equal @rr_cls, @record.cls
24
- assert_equal @rr_ttl, @record.ttl
25
- assert_equal @rr_address, @record.address
26
- assert_equal @rr_value, @record.value
27
- end
28
-
29
- def test_initialize_from_string
30
- @record = Net::DNS::RR::AAAA.new("#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} #{@rr_value}")
31
- assert_equal @rr_output, @record.to_s
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_address, @record.address
37
- assert_equal @rr_value, @record.value
38
- end
39
-
40
- def test_parse
41
- data = "\003www\003nic\002it\000\000\034\000\001\000\000\000<\000\020*\000\r@\000\001\000\001\000\000\000\000\000\000\0029"
42
- @record = Net::DNS::RR.parse(data)
43
- assert_equal @rr_output, @record.to_s
44
- assert_equal @rr_name, @record.name
45
- assert_equal @rr_type, @record.type
46
- assert_equal @rr_cls, @record.cls
47
- assert_equal @rr_ttl, @record.ttl
48
- assert_equal @rr_address, @record.address
49
- assert_equal @rr_value, @record.value
50
- end
51
-
52
- InvalidArguments = [
53
- { name: "google.com", address: "2a00" },
54
- { name: "google.com" },
55
- Object.new,
56
- Array.new(7),
57
- "10800 IN AAAA",
58
- # FIXME: "google.com. 10800 IN B",
59
- # FIXME: "google.com. 10800 IM AAAA",
60
- ].freeze
61
-
62
- InvalidArguments.each_with_index do |arguments, index|
63
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
64
- assert_raises(ArgumentError) { Net::DNS::RR::AAAA.new(arguments) }
65
- end
66
- end
67
-
68
- def test_address_getter
69
- assert_equal @rr_address, @rr.address
70
- end
71
-
72
- def test_address_setter
73
- assert_raises(ArgumentError) { @rr.address = nil }
74
-
75
- expected = IPAddr.new("2a00:d40:1:1::239")
76
- assert_equal expected, @rr.address = "2a00:d40:1:1::239"
77
- assert_equal expected, @rr.address
78
-
79
- expected = IPAddr.new("2a00:d40:1:1::240")
80
- assert_equal expected, @rr.address = IPAddr.new("2a00:d40:1:1::240")
81
- assert_equal expected, @rr.address
82
- end
83
-
84
- def test_value
85
- assert_equal @rr_value, @rr.value
86
- end
87
-
88
- def test_inspect
89
- assert_equal "www.nic.it. 60 IN AAAA 2a00:d40:1:1::239",
90
- @rr.inspect
91
- end
92
-
93
- def test_to_s
94
- assert_equal "www.nic.it. 60 IN AAAA 2a00:d40:1:1::239",
95
- @rr.to_s
96
- end
97
-
98
- def test_to_a
99
- assert_equal ["www.nic.it.", 60, "IN", "AAAA", "2a00:d40:1:1::239"],
100
- @rr.to_a
101
- end
102
- end
@@ -1,83 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRClassesTest < Minitest::Test
5
- def setup
6
- @classes = {}
7
- @regexp_string = "ANY|CH|HS|IN|NONE"
8
- end
9
-
10
- StrAndNum = [
11
- ['IN', 1],
12
- ['CH', 3],
13
- ['HS', 4],
14
- ['NONE', 254],
15
- ['ANY', 255],
16
- ].freeze
17
-
18
- StrAndNum.each do |str, num|
19
- define_method "test_initialize_from_str_#{str}" do
20
- instance = Net::DNS::RR::Classes.new(str)
21
- assert_equal str, instance.to_s
22
- assert_equal num, instance.to_i
23
- end
24
- define_method "test_initialize_from_num_#{num}" do
25
- instance = Net::DNS::RR::Classes.new(num)
26
- assert_equal str, instance.to_s
27
- assert_equal num, instance.to_i
28
- end
29
- end
30
-
31
- def test_initialize_should_raise_with_invalid_class
32
- assert_raises(ArgumentError) { Net::DNS::RR::Classes.new({}) }
33
- end
34
-
35
- def test_inspect
36
- assert_equal 1, Net::DNS::RR::Classes.new(1).inspect
37
- assert_equal 1, Net::DNS::RR::Classes.new("IN").inspect
38
- end
39
-
40
- def test_to_s
41
- assert_equal "IN", Net::DNS::RR::Classes.new(1).to_s
42
- assert_equal "IN", Net::DNS::RR::Classes.new("IN").to_s
43
- end
44
-
45
- def test_to_i
46
- assert_equal 1, Net::DNS::RR::Classes.new(1).to_i
47
- assert_equal 1, Net::DNS::RR::Classes.new("IN").to_i
48
- end
49
-
50
- def test_self_default
51
- @_default = Net::DNS::RR::Classes.default
52
-
53
- # Default type should be ANY => 255
54
- instance = Net::DNS::RR::Classes.new(nil)
55
- assert_equal 1, instance.to_i
56
- assert_equal "IN", instance.to_s
57
-
58
- # Let's change default behaviour
59
- Net::DNS::RR::Classes.default = "CH"
60
- instance = Net::DNS::RR::Classes.new(nil)
61
- assert_equal 3, instance.to_i
62
- assert_equal "CH", instance.to_s
63
-
64
- Net::DNS::RR::Classes.default = "IN"
65
- instance = Net::DNS::RR::Classes.new(nil)
66
- assert_equal 1, instance.to_i
67
- assert_equal "IN", instance.to_s
68
- ensure
69
- Net::DNS::RR::Classes.default = Net::DNS::RR::Classes::CLASSES.invert[@_default]
70
- end
71
-
72
- def test_self_valid?
73
- assert Net::DNS::RR::Classes.valid?("IN")
74
- assert Net::DNS::RR::Classes.valid?(1)
75
- assert !Net::DNS::RR::Classes.valid?("Q")
76
- assert !Net::DNS::RR::Classes.valid?(256)
77
- assert_raises(ArgumentError) { Net::DNS::RR::Classes.valid?({}) }
78
- end
79
-
80
- def test_self_regexp
81
- assert_equal @regexp_string, Net::DNS::RR::Classes.regexp
82
- end
83
- end
@@ -1,90 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRCNAMETest < Minitest::Test
5
- def setup
6
- @rr_name = "www.google.com."
7
- @rr_type = "CNAME"
8
- @rr_cls = "IN"
9
- @rr_ttl = 550_317
10
- @rr_value = "www.l.google.com."
11
- @rr_cname = @rr_value
12
-
13
- @rr_output = "www.google.com. 550317 IN CNAME www.l.google.com."
14
-
15
- @rr = Net::DNS::RR::CNAME.new(name: @rr_name, cname: @rr_cname, ttl: @rr_ttl)
16
- end
17
-
18
- def test_initialize_from_hash
19
- @record = Net::DNS::RR::CNAME.new(name: @rr_name, cname: @rr_value, ttl: @rr_ttl)
20
- assert_equal @rr_output, @record.to_s
21
- assert_equal @rr_name, @record.name
22
- assert_equal @rr_type, @record.type
23
- assert_equal @rr_cls, @record.cls
24
- assert_equal @rr_ttl, @record.ttl
25
- assert_equal @rr_cname, @record.cname
26
- assert_equal @rr_value, @record.value
27
- end
28
-
29
- def test_initialize_from_string
30
- @record = Net::DNS::RR::CNAME.new("#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} #{@rr_value}")
31
- assert_equal @rr_output, @record.to_s
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_cname, @record.cname
37
- assert_equal @rr_value, @record.value
38
- end
39
-
40
- def test_parse
41
- data = "\003www\006google\003com\000\000\005\000\001\000\be\255\000\022\003www\001l\006google\003com\000"
42
- @record = Net::DNS::RR.parse(data)
43
- assert_equal @rr_output, @record.to_s
44
- assert_equal @rr_name, @record.name
45
- assert_equal @rr_type, @record.type
46
- assert_equal @rr_cls, @record.cls
47
- assert_equal @rr_ttl, @record.ttl
48
- assert_equal @rr_cname, @record.cname
49
- assert_equal @rr_value, @record.value
50
- end
51
-
52
- InvalidArguments = [
53
- # FIXME: { :name => "google.com", :cname => "foo___bar" },
54
- # FIXME: { :name => "google.com", :cname => "foo$bar" },
55
- { name: "google.com" },
56
- Object.new,
57
- Array.new(7),
58
- "10800 IN CNAME",
59
- "google.com. 10800 IN CNAME",
60
- ].freeze
61
-
62
- InvalidArguments.each_with_index do |arguments, index|
63
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
64
- assert_raises(ArgumentError) { p Net::DNS::RR::CNAME.new(arguments) }
65
- end
66
- end
67
-
68
- def test_cname_getter
69
- assert_equal @rr_cname, @rr.cname
70
- end
71
-
72
- def test_value
73
- assert_equal @rr_value, @rr.value
74
- end
75
-
76
- def test_inspect
77
- assert_equal "www.google.com. 550317 IN CNAME www.l.google.com.",
78
- @rr.inspect
79
- end
80
-
81
- def test_to_s
82
- assert_equal "www.google.com. 550317 IN CNAME www.l.google.com.",
83
- @rr.to_s
84
- end
85
-
86
- def test_to_a
87
- assert_equal ["www.google.com.", 550_317, "IN", "CNAME", "www.l.google.com."],
88
- @rr.to_a
89
- end
90
- end
@@ -1,111 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
- require 'net/dns/rr/hinfo'
4
-
5
- class RRHINFOTest < Minitest::Test
6
- def setup
7
- @rr_name = ""
8
- @rr_type = "HINFO"
9
- @rr_cls = "IN"
10
- @rr_ttl = nil
11
- @rr_value = '"PC-Intel-700mhz" "Redhat Linux 7.1"'
12
- @rr_output = ' IN HINFO "PC-Intel-700mhz" "Redhat Linux 7.1"'
13
-
14
- @rr_cpu = "PC-Intel-700mhz"
15
- @rr_os = "Redhat Linux 7.1"
16
-
17
- @rr = Net::DNS::RR::HINFO.new(name: @rr_name, cpu: @rr_cpu, os: @rr_os)
18
- end
19
-
20
- def test_initialize_from_hash
21
- @record = Net::DNS::RR::HINFO.new(name: @rr_name, cpu: @rr_cpu, os: @rr_os)
22
- assert_equal @rr_output, @record.to_s
23
- assert_equal @rr_name, @record.name
24
- assert_equal @rr_type, @record.type
25
- assert_equal @rr_cls, @record.cls
26
- assert_equal 10_800, @record.ttl
27
- assert_equal @rr_value, @record.value
28
-
29
- assert_equal @rr_cpu, @record.cpu
30
- assert_equal @rr_os, @record.os
31
- end
32
-
33
- def test_initialize_from_string
34
- @record = Net::DNS::RR::HINFO.new(%Q(#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} PC-Intel-700mhz "Redhat Linux 7.1"))
35
- assert_equal @rr_output, @record.to_s
36
- assert_equal @rr_value, @record.value
37
-
38
- assert_equal @rr_cpu, @record.cpu
39
- assert_equal @rr_os, @record.os
40
- end
41
-
42
- def test_initialize_from_string_without_quotes
43
- @record = Net::DNS::RR::HINFO.new("#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} #{@rr_value}")
44
- assert_equal @rr_output, @record.to_s
45
- # FIXME: assert_equal @rr_name, @record.name
46
- assert_equal @rr_type, @record.type
47
- assert_equal @rr_cls, @record.cls
48
- assert_equal 10_800, @record.ttl
49
- assert_equal @rr_value, @record.value
50
-
51
- assert_equal @rr_cpu, @record.cpu
52
- assert_equal @rr_os, @record.os
53
- end
54
-
55
- # FIXME: Can't get valid data
56
- #
57
- # def test_parse
58
- # data = "\002in\000\000\r\000\001\000\000*0\000!\017PC-Intel-700mhz\020Redhat Linux 7.1"
59
- # @record = Net::DNS::RR.parse(data)
60
- # assert_equal @rr_output, @record.to_s
61
- # assert_equal @rr_name, @record.name
62
- # assert_equal @rr_type, @record.type
63
- # assert_equal @rr_cls, @record.cls
64
- # assert_equal @rr_ttl, @record.ttl
65
- # assert_equal @rr_value, @record.value
66
- #
67
- # assert_equal @rr_cpu, @record.cpu
68
- # assert_equal @rr_os, @record.os
69
- # end
70
-
71
- InvalidArguments = [
72
- { name: "google.com" },
73
- Object.new,
74
- Array.new(7),
75
- "10800 IN HINFO",
76
- "IN HINFO",
77
- ].freeze
78
-
79
- InvalidArguments.each_with_index do |arguments, index|
80
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
81
- assert_raises(ArgumentError) { p Net::DNS::RR::HINFO.new(arguments) }
82
- end
83
- end
84
-
85
- def test_cpu
86
- assert_equal @rr_cpu, @rr.cpu
87
- end
88
-
89
- def test_os
90
- assert_equal @rr_os, @rr.os
91
- end
92
-
93
- def test_value
94
- assert_equal '"PC-Intel-700mhz" "Redhat Linux 7.1"', @rr.value
95
- end
96
-
97
- def test_inspect
98
- assert_equal ' IN HINFO "PC-Intel-700mhz" "Redhat Linux 7.1"',
99
- @rr.inspect
100
- end
101
-
102
- def test_to_s
103
- assert_equal ' IN HINFO "PC-Intel-700mhz" "Redhat Linux 7.1"',
104
- @rr.to_s
105
- end
106
-
107
- def test_to_a
108
- assert_equal [nil, nil, "IN", "HINFO", '"PC-Intel-700mhz" "Redhat Linux 7.1"'],
109
- @rr.to_a
110
- end
111
- end
@@ -1,99 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRMRTest < Minitest::Test
5
- def setup
6
- @klass = Net::DNS::RR::MR
7
- @rr = @klass.new(name: "eddie.movie.edu.", newname: "eddie.bornagain.edu.", ttl: 9000)
8
-
9
- @rr_name = "eddie.movie.edu."
10
- @rr_type = "MR"
11
- @rr_cls = "IN"
12
- @rr_ttl = 9000
13
- @rr_newname = "eddie.bornagain.edu."
14
- @rr_value = "eddie.bornagain.edu."
15
- @rr_output = "eddie.movie.edu. 9000 IN MR eddie.bornagain.edu."
16
- end
17
-
18
- def test_initialize_from_hash
19
- @record = @klass.new(name: "eddie.movie.edu.", newname: "eddie.bornagain.edu.", ttl: 9000)
20
- assert_equal @rr_output, @record.inspect
21
- assert_equal @rr_name, @record.name
22
- assert_equal @rr_type, @record.type
23
- assert_equal @rr_cls, @record.cls
24
- assert_equal @rr_ttl, @record.ttl
25
- assert_equal @rr_newname, @record.newname
26
- end
27
-
28
- def test_initialize_from_string
29
- @record = @klass.new("eddie.movie.edu. 9000 IN MR eddie.bornagain.edu.")
30
- assert_equal @rr_output, @record.inspect
31
- assert_equal @rr_name, @record.name
32
- assert_equal @rr_type, @record.type
33
- assert_equal @rr_cls, @record.cls
34
- assert_equal @rr_ttl, @record.ttl
35
- assert_equal @rr_newname, @record.newname
36
- end
37
-
38
- # def test_parse
39
- # data = "\005eddie\005movie\003edu\000\000\t\000\001\000\000#(\000\025\005eddie\tbornagain\003edu\000"
40
- # @record = Net::DNS::RR.parse(data)
41
- # assert_equal @rr_output, @record.inspect
42
- # assert_equal @rr_name, @record.name
43
- # assert_equal @rr_type, @record.type
44
- # assert_equal @rr_cls, @record.cls
45
- # assert_equal @rr_ttl, @record.ttl
46
- # assert_equal @rr_newname, @record.newname
47
- # end
48
-
49
- InvalidArguments = [
50
- # FIXME: { :name => "eddie.movie.edu.", :newname => "foo___bar" },
51
- # FIXME: { :name => "eddie.movie.edu.", :newname => "foo$bar" },
52
- # FIXME: { :name => "eddie.movie.edu", :newname => "eddie.newname.edu." },
53
- Object.new,
54
- Array.new(7),
55
- "9000 IN MR",
56
- ].freeze
57
-
58
- InvalidArguments.each_with_index do |arguments, index|
59
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
60
- assert_raises(ArgumentError) { @klass.new(arguments) }
61
- end
62
- end
63
-
64
- def test_initialize_should_raise_with_missing_newname
65
- error = assert_raises(ArgumentError) { @klass.new(name: "eddie.movie.edu.") }
66
- assert_match /:newname/, error.message
67
- end
68
-
69
- def test_value
70
- @rr = @klass.new(name: "eddie.movie.edu.", newname: "eddie.newname.edu.")
71
- assert_equal "eddie.newname.edu.", @rr.value
72
-
73
- @rr = @klass.new(name: "eddie.movie.edu.", newname: "eddie.othername.edu.")
74
- assert_equal "eddie.othername.edu.", @rr.value
75
- end
76
-
77
- def test_newname
78
- @rr = @klass.new(name: "eddie.movie.edu.", newname: "eddie.newname.edu.")
79
- assert_equal "eddie.newname.edu.", @rr.newname
80
-
81
- @rr = @klass.new(name: "eddie.movie.edu.", newname: "eddie.othername.edu.")
82
- assert_equal "eddie.othername.edu.", @rr.newname
83
- end
84
-
85
- def test_inspect
86
- assert_equal "eddie.movie.edu. 9000 IN MR eddie.bornagain.edu.",
87
- @rr.inspect
88
- end
89
-
90
- def test_to_s
91
- assert_equal "eddie.movie.edu. 9000 IN MR eddie.bornagain.edu.",
92
- @rr.to_s
93
- end
94
-
95
- def test_to_a
96
- assert_equal ["eddie.movie.edu.", 9000, "IN", "MR", "eddie.bornagain.edu."],
97
- @rr.to_a
98
- end
99
- end
@@ -1,106 +0,0 @@
1
- require 'test_helper'
2
- require 'net/dns/rr'
3
-
4
- class RRMXTest < Minitest::Test
5
- def setup
6
- @rr_name = "example.com."
7
- @rr_type = "MX"
8
- @rr_cls = "IN"
9
- @rr_ttl = 10_000
10
- @rr_preference = 10
11
- @rr_exchange = "mail.example.com."
12
- @rr_value = "#{@rr_preference} #{@rr_exchange}"
13
-
14
- @rr_output = "example.com. 10000 IN MX 10 mail.example.com."
15
-
16
- @rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 10, exchange: "mail.example.com.", ttl: 10_000)
17
- end
18
-
19
- def test_initialize_from_hash
20
- @record = Net::DNS::RR::MX.new(name: "example.com.", preference: 10, exchange: "mail.example.com.", ttl: 10_000)
21
- assert_equal @rr_output, @record.to_s
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_preference, @record.preference
27
- assert_equal @rr_exchange, @record.exchange
28
- end
29
-
30
- def test_initialize_from_string
31
- @record = Net::DNS::RR::MX.new("example.com. 10000 IN MX 10 mail.example.com.")
32
- assert_equal @rr_output, @record.to_s
33
- assert_equal @rr_name, @record.name
34
- assert_equal @rr_type, @record.type
35
- assert_equal @rr_cls, @record.cls
36
- assert_equal @rr_ttl, @record.ttl
37
- assert_equal @rr_preference, @record.preference
38
- assert_equal @rr_exchange, @record.exchange
39
- end
40
-
41
- # FIXME: can't get it working with canned data
42
- # def test_parse
43
- # data = "\001\220\006google\003com\004s9b2\005psmtp\003com\000"
44
- # @record = Net::DNS::RR.parse(data)
45
- # assert_equal @rr_output, @record.to_s
46
- # assert_equal @rr_name, @record.name
47
- # assert_equal @rr_type, @record.type
48
- # assert_equal @rr_cls, @record.cls
49
- # assert_equal @rr_ttl, @record.ttl
50
- # assert_equal @rr_preference, @record.preference
51
- # assert_equal @rr_exchange, @record.exchange
52
- # end
53
-
54
- InvalidArguments = [
55
- { name: "google.com" },
56
- Object.new,
57
- Array.new(7),
58
- "10800 IN NS",
59
- "google.com. 10800 IN NS",
60
- ].freeze
61
-
62
- InvalidArguments.each_with_index do |arguments, index|
63
- define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
64
- assert_raises(ArgumentError) { p Net::DNS::RR::MX.new(arguments) }
65
- end
66
- end
67
-
68
- def test_preference
69
- @rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 10, exchange: "mail.example.com.")
70
- assert_equal 10, @rr.preference
71
-
72
- @rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 100, exchange: "mail.example.com.")
73
- assert_equal 100, @rr.preference
74
- end
75
-
76
- def test_exchange
77
- @rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 10, exchange: "mail.example.com.")
78
- assert_equal "mail.example.com.", @rr.exchange
79
-
80
- @rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 10, exchange: "mail2.example.com.")
81
- assert_equal "mail2.example.com.", @rr.exchange
82
- end
83
-
84
- def test_value
85
- @rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 10, exchange: "mail.example.com.")
86
- assert_equal "10 mail.example.com.", @rr.value
87
-
88
- @rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 100, exchange: "mail2.example.com.")
89
- assert_equal "100 mail2.example.com.", @rr.value
90
- end
91
-
92
- def test_inspect
93
- assert_equal "example.com. 10000 IN MX 10 mail.example.com.",
94
- @rr.inspect
95
- end
96
-
97
- def test_to_s
98
- assert_equal "example.com. 10000 IN MX 10 mail.example.com.",
99
- @rr.to_s
100
- end
101
-
102
- def test_to_a
103
- assert_equal ["example.com.", 10_000, "IN", "MX", "10 mail.example.com."],
104
- @rr.to_a
105
- end
106
- end