Skip to content

Commit

Permalink
whois.nic.hu parser raises a NoMethodError when trying to access 'reg…
Browse files Browse the repository at this point in the history
…istrant' property for personal domains (closes #19).
  • Loading branch information
weppos committed Mar 18, 2010
1 parent e478920 commit a7d3f19
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rdoc
@@ -1,6 +1,11 @@
= Changelog


== master

* FIXED: whois.nic.hu parser raises a NoMethodError when trying to access 'registrant' property for personal domains (closes #19).


== Release 1.0.6

* ADDED: Added simple .ve TLD parser (whois.nic.ve).
Expand Down
45 changes: 30 additions & 15 deletions lib/whois/answer/parser/whois.nic.hu.rb
Expand Up @@ -84,21 +84,21 @@ class WhoisNicHu < Base
end

property_supported :registrant do
if registered?
a1 = (node('address') || [])[1].split(/\s/)
zip = a1.shift
city = a1.join(' ')
Answer::Contact.new(
:name => node('name'),
:organization => node('org'),
:address => node('address')[0],
:city => city,
:zip => zip,
:country_code => node('address')[2],
:phone => node('phone'),
:fax => node('fax-no')
)
end
return unless registered?
return @registrant if @registrant

address, city, zip, country_code = decompose_address(node('address'))

@registrant = Answer::Contact.new(
:name => node('name'),
:organization => node('org'),
:address => address,
:city => city,
:zip => zip,
:country_code => country_code,
:phone => node('phone'),
:fax => node('fax-no')
)
end

property_supported :admin do
Expand Down Expand Up @@ -140,6 +140,21 @@ def contact(element)
end
end

# Depending on record type, the address can be <tt>nil</tt>
# or an array containing different address parts.
def decompose_address(parts)
addresses = parts || []
address, city, zip, country_code = nil, nil, nil, nil

if !addresses.empty?
address = addresses[0] if addresses[0]
zip, city = addresses[1].split(" ", 2) if addresses[1]
country_code = addresses[2] if addresses[2]
end

[address, city, zip, country_code]
end


class Scanner

Expand Down
67 changes: 53 additions & 14 deletions test/answer/parser/whois.nic.hu_test.rb
Expand Up @@ -114,25 +114,64 @@ def test_registrar_with_unregistered


def test_registrant_with_registered
registrant = @klass.new(load_part('/registered.txt')).registrant
assert_instance_of Whois::Answer::Contact, registrant
assert_equal 'Google, Inc.', registrant.name
assert_equal 'Google, Inc.', registrant.organization
assert_equal 'Amphitheatre Pkwy 1600.', registrant.address
assert_equal 'CA-94043', registrant.zip
assert_equal 'Mountain View', registrant.city
assert_equal 'US', registrant.country_code
assert_equal '+1 650 253 0000', registrant.phone
assert_equal '+1 650 253 0001', registrant.fax
parser = @klass.new(load_part('/registered.txt'))
result = parser.registrant
assert_instance_of Whois::Answer::Contact, result
assert_equal result, parser.registrant
assert_equal result, parser.instance_eval { @registrant }
end

def test_registrant_with_unregistered
assert_equal nil,
@klass.new(load_part('/available.txt')).registrant
assert_equal nil,
@klass.new(load_part('/in_progress.txt')).registrant
parser = @klass.new(load_part('/available.txt'))
result = nil
assert_equal result, parser.registrant
assert_equal result, parser.instance_eval { @registrant }

parser = @klass.new(load_part('/in_progress.txt'))
result = nil
assert_equal result, parser.registrant
assert_equal result, parser.instance_eval { @registrant }
end

def test_registrant_as_company
parser = @klass.new(load_part('/property_registrant_as_company.txt'))
result = parser.registrant

assert_instance_of Whois::Answer::Contact, result
assert_equal 'Google, Inc.', result.name
assert_equal 'Google, Inc.', result.organization
assert_equal 'Amphitheatre Pkwy 1600.', result.address
assert_equal 'CA-94043', result.zip
assert_equal 'Mountain View', result.city
assert_equal 'US', result.country_code
assert_equal '+1 650 253 0000', result.phone
assert_equal '+1 650 253 0001', result.fax
end

def test_registrant_as_private_person
parser = @klass.new(load_part('/property_registrant_as_private_person.txt'))
result = parser.registrant

assert_instance_of Whois::Answer::Contact, result
assert_match /Buruzs/, result.name # UTF-8 hack
assert_equal nil, result.organization
assert_equal nil, result.address
assert_equal nil, result.zip
assert_equal nil, result.city
assert_equal nil, result.country_code
assert_equal nil, result.phone
assert_equal nil, result.fax
end

def test_registrant_without_address
parser = @klass.new(load_part('/property_registrant_without_address.txt'))
result = parser.registrant

assert_equal nil, result.address
assert_equal nil, result.zip
assert_equal nil, result.city
assert_equal nil, result.country_code
end

def test_admin_with_registered
admin = @klass.new(load_part('/registered.txt')).admin
Expand Down
@@ -0,0 +1,65 @@
% Whois server 1.99C

Rights restricted by copyright. Szerzõi jog fenntartva.
-Legal usage of this service requires that you agree to
abide by the rules and conditions set forth at
http://www.domain.hu/domain/English/domainsearch/feltetelek.html
-A szolgaltatas csak a
http://www.domain.hu/domain/domainsearch/feltetelek.html címen
elérhetõ feltételek elfogadása és betartása mellett
használható legálisan.

domain: google.hu
org: org_name_eng: Google, Inc.
org: org_name_hun: Google, Inc.
address: Amphitheatre Pkwy 1600.
address: CA-94043 Mountain View
address: US
phone: +1 650 253 0000
fax-no: +1 650 253 0001
hun-id: 0000219547
admin-c: 2000466366
tech-c: 2000578125
zone-c: 2000578125
nameserver: ns1.google.com
nameserver: ns4.google.com
nameserver: ns3.google.com
nameserver: ns2.google.com
registered: 2000.03.25 23:20:39
changed: 2009.08.25 10:11:32
registrar: 1960108002

person: 3C Kft. (Registrar)
address: Konkoly Thege út 29-33.
address: H-1121 Budapest
address: HU
phone: +36 1 275 52 00
fax-no: +36 1 275 58 87
hun-id: 2000466366

person: Markmonitor
address: Overland Road 10400, PMB155
address: ID-83709 Boise
address: US
phone: + 1 208 389 5798
fax-no: + 1 208 389 5771
e-mail: ccops@markmonitor.com
hun-id: 2000578125

person: Markmonitor
address: Overland Road 10400, PMB155
address: ID-83709 Boise
address: US
phone: + 1 208 389 5798
fax-no: + 1 208 389 5771
hun-id: 2000578125

org: org_name_eng: 3C Ltd.
org: org_name_hun: 3C Kft. (Registrar)
address: Konkoly Thege út 29-33.
address: H-1121 Budapest
address: HU
phone: +36 1 275 52 00
fax-no: +36 1 275 58 87
hun-id: 1960108002

@@ -0,0 +1,58 @@
% Whois server 1.99C

Rights restricted by copyright. Szerzõi jog fenntartva.
-Legal usage of this service requires that you agree to
abide by the rules and conditions set forth at
http://www.domain.hu/domain/English/domainsearch/feltetelek.html
-A szolgaltatas csak a
http://www.domain.hu/domain/domainsearch/feltetelek.html címen
elérhetõ feltételek elfogadása és betartása mellett
használható legálisan.

domain: js.hu
org: Private person
org: org_name_hun: Buruzs Tamás
hun-id: 0000273611
admin-c: 2000230092
tech-c: 2960712001
zone-c: 2960712001
nameserver: a.ns.e-media.hu
nameserver: b.ns.e-media.hu
registered: 2001.01.18 02:00:41
changed: 2001.10.10 21:59:01
registrar: 1990917022

person: Buruzs Tamás
address: Pöttyös u. 3.
address: 1098 Budapest
address: HU
phone: (20) 996-8428
fax-no:
hun-id: 2000230092

person: Barna György
address: Városmajor u. 1/c.
address: 1122 Budapest
address: HU
phone: (70) 3-11111-7
fax-no: (1) 438-4568
e-mail: barna83456@kibernet.hu
hun-id: 2960712001

person: Barna György
address: Városmajor u. 1/c.
address: 1122 Budapest
address: HU
phone: (70) 3-11111-7
fax-no: (1) 438-4568
hun-id: 2960712001

org: org_name_eng: CyberNet Ltd.
org: org_name_hun: KiberNet Kft. (Registrar)
address: Városmajor u. 1/c
address: 1122 Budapest
address: HU
phone: +36 1 4384567
fax-no: +36 1 4384568
hun-id: 1990917022

@@ -0,0 +1,58 @@
% Whois server 1.99C

Rights restricted by copyright. Szerzõi jog fenntartva.
-Legal usage of this service requires that you agree to
abide by the rules and conditions set forth at
http://www.domain.hu/domain/English/domainsearch/feltetelek.html
-A szolgaltatas csak a
http://www.domain.hu/domain/domainsearch/feltetelek.html címen
elérhetõ feltételek elfogadása és betartása mellett
használható legálisan.

domain: js.hu
org: Private person
org: org_name_hun: Buruzs Tamás
hun-id: 0000273611
admin-c: 2000230092
tech-c: 2960712001
zone-c: 2960712001
nameserver: a.ns.e-media.hu
nameserver: b.ns.e-media.hu
registered: 2001.01.18 02:00:41
changed: 2001.10.10 21:59:01
registrar: 1990917022

person: Buruzs Tamás
address: Pöttyös u. 3.
address: 1098 Budapest
address: HU
phone: (20) 996-8428
fax-no:
hun-id: 2000230092

person: Barna György
address: Városmajor u. 1/c.
address: 1122 Budapest
address: HU
phone: (70) 3-11111-7
fax-no: (1) 438-4568
e-mail: barna83456@kibernet.hu
hun-id: 2960712001

person: Barna György
address: Városmajor u. 1/c.
address: 1122 Budapest
address: HU
phone: (70) 3-11111-7
fax-no: (1) 438-4568
hun-id: 2960712001

org: org_name_eng: CyberNet Ltd.
org: org_name_hun: KiberNet Kft. (Registrar)
address: Városmajor u. 1/c
address: 1122 Budapest
address: HU
phone: +36 1 4384567
fax-no: +36 1 4384568
hun-id: 1990917022

0 comments on commit a7d3f19

Please sign in to comment.