Skip to content

Commit

Permalink
[CONJ-934] MariaDbDataSource is sensitive to the order of setting of …
Browse files Browse the repository at this point in the history
…username and password
  • Loading branch information
rusher committed Mar 3, 2022
1 parent 3d92551 commit abc89b6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/mariadb/jdbc/MariaDbDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ private void config() throws SQLException {
if (url == null) throw new SQLException("url not set");
conf = Configuration.parse(url);
if (loginTimeout != null) conf.connectTimeout(loginTimeout * 1000);
if (user != null) {
if (user != null || password != null) {
conf = conf.clone(user, password);
} else {
}
if (user != null) {
user = conf.user();
}
if (password != null) {
password = conf.password();
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/mariadb/jdbc/MariaDbPoolDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ private void config() throws SQLException {
if (url == null) throw new SQLException("url not set");
conf = Configuration.parse(url);
if (loginTimeout != null) conf.connectTimeout(loginTimeout * 1000);
if (user != null) {
if (user != null || password != null) {
conf = conf.clone(user, password);
} else {
}
if (user != null) {
user = conf.user();
}
if (password != null) {
password = conf.password();
}

pool = Pools.retrievePool(conf);
}

Expand Down Expand Up @@ -268,15 +272,6 @@ public void setUser(String user) throws SQLException {
if (conf != null) config();
}

/**
* get password
*
* @return password
*/
public String getPassword() {
return password;
}

/**
* set password
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public void basic() throws SQLException {
ds = new MariaDbDataSource();
ds.setUrl(mDefUrl);
testDs(ds);

ds = new MariaDbDataSource();
ds.setPassword("ttt");
ds.setUrl(mDefUrl);
assertThrows(SQLException.class, ds::getConnection);
}

private void testDs(MariaDbDataSource ds) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public void basic2() throws SQLException {
MariaDbPoolDataSource ds = new MariaDbPoolDataSource();
assertNull(ds.getUrl());
assertNull(ds.getUser());
assertNull(ds.getPassword());
assertEquals(30, ds.getLoginTimeout());
DriverManager.setLoginTimeout(40);
assertEquals(40, ds.getLoginTimeout());
Expand All @@ -162,7 +161,6 @@ public void basic2() throws SQLException {
assertEquals("dd", ds.getUser());

ds.setPassword("pwd");
assertEquals("pwd", ds.getPassword());
assertThrows(SQLException.class, () -> ds.getConnection());
assertThrows(SQLException.class, () -> ds.getPooledConnection());

Expand Down

0 comments on commit abc89b6

Please sign in to comment.