Allow user without password in UriInfo.

This commit is contained in:
Csaba Kos
2019-06-20 13:22:59 -05:00
committed by Scott Frederick
parent 9adc1f7287
commit d510408e90
3 changed files with 13 additions and 6 deletions

View File

@@ -129,7 +129,9 @@ public class UriInfo {
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;

View File

@@ -40,10 +40,13 @@ public class StandardUriInfoFactoryTest {
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

View File

@@ -35,9 +35,11 @@ public class RelationalServiceInfoTest {
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
@@ -64,4 +66,4 @@ public class RelationalServiceInfoTest {
};
}
}
}