diff --git a/data-prepper-plugins/geoip-processor/build.gradle b/data-prepper-plugins/geoip-processor/build.gradle index a0dea794f2..321d85db62 100644 --- a/data-prepper-plugins/geoip-processor/build.gradle +++ b/data-prepper-plugins/geoip-processor/build.gradle @@ -1,3 +1,9 @@ +import javax.net.ssl.HttpsURLConnection +import javax.net.ssl.SSLContext +import javax.net.ssl.TrustManager +import javax.net.ssl.X509TrustManager +import java.security.cert.X509Certificate + /* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 @@ -25,6 +31,73 @@ dependencies { testImplementation project(':data-prepper-test-common') } +task copyGeoLite2Files(type: Copy) { + def urls = [ + 'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoLite2-City-Test.mmdb', + 'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoLite2-Country-Test.mmdb', + 'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoLite2-ASN-Test.mmdb' + ] + + def geoLite2Dir = file('/src/test/resources/mmdb-file/geo-lite2') + + from(urls.collect { url -> + def testFileName = url.substring(url.lastIndexOf('/') + 1) + def testMmdbSubString = testFileName.substring(testFileName.lastIndexOf('-')) + def fileName = testFileName.substring(0, testFileName.length() - testMmdbSubString.length()) + ant.get(src:url, dest: "$geoLite2Dir/$fileName" + ".mmdb") + }) + + into(geoLite2Dir) + + doFirst { + // Trust all certificates + def trustAllCertificates = new TrustManager[] { + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { null } + public void checkClientTrusted(X509Certificate[] certs, String authType) {} + public void checkServerTrusted(X509Certificate[] certs, String authType) {} + } + } + + SSLContext sc = SSLContext.getInstance("SSL") + sc.init(null, trustAllCertificates, new java.security.SecureRandom()) + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()) + } +} + +task copyGeoIP2File(type: Copy) { + + def urls = [ + 'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoIP2-Enterprise-Test.mmdb' + ] + + def geoIP2Dir = file('src/test/resources/mmdb-file/geo-enterprise') + + from(urls.collect { url -> + def testFileName = url.substring(url.lastIndexOf('/') + 1) + def testMmdbSubString = testFileName.substring(testFileName.lastIndexOf('-')) + def fileName = testFileName.substring(0, testFileName.length() - testMmdbSubString.length()) + ant.get(src:url, dest: "$geoIP2Dir/$fileName" + ".mmdb") + }) + + into(geoIP2Dir) + + doFirst { + // Trust all certificates + def trustAllCertificates = new TrustManager[] { + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { null } + public void checkClientTrusted(X509Certificate[] certs, String authType) {} + public void checkServerTrusted(X509Certificate[] certs, String authType) {} + } + } + + SSLContext sc = SSLContext.getInstance("SSL") + sc.init(null, trustAllCertificates, new java.security.SecureRandom()) + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()) + } +} + test { useJUnitPlatform() diff --git a/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-ASN.mmdb b/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-ASN.mmdb deleted file mode 100644 index 2397f84d0c..0000000000 Binary files a/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-ASN.mmdb and /dev/null differ diff --git a/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-City.mmdb b/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-City.mmdb deleted file mode 100644 index d954071728..0000000000 Binary files a/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-City.mmdb and /dev/null differ diff --git a/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-Country.mmdb b/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-Country.mmdb deleted file mode 100644 index 737c6f0fee..0000000000 Binary files a/data-prepper-plugins/geoip-processor/src/test/resources/mmdb-file/geo-lite2/GeoLite2-Country.mmdb and /dev/null differ