diff --git a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java index 71bb4f65f85..3b2f65e2814 100644 --- a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java +++ b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java @@ -34,7 +34,6 @@ import java.util.zip.GZIPInputStream; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; public class GeoIpProcessorTests extends ESTestCase { @@ -65,6 +64,34 @@ public class GeoIpProcessorTests extends ESTestCase { assertThat(geoData.get("location"), equalTo(location)); } + public void testCity_withIpV6() throws Exception { + InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz"); + GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", + new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); + + String address = "2602:306:33d3:8000::3257:9652"; + Map document = new HashMap<>(); + document.put("source_field", address); + IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); + processor.execute(ingestDocument); + + assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(address)); + @SuppressWarnings("unchecked") + Map geoData = (Map) ingestDocument.getSourceAndMetadata().get("target_field"); + assertThat(geoData.size(), equalTo(8)); + assertThat(geoData.get("ip"), equalTo(address)); + assertThat(geoData.get("country_iso_code"), equalTo("US")); + assertThat(geoData.get("country_name"), equalTo("United States")); + assertThat(geoData.get("continent_name"), equalTo("North America")); + assertThat(geoData.get("region_name"), equalTo("Florida")); + assertThat(geoData.get("city_name"), equalTo("Hollywood")); + assertThat(geoData.get("timezone"), equalTo("America/New_York")); + Map location = new HashMap<>(); + location.put("lat", 26.0252d); + location.put("lon", -80.296d); + assertThat(geoData.get("location"), equalTo(location)); + } + public void testCityWithMissingLocation() throws Exception { InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz"); GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", @@ -149,7 +176,7 @@ public class GeoIpProcessorTests extends ESTestCase { } } - static InputStream getDatabaseFileInputStream(String path) throws IOException { + private static InputStream getDatabaseFileInputStream(String path) throws IOException { return new GZIPInputStream(GeoIpProcessor.class.getResourceAsStream(path)); }