@@ -45,7 +45,7 @@ public class InfluxDBClientTest {
4545 @ EnabledIfEnvironmentVariable (named = "TESTING_INFLUXDB_TOKEN" , matches = ".*" )
4646 @ EnabledIfEnvironmentVariable (named = "TESTING_INFLUXDB_DATABASE" , matches = ".*" )
4747 @ Test
48- void testQueryProxyAndSslCertificate () {
48+ void testQueryWithProxy () {
4949 String proxyUrl = "http://127.0.0.1:10000" ;
5050 try {
5151 // Continue to run this test only if Envoy proxy is running in this address http://127.0.0.1:10000
@@ -55,15 +55,11 @@ void testQueryProxyAndSslCertificate() {
5555 return ;
5656 }
5757
58- // This is real certificate downloaded from https://cloud2.influxdata.com
59- String certificateFilePath = "src/test/java/com/influxdb/v3/client/testdata/valid-certificates.pem" ;
60-
6158 ClientConfig clientConfig = new ClientConfig .Builder ()
6259 .host (System .getenv ("TESTING_INFLUXDB_URL" ))
6360 .token (System .getenv ("TESTING_INFLUXDB_TOKEN" ).toCharArray ())
6461 .database (System .getenv ("TESTING_INFLUXDB_DATABASE" ))
6562 .proxyUrl (proxyUrl )
66- .certificateFilePath (certificateFilePath )
6763 .build ();
6864
6965 InfluxDBClient influxDBClient = InfluxDBClient .getInstance (clientConfig );
@@ -80,6 +76,56 @@ void testQueryProxyAndSslCertificate() {
8076 }
8177 }
8278
79+ @ EnabledIfEnvironmentVariable (named = "TESTING_INFLUXDB_URL" , matches = ".*" )
80+ @ EnabledIfEnvironmentVariable (named = "TESTING_INFLUXDB_TOKEN" , matches = ".*" )
81+ @ EnabledIfEnvironmentVariable (named = "TESTING_INFLUXDB_DATABASE" , matches = ".*" )
82+ @ Test
83+ void correctSslCertificates () throws Exception {
84+ // This is real certificate downloaded from https://cloud2.influxdata.com
85+ String influxDBcertificateFile = "src/test/java/com/influxdb/v3/client/testdata/influxdb-certificate.pem" ;
86+
87+ ClientConfig clientConfig = new ClientConfig .Builder ()
88+ .host (System .getenv ("TESTING_INFLUXDB_URL" ))
89+ .token (System .getenv ("TESTING_INFLUXDB_TOKEN" ).toCharArray ())
90+ .database (System .getenv ("TESTING_INFLUXDB_DATABASE" ))
91+ .certificateFilePath (influxDBcertificateFile )
92+ .build ();
93+ InfluxDBClient influxDBClient = InfluxDBClient .getInstance (clientConfig );
94+ assertGetdataSuccess (influxDBClient );
95+ }
96+
97+ @ Test
98+ void wrongSslCertificate () {
99+ String certificateFile = "src/test/java/com/influxdb/v3/client/testdata/docker.com.pem" ;
100+
101+ ClientConfig clientConfig = new ClientConfig .Builder ()
102+ .host (System .getenv ("TESTING_INFLUXDB_URL" ))
103+ .token (System .getenv ("TESTING_INFLUXDB_TOKEN" ).toCharArray ())
104+ .database (System .getenv ("TESTING_INFLUXDB_DATABASE" ))
105+ .certificateFilePath (certificateFile )
106+ .build ();
107+ InfluxDBClient influxDBClient = InfluxDBClient .getInstance (clientConfig );
108+ Assertions .assertThatThrownBy (() -> assertGetdataSuccess (influxDBClient ))
109+ .hasMessageContaining ("PKIX path building failed" );
110+ }
111+
112+ @ Test
113+ void disableServerCertificateValidation () throws Exception {
114+ String wrongCertificateFile = "src/test/java/com/influxdb/v3/client/testdata/docker.com.pem" ;
115+
116+ ClientConfig clientConfig = new ClientConfig .Builder ()
117+ .host (System .getenv ("TESTING_INFLUXDB_URL" ))
118+ .token (System .getenv ("TESTING_INFLUXDB_TOKEN" ).toCharArray ())
119+ .database (System .getenv ("TESTING_INFLUXDB_DATABASE" ))
120+ .disableServerCertificateValidation (true )
121+ .certificateFilePath (wrongCertificateFile )
122+ .build ();
123+
124+ // Test succeeded with wrong certificate file because disableServerCertificateValidation is true
125+ InfluxDBClient influxDBClient = InfluxDBClient .getInstance (clientConfig );
126+ assertGetdataSuccess (influxDBClient );
127+ }
128+
83129 @ Test
84130 void withProxyUrl () {
85131 String proxyUrl = "http://127.0.0.1:10000" ;
@@ -234,4 +280,17 @@ public void testQuery() throws Exception {
234280 }
235281 }
236282 }
283+
284+ private void assertGetdataSuccess (InfluxDBClient influxDBClient ) throws Exception {
285+ influxDBClient .writePoint (
286+ Point .measurement ("test1" )
287+ .setField ("field" , "field1" )
288+ );
289+ try (Stream <PointValues > stream = influxDBClient .queryPoints ("SELECT * FROM test1" )) {
290+ stream .findFirst ()
291+ .ifPresent (pointValues -> {
292+ Assertions .assertThat (pointValues .getField ("field" )).isEqualTo ("field1" );
293+ });
294+ }
295+ }
237296}
0 commit comments