Skip to content

Commit

Permalink
Limit use of useSSL flag to MySQL container
Browse files Browse the repository at this point in the history
Add template method allowing JDBCContainer subclasses to have a specific
form of JDBC URL used for establishing Connections.

Fixes #568
  • Loading branch information
rnorth committed Jan 31, 2018
1 parent 4edf9e2 commit 4641a7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SELF withUsername(String username) {
throw new UnsupportedOperationException();
}

public SELF withPassword(String password){
public SELF withPassword(String password) {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -127,16 +127,17 @@ public Driver getJdbcDriverInstance() {
/**
* Creates a connection to the underlying containerized database instance.
*
* @param queryString any special query string parameters that should be appended to the JDBC connection URL. The
* '?' character must be included
* @param queryString
* query string parameters that should be appended to the JDBC connection URL.
* The '?' character must be included
* @return a Connection
* @throws SQLException if there is a repeated failure to create the connection
*/
public Connection createConnection(String queryString) throws SQLException {
final Properties info = new Properties();
info.put("user", this.getUsername());
info.put("password", this.getPassword());
final String url = appendDisableSslConfig(this.getJdbcUrl() + queryString);
final String url = constructUrlForConnection(queryString);

final Driver jdbcDriverInstance = getJdbcDriverInstance();

Expand All @@ -147,9 +148,18 @@ public Connection createConnection(String queryString) throws SQLException {
}
}

private String appendDisableSslConfig(String connectionString){
String separator = connectionString.contains("?") ? "&" : "?";
return connectionString + separator + "useSSL=false";
/**
* Template method for constructing the JDBC URL to be used for creating {@link Connection}s.
* This should be overridden if the JDBC URL and query string concatenation or URL string
* construction needs to be different to normal.
*
* @param queryString
* query string parameters that should be appended to the JDBC connection URL.
* The '?' character must be included
* @return a full JDBC URL including queryString
*/
protected String constructUrlForConnection(String queryString) {
return getJdbcUrl() + queryString;
}

protected void optionallyMapResourceParameterAsVolume(@NotNull String paramName, @NotNull String pathNameInContainer, @NotNull String defaultResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public String getJdbcUrl() {
return "jdbc:mysql://" + getContainerIpAddress() + ":" + getMappedPort(MYSQL_PORT) + "/" + databaseName;
}

@Override
protected String constructUrlForConnection(String queryString) {
String separator = queryString.contains("?") ? "&" : "?";
return getJdbcUrl() + separator + "useSSL=false";
}

@Override
public String getDatabaseName() {
return databaseName;
Expand Down

0 comments on commit 4641a7e

Please sign in to comment.