Merge pull request #15851 from rmuir/geoip-nodns
[ingest] Don't do DNS lookups from GeoIpProcessor
This commit is contained in:
commit
46a8a48d23
|
@ -30,6 +30,7 @@ import com.maxmind.geoip2.record.Location;
|
|||
import com.maxmind.geoip2.record.Subdivision;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.SpecialPermission;
|
||||
import org.elasticsearch.common.network.InetAddresses;
|
||||
import org.elasticsearch.common.network.NetworkAddress;
|
||||
import org.elasticsearch.ingest.core.IngestDocument;
|
||||
import org.elasticsearch.ingest.core.Processor;
|
||||
|
@ -38,7 +39,6 @@ import java.io.Closeable;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
|
@ -78,12 +78,7 @@ public final class GeoIpProcessor implements Processor {
|
|||
@Override
|
||||
public void execute(IngestDocument ingestDocument) {
|
||||
String ip = ingestDocument.getFieldValue(sourceField, String.class);
|
||||
final InetAddress ipAddress;
|
||||
try {
|
||||
ipAddress = InetAddress.getByName(ip);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final InetAddress ipAddress = InetAddresses.forString(ip);
|
||||
|
||||
Map<String, Object> geoData;
|
||||
switch (dbReader.getMetadata().getDatabaseType()) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.EnumSet;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class GeoIpProcessorTests extends ESTestCase {
|
||||
|
@ -91,4 +92,21 @@ public class GeoIpProcessorTests extends ESTestCase {
|
|||
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