-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathipinfo_test.rb
More file actions
194 lines (179 loc) · 5.8 KB
/
ipinfo_test.rb
File metadata and controls
194 lines (179 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# frozen_string_literal: true
require_relative './test_helper'
class IPinfoTest < Minitest::Test
TEST_IPV4 = '8.8.8.8'
TEST_IPV6 = '2001:240:2a54:3900::'
def assert_ip6(resp)
assert_equal(resp.ip, TEST_IPV6)
assert_equal(resp.ip_address, IPAddr.new(TEST_IPV6))
refute_nil(resp.city)
refute_nil(resp.region)
assert_equal(resp.country, 'JP')
assert_equal(resp.country_name, 'Japan')
assert_equal(resp.is_eu, false)
refute_nil(resp.loc)
refute_nil(resp.latitude)
refute_nil(resp.longitude)
refute_nil(resp.postal)
assert_equal(resp.timezone, 'Asia/Tokyo')
assert_equal(resp.country_flag_url, 'https://cdn.ipinfo.io/static/images/countries-flags/JP.svg')
refute_nil(resp.asn)
assert_equal(resp.asn[:asn], 'AS2497')
assert_equal(resp.asn[:name], 'Internet Initiative Japan Inc.')
refute_nil(resp.asn[:domain])
assert_equal(resp.asn[:route], '2001:240::/32')
assert_equal(resp.asn[:type], 'isp')
refute_nil(resp.company)
refute_nil(resp.company[:name])
refute_nil(resp.company[:domain])
assert_equal(resp.company[:type], "isp")
assert_equal(
resp.privacy,
{
vpn: false,
proxy: false,
tor: false,
relay: false,
hosting: false,
service: ''
}
)
assert_equal(
resp.abuse,
{
address: 'Brisbane, Australia',
country: 'AU',
email: 'helpdesk@apnic.net',
name: 'ABUSE APNICAP',
network: '2001:200::/23',
phone: '+000000000'
}
)
assert_equal(
resp.domains,
{
page: 0,
total: 0,
domains: []
}
)
end
def assert_ip4(resp)
assert_equal(resp.ip, TEST_IPV4)
assert_equal(resp.ip_address, IPAddr.new(TEST_IPV4))
assert_equal(resp.hostname, 'dns.google')
assert_equal(resp.is_anycast, true)
assert_equal(resp.city, 'Mountain View')
assert_equal(resp.region, 'California')
assert_equal(resp.country, 'US')
assert_equal(resp.country_name, 'United States')
assert_equal(resp.is_eu, false)
assert_equal(resp.country_flag['emoji'], '🇺🇸')
assert_equal(resp.country_flag['unicode'], 'U+1F1FA U+1F1F8')
assert_equal(resp.country_flag_url, 'https://cdn.ipinfo.io/static/images/countries-flags/US.svg')
assert_equal(resp.country_currency['code'], 'USD')
assert_equal(resp.country_currency['symbol'], '$')
assert_equal(resp.continent['code'], 'NA')
assert_equal(resp.continent['name'], 'North America')
refute_nil(resp.loc)
refute_nil(resp.latitude)
refute_nil(resp.longitude)
assert_equal(resp.postal, '94043')
assert_equal(resp.timezone, 'America/Los_Angeles')
assert_equal(
resp.asn,
{
asn: 'AS15169',
name: 'Google LLC',
domain: 'google.com',
route: '8.8.8.0/24',
type: 'hosting'
}
)
assert_equal(
resp.company,
{
name: 'Google LLC',
domain: 'google.com',
type: 'hosting',
firmographic: {
name: 'Google LLC',
domain: 'google.com',
founded: '2002-10-22',
employees: nil,
sic: 5734
}
}
)
assert_equal(
resp.privacy,
{
vpn: false,
proxy: false,
tor: false,
relay: false,
hosting: true,
service: ''
}
)
assert_equal(
resp.abuse,
{
address: 'US, CA, Mountain View, ' \
'1600 Amphitheatre Parkway, 94043',
country: 'US',
email: 'network-abuse@google.com',
name: 'Abuse',
network: '8.8.8.0/24',
phone: '+1-650-253-0000'
}
)
assert_equal(resp.domains[:ip], TEST_IPV4)
refute_nil(resp.domains[:total])
refute_nil(resp.domains[:domains])
end
def test_that_it_has_a_version_number
refute_nil ::IPinfo::VERSION
end
def test_set_adapter_v4
ipinfo = IPinfo.create(
ENV['IPINFO_TOKEN'],
{ http_client: :excon }
)
assert(ipinfo.httpc = :excon)
end
def test_lookup_ip6
ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
# multiple checks for cache
(0...5).each do |_|
resp = ipinfo.details(TEST_IPV6)
assert_ip6(resp)
end
end
# # Requires IPv6 support
# def test_lookup_ip6_on_host_v6
# ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
# # multiple checks for cache
# (0...5).each do |_|
# resp = ipinfo.details_v6(TEST_IPV6)
# assert_ip6(resp)
# end
# end
def test_lookup_ip4
ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
# multiple checks for cache
(0...5).each do |_|
resp = ipinfo.details(TEST_IPV4)
assert_ip4(resp)
end
end
# # Requires IPv6 support
# def test_lookup_ip4_on_host_v6
# ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
# # multiple checks for cache
# (0...5).each do |_|
# resp = ipinfo.details_v6(TEST_IPV4)
# assert_ip4(resp)
# end
# end
end