Don't do DNS lookups from GeoIpProcessor
There is no need to involve DNS in this!
This commit is contained in:
parent
adac314328
commit
9c3ebb83a7
|
@ -30,6 +30,7 @@ import com.maxmind.geoip2.record.Location;
|
||||||
import com.maxmind.geoip2.record.Subdivision;
|
import com.maxmind.geoip2.record.Subdivision;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
import org.elasticsearch.SpecialPermission;
|
import org.elasticsearch.SpecialPermission;
|
||||||
|
import org.elasticsearch.common.network.InetAddresses;
|
||||||
import org.elasticsearch.common.network.NetworkAddress;
|
import org.elasticsearch.common.network.NetworkAddress;
|
||||||
import org.elasticsearch.ingest.core.IngestDocument;
|
import org.elasticsearch.ingest.core.IngestDocument;
|
||||||
import org.elasticsearch.ingest.core.Processor;
|
import org.elasticsearch.ingest.core.Processor;
|
||||||
|
@ -38,7 +39,6 @@ import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.PathMatcher;
|
import java.nio.file.PathMatcher;
|
||||||
|
@ -78,12 +78,7 @@ public final class GeoIpProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument ingestDocument) {
|
public void execute(IngestDocument ingestDocument) {
|
||||||
String ip = ingestDocument.getFieldValue(sourceField, String.class);
|
String ip = ingestDocument.getFieldValue(sourceField, String.class);
|
||||||
final InetAddress ipAddress;
|
final InetAddress ipAddress = InetAddresses.forString(ip);
|
||||||
try {
|
|
||||||
ipAddress = InetAddress.getByName(ip);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> geoData;
|
Map<String, Object> geoData;
|
||||||
switch (dbReader.getMetadata().getDatabaseType()) {
|
switch (dbReader.getMetadata().getDatabaseType()) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
public class GeoIpProcessorTests extends ESTestCase {
|
public class GeoIpProcessorTests extends ESTestCase {
|
||||||
|
@ -91,4 +92,21 @@ public class GeoIpProcessorTests extends ESTestCase {
|
||||||
assertThat(geoData.size(), equalTo(0));
|
assertThat(geoData.size(), equalTo(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Don't silently do DNS lookups or anything trappy on bogus data */
|
||||||
|
public void testInvalid() throws Exception {
|
||||||
|
InputStream database = GeoIpProcessor.class.getResourceAsStream("/GeoLite2-City.mmdb");
|
||||||
|
GeoIpProcessor processor = new GeoIpProcessor("source_field", new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Field.class));
|
||||||
|
|
||||||
|
Map<String, Object> document = new HashMap<>();
|
||||||
|
document.put("source_field", "www.google.com");
|
||||||
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
||||||
|
try {
|
||||||
|
processor.execute(ingestDocument);
|
||||||
|
fail("did not get expected exception");
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
assertNotNull(expected.getMessage());
|
||||||
|
assertThat(expected.getMessage(), containsString("not an IP string literal"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue