Skip to content

Commit

Permalink
Allow user without password in UriInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
csabakos authored and scottfrederick committed Jul 8, 2019
1 parent 9adc1f7 commit d510408
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Expand Up @@ -129,7 +129,9 @@ private String[] parseUserinfo(URI uri) {

if (userInfo != null) {
String[] userPass = userInfo.split(":");
if (userPass.length != 2) {
if (userPass.length == 1) {
return new String[]{userPass[0], null};
} else if (userPass.length != 2) {
throw new IllegalArgumentException("Bad userinfo in URI: " + uri);
}
return userPass;
Expand Down
Expand Up @@ -40,10 +40,13 @@ public void createNoUsernamePassword() {
assertEquals(uri, result.getUriString());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void createWithUsernameNoPassword() {
String uri = "mysql://joe@localhost:1527/big_db";
factory.createUri(uri);
UriInfo result = factory.createUri(uri);

assertUriInfoEquals(result, "localhost", 1527, "joe", null, "big_db", null);
assertEquals(uri, result.getUriString());
}

@Test
Expand Down
Expand Up @@ -35,9 +35,11 @@ public void jdbcUrlNoUsernamePassword() {
assertEquals("jdbc:jdbcdbtype://hostname:1234/database", serviceInfo.getJdbcUrl());
}

@Test(expected = java.lang.IllegalArgumentException.class)
@Test
public void jdbcUrlNoPassword() {
createServiceInfo("dbtype://username@hostname/database");
RelationalServiceInfo serviceInfo = createServiceInfo("dbtype://username@hostname/database");

assertEquals("jdbc:jdbcdbtype://hostname/database?user=username", serviceInfo.getJdbcUrl());
}

@Test
Expand All @@ -64,4 +66,4 @@ private RelationalServiceInfo createServiceInfoWithJdbcUrl(final String uri, fin
};
}

}
}

0 comments on commit d510408

Please sign in to comment.