-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitHub-issue#253 : Implemented download maxmind test mmdb files to re… #3193
Changes from 2 commits
c413fad
16a436f
7bfb3e4
ea8bbec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to trust all? The GitHub certificate is valid. For example, a simple download works just fine:
|
||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is still checked in. Let's remove this too. |
||
] | ||
|
||
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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than use a
Copy
task, you can use aDownload
task.See this example:
data-prepper/release/archives/build.gradle
Lines 77 to 81 in 733e7bc
The download plugin will help:
data-prepper/release/archives/build.gradle
Line 7 in 733e7bc