net-dns 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +3 -0
  5. data/.rubocop_defaults.yml +364 -0
  6. data/.rubocop_todo.yml +207 -0
  7. data/.travis.yml +9 -16
  8. data/CHANGELOG.md +12 -1
  9. data/Gemfile +6 -2
  10. data/LICENSE.txt +56 -0
  11. data/README.md +94 -77
  12. data/Rakefile +23 -56
  13. data/bin/console +14 -0
  14. data/demo/check_soa.rb +27 -38
  15. data/demo/threads.rb +3 -7
  16. data/lib/net/dns.rb +4 -11
  17. data/lib/net/dns/core_ext.rb +8 -15
  18. data/lib/net/dns/header.rb +58 -66
  19. data/lib/net/dns/names.rb +25 -23
  20. data/lib/net/dns/packet.rb +136 -139
  21. data/lib/net/dns/question.rb +36 -39
  22. data/lib/net/dns/resolver.rb +103 -113
  23. data/lib/net/dns/resolver/socks.rb +45 -51
  24. data/lib/net/dns/resolver/timeouts.rb +17 -26
  25. data/lib/net/dns/rr.rb +107 -117
  26. data/lib/net/dns/rr/a.rb +46 -55
  27. data/lib/net/dns/rr/aaaa.rb +40 -49
  28. data/lib/net/dns/rr/classes.rb +26 -29
  29. data/lib/net/dns/rr/cname.rb +33 -41
  30. data/lib/net/dns/rr/hinfo.rb +44 -56
  31. data/lib/net/dns/rr/mr.rb +33 -42
  32. data/lib/net/dns/rr/mx.rb +37 -47
  33. data/lib/net/dns/rr/ns.rb +33 -41
  34. data/lib/net/dns/rr/null.rb +8 -11
  35. data/lib/net/dns/rr/ptr.rb +14 -20
  36. data/lib/net/dns/rr/soa.rb +27 -30
  37. data/lib/net/dns/rr/srv.rb +13 -17
  38. data/lib/net/dns/rr/txt.rb +8 -11
  39. data/lib/net/dns/rr/types.rb +97 -99
  40. data/lib/net/dns/version.rb +5 -13
  41. data/net-dns.gemspec +17 -29
  42. data/{fixtures → spec/fixtures}/resolv.conf +0 -0
  43. data/spec/spec_helper.rb +14 -0
  44. data/spec/unit/resolver/dns_timeout_spec.rb +36 -0
  45. data/spec/unit/resolver/tcp_timeout_spec.rb +46 -0
  46. data/spec/unit/resolver/udp_timeout_spec.rb +46 -0
  47. data/test/test_helper.rb +12 -3
  48. data/test/{header_test.rb → unit/header_test.rb} +43 -46
  49. data/test/{names_test.rb → unit/names_test.rb} +1 -1
  50. data/test/{packet_test.rb → unit/packet_test.rb} +3 -5
  51. data/test/{question_test.rb → unit/question_test.rb} +3 -5
  52. data/test/{resolver_test.rb → unit/resolver_test.rb} +10 -13
  53. data/test/{rr → unit/rr}/a_test.rb +10 -17
  54. data/test/{rr → unit/rr}/aaaa_test.rb +7 -14
  55. data/test/{rr → unit/rr}/classes_test.rb +14 -16
  56. data/test/{rr → unit/rr}/cname_test.rb +7 -14
  57. data/test/{rr → unit/rr}/hinfo_test.rb +16 -22
  58. data/test/{rr → unit/rr}/mr_test.rb +12 -18
  59. data/test/{rr → unit/rr}/mx_test.rb +18 -24
  60. data/test/{rr → unit/rr}/ns_test.rb +10 -16
  61. data/test/{rr → unit/rr}/types_test.rb +10 -8
  62. data/test/{rr_test.rb → unit/rr_test.rb} +33 -37
  63. metadata +77 -49
  64. data/test/resolver/timeouts_test.rb +0 -109
@@ -1,7 +1,6 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #
6
5
  # = System Information Record (HINFO)
7
6
  #
@@ -13,30 +12,24 @@ module Net # :nodoc:
13
12
  # Single space between CPU and OS parameters.
14
13
  #
15
14
  class HINFO < RR
16
-
17
15
  # Gets the CPU value.
18
16
  #
19
17
  # Returns a String.
20
- def cpu
21
- @cpu
22
- end
18
+ attr_reader :cpu
23
19
 
24
20
  # Gets the OS value.
25
21
  #
26
22
  # Returns a String.
27
- def os
28
- @os
29
- end
23
+ attr_reader :os
30
24
 
31
25
  # Gets the standardized value for this record,
32
26
  # represented by the value of <tt>cpu</tt> and <tt>os</tt>.
33
27
  #
34
28
  # Returns a String.
35
29
  def value
36
- %Q{"#{cpu}" "#{os}"}
30
+ %Q("#{cpu}" "#{os}")
37
31
  end
38
32
 
39
-
40
33
  # Gets a list of all the attributes for this record.
41
34
  #
42
35
  # Returns an Array of values.
@@ -44,65 +37,60 @@ module Net # :nodoc:
44
37
  [nil, nil, cls.to_s, type.to_s, value]
45
38
  end
46
39
 
47
-
48
40
  private
49
41
 
50
- def subclass_new_from_hash(options)
51
- if options.has_key?(:cpu) && options.has_key?(:os)
52
- @cpu = options[:cpu]
53
- @os = options[:os]
54
- else
55
- raise ArgumentError, ":cpu and :os fields are mandatory"
56
- end
57
- end
58
-
59
- def subclass_new_from_string(str)
60
- @cpu, @os = check_hinfo(str)
42
+ def subclass_new_from_hash(options)
43
+ if options.key?(:cpu) && options.key?(:os)
44
+ @cpu = options[:cpu]
45
+ @os = options[:os]
46
+ else
47
+ raise ArgumentError, ":cpu and :os fields are mandatory"
61
48
  end
49
+ end
62
50
 
63
- def subclass_new_from_binary(data, offset)
64
- len = data.unpack("@#{offset} C").first
65
- offset += 1
66
- @cpu = data[offset..(offset + len)]
67
- offset += len
68
-
69
- len = data.unpack("@#{offset} C").first
70
- offset += 1
71
- @os = data[offset..(offset + len)]
72
- offset += len
73
- end
51
+ def subclass_new_from_string(str)
52
+ @cpu, @os = check_hinfo(str)
53
+ end
74
54
 
55
+ def subclass_new_from_binary(data, offset)
56
+ len = data.unpack("@#{offset} C").first
57
+ offset += 1
58
+ @cpu = data[offset..(offset + len)]
59
+ offset += len
75
60
 
76
- def set_type
77
- @type = Net::DNS::RR::Types.new("HINFO")
78
- end
79
-
80
- def get_inspect
81
- value
82
- end
61
+ len = data.unpack("@#{offset} C").first
62
+ offset += 1
63
+ @os = data[offset..(offset + len)]
64
+ offset += len
65
+ end
83
66
 
67
+ def set_type
68
+ @type = Net::DNS::RR::Types.new("HINFO")
69
+ end
84
70
 
85
- def check_hinfo(input)
86
- if input.to_s.strip =~ /^(?:["']?(.*?)["']?)\s+(?:["']?(.*?)["']?)$/
87
- [$1, $2]
88
- else
89
- raise ArgumentError, "Invalid HINFO Section `#{input}'"
90
- end
91
- end
71
+ def get_inspect
72
+ value
73
+ end
92
74
 
93
- def build_pack
94
- @hinfo_pack = ""
95
- @hinfo_pack += [cpu.size].pack("C") + cpu
96
- @hinfo_pack += [os.size ].pack("C") + os
97
- @rdlength = @hinfo_pack.size
75
+ def check_hinfo(input)
76
+ if input.to_s.strip =~ /^(?:["']?(.*?)["']?)\s+(?:["']?(.*?)["']?)$/
77
+ [Regexp.last_match(1), Regexp.last_match(2)]
78
+ else
79
+ raise ArgumentError, "Invalid HINFO Section `#{input}'"
98
80
  end
81
+ end
99
82
 
100
- def get_data
101
- @hinfo_pack
102
- end
83
+ def build_pack
84
+ @hinfo_pack = ""
85
+ @hinfo_pack += [cpu.size].pack("C") + cpu
86
+ @hinfo_pack += [os.size].pack("C") + os
87
+ @rdlength = @hinfo_pack.size
88
+ end
103
89
 
90
+ def get_data
91
+ @hinfo_pack
92
+ end
104
93
  end
105
-
106
94
  end
107
95
  end
108
96
  end
@@ -1,21 +1,16 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
-
4
3
  class RR
5
-
6
4
  #
7
5
  # = Mail Rename Record (MR)
8
6
  #
9
7
  # Class for DNS MR resource records.
10
8
  #
11
9
  class MR < RR
12
-
13
10
  # Gets the newname value.
14
11
  #
15
12
  # Returns a String.
16
- def newname
17
- @newname
18
- end
13
+ attr_reader :newname
19
14
 
20
15
  # Gets the standardized value for this record,
21
16
  # represented by the value of <tt>newname</tt>.
@@ -25,55 +20,51 @@ module Net # :nodoc:
25
20
  newname.to_s
26
21
  end
27
22
 
28
-
29
23
  private
30
24
 
31
- def subclass_new_from_hash(options)
32
- if options.has_key?(:newname)
33
- @newname = check_name(options[:newname])
34
- else
35
- raise ArgumentError, ":newname field is mandatory"
36
- end
37
- end
38
-
39
- def subclass_new_from_string(str)
40
- @newname = check_name(str)
41
- end
42
-
43
- def subclass_new_from_binary(data, offset)
44
- @newname = dn_expand(data,offset)
45
- offset
25
+ def subclass_new_from_hash(options)
26
+ if options.key?(:newname)
27
+ @newname = check_name(options[:newname])
28
+ else
29
+ raise ArgumentError, ":newname field is mandatory"
46
30
  end
31
+ end
47
32
 
33
+ def subclass_new_from_string(str)
34
+ @newname = check_name(str)
35
+ end
48
36
 
49
- def set_type
50
- @type = Net::DNS::RR::Types.new("MR")
51
- end
37
+ def subclass_new_from_binary(data, offset)
38
+ @newname = dn_expand(data, offset)
39
+ offset
40
+ end
52
41
 
53
- def get_inspect
54
- value
55
- end
42
+ def set_type
43
+ @type = Net::DNS::RR::Types.new("MR")
44
+ end
56
45
 
46
+ def get_inspect
47
+ value
48
+ end
57
49
 
58
- def check_name(input)
59
- name = input.to_s
60
- unless name =~ /(\w\.?)+\s*$/
61
- raise ArgumentError, "Invalid Domain Name `#{name}'"
62
- end
63
- name
50
+ def check_name(input)
51
+ name = input.to_s
52
+ unless name =~ /(\w\.?)+\s*$/
53
+ raise ArgumentError, "Invalid Domain Name `#{name}'"
64
54
  end
65
55
 
66
- def build_pack
67
- @newname_pack = pack_name(@newname)
68
- @rdlength = @newname_pack.size
69
- end
56
+ name
57
+ end
70
58
 
71
- def get_data
72
- @newname_pack
73
- end
59
+ def build_pack
60
+ @newname_pack = pack_name(@newname)
61
+ @rdlength = @newname_pack.size
62
+ end
74
63
 
64
+ def get_data
65
+ @newname_pack
66
+ end
75
67
  end
76
-
77
68
  end
78
69
  end
79
70
  end
@@ -1,7 +1,6 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #
6
5
  # = Mail Exchange Record (MX)
7
6
  #
@@ -12,20 +11,15 @@ module Net # :nodoc:
12
11
  # The MX RR is used by SMTP (Mail) Agents to route mail for the domain.
13
12
  #
14
13
  class MX < RR
15
-
16
14
  # Gets the preference value.
17
15
  #
18
16
  # Returns an Integer.
19
- def preference
20
- @preference
21
- end
17
+ attr_reader :preference
22
18
 
23
19
  # Gets the exchange value.
24
20
  #
25
21
  # Returns a String.
26
- def exchange
27
- @exchange
28
- end
22
+ attr_reader :exchange
29
23
 
30
24
  # Gets the standardized value for this record,
31
25
  # represented by the value of <tt>preference</tt> and <tt>exchange</tt>.
@@ -35,58 +29,54 @@ module Net # :nodoc:
35
29
  "#{preference} #{exchange}"
36
30
  end
37
31
 
38
-
39
32
  private
40
33
 
41
- def subclass_new_from_hash(options)
42
- if options.has_key?(:preference) && options.has_key?(:exchange)
43
- @preference = options[:preference].to_i
44
- @exchange = options[:exchange]
45
- else
46
- raise ArgumentError, ":preference and :exchange fields are mandatory"
47
- end
48
- end
49
-
50
- def subclass_new_from_string(str)
51
- @preference, @exchange = check_mx(str)
52
- end
53
-
54
- def subclass_new_from_binary(data, offset)
55
- @preference = data.unpack("@#{offset} n")[0]
56
- offset += 2
57
- @exchange, offset = dn_expand(data, offset)
58
- offset
34
+ def subclass_new_from_hash(options)
35
+ if options.key?(:preference) && options.key?(:exchange)
36
+ @preference = options[:preference].to_i
37
+ @exchange = options[:exchange]
38
+ else
39
+ raise ArgumentError, ":preference and :exchange fields are mandatory"
59
40
  end
41
+ end
60
42
 
43
+ def subclass_new_from_string(str)
44
+ @preference, @exchange = check_mx(str)
45
+ end
61
46
 
62
- def set_type
63
- @type = Net::DNS::RR::Types.new("MX")
64
- end
47
+ def subclass_new_from_binary(data, offset)
48
+ @preference = data.unpack("@#{offset} n")[0]
49
+ offset += 2
50
+ @exchange, offset = dn_expand(data, offset)
51
+ offset
52
+ end
65
53
 
66
- def get_inspect
67
- value
68
- end
54
+ def set_type
55
+ @type = Net::DNS::RR::Types.new("MX")
56
+ end
69
57
 
58
+ def get_inspect
59
+ value
60
+ end
70
61
 
71
- def check_mx(input)
72
- str = input.to_s
73
- unless str.strip =~ /^(\d+)\s+(\S+)$/
74
- raise ArgumentError, "Invalid MX section `#{str}'"
75
- end
76
- [$1.to_i, $2]
62
+ def check_mx(input)
63
+ str = input.to_s
64
+ unless str.strip =~ /^(\d+)\s+(\S+)$/
65
+ raise ArgumentError, "Invalid MX section `#{str}'"
77
66
  end
78
67
 
79
- def build_pack
80
- @mx_pack = [@preference].pack("n") + pack_name(@exchange)
81
- @rdlength = @mx_pack.size
82
- end
68
+ [Regexp.last_match(1).to_i, Regexp.last_match(2)]
69
+ end
83
70
 
84
- def get_data
85
- @mx_pack
86
- end
71
+ def build_pack
72
+ @mx_pack = [@preference].pack("n") + pack_name(@exchange)
73
+ @rdlength = @mx_pack.size
74
+ end
87
75
 
76
+ def get_data
77
+ @mx_pack
78
+ end
88
79
  end
89
-
90
80
  end
91
81
  end
92
82
  end
@@ -1,20 +1,16 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #
6
5
  # = Name Server Record (NS)
7
6
  #
8
7
  # Class for DNS NS resource records.
9
8
  #
10
9
  class NS < RR
11
-
12
10
  # Gets the name server value.
13
11
  #
14
12
  # Returns a String.
15
- def nsdname
16
- @nsdname
17
- end
13
+ attr_reader :nsdname
18
14
 
19
15
  # Gets the standardized value for this record,
20
16
  # represented by the value of <tt>nsdname</tt>.
@@ -24,55 +20,51 @@ module Net # :nodoc:
24
20
  nsdname.to_s
25
21
  end
26
22
 
27
-
28
23
  private
29
24
 
30
- def subclass_new_from_hash(options)
31
- if options.has_key?(:nsdname)
32
- @nsdname = check_name(options[:nsdname])
33
- else
34
- raise ArgumentError, ":nsdname field is mandatory"
35
- end
36
- end
37
-
38
- def subclass_new_from_string(str)
39
- @nsdname = check_name(str)
40
- end
41
-
42
- def subclass_new_from_binary(data, offset)
43
- @nsdname, offset = dn_expand(data, offset)
44
- offset
25
+ def subclass_new_from_hash(options)
26
+ if options.key?(:nsdname)
27
+ @nsdname = check_name(options[:nsdname])
28
+ else
29
+ raise ArgumentError, ":nsdname field is mandatory"
45
30
  end
31
+ end
46
32
 
33
+ def subclass_new_from_string(str)
34
+ @nsdname = check_name(str)
35
+ end
47
36
 
48
- def set_type
49
- @type = Net::DNS::RR::Types.new("NS")
50
- end
37
+ def subclass_new_from_binary(data, offset)
38
+ @nsdname, offset = dn_expand(data, offset)
39
+ offset
40
+ end
51
41
 
52
- def get_inspect
53
- value
54
- end
42
+ def set_type
43
+ @type = Net::DNS::RR::Types.new("NS")
44
+ end
55
45
 
46
+ def get_inspect
47
+ value
48
+ end
56
49
 
57
- def check_name(input)
58
- name = input.to_s
59
- unless name =~ /(\w\.?)+\s*$/ and name =~ /[a-zA-Z]/
60
- raise ArgumentError, "Invalid Name Server `#{name}'"
61
- end
62
- name
50
+ def check_name(input)
51
+ name = input.to_s
52
+ unless name =~ /(\w\.?)+\s*$/ && name =~ /[a-zA-Z]/
53
+ raise ArgumentError, "Invalid Name Server `#{name}'"
63
54
  end
64
55
 
65
- def build_pack
66
- @nsdname_pack = pack_name(@nsdname)
67
- @rdlength = @nsdname_pack.size
68
- end
56
+ name
57
+ end
69
58
 
70
- def get_data
71
- @nsdname_pack
72
- end
59
+ def build_pack
60
+ @nsdname_pack = pack_name(@nsdname)
61
+ @rdlength = @nsdname_pack.size
62
+ end
73
63
 
64
+ def get_data
65
+ @nsdname_pack
66
+ end
74
67
  end
75
-
76
68
  end
77
69
  end
78
70
  end