From dcead2e9b229840e34b2dca09afd12f2d714eb30 Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 00:55:09 +0300 Subject: [PATCH 01/11] adding support for unsecure ssl InfluxDbHttpSender - using http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/ as reference, use additional parameters to disable cert/hostname verification, if unsecure ssl is required. InfluxDbReporterFactory - support the new parameters when read through json properties README.md - updated to reflect additional parameters and their default values --- README.md | 2 + .../metrics/dw/InfluxDbReporterFactory.java | 40 ++- .../metrics/influxdb/InfluxDbHttpSender.java | 228 ++++++++++++------ 3 files changed, 194 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 651967e..6e8c676 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,8 @@ excludes: - jvm.memory.pools.PS-Survivor-Space.usage precision: 1m # only store time precision to the minute prefix: "" +trustAllCerts: false +trustAllHostnames: false database: "" auth: "" measurementMappings: {} diff --git a/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java b/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java index ea46eb9..9df33e8 100644 --- a/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java +++ b/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java @@ -67,6 +67,16 @@ * The prefix for Metric key names (measurement) to report to InfluxDb. * * + * trustAllCerts + * false + * Whether we should trust all certs supplied by the server or not + * + * + * trustAllHostnames + * false + * Whether we should trust all hostnames supplied by the server or not + * + * * tags * None * tags for all metrics reported to InfluxDb. @@ -164,6 +174,12 @@ public class InfluxDbReporterFactory extends BaseReporterFactory { @NotNull private String prefix = ""; + + @NotNull + private Boolean trustAllCerts = false; + + @NotNull + private Boolean trustAllHostnames = false; @NotNull private Map tags = new HashMap<>(); @@ -283,6 +299,26 @@ public String getPrefix() { public void setPrefix(String prefix) { this.prefix = prefix; } + + @JsonProperty + public Boolean isTrustAllCerts(Boolean trustAllCerts) { + return this.trustAllCerts; + } + + @JsonProperty + public void setTrustAllCerts(Boolean trustAllCerts) { + this.trustAllCerts = trustAllCerts; + } + + @JsonProperty + public Boolean isTrustAllHostnames(Boolean trustAllHostnames) { + return this.trustAllHostnames; + } + + @JsonProperty + public void setTrustAllHostnames(Boolean trustAllHostnames) { + this.trustAllHostnames = trustAllHostnames; + } @JsonProperty private Map getTags() { @@ -433,7 +469,9 @@ public ScheduledReporter build(MetricRegistry registry) { precision.getUnit(), connectTimeout, readTimeout, - prefix + prefix, + trustAllCerts, + trustAllHostnames ) ); case TCP: diff --git a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java index 247780c..095934b 100644 --- a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java +++ b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java @@ -6,7 +6,19 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.util.concurrent.TimeUnit; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + import org.apache.commons.codec.binary.Base64; /** @@ -14,79 +26,145 @@ */ public class InfluxDbHttpSender extends InfluxDbBaseSender { - private final URL url; - // The base64 encoded authString. - private final String authStringEncoded; - private final int connectTimeout; - private final int readTimeout; - - /** - * Creates a new http sender given connection details. - * - * @param hostname the influxDb hostname - * @param port the influxDb http port - * @param database the influxDb database to write to - * @param authString the authorization string to be used to connect to InfluxDb, of format username:password - * @param timePrecision the time precision of the metrics - * @param connectTimeout the connect timeout - * @param connectTimeout the read timeout - * @throws Exception exception while creating the influxDb sender(MalformedURLException) - */ - public InfluxDbHttpSender( - final String protocol, final String hostname, final int port, final String database, final String authString, - final TimeUnit timePrecision, final int connectTimeout, final int readTimeout, final String measurementPrefix) - throws Exception { - super(database, timePrecision, measurementPrefix); - - String endpoint = new URL(protocol, hostname, port, "/write").toString(); - String queryDb = String.format("db=%s", URLEncoder.encode(database, "UTF-8")); - String queryPrecision = String.format("precision=%s", TimeUtils.toTimePrecision(timePrecision)); - this.url = new URL(endpoint + "?" + queryDb + "&" + queryPrecision); - - if (authString != null && !authString.isEmpty()) { - this.authStringEncoded = Base64.encodeBase64String(authString.getBytes(UTF_8)); - } else { - this.authStringEncoded = ""; - } - - this.connectTimeout = connectTimeout; - this.readTimeout = readTimeout; - } - - @Deprecated - public InfluxDbHttpSender( - final String protocol, final String hostname, final int port, final String database, final String authString, - final TimeUnit timePrecision) throws Exception { - this(protocol, hostname, port, database, authString, timePrecision, 1000, 1000, ""); - } - - @Override - protected int writeData(byte[] line) throws Exception { - final HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - if (authStringEncoded != null && !authStringEncoded.isEmpty()) { - con.setRequestProperty("Authorization", "Basic " + authStringEncoded); - } - con.setDoOutput(true); - con.setConnectTimeout(connectTimeout); - con.setReadTimeout(readTimeout); - - OutputStream out = con.getOutputStream(); - try { - out.write(line); - out.flush(); - } finally { - out.close(); - } - - int responseCode = con.getResponseCode(); - - // Check if non 2XX response code. - if (responseCode / 100 != 2) { - throw new IOException( - "Server returned HTTP response code: " + responseCode + " for URL: " + url + " with content :'" - + con.getResponseMessage() + "'"); - } - return responseCode; - } + private final URL url; + // The base64 encoded authString. + private final String authStringEncoded; + private final int connectTimeout; + private final int readTimeout; + + /** + * Creates a new http sender given connection details. + * + * @param hostname + * the influxDb hostname + * @param port + * the influxDb http port + * @param database + * the influxDb database to write to + * @param authString + * the authorization string to be used to connect to InfluxDb, of + * format username:password + * @param timePrecision + * the time precision of the metrics + * @param connectTimeout + * the connect timeout + * @param connectTimeout + * the read timeout + * @param trustAllCerts + * whether all certs should be trusted or not + * @param trustAllHostnames + * whether all hostnames should be trusted or not + * @throws Exception + * exception while creating the influxDb + * sender(MalformedURLException) + */ + public InfluxDbHttpSender(final String protocol, final String hostname, final int port, final String database, + final String authString, final TimeUnit timePrecision, final int connectTimeout, final int readTimeout, + final String measurementPrefix, boolean trustAllCerts, boolean trustAllHostnames) throws Exception { + super(database, timePrecision, measurementPrefix); + updateSecurity(trustAllCerts, trustAllHostnames); + String endpoint = new URL(protocol, hostname, port, "/write").toString(); + String queryDb = String.format("db=%s", URLEncoder.encode(database, "UTF-8")); + String queryPrecision = String.format("precision=%s", TimeUtils.toTimePrecision(timePrecision)); + this.url = new URL(endpoint + "?" + queryDb + "&" + queryPrecision); + + if (authString != null && !authString.isEmpty()) { + this.authStringEncoded = Base64.encodeBase64String(authString.getBytes(UTF_8)); + } else { + this.authStringEncoded = ""; + } + + this.connectTimeout = connectTimeout; + this.readTimeout = readTimeout; + } + + private void updateSecurity(boolean trustAllCerts, boolean trustAllHostnames) + throws NoSuchAlgorithmException, KeyManagementException { + updateCertTrust(trustAllCerts); + updateHostnameTrust(trustAllHostnames); + } + + private void updateHostnameTrust(boolean trusting) { + if (trusting) { + // Create all-trusting host name verifier + HostnameVerifier allHostsValid = new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + + // Install the all-trusting host verifier + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } + } + + private void updateCertTrust(boolean trusting) throws NoSuchAlgorithmException, KeyManagementException { + if (trusting) { + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { + + @Override + public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + } }; + + // Install the all-trusting trust manager + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + } + + @Deprecated + public InfluxDbHttpSender(final String protocol, final String hostname, final int port, final String database, + final String authString, final TimeUnit timePrecision, final int connectTimeout, final int readTimeout, + final String measurementPrefix) throws Exception { + this(protocol, hostname, port, database, authString, timePrecision, connectTimeout, readTimeout, + measurementPrefix, false, false); + } + + @Deprecated + public InfluxDbHttpSender(final String protocol, final String hostname, final int port, final String database, + final String authString, final TimeUnit timePrecision) throws Exception { + this(protocol, hostname, port, database, authString, timePrecision, 1000, 1000, ""); + } + + @Override + protected int writeData(byte[] line) throws Exception { + final HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + if (authStringEncoded != null && !authStringEncoded.isEmpty()) { + con.setRequestProperty("Authorization", "Basic " + authStringEncoded); + } + con.setDoOutput(true); + con.setConnectTimeout(connectTimeout); + con.setReadTimeout(readTimeout); + + OutputStream out = con.getOutputStream(); + try { + out.write(line); + out.flush(); + } finally { + out.close(); + } + + int responseCode = con.getResponseCode(); + + // Check if non 2XX response code. + if (responseCode / 100 != 2) { + throw new IOException("Server returned HTTP response code: " + responseCode + " for URL: " + url + + " with content :'" + con.getResponseMessage() + "'"); + } + return responseCode; + } } From 06abf25e7e91bae8c8baf9aea1f3390c47aa7548 Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 00:57:30 +0300 Subject: [PATCH 02/11] stabilize a test InfluxDbHttpSenderTest.shouldThrowConnectException throws SocketTimeoutException for slow / non-responsive setups, fixed by making the timeout 0 --- .../com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java b/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java index 9c598d8..acb9f07 100644 --- a/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java +++ b/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java @@ -51,8 +51,8 @@ public void shouldThrowConnectException() throws Exception { "testdb", "asdf", TimeUnit.MINUTES, - 1000, - 1000, + 0, + 0, "" ); influxDbHttpSender.writeData(new byte[0]); From 80500012094e85538d101531db372105c5f3bfe3 Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 01:20:15 +0300 Subject: [PATCH 03/11] upgrade to TLS --- .../java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java index 095934b..ab34fd2 100644 --- a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java +++ b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java @@ -119,7 +119,7 @@ public X509Certificate[] getAcceptedIssuers() { } }; // Install the all-trusting trust manager - SSLContext sc = SSLContext.getInstance("SSL"); + SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } From 099cfaa76458a9d4d7a6f5f251c87e686e242189 Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 01:24:34 +0300 Subject: [PATCH 04/11] resolving SIC_INNER_SHOULD_BE_STATIC_ANON --- .../metrics/influxdb/InfluxDbHttpSender.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java index ab34fd2..2c3a741 100644 --- a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java +++ b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java @@ -84,17 +84,19 @@ private void updateSecurity(boolean trustAllCerts, boolean trustAllHostnames) updateHostnameTrust(trustAllHostnames); } + public static class TrustingHostNameVerifier implements HostnameVerifier { + + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + + } + private void updateHostnameTrust(boolean trusting) { if (trusting) { - // Create all-trusting host name verifier - HostnameVerifier allHostsValid = new HostnameVerifier() { - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - // Install the all-trusting host verifier - HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + HttpsURLConnection.setDefaultHostnameVerifier(new TrustingHostNameVerifier()); } } From 50916fd2d16f9a808045865c0f9ebf897c5f2abf Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 01:42:06 +0300 Subject: [PATCH 05/11] really trying to make find-bugs like me --- findbugs/excludes.xml | 8 ++++ .../metrics/influxdb/InfluxDbHttpSender.java | 38 ++++++++++--------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/findbugs/excludes.xml b/findbugs/excludes.xml index 7fc6ad6..a5bea3e 100644 --- a/findbugs/excludes.xml +++ b/findbugs/excludes.xml @@ -6,4 +6,12 @@ + + + + + + + + diff --git a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java index 2c3a741..12ec75b 100644 --- a/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java +++ b/metrics-influxdb/src/main/java/com/izettle/metrics/influxdb/InfluxDbHttpSender.java @@ -51,9 +51,9 @@ public class InfluxDbHttpSender extends InfluxDbBaseSender { * @param connectTimeout * the read timeout * @param trustAllCerts - * whether all certs should be trusted or not + * whether all certs should be trusted or not (setting this to true may expose you to MITM attacks) * @param trustAllHostnames - * whether all hostnames should be trusted or not + * whether all hostnames should be trusted or not (setting this to true may expose you to MITM attacks) * @throws Exception * exception while creating the influxDb * sender(MalformedURLException) @@ -99,26 +99,28 @@ private void updateHostnameTrust(boolean trusting) { HttpsURLConnection.setDefaultHostnameVerifier(new TrustingHostNameVerifier()); } } + + public static class TrustingX509TrustManager implements X509TrustManager { - private void updateCertTrust(boolean trusting) throws NoSuchAlgorithmException, KeyManagementException { - if (trusting) { - // Create a trust manager that does not validate certificate chains - TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { - - @Override - public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { - } + @Override + public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } - @Override - public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { - } + @Override + public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } - @Override - public X509Certificate[] getAcceptedIssuers() { - return null; - } + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[] {}; + } + + } - } }; + private void updateCertTrust(boolean trusting) throws NoSuchAlgorithmException, KeyManagementException { + if (trusting) { + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[] { new TrustingX509TrustManager() }; // Install the all-trusting trust manager SSLContext sc = SSLContext.getInstance("TLS"); From 0e090866e51c8bf55cc11200b43ebee09303c476 Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 01:51:53 +0300 Subject: [PATCH 06/11] trying to see whether this file is being used --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 711dced..e2047c3 100644 --- a/pom.xml +++ b/pom.xml @@ -108,7 +108,7 @@ Low true true - ${session.executionRootDirectory}/findbugs/excludes.xml + ${session.executionRootDirectory}/findbugs/verifyexcludes.xml From 54ada5bd9fcfbbec86a2976fa8f2d10d0737673a Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 02:09:09 +0300 Subject: [PATCH 07/11] what is wrong with my excludes.xml file? --- findbugs/excludes.xml | 1 - pom.xml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/findbugs/excludes.xml b/findbugs/excludes.xml index a5bea3e..97a3b7e 100644 --- a/findbugs/excludes.xml +++ b/findbugs/excludes.xml @@ -11,7 +11,6 @@ - diff --git a/pom.xml b/pom.xml index e2047c3..711dced 100644 --- a/pom.xml +++ b/pom.xml @@ -108,7 +108,7 @@ Low true true - ${session.executionRootDirectory}/findbugs/verifyexcludes.xml + ${session.executionRootDirectory}/findbugs/excludes.xml From 434be823719a09553bcd70b5b39b516eb06dc92a Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 02:15:15 +0300 Subject: [PATCH 08/11] more specific class names --- findbugs/excludes.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/findbugs/excludes.xml b/findbugs/excludes.xml index 97a3b7e..072e37f 100644 --- a/findbugs/excludes.xml +++ b/findbugs/excludes.xml @@ -7,10 +7,11 @@ - + + From 0248eee2889387320122fc267676f01512573bbe Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 02:17:56 +0300 Subject: [PATCH 09/11] I'm trying so hard --- findbugs/excludes.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/findbugs/excludes.xml b/findbugs/excludes.xml index 072e37f..34d6de7 100644 --- a/findbugs/excludes.xml +++ b/findbugs/excludes.xml @@ -7,11 +7,11 @@ - + - + From 6d6add25512c376b4d96a1689efadc75a0bae999 Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 07:43:16 +0300 Subject: [PATCH 10/11] improve coverage --- .../com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java b/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java index acb9f07..ba765ed 100644 --- a/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java +++ b/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java @@ -53,7 +53,9 @@ public void shouldThrowConnectException() throws Exception { TimeUnit.MINUTES, 0, 0, - "" + "", + true, + true ); influxDbHttpSender.writeData(new byte[0]); } From e0513a10f0887e535186bcf297159125ad002626 Mon Sep 17 00:00:00 2001 From: royshahaf Date: Thu, 6 Sep 2018 08:28:33 +0300 Subject: [PATCH 11/11] trying to improve code coverage --- .../metrics/dw/InfluxDbReporterFactory.java | 4 ++-- .../metrics/dw/InfluxDbReporterFactoryTest.java | 14 ++++++++++++++ .../metrics/influxdb/InfluxDbHttpSenderTest.java | 5 +---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java b/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java index 9df33e8..1622e72 100644 --- a/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java +++ b/dropwizard-metrics-influxdb/src/main/java/com/izettle/metrics/dw/InfluxDbReporterFactory.java @@ -301,7 +301,7 @@ public void setPrefix(String prefix) { } @JsonProperty - public Boolean isTrustAllCerts(Boolean trustAllCerts) { + public Boolean isTrustAllCerts() { return this.trustAllCerts; } @@ -311,7 +311,7 @@ public void setTrustAllCerts(Boolean trustAllCerts) { } @JsonProperty - public Boolean isTrustAllHostnames(Boolean trustAllHostnames) { + public Boolean isTrustAllHostnames() { return this.trustAllHostnames; } diff --git a/dropwizard-metrics-influxdb/src/test/java/com/izettle/metrics/dw/InfluxDbReporterFactoryTest.java b/dropwizard-metrics-influxdb/src/test/java/com/izettle/metrics/dw/InfluxDbReporterFactoryTest.java index 5640bca..f3bdb62 100644 --- a/dropwizard-metrics-influxdb/src/test/java/com/izettle/metrics/dw/InfluxDbReporterFactoryTest.java +++ b/dropwizard-metrics-influxdb/src/test/java/com/izettle/metrics/dw/InfluxDbReporterFactoryTest.java @@ -2,6 +2,8 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -152,6 +154,18 @@ protected InfluxDbReporter.Builder builder(MetricRegistry registry) { assertThat(getField(influxDb, InfluxDbHttpSender.class, "connectTimeout")).isEqualTo(2000); assertThat(getField(influxDb, InfluxDbHttpSender.class, "readTimeout")).isEqualTo(3000); } + + @Test + public void shouldChangeTrusts() throws Exception { + factory.setTrustAllCerts(true); + assertTrue(factory.isTrustAllCerts()); + factory.setTrustAllHostnames(true); + assertTrue(factory.isTrustAllHostnames()); + factory.setTrustAllCerts(false); + assertFalse(factory.isTrustAllCerts()); + factory.setTrustAllHostnames(false); + assertFalse(factory.isTrustAllHostnames()); + } @Test public void shouldBuildWithTcpSender() throws Exception { diff --git a/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java b/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java index ba765ed..7ea9460 100644 --- a/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java +++ b/metrics-influxdb/src/test/java/com/izettle/metrics/influxdb/InfluxDbHttpSenderTest.java @@ -34,10 +34,7 @@ public void shouldThrowUnknownHostException() throws Exception { 80, "testdb", "asdf", - TimeUnit.MINUTES, - 1000, - 1000, - "" + TimeUnit.MINUTES ); influxDbHttpSender.writeData(new byte[0]); }