22
33import com .clickhouse .client .api .enums .SSLMode ;
44import org .testng .Assert ;
5+ import org .testng .annotations .DataProvider ;
56import org .testng .annotations .Test ;
67
78import java .lang .reflect .Field ;
@@ -23,6 +24,44 @@ public void testAddEndpointToleratesUnderscoreHostname() throws Exception {
2324 }
2425 }
2526
27+ @ Test (dataProvider = "testSslModeViaString_DP" )
28+ public void testSslModeViaString (String modeStr , SSLMode mode ) {
29+ try (Client client = new Client .Builder ()
30+ .addEndpoint ("http://localhost:8123" )
31+ .setUsername ("default" )
32+ .setPassword ("" )
33+ .setOption (ClientConfigProperties .SSL_MODE .getKey (), modeStr )
34+ .build ()) {
35+ Assert .assertEquals (client .getConfiguration ().get (ClientConfigProperties .SSL_MODE .getKey ()),
36+ mode .name ());
37+ }
38+
39+ try (Client client = new Client .Builder ()
40+ .addEndpoint ("http://localhost:8123" )
41+ .setUsername ("default" )
42+ .setPassword ("" )
43+ .setSSLMode (mode )
44+ .build ()) {
45+ Assert .assertEquals (client .getConfiguration ().get (ClientConfigProperties .SSL_MODE .getKey ()),
46+ mode .name ());
47+ }
48+ }
49+
50+ @ DataProvider
51+ public static Object [][] testSslModeViaString_DP () {
52+ return new Object [][] {
53+ {"DISABLED" , SSLMode .DISABLED },
54+ {"disabled" , SSLMode .DISABLED },
55+ {"TRUST" , SSLMode .TRUST },
56+ {"trust" , SSLMode .TRUST },
57+ {"VERIFY_CA" , SSLMode .VERIFY_CA },
58+ {"verify_ca" , SSLMode .VERIFY_CA },
59+ {"STRICT" , SSLMode .STRICT },
60+ {"strict" , SSLMode .STRICT },
61+ };
62+ }
63+
64+
2665 @ Test
2766 public void testSslModeDisabledRejectedForHttpsRegardlessOfCase () {
2867 // Value supplied as a raw (non-canonical case) string via setOption must still be recognized
@@ -43,24 +82,10 @@ public void testSslModeInvalidValueRejected() {
4382 .addEndpoint ("https://localhost:8443" )
4483 .setUsername ("default" )
4584 .setPassword ("" )
46- .setOption (ClientConfigProperties .SSL_MODE .getKey (), "insecure " )
85+ .setOption (ClientConfigProperties .SSL_MODE .getKey (), "verify-ca " )
4786 .build ());
4887 }
4988
50- @ Test
51- public void testSslModeNormalizedToCanonicalName () throws Exception {
52- // A non-canonical case value is accepted and normalized to the canonical enum name.
53- try (Client client = new Client .Builder ()
54- .addEndpoint ("http://localhost:8123" )
55- .setUsername ("default" )
56- .setPassword ("" )
57- .setOption (ClientConfigProperties .SSL_MODE .getKey (), "trust" )
58- .build ()) {
59- Assert .assertEquals (client .getConfiguration ().get (ClientConfigProperties .SSL_MODE .getKey ()),
60- SSLMode .TRUST .name ());
61- }
62- }
63-
6489 private static String extractFirstEndpointUri (Client client ) throws Exception {
6590 Field endpointsField = Client .class .getDeclaredField ("endpoints" );
6691 endpointsField .setAccessible (true );
0 commit comments