Skip to content

DATAMONGO-2016 fixing issue where question mark in password broke option extraction #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*
* @author Christoph Strobl
* @author Oliver Gierke
* @author Stephen Tyler Conrad
* @since 1.7
*/
public class MongoCredentialPropertyEditor extends PropertyEditorSupport {
Expand Down Expand Up @@ -164,7 +165,7 @@ private static String extractDB(String text) {
private static Properties extractOptions(String text) {

int optionsSeparationIndex = text.lastIndexOf(OPTIONS_DELIMITER);
int dbSeparationIndex = text.lastIndexOf(OPTIONS_DELIMITER);
int dbSeparationIndex = text.lastIndexOf(DATABASE_DELIMITER);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line in the source jumped out at me as a possible copy/paste error. changing the delimiter we check for fixed the issue


if (optionsSeparationIndex == -1 || dbSeparationIndex > optionsSeparationIndex) {
return new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Unit tests for {@link MongoCredentialPropertyEditor}.
*
* @author Christoph Strobl
* @author Stephen Tyler Conrad
*/
public class MongoCredentialPropertyEditorUnitTests {

Expand All @@ -54,6 +55,10 @@ public class MongoCredentialPropertyEditorUnitTests {
static final String USER_4_ENCODED_PWD;
static final String USER_4_DB = "targaryen";

static final String USER_5_NAME = "lyanna";
static final String USER_5_PWD = "random?password";
static final String USER_5_DB = "mormont";

static final String USER_1_AUTH_STRING = USER_1_NAME + ":" + USER_1_PWD + "@" + USER_1_DB;
static final String USER_1_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM = USER_1_AUTH_STRING + "?uri.authMechanism=PLAIN";

Expand All @@ -66,6 +71,9 @@ public class MongoCredentialPropertyEditorUnitTests {

static final String USER_4_AUTH_STRING;

static final String USER_5_AUTH_STRING = USER_5_NAME + ":" + USER_5_PWD + "@" + USER_5_DB;
static final String USER_5_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM = USER_5_AUTH_STRING + "?uri.authMechanism=PLAIN";

static final MongoCredential USER_1_CREDENTIALS = MongoCredential.createCredential(USER_1_NAME, USER_1_DB,
USER_1_PWD.toCharArray());
static final MongoCredential USER_1_CREDENTIALS_PLAIN_AUTH = MongoCredential.createPlainCredential(USER_1_NAME,
Expand All @@ -81,6 +89,11 @@ public class MongoCredentialPropertyEditorUnitTests {
static final MongoCredential USER_4_CREDENTIALS = MongoCredential.createCredential(USER_4_PLAIN_NAME, USER_4_DB,
USER_4_PLAIN_PWD.toCharArray());

static final MongoCredential USER_5_CREDENTIALS = MongoCredential.createCredential(USER_5_NAME, USER_5_DB,
USER_5_PWD.toCharArray());
static final MongoCredential USER_5_CREDENTIALS_PLAIN_AUTH = MongoCredential.createPlainCredential(USER_5_NAME, USER_5_DB,
USER_5_PWD.toCharArray());

MongoCredentialPropertyEditor editor;

static {
Expand Down Expand Up @@ -239,4 +252,22 @@ public void encodedUserNameAndPasswrodShouldBeDecoded() throws UnsupportedEncodi

assertThat((List<MongoCredential>) editor.getValue(), contains(USER_4_CREDENTIALS));
}

@Test //DATAMONGO-2016
@SuppressWarnings("unchecked")
public void passwordWithQuestionMarkShouldNotBeInterpretedAsOptionString() {

editor.setAsText(USER_5_AUTH_STRING);

assertThat((List<MongoCredential>) editor.getValue(), contains(USER_5_CREDENTIALS));
}

@Test //DATAMONGO-2016
@SuppressWarnings("unchecked")
public void passwordWithQuestionMarkShouldNotBreakParsingOfOptionString() {

editor.setAsText(USER_5_AUTH_STRING_WITH_PLAIN_AUTH_MECHANISM);

assertThat((List<MongoCredential>) editor.getValue(), contains(USER_5_CREDENTIALS_PLAIN_AUTH));
}
}