|
@@ -10,7 +10,6 @@
|
|
|
package org.elasticsearch.ingest.geoip;
|
|
|
|
|
|
import org.elasticsearch.common.CheckedSupplier;
|
|
|
-import org.elasticsearch.common.util.set.Sets;
|
|
|
import org.elasticsearch.core.IOUtils;
|
|
|
import org.elasticsearch.ingest.IngestDocument;
|
|
|
import org.elasticsearch.ingest.RandomDocumentPicks;
|
|
@@ -24,14 +23,12 @@ import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument;
|
|
|
import static org.elasticsearch.ingest.geoip.GeoIpProcessor.GEOIP_TYPE;
|
|
|
import static org.elasticsearch.ingest.geoip.GeoIpTestUtils.copyDatabase;
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
-import static org.hamcrest.Matchers.empty;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.hasEntry;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
@@ -57,71 +54,6 @@ public class GeoIpProcessorTests extends ESTestCase {
|
|
|
IOUtils.rm(tmpDir);
|
|
|
}
|
|
|
|
|
|
- public void testDatabasePropertyInvariants() {
|
|
|
- // the city database is like a specialization of the country database
|
|
|
- assertThat(Sets.difference(Database.Country.properties(), Database.City.properties()), is(empty()));
|
|
|
- assertThat(Sets.difference(Database.Country.defaultProperties(), Database.City.defaultProperties()), is(empty()));
|
|
|
-
|
|
|
- // the isp database is like a specialization of the asn database
|
|
|
- assertThat(Sets.difference(Database.Asn.properties(), Database.Isp.properties()), is(empty()));
|
|
|
- assertThat(Sets.difference(Database.Asn.defaultProperties(), Database.Isp.defaultProperties()), is(empty()));
|
|
|
-
|
|
|
- // the enterprise database is like these other databases joined together
|
|
|
- for (Database type : Set.of(
|
|
|
- Database.City,
|
|
|
- Database.Country,
|
|
|
- Database.Asn,
|
|
|
- Database.AnonymousIp,
|
|
|
- Database.ConnectionType,
|
|
|
- Database.Domain,
|
|
|
- Database.Isp
|
|
|
- )) {
|
|
|
- assertThat(Sets.difference(type.properties(), Database.Enterprise.properties()), is(empty()));
|
|
|
- }
|
|
|
- // but in terms of the default fields, it's like a drop-in replacement for the city database
|
|
|
- // n.b. this is just a choice we decided to make here at Elastic
|
|
|
- assertThat(Database.Enterprise.defaultProperties(), equalTo(Database.City.defaultProperties()));
|
|
|
- }
|
|
|
-
|
|
|
- public void testCity() throws Exception {
|
|
|
- String ip = "8.8.8.8";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoLite2-City.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.City),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(12));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("country_in_european_union"), equalTo(false));
|
|
|
- assertThat(geoData.get("country_iso_code"), equalTo("US"));
|
|
|
- assertThat(geoData.get("country_name"), equalTo("United States"));
|
|
|
- assertThat(geoData.get("continent_code"), equalTo("NA"));
|
|
|
- assertThat(geoData.get("continent_name"), equalTo("North America"));
|
|
|
- assertThat(geoData.get("timezone"), equalTo("America/Chicago"));
|
|
|
- assertThat(geoData.get("location"), equalTo(Map.of("lat", 37.751d, "lon", -97.822d)));
|
|
|
- assertThat(geoData.get("registered_country_in_european_union"), equalTo(false));
|
|
|
- assertThat(geoData.get("registered_country_iso_code"), equalTo("US"));
|
|
|
- assertThat(geoData.get("registered_country_name"), equalTo("United States"));
|
|
|
- }
|
|
|
-
|
|
|
public void testNullValueWithIgnoreMissing() throws Exception {
|
|
|
GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
GEOIP_TYPE,
|
|
@@ -208,369 +140,6 @@ public class GeoIpProcessorTests extends ESTestCase {
|
|
|
assertThat(exception.getMessage(), equalTo("field [source_field] not present as part of path [source_field]"));
|
|
|
}
|
|
|
|
|
|
- public void testCity_withIpV6() throws Exception {
|
|
|
- String ip = "2602:306:33d3:8000::3257:9652";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoLite2-City.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.City),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(16));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("country_in_european_union"), equalTo(false));
|
|
|
- assertThat(geoData.get("country_iso_code"), equalTo("US"));
|
|
|
- assertThat(geoData.get("country_name"), equalTo("United States"));
|
|
|
- assertThat(geoData.get("continent_code"), equalTo("NA"));
|
|
|
- assertThat(geoData.get("continent_name"), equalTo("North America"));
|
|
|
- assertThat(geoData.get("region_iso_code"), equalTo("US-FL"));
|
|
|
- assertThat(geoData.get("region_name"), equalTo("Florida"));
|
|
|
- assertThat(geoData.get("city_name"), equalTo("Homestead"));
|
|
|
- assertThat(geoData.get("timezone"), equalTo("America/New_York"));
|
|
|
- assertThat(geoData.get("location"), equalTo(Map.of("lat", 25.4573d, "lon", -80.4572d)));
|
|
|
- assertThat(geoData.get("accuracy_radius"), equalTo(50));
|
|
|
- assertThat(geoData.get("postal_code"), equalTo("33035"));
|
|
|
- assertThat(geoData.get("registered_country_in_european_union"), equalTo(false));
|
|
|
- assertThat(geoData.get("registered_country_iso_code"), equalTo("US"));
|
|
|
- assertThat(geoData.get("registered_country_name"), equalTo("United States"));
|
|
|
- }
|
|
|
-
|
|
|
- public void testCityWithMissingLocation() throws Exception {
|
|
|
- String ip = "80.231.5.0";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoLite2-City.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.City),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(1));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- }
|
|
|
-
|
|
|
- public void testCountry() throws Exception {
|
|
|
- String ip = "82.170.213.79";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoLite2-Country.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.Country),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(9));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("country_in_european_union"), equalTo(true));
|
|
|
- assertThat(geoData.get("country_iso_code"), equalTo("NL"));
|
|
|
- assertThat(geoData.get("country_name"), equalTo("Netherlands"));
|
|
|
- assertThat(geoData.get("continent_code"), equalTo("EU"));
|
|
|
- assertThat(geoData.get("continent_name"), equalTo("Europe"));
|
|
|
- assertThat(geoData.get("registered_country_in_european_union"), equalTo(true));
|
|
|
- assertThat(geoData.get("registered_country_iso_code"), equalTo("NL"));
|
|
|
- assertThat(geoData.get("registered_country_name"), equalTo("Netherlands"));
|
|
|
- }
|
|
|
-
|
|
|
- public void testCountryWithMissingLocation() throws Exception {
|
|
|
- String ip = "80.231.5.0";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoLite2-Country.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.Country),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(1));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- }
|
|
|
-
|
|
|
- public void testAsn() throws Exception {
|
|
|
- String ip = "82.171.64.0";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoLite2-ASN.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.Asn),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(4));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("asn"), equalTo(1136L));
|
|
|
- assertThat(geoData.get("organization_name"), equalTo("KPN B.V."));
|
|
|
- assertThat(geoData.get("network"), equalTo("82.168.0.0/14"));
|
|
|
- }
|
|
|
-
|
|
|
- public void testAnonymmousIp() throws Exception {
|
|
|
- String ip = "81.2.69.1";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoIP2-Anonymous-IP-Test.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.AnonymousIp),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(7));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("hosting_provider"), equalTo(true));
|
|
|
- assertThat(geoData.get("tor_exit_node"), equalTo(true));
|
|
|
- assertThat(geoData.get("anonymous_vpn"), equalTo(true));
|
|
|
- assertThat(geoData.get("anonymous"), equalTo(true));
|
|
|
- assertThat(geoData.get("public_proxy"), equalTo(true));
|
|
|
- assertThat(geoData.get("residential_proxy"), equalTo(true));
|
|
|
- }
|
|
|
-
|
|
|
- public void testConnectionType() throws Exception {
|
|
|
- String ip = "214.78.120.5";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoIP2-Connection-Type-Test.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.ConnectionType),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(2));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("connection_type"), equalTo("Satellite"));
|
|
|
- }
|
|
|
-
|
|
|
- public void testDomain() throws Exception {
|
|
|
- String ip = "69.219.64.2";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoIP2-Domain-Test.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.Domain),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(2));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("domain"), equalTo("ameritech.net"));
|
|
|
- }
|
|
|
-
|
|
|
- public void testEnterprise() throws Exception {
|
|
|
- String ip = "74.209.24.4";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoIP2-Enterprise-Test.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.Enterprise),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(33));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("country_confidence"), equalTo(99));
|
|
|
- assertThat(geoData.get("country_in_european_union"), equalTo(false));
|
|
|
- assertThat(geoData.get("country_iso_code"), equalTo("US"));
|
|
|
- assertThat(geoData.get("country_name"), equalTo("United States"));
|
|
|
- assertThat(geoData.get("continent_code"), equalTo("NA"));
|
|
|
- assertThat(geoData.get("continent_name"), equalTo("North America"));
|
|
|
- assertThat(geoData.get("region_iso_code"), equalTo("US-NY"));
|
|
|
- assertThat(geoData.get("region_name"), equalTo("New York"));
|
|
|
- assertThat(geoData.get("city_confidence"), equalTo(11));
|
|
|
- assertThat(geoData.get("city_name"), equalTo("Chatham"));
|
|
|
- assertThat(geoData.get("timezone"), equalTo("America/New_York"));
|
|
|
- assertThat(geoData.get("location"), equalTo(Map.of("lat", 42.3478, "lon", -73.5549)));
|
|
|
- assertThat(geoData.get("accuracy_radius"), equalTo(27));
|
|
|
- assertThat(geoData.get("postal_code"), equalTo("12037"));
|
|
|
- assertThat(geoData.get("city_confidence"), equalTo(11));
|
|
|
- assertThat(geoData.get("asn"), equalTo(14671L));
|
|
|
- assertThat(geoData.get("organization_name"), equalTo("FairPoint Communications"));
|
|
|
- assertThat(geoData.get("network"), equalTo("74.209.16.0/20"));
|
|
|
- assertThat(geoData.get("hosting_provider"), equalTo(false));
|
|
|
- assertThat(geoData.get("tor_exit_node"), equalTo(false));
|
|
|
- assertThat(geoData.get("anonymous_vpn"), equalTo(false));
|
|
|
- assertThat(geoData.get("anonymous"), equalTo(false));
|
|
|
- assertThat(geoData.get("public_proxy"), equalTo(false));
|
|
|
- assertThat(geoData.get("residential_proxy"), equalTo(false));
|
|
|
- assertThat(geoData.get("domain"), equalTo("frpt.net"));
|
|
|
- assertThat(geoData.get("isp"), equalTo("Fairpoint Communications"));
|
|
|
- assertThat(geoData.get("isp_organization_name"), equalTo("Fairpoint Communications"));
|
|
|
- assertThat(geoData.get("user_type"), equalTo("residential"));
|
|
|
- assertThat(geoData.get("connection_type"), equalTo("Cable/DSL"));
|
|
|
- assertThat(geoData.get("registered_country_in_european_union"), equalTo(false));
|
|
|
- assertThat(geoData.get("registered_country_iso_code"), equalTo("US"));
|
|
|
- assertThat(geoData.get("registered_country_name"), equalTo("United States"));
|
|
|
- }
|
|
|
-
|
|
|
- public void testIsp() throws Exception {
|
|
|
- String ip = "149.101.100.1";
|
|
|
- GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
- GEOIP_TYPE,
|
|
|
- randomAlphaOfLength(10),
|
|
|
- null,
|
|
|
- "source_field",
|
|
|
- loader("GeoIP2-ISP-Test.mmdb"),
|
|
|
- () -> true,
|
|
|
- "target_field",
|
|
|
- ipDataLookupAll(Database.Isp),
|
|
|
- false,
|
|
|
- false,
|
|
|
- "filename"
|
|
|
- );
|
|
|
-
|
|
|
- Map<String, Object> document = new HashMap<>();
|
|
|
- document.put("source_field", ip);
|
|
|
- IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
- processor.execute(ingestDocument);
|
|
|
-
|
|
|
- assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(ip));
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
|
|
- assertThat(geoData, notNullValue());
|
|
|
- assertThat(geoData.size(), equalTo(8));
|
|
|
- assertThat(geoData.get("ip"), equalTo(ip));
|
|
|
- assertThat(geoData.get("asn"), equalTo(6167L));
|
|
|
- assertThat(geoData.get("organization_name"), equalTo("CELLCO-PART"));
|
|
|
- assertThat(geoData.get("network"), equalTo("149.101.100.0/28"));
|
|
|
- assertThat(geoData.get("isp"), equalTo("Verizon Wireless"));
|
|
|
- assertThat(geoData.get("isp_organization_name"), equalTo("Verizon Wireless"));
|
|
|
- assertThat(geoData.get("mobile_network_code"), equalTo("004"));
|
|
|
- assertThat(geoData.get("mobile_country_code"), equalTo("310"));
|
|
|
- }
|
|
|
-
|
|
|
public void testAddressIsNotInTheDatabase() throws Exception {
|
|
|
GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
GEOIP_TYPE,
|
|
@@ -594,9 +163,9 @@ public class GeoIpProcessorTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Don't silently do DNS lookups or anything trappy on bogus data
|
|
|
+ * Tests that an exception in the IpDataLookup is propagated out of the GeoIpProcessor's execute method
|
|
|
*/
|
|
|
- public void testInvalid() {
|
|
|
+ public void testExceptionPropagates() {
|
|
|
GeoIpProcessor processor = new GeoIpProcessor(
|
|
|
GEOIP_TYPE,
|
|
|
randomAlphaOfLength(10),
|