|
19 | 19 | import com.maxmind.geoip2.model.CountryResponse; |
20 | 20 | import com.maxmind.geoip2.model.DomainResponse; |
21 | 21 | import com.maxmind.geoip2.model.EnterpriseResponse; |
| 22 | +import com.maxmind.geoip2.model.IpRiskResponse; |
22 | 23 | import com.maxmind.geoip2.model.IspResponse; |
23 | 24 | import java.io.File; |
24 | 25 | import java.io.IOException; |
@@ -427,6 +428,48 @@ public void testIsp() throws Exception { |
427 | 428 | } |
428 | 429 | } |
429 | 430 |
|
| 431 | + @Test |
| 432 | + public void testIpRisk() throws Exception { |
| 433 | + try (DatabaseReader reader = new DatabaseReader.Builder( |
| 434 | + this.getFile("GeoIP2-IP-Risk-Test.mmdb")).build() |
| 435 | + ) { |
| 436 | + InetAddress ipAddress = InetAddress.getByName("214.2.3.0"); |
| 437 | + IpRiskResponse response = reader.ipRisk(ipAddress); |
| 438 | + assertEquals(25.0, response.ipRisk()); |
| 439 | + assertTrue(response.isAnonymous()); |
| 440 | + assertTrue(response.isAnonymousVpn()); |
| 441 | + assertFalse(response.isHostingProvider()); |
| 442 | + assertFalse(response.isPublicProxy()); |
| 443 | + assertFalse(response.isResidentialProxy()); |
| 444 | + assertFalse(response.isTorExitNode()); |
| 445 | + assertEquals(ipAddress.getHostAddress(), response.ipAddress().getHostAddress()); |
| 446 | + assertEquals("214.2.3.0/30", response.network().toString()); |
| 447 | + |
| 448 | + IpRiskResponse tryResponse = reader.tryIpRisk(ipAddress).get(); |
| 449 | + assertEquals(response.toJson(), tryResponse.toJson()); |
| 450 | + } |
| 451 | + } |
| 452 | + |
| 453 | + @Test |
| 454 | + public void testIpRiskWithoutIpRiskField() throws Exception { |
| 455 | + // Test that records without ip_risk field default to 0.0. |
| 456 | + // A value of 0.0 indicates that the risk score was not set in the database. |
| 457 | + try (DatabaseReader reader = new DatabaseReader.Builder( |
| 458 | + this.getFile("GeoIP2-IP-Risk-Test.mmdb")).build() |
| 459 | + ) { |
| 460 | + InetAddress ipAddress = InetAddress.getByName("11.1.2.3"); |
| 461 | + IpRiskResponse response = reader.ipRisk(ipAddress); |
| 462 | + assertEquals(0.0, response.ipRisk()); |
| 463 | + assertTrue(response.isAnonymous()); |
| 464 | + assertFalse(response.isAnonymousVpn()); |
| 465 | + assertFalse(response.isHostingProvider()); |
| 466 | + assertTrue(response.isPublicProxy()); |
| 467 | + assertFalse(response.isResidentialProxy()); |
| 468 | + assertFalse(response.isTorExitNode()); |
| 469 | + assertEquals(ipAddress.getHostAddress(), response.ipAddress().getHostAddress()); |
| 470 | + } |
| 471 | + } |
| 472 | + |
430 | 473 | private File getFile(String filename) throws URISyntaxException { |
431 | 474 | URL resource = DatabaseReaderTest.class |
432 | 475 | .getResource("/maxmind-db/test-data/" + filename); |
|
0 commit comments