27
27
28
28
import ch .qos .logback .classic .Level ;
29
29
import ch .qos .logback .classic .spi .ILoggingEvent ;
30
+ import com .datastax .oss .driver .api .core .AllNodesFailedException ;
30
31
import com .datastax .oss .driver .api .core .CqlSession ;
32
+ import com .datastax .oss .driver .api .core .auth .AuthenticationException ;
31
33
import com .datastax .oss .driver .api .core .config .DefaultDriverOption ;
32
34
import com .datastax .oss .driver .api .core .config .DriverConfigLoader ;
33
35
import com .datastax .oss .driver .api .core .cql .ResultSet ;
34
36
import com .datastax .oss .driver .api .core .session .SessionBuilder ;
35
37
import com .datastax .oss .driver .api .testinfra .session .SessionUtils ;
36
38
import com .datastax .oss .driver .categories .IsolatedTests ;
39
+ import com .datastax .oss .driver .internal .core .config .cloud .CloudConfigFactory ;
37
40
import com .datastax .oss .driver .internal .core .ssl .DefaultSslEngineFactory ;
38
41
import com .datastax .oss .driver .internal .core .util .LoggerTest ;
39
42
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
45
48
import java .nio .file .Path ;
46
49
import java .security .NoSuchAlgorithmException ;
47
50
import java .util .Collections ;
51
+ import java .util .List ;
48
52
import javax .net .ssl .SSLContext ;
49
53
import org .junit .ClassRule ;
50
54
import org .junit .Rule ;
@@ -67,12 +71,57 @@ public class CloudIT {
67
71
public void should_connect_to_proxy_using_path () {
68
72
ResultSet set ;
69
73
Path bundle = proxyRule .getProxy ().getDefaultBundlePath ();
70
- try (CqlSession session = CqlSession .builder ().withCloudSecureConnectBundle (bundle ).build ()) {
74
+ try (CqlSession session =
75
+ CqlSession .builder ()
76
+ .withAuthCredentials ("cassandra" , "cassandra" )
77
+ .withCloudSecureConnectBundle (bundle )
78
+ .build ()) {
71
79
set = session .execute ("select * from system.local" );
72
80
}
73
81
assertThat (set ).isNotNull ();
74
82
}
75
83
84
+ @ Test
85
+ public void should_connect_and_log_info_that_config_json_with_username_password_was_provided () {
86
+ ResultSet set ;
87
+ Path bundle = proxyRule .getProxy ().getDefaultBundlePath ();
88
+ LoggerTest .LoggerSetup logger = setupTestLogger (CloudConfigFactory .class , Level .INFO );
89
+
90
+ try (CqlSession session =
91
+ CqlSession .builder ()
92
+ .withAuthCredentials ("cassandra" , "cassandra" )
93
+ .withCloudSecureConnectBundle (bundle )
94
+ .build ()) {
95
+ set = session .execute ("select * from system.local" );
96
+ verify (logger .appender , timeout (500 ).atLeast (1 ))
97
+ .doAppend (logger .loggingEventCaptor .capture ());
98
+ assertThat (
99
+ logger .loggingEventCaptor .getAllValues ().stream ()
100
+ .map (ILoggingEvent ::getFormattedMessage ))
101
+ .contains (
102
+ "The bundle contains config.json with username and/or password. Providing it in the bundle is deprecated and ignored." );
103
+ }
104
+ assertThat (set ).isNotNull ();
105
+ }
106
+
107
+ @ Test
108
+ public void
109
+ should_fail_with_auth_error_when_connecting_using_bundle_with_username_password_in_config_json () {
110
+ Path bundle = proxyRule .getProxy ().getDefaultBundlePath ();
111
+
112
+ // fails with auth error because username/password from config.json is ignored
113
+ AllNodesFailedException exception = null ;
114
+ try {
115
+ CqlSession .builder ().withCloudSecureConnectBundle (bundle ).build ();
116
+ } catch (AllNodesFailedException ex ) {
117
+ exception = ex ;
118
+ }
119
+ assertThat (exception ).isNotNull ();
120
+ List <Throwable > errors = exception .getAllErrors ().values ().iterator ().next ();
121
+ Throwable firstError = errors .get (0 );
122
+ assertThat (firstError ).isInstanceOf (AuthenticationException .class );
123
+ }
124
+
76
125
@ Test
77
126
public void should_connect_to_proxy_without_credentials () {
78
127
ResultSet set ;
@@ -91,7 +140,11 @@ public void should_connect_to_proxy_without_credentials() {
91
140
public void should_connect_to_proxy_using_non_normalized_path () {
92
141
Path bundle = proxyRule .getProxy ().getBundlesRootPath ().resolve ("../bundles/creds-v1.zip" );
93
142
ResultSet set ;
94
- try (CqlSession session = CqlSession .builder ().withCloudSecureConnectBundle (bundle ).build ()) {
143
+ try (CqlSession session =
144
+ CqlSession .builder ()
145
+ .withAuthCredentials ("cassandra" , "cassandra" )
146
+ .withCloudSecureConnectBundle (bundle )
147
+ .build ()) {
95
148
set = session .execute ("select * from system.local" );
96
149
}
97
150
assertThat (set ).isNotNull ();
@@ -101,7 +154,11 @@ public void should_connect_to_proxy_using_non_normalized_path() {
101
154
public void should_connect_to_proxy_using_input_stream () throws IOException {
102
155
InputStream bundle = Files .newInputStream (proxyRule .getProxy ().getDefaultBundlePath ());
103
156
ResultSet set ;
104
- try (CqlSession session = CqlSession .builder ().withCloudSecureConnectBundle (bundle ).build ()) {
157
+ try (CqlSession session =
158
+ CqlSession .builder ()
159
+ .withAuthCredentials ("cassandra" , "cassandra" )
160
+ .withCloudSecureConnectBundle (bundle )
161
+ .build ()) {
105
162
set = session .execute ("select * from system.local" );
106
163
}
107
164
assertThat (set ).isNotNull ();
@@ -124,7 +181,10 @@ public void should_connect_to_proxy_using_URL() throws IOException {
124
181
// when
125
182
ResultSet set ;
126
183
try (CqlSession session =
127
- CqlSession .builder ().withCloudSecureConnectBundle (bundleUrl ).build ()) {
184
+ CqlSession .builder ()
185
+ .withAuthCredentials ("cassandra" , "cassandra" )
186
+ .withCloudSecureConnectBundle (bundleUrl )
187
+ .build ()) {
128
188
129
189
// then
130
190
set = session .execute ("select * from system.local" );
@@ -142,7 +202,11 @@ public void should_connect_to_proxy_using_absolute_path_provided_in_the_session_
142
202
.build ();
143
203
// when
144
204
ResultSet set ;
145
- try (CqlSession session = CqlSession .builder ().withConfigLoader (loader ).build ()) {
205
+ try (CqlSession session =
206
+ CqlSession .builder ()
207
+ .withAuthCredentials ("cassandra" , "cassandra" )
208
+ .withConfigLoader (loader )
209
+ .build ()) {
146
210
147
211
// then
148
212
set = session .execute ("select * from system.local" );
@@ -161,7 +225,11 @@ public void should_connect_to_proxy_using_non_normalized_path_provided_in_the_se
161
225
.build ();
162
226
// when
163
227
ResultSet set ;
164
- try (CqlSession session = CqlSession .builder ().withConfigLoader (loader ).build ()) {
228
+ try (CqlSession session =
229
+ CqlSession .builder ()
230
+ .withAuthCredentials ("cassandra" , "cassandra" )
231
+ .withConfigLoader (loader )
232
+ .build ()) {
165
233
166
234
// then
167
235
set = session .execute ("select * from system.local" );
@@ -180,7 +248,11 @@ public void should_connect_to_proxy_using_non_normalized_path_provided_in_the_se
180
248
.build ();
181
249
// when
182
250
ResultSet set ;
183
- try (CqlSession session = CqlSession .builder ().withConfigLoader (loader ).build ()) {
251
+ try (CqlSession session =
252
+ CqlSession .builder ()
253
+ .withAuthCredentials ("cassandra" , "cassandra" )
254
+ .withConfigLoader (loader )
255
+ .build ()) {
184
256
185
257
// then
186
258
set = session .execute ("select * from system.local" );
@@ -207,7 +279,11 @@ public void should_connect_to_proxy_using_url_with_http_protocol_provided_in_the
207
279
.build ();
208
280
// when
209
281
ResultSet set ;
210
- try (CqlSession session = CqlSession .builder ().withConfigLoader (loader ).build ()) {
282
+ try (CqlSession session =
283
+ CqlSession .builder ()
284
+ .withAuthCredentials ("cassandra" , "cassandra" )
285
+ .withConfigLoader (loader )
286
+ .build ()) {
211
287
212
288
// then
213
289
set = session .execute ("select * from system.local" );
0 commit comments