Skip to content

Commit ac94377

Browse files
kuysengPetri Salminen
andauthored
Fix the parser for the .fi TLD (#4)
weppos#133 The whole response format was changed in 2016, this commit changes the tests, the scanner and the parser in order to respond to the change. Co-authored-by: Petri Salminen <petri@seravo.fi>
1 parent 12969e8 commit ac94377

14 files changed

Lines changed: 372 additions & 194 deletions

‎lib/whois/parsers/whois.fi.rb‎

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class WhoisFi < Base
4242
:reserved
4343
elsif registered?
4444
case node("status", &:downcase)
45+
when "registered"
46+
:registered
4547
when "granted"
4648
:registered
4749
when "grace period"
@@ -76,33 +78,51 @@ class WhoisFi < Base
7678
end
7779

7880

79-
property_not_supported :registrar
81+
property_supported :registrar do
82+
node("Registrar") do |hash|
83+
Parser::Registrar.new(
84+
name: hash['registrar'],
85+
organization: hash['registrar'],
86+
url: hash['www']
87+
)
88+
end
89+
end
8090

81-
property_supported :registrant_contacts do
82-
node("descr") do |array|
83-
address = node("address")
91+
property_not_supported :registrant_contacts do
92+
end
8493

94+
property_supported :admin_contacts do
95+
node("Holder") do |hash|
8596
Parser::Contact.new(
86-
type: Parser::Contact::TYPE_REGISTRANT,
87-
id: array[1],
88-
name: address[0],
89-
organization: array[0],
90-
address: address[1],
91-
zip: address[2],
92-
city: address[3],
93-
phone: node("phone")
97+
type: Parser::Contact::TYPE_ADMINISTRATIVE,
98+
id: hash['register number'],
99+
name: hash['name'],
100+
address: hash['address'][0],
101+
zip: hash['address'][1],
102+
city: hash['address'][2],
103+
country: hash['country'],
104+
phone: hash['phone'],
105+
email: hash['holder email']
94106
)
95107
end
96108
end
97109

98-
property_not_supported :admin_contacts
99-
100-
property_not_supported :technical_contacts
110+
property_supported :technical_contacts do
111+
node("Tech") do |hash|
112+
Parser::Contact.new(
113+
type: Parser::Contact::TYPE_TECHNICAL,
114+
name: hash['name'],
115+
email: hash['email']
116+
)
117+
end
118+
end
101119

102120

103121
property_supported :nameservers do
104-
Array.wrap(node("nserver")).map do |line|
105-
Parser::Nameserver.new(name: line.split(" ").first)
122+
node('Nameservers') do |hash|
123+
Array.wrap(hash['nserver']).map do |line|
124+
Parser::Nameserver.new(name: line.split(" ").first)
125+
end
106126
end
107127
end
108128

‎lib/whois/scanners/whois.fi.rb‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ class WhoisFi < Base
99
self.tokenizers += [
1010
:skip_empty_line,
1111
:scan_available,
12-
:scan_disclaimer,
1312
:scan_keyvalue,
14-
:scan_reserved
13+
:scan_reserved,
14+
:scan_section,
15+
:scan_keyvalue,
16+
:skip_last_update,
17+
:scan_disclaimer
1518
]
1619

17-
1820
tokenizer :scan_available do
1921
if @input.skip(/^Domain not found/)
2022
@ast["status:available"] = true
@@ -27,13 +29,40 @@ class WhoisFi < Base
2729
end
2830
end
2931

30-
tokenizer :scan_disclaimer do
31-
if @input.match?(/^More information/)
32-
@ast["field:disclaimer"] = @input.scan_until(/(.*)\n\n/).strip
32+
tokenizer :scan_section do
33+
if @input.scan(/^(Nameservers|DNSSEC|Holder|Registrar|Tech)\n\n/)
34+
@tmp['_section'] = @input[1]
35+
while scan_keyvalue
36+
end
37+
@tmp.delete('_section')
3338
end
3439
end
3540

36-
end
41+
# Override scan_keyvalue to match the weird
42+
# key.........: value -format
43+
tokenizer :scan_keyvalue do
44+
if @input.scan(/(.+?)(\.+):(.*?)(\n|\z)/)
45+
key, value = @input[1].strip, @input[3].strip
46+
target = @tmp['_section'] ? (@ast[@tmp['_section']] ||= {}) : @ast
47+
48+
if target[key].nil?
49+
target[key] = value
50+
else
51+
target[key] = Array.wrap(target[key])
52+
target[key] << value
53+
end
54+
end
55+
end
3756

57+
tokenizer :skip_last_update do
58+
@input.skip(/^>>> Last update.*<<<\n\n/)
59+
end
60+
61+
tokenizer :scan_disclaimer do
62+
@input.skip_until(/^(Copyright \(c\) Finnish Transport and Communications Agency Traficom)/)
63+
@ast["field:disclaimer"] = @input[1]
64+
end
65+
66+
end
3867
end
3968
end
Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#disclaimer
2-
%s == "More information is available at https://domain.fi/\nCopyright (c) Finnish Communications Regulatory Authority"
2+
%s == "Copyright (c) Finnish Transport and Communications Agency Traficom"
33

44

55
#domain
6-
%s == "oogle.fi"
6+
%s == "kalatalousministeri.fi"
77

88
#domain_id
99
%s %ERROR{AttributeNotSupported}
@@ -21,51 +21,69 @@
2121

2222
#created_on
2323
%s %CLASS{time}
24-
%s %TIME{2012-06-21}
24+
%s %TIME{2018-03-14 17:47:42}
2525

2626
#updated_on
2727
%s %CLASS{time}
28-
%s %TIME{2013-06-22}
28+
%s %TIME{2019-11-06}
2929

3030
#expires_on
3131
%s %CLASS{time}
32-
%s %TIME{2013-06-21}
32+
%s %TIME{2020-03-14 17:47:42}
3333

3434

3535
#registrar
36-
%s %ERROR{AttributeNotSupported}
36+
%s.name == "Gandi SAS"
37+
%s.url == "www.gandi.net"
3738

3839
#registrant_contacts
40+
%s %ERROR{AttributeNotSupported}
41+
42+
#admin_contacts
3943
%s %CLASS{array}
4044
%s %SIZE{1}
4145
%s[0] %CLASS{contact}
42-
%s[0].type == Whois::Parser::Contact::TYPE_REGISTRANT
43-
%s[0].id == "NURMI"
44-
%s[0].name == "-"
45-
%s[0].organization == "Minna"
46-
%s[0].address == "Huovitie 3"
47-
%s[0].city == "HELSINKI"
48-
%s[0].zip == "00400"
46+
%s[0].type == Whois::Parser::Contact::TYPE_ADMINISTRATIVE
47+
%s[0].id == "2823344-7"
48+
%s[0].name == "Digiteam Oy"
49+
%s[0].address == "Myllyniityntie 71"
50+
%s[0].city == "Lohja"
51+
%s[0].zip == "08100"
4952
%s[0].state == nil
50-
%s[0].country == nil
53+
%s[0].country == "Finland"
5154
%s[0].country_code == nil
52-
%s[0].phone == "+358201599789"
55+
%s[0].phone == "+358.503716096"
5356
%s[0].fax == nil
54-
%s[0].email == nil
57+
%s[0].email == ""
5558
%s[0].created_on == nil
5659
%s[0].updated_on == nil
5760

58-
#admin_contacts
59-
%s %ERROR{AttributeNotSupported}
60-
6161
#technical_contacts
62-
%s %ERROR{AttributeNotSupported}
62+
%s %CLASS{array}
63+
%s %SIZE{1}
64+
%s[0] %CLASS{contact}
65+
%s[0].type == Whois::Parser::Contact::TYPE_TECHNICAL
66+
%s[0].id == nil
67+
%s[0].name == "Seravo Oy"
68+
%s[0].address == nil
69+
%s[0].city == nil
70+
%s[0].zip == nil
71+
%s[0].state == nil
72+
%s[0].country == nil
73+
%s[0].country_code == nil
74+
%s[0].phone == nil
75+
%s[0].fax == nil
76+
%s[0].email == "hostmaster@seravo.com"
77+
%s[0].created_on == nil
78+
%s[0].updated_on == nil
6379

6480

6581
#nameservers
6682
%s %CLASS{array}
67-
%s %SIZE{2}
83+
%s %SIZE{3}
6884
%s[0] %CLASS{nameserver}
69-
%s[0].name == "a.ns.netim.net"
85+
%s[0].name == "ns-184-c.gandi.net"
7086
%s[1] %CLASS{nameserver}
71-
%s[1].name == "b.ns.netim.net"
87+
%s[1].name == "ns-196-a.gandi.net"
88+
%s[2] %CLASS{nameserver}
89+
%s[2].name == "ns-73-b.gandi.net"
Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
1-
IP: UNABLE TO RESOLVE
2-
3-
domain: oogle.fi
4-
descr: Minna
5-
descr: NURMI
6-
address: -
7-
address: Huovitie 3
8-
address: 00400
9-
address: HELSINKI
10-
phone: +358201599789
11-
status: Grace Period
12-
created: 21.6.2012
13-
modified: 22.6.2013
14-
expires: 21.6.2013
15-
nserver: a.ns.netim.net [Ok]
16-
nserver: b.ns.netim.net [Ok]
17-
dnssec: no
18-
19-
More information is available at https://domain.fi/
20-
Copyright (c) Finnish Communications Regulatory Authority
1+
2+
domain.............: kalatalousministeri.fi
3+
status.............: Grace Period
4+
created............: 14.3.2018 17:47:42
5+
expires............: 14.3.2020 17:47:42
6+
available..........: 14.4.2020 17:47:42
7+
modified...........: 6.11.2019
8+
RegistryLock.......: no
9+
10+
Nameservers
11+
12+
nserver............: ns-184-c.gandi.net [OK]
13+
nserver............: ns-196-a.gandi.net [OK]
14+
nserver............: ns-73-b.gandi.net [OK]
15+
16+
DNSSEC
17+
18+
dnssec.............: no
19+
20+
Holder
21+
22+
name...............: Digiteam Oy
23+
register number....: 2823344-7
24+
address............: Myllyniityntie 71
25+
address............: 08100
26+
address............: Lohja
27+
country............: Finland
28+
phone..............: +358.503716096
29+
holder email.......:
30+
31+
Registrar
32+
33+
registrar..........: Gandi SAS
34+
www................: www.gandi.net
35+
36+
Tech
37+
38+
name...............: Seravo Oy
39+
email..............: hostmaster@seravo.com
40+
41+
>>> Last update of WHOIS database: 22.3.2020 13:47:27 (EET) <<<
42+
43+
44+
Copyright (c) Finnish Transport and Communications Agency Traficom
2145

‎spec/fixtures/responses/whois.fi/fi/status_available.expected‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#disclaimer
2-
%s == "More information is available at https://domain.fi/\nCopyright (c) Finnish Communications Regulatory Authority"
2+
%s == "Copyright (c) Finnish Transport and Communications Agency Traficom"
33

44

55
#domain
@@ -30,17 +30,19 @@
3030

3131

3232
#registrar
33-
%s %ERROR{AttributeNotSupported}
33+
%s == nil
3434

3535
#registrant_contacts
36-
%s %CLASS{array}
37-
%s == []
36+
%s %ERROR{AttributeNotSupported}
3837

3938
#admin_contacts
40-
%s %ERROR{AttributeNotSupported}
39+
%s %CLASS{array}
40+
%s == []
4141

4242
#technical_contacts
43-
%s %ERROR{AttributeNotSupported}
43+
%s %CLASS{array}
44+
%s == []
45+
4446

4547

4648
#nameservers
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
Domain not found
33

4-
More information is available at https://domain.fi/
5-
Copyright (c) Finnish Communications Regulatory Authority
4+
Copyright (c) Finnish Transport and Communications Agency Traficom
65

0 commit comments

Comments
 (0)