Skip to content
This repository
Browse code

In some rare circumstances the server guessing fails to return the ri…

…ght server but returns an other server instead (closes #260).
  • Loading branch information...
commit 60093912c1ad1020dc8cf5f5001bcb68e19d206a 1 parent 1fd11c3
Simone Carletti authored September 18, 2009
4  CHANGELOG.rdoc
Source Rendered
... ...
@@ -1,10 +1,12 @@
1 1
 = Changelog
2 2
 
3 3
 
4  
-== master
  4
+== release-0.5
5 5
 
6 6
 FIXED: self.valid_ipv6?(addr) references valid_v4? instead of valid_ipv4? (closes #300)
7 7
 
  8
+FIXED: In some rare circumstances the server guessing fails to return the right server but returns an other server instead (closes #260).
  9
+
8 10
 
9 11
 == Release 0.5.2
10 12
 
2  lib/whois/server.rb
@@ -175,7 +175,7 @@ def self.find_for_email(qstring)
175 175
 
176 176
       def self.find_for_tld(qstring)
177 177
         definitions(:tld).each do |definition|
178  
-          return factory(:tld, *definition) if /#{definition.first}$/ =~ qstring
  178
+          return factory(:tld, *definition) if /#{Regexp.escape(definition.first)}$/ =~ qstring
179 179
         end
180 180
         nil
181 181
       end
78  test/server_test.rb
... ...
@@ -1,89 +1,99 @@
1 1
 require 'test_helper'
2 2
 
3 3
 class ServerTest < Test::Unit::TestCase
4  
-  include Whois
  4
+
  5
+  def setup
  6
+    Whois::Server.class_eval { class_variable_set("@@definitions", { :tld => [], :ipv4 =>[], :ipv6 => [] }) }  
  7
+  end
  8
+
5 9
 
6 10
   def test_guess_should_recognize_email
7  
-    Server.expects(:find_for_email).with("email@example.org").returns(true)
8  
-    assert Server.guess("email@example.org")
  11
+    Whois::Server.expects(:find_for_email).with("email@example.org").returns(true)
  12
+    assert Whois::Server.guess("email@example.org")
9 13
   end
10 14
 
11 15
   def test_guess_should_recognize_tld
12  
-    Server.expects(:find_for_tld).with("google.com").returns(true)
13  
-    assert Server.guess("google.com")
  16
+    Whois::Server.expects(:find_for_tld).with("google.com").returns(true)
  17
+    assert Whois::Server.guess("google.com")
14 18
   end
15 19
 
16 20
   def test_guess_should_recognize_ipv4
17  
-    Server.expects(:find_for_ipv4).with("192.168.1.1").returns(true)
18  
-    assert Server.guess("192.168.1.1")
  21
+    Whois::Server.expects(:find_for_ipv4).with("192.168.1.1").returns(true)
  22
+    assert Whois::Server.guess("192.168.1.1")
19 23
   end
20 24
 
21 25
   def test_guess_should_recognize_ipv6
22  
-    Server.expects(:find_for_ipv6).with("2001:0db8:85a3:0000:0000:8a2e:0370:7334").returns(true)
23  
-    assert Server.guess("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
  26
+    Whois::Server.expects(:find_for_ipv6).with("2001:0db8:85a3:0000:0000:8a2e:0370:7334").returns(true)
  27
+    assert Whois::Server.guess("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
24 28
   end
25 29
 
26 30
   def test_guess_should_recognize_ipv6_with_zeros_group
27  
-    Server.expects(:find_for_ipv6).with("2002::1").returns(true)
28  
-    assert Server.guess("2002::1")
  31
+    Whois::Server.expects(:find_for_ipv6).with("2002::1").returns(true)
  32
+    assert Whois::Server.guess("2002::1")
29 33
   end
30 34
 
31 35
   def test_guess_should_raise_servernotfound_with_unrecognized_query
32  
-    assert_raise(ServerNotFound){ Server.guess("xyz") }
  36
+    assert_raise(Whois::ServerNotFound){ Whois::Server.guess("xyz") }
33 37
   end
34  
-  
35  
-  
  38
+
  39
+
  40
+  def test_find_for_tld_should_not_consider_dot_as_regexp_instruction
  41
+    Whois::Server.define(:tld, ".no.com", "whois.no.com")
  42
+    Whois::Server.define(:tld, ".com", "whois.com")
  43
+    assert_equal "whois.com", Whois::Server.guess("antoniocangiano.com").host
  44
+  end
  45
+
36 46
   def test_find_for_ipv6_should_factory_ipv6_with_ipv4_compatibility
37  
-    Server.define(:ipv6, "::192.168.1.1", "whois.foo")
38  
-    Server.expects(:factory).with(:ipv6, any_parameters).returns(true)
39  
-    assert Server.guess("::192.168.1.1")
  47
+    Whois::Server.define(:ipv6, "::192.168.1.1", "whois.foo")
  48
+    Whois::Server.expects(:factory).with(:ipv6, any_parameters).returns(true)
  49
+    assert Whois::Server.guess("::192.168.1.1")
40 50
   end
41 51
 
42 52
 
43 53
   def test_definitions
44  
-    assert_instance_of Hash, Server.definitions
  54
+    assert_instance_of Hash, Whois::Server.definitions
45 55
   end
46 56
 
47 57
   def test_definitions_with_key
48  
-    assert_equal nil, Server.definitions(:foo)
49  
-    Server.define(:foo, ".foo", "whois.foo")
50  
-    assert_equal [[".foo", "whois.foo", {}]], Server.definitions(:foo)
  58
+    assert_equal nil, Whois::Server.definitions(:foo)
  59
+    Whois::Server.define(:foo, ".foo", "whois.foo")
  60
+    assert_equal [[".foo", "whois.foo", {}]], Whois::Server.definitions(:foo)
51 61
   end
52 62
 
53 63
 
54 64
   def test_define_tld
55  
-    Server.define(:tld, ".foo", "whois.foo")
56  
-    assert_equal [".foo", "whois.foo", {}], Server.definitions[:tld].last
  65
+    Whois::Server.define(:tld, ".foo", "whois.foo")
  66
+    assert_equal [".foo", "whois.foo", {}], Whois::Server.definitions[:tld].last
57 67
   end
58 68
 
59 69
   def test_define_tld_with_options
60  
-    Server.define(:tld, ".foo", "whois.foo", :foo => "bar")
61  
-    assert_equal [".foo", "whois.foo", { :foo => "bar" }], Server.definitions[:tld].last
  70
+    Whois::Server.define(:tld, ".foo", "whois.foo", :foo => "bar")
  71
+    assert_equal [".foo", "whois.foo", { :foo => "bar" }], Whois::Server.definitions[:tld].last
62 72
   end
63 73
 
64 74
   def test_define_ipv4
65  
-    Server.define(:ipv4, ".foo", "whois.foo")
66  
-    assert_equal [".foo", "whois.foo", {}], Server.definitions[:ipv4].last
  75
+    Whois::Server.define(:ipv4, ".foo", "whois.foo")
  76
+    assert_equal [".foo", "whois.foo", {}], Whois::Server.definitions[:ipv4].last
67 77
   end
68 78
 
69 79
   def test_define_ipv4_with_options
70  
-    Server.define(:ipv4, ".foo", "whois.foo", :foo => "bar")
71  
-    assert_equal [".foo", "whois.foo", { :foo => "bar" }], Server.definitions[:ipv4].last
  80
+    Whois::Server.define(:ipv4, ".foo", "whois.foo", :foo => "bar")
  81
+    assert_equal [".foo", "whois.foo", { :foo => "bar" }], Whois::Server.definitions[:ipv4].last
72 82
   end
73 83
 
74 84
 
75 85
   def test_factory
76  
-    server = Server.factory(:tld, ".foo", "whois.foo")
77  
-    assert_instance_of Server::Adapters::Standard, server
  86
+    server = Whois::Server.factory(:tld, ".foo", "whois.foo")
  87
+    assert_instance_of Whois::Server::Adapters::Standard, server
78 88
   end
79 89
 
80 90
   def test_factory_with_adapter
81  
-    server = Server.factory(:tld, ".foo", "whois.foo", :adapter => Server::Adapters::None)
82  
-    assert_instance_of Server::Adapters::None, server
  91
+    server = Whois::Server.factory(:tld, ".foo", "whois.foo", :adapter => Whois::Server::Adapters::None)
  92
+    assert_instance_of Whois::Server::Adapters::None, server
83 93
   end
84 94
 
85 95
   def test_factory_with_adapter_should_delete_adapter_option
86  
-    server = Server.factory(:tld, ".foo", "whois.foo", :adapter => Server::Adapters::None, :foo => "bar")
  96
+    server = Whois::Server.factory(:tld, ".foo", "whois.foo", :adapter => Whois::Server::Adapters::None, :foo => "bar")
87 97
     assert_equal server.options, { :foo => "bar" } 
88 98
   end
89 99
 

0 notes on commit 6009391

Please sign in to comment.
Something went wrong with that request. Please try again.