whois 0.5.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGELOG.rdoc +55 -0
  2. data/Manifest +43 -8
  3. data/README.rdoc +53 -20
  4. data/lib/whois.rb +69 -1
  5. data/lib/whois/answer.rb +126 -0
  6. data/lib/whois/answer/contact.rb +55 -0
  7. data/lib/whois/answer/parser.rb +110 -0
  8. data/lib/whois/answer/parser/README.rdoc +21 -0
  9. data/lib/whois/answer/parser/base.rb +144 -0
  10. data/lib/whois/answer/parser/blank.rb +45 -0
  11. data/lib/whois/answer/parser/whois.crsnic.net.rb +209 -0
  12. data/lib/whois/answer/parser/whois.denic.de.rb +202 -0
  13. data/lib/whois/answer/parser/whois.nic.it.rb +330 -0
  14. data/lib/whois/answer/parser/whois.publicinterestregistry.net.rb +232 -0
  15. data/lib/whois/answer/part.rb +35 -0
  16. data/lib/whois/answer/registrar.rb +42 -0
  17. data/lib/whois/answer/super_struct.rb +57 -0
  18. data/lib/whois/client.rb +6 -0
  19. data/lib/whois/definitions/tlds.rb +2 -2
  20. data/lib/whois/errors.rb +25 -8
  21. data/lib/whois/server.rb +0 -1
  22. data/lib/whois/server/adapters/afilias.rb +5 -5
  23. data/lib/whois/server/adapters/base.rb +31 -4
  24. data/lib/whois/server/adapters/formatted.rb +3 -1
  25. data/lib/whois/server/adapters/none.rb +20 -1
  26. data/lib/whois/server/adapters/pir.rb +5 -5
  27. data/lib/whois/server/adapters/standard.rb +13 -2
  28. data/lib/whois/server/adapters/verisign.rb +5 -5
  29. data/lib/whois/server/adapters/web.rb +15 -0
  30. data/lib/whois/version.rb +2 -2
  31. data/lib/whois/whois.rb +2 -2
  32. data/test/answer/parser/base_test.rb +27 -0
  33. data/test/answer/parser/blank_test.rb +19 -0
  34. data/test/answer/parser/whois_crsnic_net_test.rb +175 -0
  35. data/test/answer/parser/whois_denic_de_test.rb +209 -0
  36. data/test/answer/parser/whois_nic_it_test.rb +255 -0
  37. data/test/answer/parser/whois_publicinterestregistry_net_test.rb +210 -0
  38. data/test/answer/parser_test.rb +77 -0
  39. data/test/answer_test.rb +99 -0
  40. data/test/client_test.rb +3 -3
  41. data/test/integration_test.rb +31 -0
  42. data/test/{adapters → server/adapters}/afilias_test.rb +10 -5
  43. data/test/server/adapters/base_test.rb +15 -0
  44. data/test/server/adapters/formatted_test.rb +26 -0
  45. data/test/{adapters → server/adapters}/none_test.rb +0 -0
  46. data/test/{adapters → server/adapters}/not_implemented_test.rb +0 -0
  47. data/test/{adapters → server/adapters}/pir_test.rb +10 -5
  48. data/test/server/adapters/standard_test.rb +29 -0
  49. data/test/{adapters → server/adapters}/verisign_test.rb +10 -5
  50. data/test/{adapters → server/adapters}/web_test.rb +0 -0
  51. data/test/server_test.rb +5 -1
  52. data/test/testcases/responses/super_struct_test.rb +25 -0
  53. data/test/testcases/responses/whois.crsnic.net/available.txt +43 -0
  54. data/test/testcases/responses/whois.crsnic.net/registered.txt +57 -0
  55. data/test/testcases/responses/whois.denic.de/available.txt +30 -0
  56. data/test/testcases/responses/whois.denic.de/registered.txt +77 -0
  57. data/test/testcases/responses/whois.nic.it/available.txt +2 -0
  58. data/test/testcases/responses/{it.txt → whois.nic.it/registered.txt} +1 -0
  59. data/test/testcases/responses/whois.nic.it/status_active.txt +53 -0
  60. data/test/testcases/responses/whois.nic.it/status_available.txt +2 -0
  61. data/test/testcases/responses/whois.publicinterestregistry.net/available.txt +1 -0
  62. data/test/testcases/responses/whois.publicinterestregistry.net/registered.txt +85 -0
  63. data/test/whois_test.rb +23 -1
  64. data/utils/bm_delegation_vs_inheritance.rb +150 -0
  65. data/whois.gemspec +6 -6
  66. metadata +78 -18
  67. data/test/adapters/standard_test.rb +0 -23
@@ -0,0 +1,210 @@
1
+ require 'test_helper'
2
+ require 'whois/answer/parser/whois.publicinterestregistry.net'
3
+
4
+ class AnswerParserWhoisPublicinterestregistryNetTest < Test::Unit::TestCase
5
+
6
+ TESTCASE_PATH = File.expand_path(File.dirname(__FILE__) + '/../../testcases/responses/whois.publicinterestregistry.net')
7
+
8
+ def setup
9
+ @klass = Whois::Answer::Parser::WhoisPublicinterestregistryNet
10
+ @host = "whois.publicinterestregistry.net"
11
+ end
12
+
13
+
14
+ def test_disclaimer
15
+ expected = <<-EOS.strip
16
+ NOTICE: Access to .ORG WHOIS information is provided to assist persons in \
17
+ determining the contents of a domain name registration record in the Public Interest Registry \
18
+ registry database. The data in this record is provided by Public Interest Registry \
19
+ for informational purposes only, and Public Interest Registry does not guarantee its \
20
+ accuracy. This service is intended only for query-based access. You agree \
21
+ that you will use this data only for lawful purposes and that, under no \
22
+ circumstances will you use this data to: (a) allow, enable, or otherwise \
23
+ support the transmission by e-mail, telephone, or facsimile of mass \
24
+ unsolicited, commercial advertising or solicitations to entities other than \
25
+ the data recipient's own existing customers; or (b) enable high volume, \
26
+ automated, electronic processes that send queries or data to the systems of \
27
+ Registry Operator or any ICANN-Accredited Registrar, except as reasonably \
28
+ necessary to register domain names or modify existing registrations. All \
29
+ rights reserved. Public Interest Registry reserves the right to modify these terms at any \
30
+ time. By submitting this query, you agree to abide by this policy.
31
+ EOS
32
+ assert_equal expected,
33
+ @klass.new(load_part('/registered.txt')).disclaimer
34
+ end
35
+
36
+ def test_disclaimer_with_available
37
+ assert_equal nil,
38
+ @klass.new(load_part('/available.txt')).disclaimer
39
+ end
40
+
41
+
42
+ def test_domain
43
+ assert_equal nil,
44
+ @klass.new(load_part('/available.txt')).domain
45
+ assert_equal "google.org",
46
+ @klass.new(load_part('/registered.txt')).domain
47
+ end
48
+
49
+ def test_domain_id
50
+ assert_equal nil,
51
+ @klass.new(load_part('/available.txt')).domain_id
52
+ assert_equal "D2244233-LROR",
53
+ @klass.new(load_part('/registered.txt')).domain_id
54
+ end
55
+
56
+
57
+ def test_status
58
+ assert_equal nil,
59
+ @klass.new(load_part('/available.txt')).status
60
+ assert_equal ["CLIENT DELETE PROHIBITED", "CLIENT TRANSFER PROHIBITED", "CLIENT UPDATE PROHIBITED"],
61
+ @klass.new(load_part('/registered.txt')).status
62
+ end
63
+
64
+ def test_available?
65
+ assert !@klass.new(load_part('/registered.txt')).available?
66
+ assert @klass.new(load_part('/available.txt')).available?
67
+ end
68
+
69
+ def test_registered?
70
+ assert !@klass.new(load_part('/available.txt')).registered?
71
+ assert @klass.new(load_part('/registered.txt')).registered?
72
+ end
73
+
74
+
75
+ def test_created_on
76
+ assert_equal Time.parse("21-Oct-1998 04:00:00 UTC"),
77
+ @klass.new(load_part('/registered.txt')).created_on
78
+ end
79
+
80
+ def test_created_on_with_available
81
+ assert_equal nil,
82
+ @klass.new(load_part('/available.txt')).created_on
83
+ end
84
+
85
+ def test_updated_on
86
+ assert_equal Time.parse("04-Mar-2009 12:07:19 UTC"),
87
+ @klass.new(load_part('/registered.txt')).updated_on
88
+ end
89
+
90
+ def test_updated_on_with_available
91
+ assert_equal nil,
92
+ @klass.new(load_part('/available.txt')).updated_on
93
+ end
94
+
95
+ def test_expires_on
96
+ assert_equal Time.parse("20-Oct-2012 04:00:00 UTC"),
97
+ @klass.new(load_part('/registered.txt')).expires_on
98
+ end
99
+
100
+ def test_expires_on_with_available
101
+ assert_equal nil,
102
+ @klass.new(load_part('/available.txt')).expires_on
103
+ end
104
+
105
+
106
+ def test_registrar
107
+ registrar = @klass.new(load_part('/registered.txt')).registrar
108
+ assert_instance_of Whois::Answer::Registrar, registrar
109
+ assert_equal "R37-LROR", registrar.id
110
+ assert_equal "MarkMonitor Inc.", registrar.name
111
+ assert_equal nil, registrar.organization
112
+ end
113
+
114
+ def test_registrar_with_available
115
+ assert_equal nil,
116
+ @klass.new(load_part('/available.txt')).registrar
117
+ end
118
+
119
+
120
+ def test_registrant
121
+ contact = @klass.new(load_part('/registered.txt')).registrant
122
+ assert_instance_of Whois::Answer::Contact, contact
123
+ assert_equal "mmr-32097", contact.id
124
+ assert_equal "DNS Admin", contact.name
125
+ assert_equal "Google Inc.", contact.organization
126
+ assert_equal "1600 Amphitheatre Parkway", contact.address
127
+ assert_equal "Mountain View", contact.city
128
+ assert_equal "CA", contact.state
129
+ assert_equal "94043", contact.zip
130
+ assert_equal nil, contact.country
131
+ assert_equal "US", contact.country_code
132
+ assert_equal "+1.6506234000", contact.phone
133
+ assert_equal "+1.6506188571", contact.fax
134
+ assert_equal "dns-admin@google.com", contact.email
135
+ end
136
+
137
+ def test_registrant_with_available
138
+ assert_equal nil,
139
+ @klass.new(load_part('/available.txt')).registrant
140
+ end
141
+
142
+
143
+ def test_admin
144
+ contact = @klass.new(load_part('/registered.txt')).admin
145
+ assert_instance_of Whois::Answer::Contact, contact
146
+ assert_equal "mmr-32097", contact.id
147
+ assert_equal "DNS Admin", contact.name
148
+ assert_equal "Google Inc.", contact.organization
149
+ assert_equal "1600 Amphitheatre Parkway", contact.address
150
+ assert_equal "Mountain View", contact.city
151
+ assert_equal "CA", contact.state
152
+ assert_equal "94043", contact.zip
153
+ assert_equal nil, contact.country
154
+ assert_equal "US", contact.country_code
155
+ assert_equal "+1.6506234000", contact.phone
156
+ assert_equal "+1.6506188571", contact.fax
157
+ assert_equal "dns-admin@google.com", contact.email
158
+ end
159
+
160
+ def test_admin_with_available
161
+ assert_equal nil,
162
+ @klass.new(load_part('/available.txt')).admin
163
+ end
164
+
165
+
166
+ def test_technical
167
+ contact = @klass.new(load_part('/registered.txt')).technical
168
+ assert_instance_of Whois::Answer::Contact, contact
169
+ assert_equal "mmr-32097", contact.id
170
+ assert_equal "DNS Admin", contact.name
171
+ assert_equal "Google Inc.", contact.organization
172
+ assert_equal "1600 Amphitheatre Parkway", contact.address
173
+ assert_equal "Mountain View", contact.city
174
+ assert_equal "CA", contact.state
175
+ assert_equal "94043", contact.zip
176
+ assert_equal nil, contact.country
177
+ assert_equal "US", contact.country_code
178
+ assert_equal "+1.6506234000", contact.phone
179
+ assert_equal "+1.6506188571", contact.fax
180
+ assert_equal "dns-admin@google.com", contact.email
181
+ end
182
+
183
+ def test_technical_with_available
184
+ assert_equal nil,
185
+ @klass.new(load_part('/available.txt')).technical
186
+ end
187
+
188
+
189
+ def test_nameservers
190
+ assert_equal %w(ns2.google.com ns1.google.com ns3.google.com ns4.google.com),
191
+ @klass.new(load_part('/registered.txt')).nameservers
192
+ end
193
+
194
+ def test_nameservers_with_available
195
+ assert_equal nil,
196
+ @klass.new(load_part('/available.txt')).nameservers
197
+ end
198
+
199
+
200
+ protected
201
+
202
+ def load_part(path)
203
+ part(File.read(TESTCASE_PATH + path), @host)
204
+ end
205
+
206
+ def part(*args)
207
+ Whois::Answer::Part.new(*args)
208
+ end
209
+
210
+ end
@@ -0,0 +1,77 @@
1
+ require 'test_helper'
2
+
3
+ class AnswerParserTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @klass = Whois::Answer::Parser
7
+ @answer = Whois::Answer.new(nil, [])
8
+ @parser = @klass.new(@answer)
9
+ end
10
+
11
+
12
+ def test_initialize
13
+ parser = @klass.new(@answer)
14
+ assert_instance_of @klass, parser
15
+ assert_equal @answer, parser.answer
16
+ end
17
+
18
+ def test_initialize_should_require_answer
19
+ assert_raise(ArgumentError) { @klass.new }
20
+ end
21
+
22
+
23
+ def test_parsers_should_not_create_parser_instance_with_zero_parts
24
+ answer = Whois::Answer.new(nil, [])
25
+ parser = @klass.new(answer)
26
+ assert_equal 0, parser.parsers.length
27
+ assert_equal [], parser.parsers
28
+ end
29
+
30
+ def test_parsers_should_create_parser_instance_with_supported_server
31
+ answer = Whois::Answer.new(nil, [Whois::Answer::Part.new(nil, "whois.nic.it")])
32
+ parser = @klass.new(answer)
33
+ assert_equal 1, parser.parsers.length
34
+ assert_instance_of Whois::Answer::Parser::WhoisNicIt, parser.parsers.first
35
+ end
36
+
37
+ def test_parsers_should_create_blank_parser_instance_with_not_supported_server
38
+ answer = Whois::Answer.new(nil, [Whois::Answer::Part.new(nil, "invalid.nic.it")])
39
+ parser = @klass.new(answer)
40
+ assert_equal 1, parser.parsers.length
41
+ assert_instance_of Whois::Answer::Parser::Blank, parser.parsers.first
42
+ end
43
+
44
+
45
+ (Whois::Answer::Parser.registrable_methods - [:referral_url, :referral_whois]).each do |method|
46
+ define_method "test_should_delegate_#{method}_to_parsers_first_parser_if_supported" do
47
+ answer = Whois::Answer.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])
48
+ parser = @klass.new(answer)
49
+ parser.parsers.first.expects(method).returns(:value)
50
+ assert_equal :value, parser.send(method)
51
+ end
52
+ end
53
+
54
+ [:referral_url, :referral_whois].each do |method|
55
+ define_method "test_should_delegate_#{method}_to_parsers_raise_unless_supported" do
56
+ answer = Whois::Answer.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])
57
+ parser = @klass.new(answer)
58
+ assert_raise(Whois::PropertyNotSupported) { parser.send(method) }
59
+ end
60
+ end
61
+
62
+ Whois::Answer::Parser.registrable_methods.each do |method|
63
+ define_method "test_should_delegate_#{method}_to_parser_raise_with_no_zero_parts" do
64
+ answer = Whois::Answer.new(nil, [])
65
+ parser = @klass.new(answer)
66
+ assert_raise(Whois::ParserError) { parser.send(method) }
67
+ end
68
+ end
69
+
70
+ def test_should_not_delegate_unallowed_method_to_parser
71
+ answer = Whois::Answer.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])
72
+ parser = @klass.new(answer)
73
+ parser.parsers.expects("unallowed_method").never
74
+ assert_raise(NoMethodError) { parser.send("unallowed_method") }
75
+ end
76
+
77
+ end
@@ -0,0 +1,99 @@
1
+ require 'test_helper'
2
+
3
+ class AnswerTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @klass = Whois::Answer
7
+ @server = Whois::Server.factory(:tld, ".foo", "whois.foo")
8
+ @parts = [
9
+ Whois::Answer::Part.new("This is a answer for domain.foo.", "foo.whois.com"),
10
+ Whois::Answer::Part.new("This is a answer for domain.bar.", "bar.whois.com")
11
+ ]
12
+ @content = "This is a answer for domain.foo.\nThis is a answer for domain.bar."
13
+ @answer = @klass.new(@server, @parts)
14
+ end
15
+
16
+
17
+ def test_initialize
18
+ answer = @klass.new(@server, @parts)
19
+ assert_instance_of @klass, answer
20
+ assert_equal @server, answer.server
21
+ assert_equal @parts, answer.parts
22
+ end
23
+
24
+ def test_initialize_should_require_server
25
+ assert_raise(ArgumentError) { @klass.new }
26
+ end
27
+
28
+ def test_initialize_should_require_parts
29
+ assert_raise(ArgumentError) { @klass.new(@server) }
30
+ end
31
+
32
+
33
+ def test_to_s
34
+ assert_equal @content, @answer.to_s
35
+ end
36
+
37
+ def test_inspect
38
+ assert_equal @content.inspect, @answer.inspect
39
+ end
40
+
41
+ def test_match
42
+ # Force .to_a otherwise Match will be compared as Object instance
43
+ # and the test will fail because they actually are different instances.
44
+ assert_equal @content.match(/domain\.foo/).to_a, @answer.match(/domain\.foo/).to_a
45
+ assert_equal @content.match(/google/), @answer.match(/google/)
46
+ end
47
+
48
+ def test_equality_check_self
49
+ assert_equal @answer, @answer
50
+ assert @answer.eql?(@answer)
51
+ end
52
+
53
+ def test_equality_check_string
54
+ assert_equal @answer, @content
55
+ assert_not_equal @content, @answer
56
+ assert @answer.eql?(@content)
57
+ assert !@content.eql?(@answer)
58
+ end
59
+
60
+ def test_equality_check_content
61
+ other = @klass.new(@server, @parts)
62
+ assert_equal @answer, other
63
+ assert_equal other, @answer
64
+ assert @answer.eql?(other)
65
+ assert other.eql?(@answer)
66
+ end
67
+
68
+
69
+ def test_content
70
+ answer = @klass.new(@server, @parts)
71
+ assert_equal @content, answer.content
72
+ end
73
+
74
+ def test_match?
75
+ assert @answer.match?(/domain\.foo/)
76
+ assert !@answer.match?(/google/)
77
+ end
78
+
79
+
80
+ def test_parser
81
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])
82
+ assert_instance_of Whois::Answer::Parser,
83
+ answer.parser
84
+
85
+ answer = @klass.new(nil, [])
86
+ assert_instance_of Whois::Answer::Parser,
87
+ answer.parser
88
+ end
89
+
90
+ Whois::Answer::Parser.registrable_methods.each do |method|
91
+ define_method "test_should_delegate_#{method}_to_parser" do
92
+ answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])
93
+ parser = answer.parser
94
+ parser.expects(method).returns(:value)
95
+ assert_equal :value, answer.send(method)
96
+ end
97
+ end
98
+
99
+ end
@@ -76,9 +76,9 @@ class ClientTest < Test::Unit::TestCase
76
76
  need_connectivity do
77
77
 
78
78
  def test_query_with_domain
79
- response = @client.query("weppos.it")
80
- assert_match /Domain:\s+weppos\.it/, response
81
- assert_match /Created:/, response
79
+ answer = @client.query("weppos.it")
80
+ assert answer.match?(/Domain:\s+weppos\.it/)
81
+ assert answer.match?(/Created:/)
82
82
  end
83
83
 
84
84
  end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class IntegrationTest < Test::Unit::TestCase
4
+
5
+ def test_should_query_domain_get_answer_load_parser_parse_response_and_return_boolean
6
+ Whois::Server.define(:tld, ".it", "whois.nic.it")
7
+ response = <<-EOS
8
+ Domain: google.it
9
+ Status: AVAILABLE
10
+ EOS
11
+
12
+ Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("google.it", "whois.nic.it").returns(response)
13
+ assert Whois.available?("google.it")
14
+ end
15
+
16
+ def test_should_query_domain_get_answer_load_parser_parse_response
17
+ Whois::Server.define(:tld, ".it", "whois.nic.it")
18
+ response = <<-EOS
19
+ Domain: google.it
20
+ Status: AVAILABLE
21
+ EOS
22
+
23
+ Whois::Server::Adapters::Standard.any_instance.expects(:query_the_socket).with("google.it", "whois.nic.it").returns(response)
24
+ answer = Whois.query("google.it")
25
+ assert_instance_of Whois::Answer, answer
26
+ assert answer.available?
27
+ assert_instance_of Whois::Answer::Parser, answer.parser
28
+ assert_instance_of Whois::Answer::Parser::WhoisNicIt, answer.parser.parsers.first
29
+ end
30
+
31
+ end
@@ -1,11 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ServerAdaptersAfiliasTest < Test::Unit::TestCase
4
- include Whois
5
4
 
6
5
  def setup
7
6
  @definition = [:tld, ".foo", "whois.foo", {}]
8
- @klass = Server::Adapters::Afilias
7
+ @klass = Whois::Server::Adapters::Afilias
9
8
  @server = @klass.new(*@definition)
10
9
  end
11
10
 
@@ -13,16 +12,22 @@ class ServerAdaptersAfiliasTest < Test::Unit::TestCase
13
12
  response = "No match for DOMAIN.FOO."
14
13
  expected = response
15
14
  @server.expects(:ask_the_socket).with("domain.foo", "whois.afilias-grs.info", 43).returns(response)
16
- assert_equal expected, @server.query("domain.foo")
15
+ assert_equal expected,
16
+ @server.query("domain.foo").to_s
17
+ assert_equal [Whois::Answer::Part.new(response, "whois.afilias-grs.info")],
18
+ @server.buffer
17
19
  end
18
20
 
19
21
  def test_query_with_referral
20
- referral = File.read(File.dirname(__FILE__) + "/../testcases/referrals/afilias.bz.txt")
22
+ referral = File.read(File.dirname(__FILE__) + "/../../testcases/referrals/afilias.bz.txt")
21
23
  response = "Match for DOMAIN.FOO."
22
24
  expected = referral + "\n" + response
23
25
  @server.expects(:ask_the_socket).with("domain.foo", "whois.afilias-grs.info", 43).returns(referral)
24
26
  @server.expects(:ask_the_socket).with("domain.foo", "whois.belizenic.bz", 43).returns(response)
25
- assert_equal expected, @server.query("domain.foo")
27
+ assert_equal expected,
28
+ @server.query("domain.foo").to_s
29
+ assert_equal [Whois::Answer::Part.new(referral, "whois.afilias-grs.info"), Whois::Answer::Part.new(response, "whois.belizenic.bz")],
30
+ @server.buffer
26
31
  end
27
32
 
28
33
  end