@@ -63,6 +63,7 @@ public class MongoCredentialPropertyEditorUnitTests {
63
63
64
64
static final String USER_5_AUTH_STRING = USER_5_NAME + ":" + USER_5_PWD + "@" + USER_5_DB ;
65
65
static final String USER_5_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM = USER_5_AUTH_STRING + "?uri.authMechanism=PLAIN" ;
66
+ static final String USER_5_AUTH_STRING_WITH_QUERY_ARGS = USER_5_AUTH_STRING + "?uri.authMechanism=PLAIN&foo=&bar" ;
66
67
67
68
static final MongoCredential USER_1_CREDENTIALS = MongoCredential .createCredential (USER_1_NAME , USER_1_DB ,
68
69
USER_1_PWD .toCharArray ());
@@ -78,8 +79,8 @@ public class MongoCredentialPropertyEditorUnitTests {
78
79
79
80
static final MongoCredential USER_5_CREDENTIALS = MongoCredential .createCredential (USER_5_NAME , USER_5_DB ,
80
81
USER_5_PWD .toCharArray ());
81
- static final MongoCredential USER_5_CREDENTIALS_PLAIN_AUTH = MongoCredential .createPlainCredential (USER_5_NAME , USER_5_DB ,
82
- USER_5_PWD .toCharArray ());
82
+ static final MongoCredential USER_5_CREDENTIALS_PLAIN_AUTH = MongoCredential .createPlainCredential (USER_5_NAME ,
83
+ USER_5_DB , USER_5_PWD .toCharArray ());
83
84
84
85
MongoCredentialPropertyEditor editor ;
85
86
@@ -146,8 +147,8 @@ public void shouldReturnCredentialsValueCorrectlyWhenGivenMultipleUserNamePasswo
146
147
@ SuppressWarnings ("unchecked" )
147
148
public void shouldReturnCredentialsValueCorrectlyWhenGivenMultipleUserNamePasswordStringWithDatabaseAndAuthOptions () {
148
149
149
- editor .setAsText (StringUtils .collectionToCommaDelimitedString (Arrays . asList (
150
- USER_1_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM , USER_2_AUTH_STRING_WITH_MONGODB_CR_AUTH_MECHANISM )));
150
+ editor .setAsText (StringUtils .collectionToCommaDelimitedString (Arrays
151
+ . asList ( USER_1_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM , USER_2_AUTH_STRING_WITH_MONGODB_CR_AUTH_MECHANISM )));
151
152
152
153
assertThat ((List <MongoCredential >) editor .getValue (),
153
154
contains (USER_1_CREDENTIALS_PLAIN_AUTH , USER_2_CREDENTIALS_CR_AUTH ));
@@ -157,8 +158,8 @@ public void shouldReturnCredentialsValueCorrectlyWhenGivenMultipleUserNamePasswo
157
158
@ SuppressWarnings ("unchecked" )
158
159
public void shouldReturnCredentialsValueCorrectlyWhenGivenMultipleUserNamePasswordStringWithDatabaseAndMixedOptions () {
159
160
160
- editor .setAsText (StringUtils .collectionToCommaDelimitedString (Arrays . asList (
161
- USER_1_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM , USER_2_AUTH_STRING )));
161
+ editor .setAsText (StringUtils .collectionToCommaDelimitedString (
162
+ Arrays . asList ( USER_1_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM , USER_2_AUTH_STRING )));
162
163
163
164
assertThat ((List <MongoCredential >) editor .getValue (), contains (USER_1_CREDENTIALS_PLAIN_AUTH , USER_2_CREDENTIALS ));
164
165
}
@@ -167,8 +168,8 @@ public void shouldReturnCredentialsValueCorrectlyWhenGivenMultipleUserNamePasswo
167
168
@ SuppressWarnings ("unchecked" )
168
169
public void shouldReturnCredentialsValueCorrectlyWhenGivenMultipleQuotedUserNamePasswordStringWithDatabaseAndNoOptions () {
169
170
170
- editor .setAsText (StringUtils .collectionToCommaDelimitedString (Arrays . asList ( "'" + USER_1_AUTH_STRING + "'" , "'"
171
- + USER_2_AUTH_STRING + "'" )));
171
+ editor .setAsText (StringUtils .collectionToCommaDelimitedString (
172
+ Arrays . asList ( "'" + USER_1_AUTH_STRING + "'" , "'" + USER_2_AUTH_STRING + "'" )));
172
173
173
174
assertThat ((List <MongoCredential >) editor .getValue (), contains (USER_1_CREDENTIALS , USER_2_CREDENTIALS ));
174
175
}
@@ -197,7 +198,8 @@ public void shouldReturnX509CredentialsCorrectlyWhenNoDbSpecified() {
197
198
198
199
editor .setAsText ("tyrion?uri.authMechanism=MONGODB-X509" );
199
200
200
- assertThat ((List <MongoCredential >) editor .getValue (), contains (MongoCredential .createMongoX509Credential ("tyrion" )));
201
+ assertThat ((List <MongoCredential >) editor .getValue (),
202
+ contains (MongoCredential .createMongoX509Credential ("tyrion" )));
201
203
}
202
204
203
205
@ Test (expected = IllegalArgumentException .class ) // DATAMONGO-1257
@@ -225,12 +227,18 @@ public void passwordWithQuestionMarkShouldNotBeInterpretedAsOptionString() {
225
227
assertThat ((List <MongoCredential >) editor .getValue (), contains (USER_5_CREDENTIALS ));
226
228
}
227
229
228
- @ Test //DATAMONGO-2016
230
+ @ Test // DATAMONGO-2016
229
231
@ SuppressWarnings ("unchecked" )
230
232
public void passwordWithQuestionMarkShouldNotBreakParsingOfOptionString () {
231
233
232
234
editor .setAsText (USER_5_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM );
233
235
234
236
assertThat ((List <MongoCredential >) editor .getValue (), contains (USER_5_CREDENTIALS_PLAIN_AUTH ));
235
237
}
238
+
239
+ @ Test (expected = IllegalArgumentException .class ) // DATAMONGO-2016
240
+ @ SuppressWarnings ("unchecked" )
241
+ public void failsGracefullyOnEmptyQueryArgument () {
242
+ editor .setAsText (USER_5_AUTH_STRING_WITH_QUERY_ARGS );
243
+ }
236
244
}
0 commit comments