maxmind-geoip2 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +10 -5
  4. data/lib/maxmind/geoip2/client.rb +18 -9
  5. data/lib/maxmind/geoip2/model/city.rb +4 -5
  6. data/lib/maxmind/geoip2/model/connection_type.rb +3 -2
  7. data/lib/maxmind/geoip2/model/enterprise.rb +2 -3
  8. data/lib/maxmind/geoip2/model/insights.rb +3 -5
  9. data/lib/maxmind/geoip2/record/traits.rb +39 -27
  10. data/lib/maxmind/geoip2/version.rb +8 -0
  11. data/maxmind-geoip2.gemspec +7 -2
  12. data/test/data/cmd/write-test-data/main.go +68 -0
  13. data/test/data/go.mod +13 -0
  14. data/test/data/go.sum +16 -0
  15. data/test/data/perltidyrc +6 -0
  16. data/test/data/pkg/writer/decoder.go +178 -0
  17. data/test/data/pkg/writer/geoip2.go +182 -0
  18. data/test/data/pkg/writer/ip.go +39 -0
  19. data/test/data/pkg/writer/maxmind.go +245 -0
  20. data/test/data/pkg/writer/nestedstructures.go +73 -0
  21. data/test/data/pkg/writer/writer.go +58 -0
  22. data/test/data/source-data/GeoIP2-City-Test.json +322 -1
  23. data/test/data/source-data/GeoIP2-Connection-Type-Test.json +15 -10
  24. data/test/data/source-data/GeoIP2-Country-Test.json +99 -0
  25. data/test/data/source-data/GeoIP2-Domain-Test.json +5 -0
  26. data/test/data/source-data/GeoIP2-Enterprise-Test.json +347 -1
  27. data/test/data/source-data/GeoIP2-Precision-Enterprise-Sandbox-Test.json +296 -0
  28. data/test/data/source-data/GeoIP2-Precision-Enterprise-Test.json +412 -2
  29. data/test/data/source-data/GeoIP2-Static-IP-Score-Test.json +15 -0
  30. data/test/data/source-data/GeoIP2-User-Count-Test.json +18 -0
  31. data/test/data/source-data/GeoLite2-City-Test.json +168 -0
  32. data/test/data/source-data/GeoLite2-Country-Test.json +92 -0
  33. data/test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  34. data/test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  35. data/test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  36. data/test/data/test-data/GeoIP2-City-Test.mmdb +0 -0
  37. data/test/data/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  38. data/test/data/test-data/GeoIP2-Country-Test.mmdb +0 -0
  39. data/test/data/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  40. data/test/data/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  41. data/test/data/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  42. data/test/data/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  43. data/test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  44. data/test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb +0 -0
  45. data/test/data/test-data/GeoIP2-User-Count-Test.mmdb +0 -0
  46. data/test/data/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  47. data/test/data/test-data/GeoLite2-City-Test.mmdb +0 -0
  48. data/test/data/test-data/GeoLite2-Country-Test.mmdb +0 -0
  49. data/test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  50. data/test/data/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  51. data/test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  52. data/test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  53. data/test/data/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  54. data/test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  55. data/test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  56. data/test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  57. data/test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  58. data/test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  59. data/test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  60. data/test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  61. data/test/data/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  62. data/test/data/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  63. data/test/data/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  64. data/test/data/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  65. data/test/data/test-data/MaxMind-DB-test-pointer-decoder.mmdb +0 -0
  66. data/test/data/test-data/README.md +28 -12
  67. data/test/test_client.rb +18 -2
  68. data/test/test_reader.rb +19 -1
  69. metadata +16 -7
  70. data/test/data/source-data/README +0 -15
  71. data/test/data/test-data/write-test-data.pl +0 -695
@@ -11276,5 +11276,97 @@
11276
11276
  }
11277
11277
  }
11278
11278
  }
11279
+ },
11280
+ {
11281
+ "214.78.0.0/19" : {
11282
+ "continent" : {
11283
+ "code" : "NA",
11284
+ "geoname_id" : 6255149,
11285
+ "names" : {
11286
+ "de" : "Nordamerika",
11287
+ "en" : "North America",
11288
+ "es" : "Norteamérica",
11289
+ "fr" : "Amérique du Nord",
11290
+ "ja" : "北アメリカ",
11291
+ "pt-BR" : "América do Norte",
11292
+ "ru" : "Северная Америка",
11293
+ "zh-CN" : "北美洲"
11294
+ }
11295
+ },
11296
+ "country" : {
11297
+ "geoname_id" : 6252001,
11298
+ "iso_code" : "US",
11299
+ "names" : {
11300
+ "de" : "Vereinigte Staaten",
11301
+ "en" : "United States",
11302
+ "es" : "Estados Unidos",
11303
+ "fr" : "États Unis",
11304
+ "ja" : "アメリカ",
11305
+ "pt-BR" : "EUA",
11306
+ "ru" : "США",
11307
+ "zh-CN" : "美国"
11308
+ }
11309
+ },
11310
+ "registered_country" : {
11311
+ "geoname_id" : 6252001,
11312
+ "iso_code" : "US",
11313
+ "names" : {
11314
+ "de" : "Vereinigte Staaten",
11315
+ "en" : "United States",
11316
+ "es" : "Estados Unidos",
11317
+ "fr" : "États Unis",
11318
+ "ja" : "アメリカ",
11319
+ "pt-BR" : "EUA",
11320
+ "ru" : "США",
11321
+ "zh-CN" : "美国"
11322
+ }
11323
+ }
11324
+ }
11325
+ },
11326
+ {
11327
+ "2001:480::/43" : {
11328
+ "continent" : {
11329
+ "code" : "NA",
11330
+ "geoname_id" : 6255149,
11331
+ "names" : {
11332
+ "de" : "Nordamerika",
11333
+ "en" : "North America",
11334
+ "es" : "Norteamérica",
11335
+ "fr" : "Amérique du Nord",
11336
+ "ja" : "北アメリカ",
11337
+ "pt-BR" : "América do Norte",
11338
+ "ru" : "Северная Америка",
11339
+ "zh-CN" : "北美洲"
11340
+ }
11341
+ },
11342
+ "country" : {
11343
+ "geoname_id" : 6252001,
11344
+ "iso_code" : "US",
11345
+ "names" : {
11346
+ "de" : "Vereinigte Staaten",
11347
+ "en" : "United States",
11348
+ "es" : "Estados Unidos",
11349
+ "fr" : "États Unis",
11350
+ "ja" : "アメリカ",
11351
+ "pt-BR" : "EUA",
11352
+ "ru" : "США",
11353
+ "zh-CN" : "美国"
11354
+ }
11355
+ },
11356
+ "registered_country" : {
11357
+ "geoname_id" : 6252001,
11358
+ "iso_code" : "US",
11359
+ "names" : {
11360
+ "de" : "Vereinigte Staaten",
11361
+ "en" : "United States",
11362
+ "es" : "Estados Unidos",
11363
+ "fr" : "États Unis",
11364
+ "ja" : "アメリカ",
11365
+ "pt-BR" : "EUA",
11366
+ "ru" : "США",
11367
+ "zh-CN" : "美国"
11368
+ }
11369
+ }
11370
+ }
11279
11371
  }
11280
11372
  ]
@@ -1,13 +1,10 @@
1
- The write-test-dbs script will create a small set of test databases with a
2
- variety of data and record sizes (24, 28, & 32 bit).
1
+ ## How to generate test data
2
+ Use the [write-test-data](https://github.com/maxmind/MaxMind-DB/blob/main/cmd/write-test-data)
3
+ go tool to create a small set of test databases with a variety of data and
4
+ record sizes.
3
5
 
4
6
  These test databases are useful for testing code that reads MaxMind DB files.
5
7
 
6
- There is also a `maps-with-pointers.raw` file. This contains the raw output of
7
- the MaxMind::DB::Writer::Serializer module, when given a series of maps which
8
- share some keys and values. It is used to test that decoder code can handle
9
- pointers to map keys and values, as well as to the whole map.
10
-
11
8
  There are several ways to figure out what IP addresses are actually in the
12
9
  test databases. You can take a look at the
13
10
  [source-data directory](https://github.com/maxmind/MaxMind-DB/tree/main/source-data)
@@ -19,8 +16,27 @@ You can also use the
19
16
  in the
20
17
  [MaxMind-DB-Reader-perl repository](https://github.com/maxmind/MaxMind-DB-Reader-perl).
21
18
 
22
- Some databases are intentionally broken and cannot be dumped. You can look at
23
- the
24
- [script which generates these databases](https://github.com/maxmind/MaxMind-DB/blob/main/test-data/write-test-data.pl)
25
- to see what IP addresses they include, which will be necessary for those
26
- databases which cannot be dumped because they contain intentional errors.
19
+ ## Static test data
20
+ Some of the test files are remnants of the
21
+ [old perl test data writer](https://github.com/maxmind/MaxMind-DB/blob/f0a85c671c5b6e9c5e514bd66162724ee1dedea3/test-data/write-test-data.pl)
22
+ and cannot be generated with the go tool. These databases are intentionally broken,
23
+ and exploited functionality simply not available in the go mmdbwriter:
24
+
25
+ - MaxMind-DB-test-broken-pointers-24.mmdb
26
+ - MaxMind-DB-test-broken-search-tree-24.mmdb
27
+ - MaxMind-DB-test-pointer-decoder.mmdb
28
+ - GeoIP2-City-Test-Broken-Double-Format.mmdb
29
+ - GeoIP2-City-Test-Invalid-Node-Count.mmdb
30
+ - maps-with-pointers.raw
31
+
32
+ ## Usage
33
+ ```
34
+ Usage of ./write-test-data:
35
+ -source string
36
+ Source data directory
37
+ -target string
38
+ Destination directory for the generated mmdb files
39
+ ```
40
+
41
+ Example:
42
+ `./write-test-data --source ../../source-data --target ../../test-data`
data/test/test_client.rb CHANGED
@@ -22,6 +22,7 @@ class ClientTest < Minitest::Test
22
22
  },
23
23
  'traits' => {
24
24
  'ip_address' => '1.2.3.4',
25
+ 'is_anycast' => true,
25
26
  'network' => '1.2.3.0/24',
26
27
  },
27
28
  }.freeze
@@ -42,6 +43,7 @@ class ClientTest < Minitest::Test
42
43
  },
43
44
  'traits' => {
44
45
  'ip_address' => '1.2.3.40',
46
+ 'is_anycast' => true,
45
47
  'is_residential_proxy' => true,
46
48
  'network' => '1.2.3.0/24',
47
49
  'static_ip_score' => 1.3,
@@ -73,6 +75,7 @@ class ClientTest < Minitest::Test
73
75
 
74
76
  assert_equal(false, record.registered_country.in_european_union?)
75
77
 
78
+ assert_equal(true, record.traits.anycast?)
76
79
  assert_equal('1.2.3.0/24', record.traits.network)
77
80
  end
78
81
 
@@ -83,6 +86,7 @@ class ClientTest < Minitest::Test
83
86
 
84
87
  assert_equal(42, record.continent.geoname_id)
85
88
 
89
+ assert_equal(true, record.traits.anycast?)
86
90
  assert_equal(true, record.traits.residential_proxy?)
87
91
  assert_equal('1.2.3.0/24', record.traits.network)
88
92
  assert_equal(1.3, record.traits.static_ip_score)
@@ -126,7 +130,7 @@ class ClientTest < Minitest::Test
126
130
  )
127
131
  end
128
132
 
129
- def test_invalid_ip_error
133
+ def test_invalid_ip_error_from_web_service
130
134
  error = assert_raises(
131
135
  MaxMind::GeoIP2::AddressInvalidError,
132
136
  ) { request(:country, '1.2.3.6') }
@@ -137,6 +141,17 @@ class ClientTest < Minitest::Test
137
141
  )
138
142
  end
139
143
 
144
+ def test_invalid_ip_error_from_client
145
+ error = assert_raises(
146
+ MaxMind::GeoIP2::AddressInvalidError,
147
+ ) { request(:country, '1.2.3') }
148
+
149
+ assert_equal(
150
+ 'The value "1.2.3" is not a valid IP address',
151
+ error.message,
152
+ )
153
+ end
154
+
140
155
  def test_no_error_body_ip_error
141
156
  assert_raises(
142
157
  JSON::ParserError,
@@ -290,7 +305,7 @@ class ClientTest < Minitest::Test
290
305
  license_key: 'abcdef123456',
291
306
  )
292
307
 
293
- client.send(method, '1.2.3.4')
308
+ client.send(method, ip_address)
294
309
  end
295
310
 
296
311
  def get_response(ip_address)
@@ -300,6 +315,7 @@ class ClientTest < Minitest::Test
300
315
  headers: { 'Content-Type': CONTENT_TYPES[:country] },
301
316
  status: 200,
302
317
  },
318
+ '1.2.3' => {},
303
319
  '1.2.3.4' => {
304
320
  body: JSON.generate(COUNTRY),
305
321
  headers: { 'Content-Type': CONTENT_TYPES[:country] },
data/test/test_reader.rb CHANGED
@@ -97,6 +97,12 @@ class ReaderTest < Minitest::Test
97
97
  assert_equal('WA', record.most_specific_subdivision.iso_code)
98
98
  )
99
99
 
100
+ # This IP has is_anycast.
101
+
102
+ ip_address = '214.1.1.0'
103
+ record = reader.city(ip_address)
104
+ assert_equal(true, record.traits.anycast?)
105
+
100
106
  reader.close
101
107
  end
102
108
 
@@ -119,7 +125,7 @@ class ReaderTest < Minitest::Test
119
125
  ip = '1.0.1.1'
120
126
  record = reader.connection_type(ip)
121
127
 
122
- assert_equal('Cable/DSL', record.connection_type)
128
+ assert_equal('Cellular', record.connection_type)
123
129
  assert_equal(ip, record.ip_address)
124
130
  assert_equal('1.0.1.0/24', record.network)
125
131
 
@@ -209,6 +215,12 @@ class ReaderTest < Minitest::Test
209
215
  assert_equal('81.2.69.163', record.traits.ip_address)
210
216
  assert_equal('81.2.69.160/27', record.traits.network)
211
217
 
218
+ # This IP has is_anycast.
219
+
220
+ ip_address = '214.1.1.0'
221
+ record = reader.country(ip_address)
222
+ assert_equal(true, record.traits.anycast?)
223
+
212
224
  assert_raises(NoMethodError) { record.foo }
213
225
  reader.close
214
226
  end
@@ -274,6 +286,12 @@ class ReaderTest < Minitest::Test
274
286
  assert_equal('310', record.traits.mobile_country_code)
275
287
  assert_equal('004', record.traits.mobile_network_code)
276
288
 
289
+ # This IP has is_anycast.
290
+
291
+ ip_address = '214.1.1.0'
292
+ record = reader.enterprise(ip_address)
293
+ assert_equal(true, record.traits.anycast?)
294
+
277
295
  reader.close
278
296
  end
279
297
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxmind-geoip2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Storey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-18 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '1.1'
53
+ version: '1.2'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '1.1'
60
+ version: '1.2'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: minitest
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +167,7 @@ files:
167
167
  - lib/maxmind/geoip2/record/represented_country.rb
168
168
  - lib/maxmind/geoip2/record/subdivision.rb
169
169
  - lib/maxmind/geoip2/record/traits.rb
170
+ - lib/maxmind/geoip2/version.rb
170
171
  - maxmind-geoip2.gemspec
171
172
  - test/data/LICENSE
172
173
  - test/data/MaxMind-DB-spec.md
@@ -181,7 +182,16 @@ files:
181
182
  - test/data/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb
182
183
  - test/data/bad-data/maxminddb-golang/unexpected-bytes.mmdb
183
184
  - test/data/bad-data/maxminddb-python/bad-unicode-in-map-key.mmdb
185
+ - test/data/cmd/write-test-data/main.go
186
+ - test/data/go.mod
187
+ - test/data/go.sum
184
188
  - test/data/perltidyrc
189
+ - test/data/pkg/writer/decoder.go
190
+ - test/data/pkg/writer/geoip2.go
191
+ - test/data/pkg/writer/ip.go
192
+ - test/data/pkg/writer/maxmind.go
193
+ - test/data/pkg/writer/nestedstructures.go
194
+ - test/data/pkg/writer/writer.go
185
195
  - test/data/source-data/GeoIP2-Anonymous-IP-Test.json
186
196
  - test/data/source-data/GeoIP2-City-Test.json
187
197
  - test/data/source-data/GeoIP2-Connection-Type-Test.json
@@ -190,13 +200,13 @@ files:
190
200
  - test/data/source-data/GeoIP2-Domain-Test.json
191
201
  - test/data/source-data/GeoIP2-Enterprise-Test.json
192
202
  - test/data/source-data/GeoIP2-ISP-Test.json
203
+ - test/data/source-data/GeoIP2-Precision-Enterprise-Sandbox-Test.json
193
204
  - test/data/source-data/GeoIP2-Precision-Enterprise-Test.json
194
205
  - test/data/source-data/GeoIP2-Static-IP-Score-Test.json
195
206
  - test/data/source-data/GeoIP2-User-Count-Test.json
196
207
  - test/data/source-data/GeoLite2-ASN-Test.json
197
208
  - test/data/source-data/GeoLite2-City-Test.json
198
209
  - test/data/source-data/GeoLite2-Country-Test.json
199
- - test/data/source-data/README
200
210
  - test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb
201
211
  - test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb
202
212
  - test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb
@@ -232,7 +242,6 @@ files:
232
242
  - test/data/test-data/MaxMind-DB-test-pointer-decoder.mmdb
233
243
  - test/data/test-data/README.md
234
244
  - test/data/test-data/maps-with-pointers.raw
235
- - test/data/test-data/write-test-data.pl
236
245
  - test/data/tidyall.ini
237
246
  - test/test_client.rb
238
247
  - test/test_model_country.rb
@@ -264,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
273
  - !ruby/object:Gem::Version
265
274
  version: '0'
266
275
  requirements: []
267
- rubygems_version: 3.2.22
276
+ rubygems_version: 3.4.18
268
277
  signing_key:
269
278
  specification_version: 4
270
279
  summary: A gem for interacting with the GeoIP2 webservices and databases.
@@ -1,15 +0,0 @@
1
- All of these but the City and Enterprise files are JSON dumps of the databases
2
- created by the GeoIP2 build integration tests
3
- (TestFor::MM::Integration::GeoIP2::Build).
4
-
5
- Additional data was added to match our legacy test databases.
6
-
7
- The City file is of unknown origin.
8
-
9
- The Enterprise file was a single example IP address, modified slightly to
10
- include all fields. It now has more than that.
11
-
12
- The Precision file was the normal Enterprise file with an additional marker
13
- (128.101.101.101) to differentiate the two. It now contains additional
14
- additions and changes as it is the database used in many MaxMind
15
- integration tests.