Skip to content

Commit

Permalink
Merge pull request #3 from aws/develop
Browse files Browse the repository at this point in the history
Correctly handle JDBC urls
  • Loading branch information
willtong1234 authored Dec 5, 2018
2 parents 754f58e + e2cc1b4 commit 2823ced
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

### Release 1.0.1 (December 5, 2018)
* Fixed an issue with the way JDBC URLs are handled:
* acceptsURL() now returns false if the URL is a JDBC URL that does not begin with jdbc-secretsmanager
* connect() returns null if the URL parameter is not one we accept
* Updated jackson-databind dependency to 2.8.11.1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The recommended way to use the SQL Connection Library is to consume it from Mave
<dependency>
<groupId>com.amazonaws.secretsmanager</groupId>
<artifactId>aws-secretsmanager-jdbc</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
```

Expand Down Expand Up @@ -88,4 +88,4 @@ The secret being used should be in the JSON format we use for our rotation lambd
"password": "pass",
...
}
```
```
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<artifactId>aws-secretsmanager-jdbc</artifactId>
<packaging>jar</packaging>
<name>AWS Secrets Manager SQL Connection Library</name>
<version>1.0.0</version>
<version>1.0.1</version>
<description>The AWS Secrets Manager SQL Connection Library for Java enables Java developers to easily
connect to SQL databases using secrets stored in AWS Secrets Manager.
</description>
Expand All @@ -28,7 +28,7 @@
<aws-java-sdk.version>1.11.418</aws-java-sdk.version>
<aws-secretsmanager-cache.version>1.0.0</aws-secretsmanager-cache.version>
<lombok.version>1.16.20</lombok.version>
<jackson.version>2.6.7</jackson.version>
<jackson.version>2.8.11.1</jackson.version>
<junit.version>4.11</junit.version>
<mockito.version>1.10.19</mockito.version>
<powermock.version>1.6.6</powermock.version>
Expand Down Expand Up @@ -237,7 +237,7 @@
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://oss.sonatype.org</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ public boolean acceptsURL(String url) throws SQLException {
}

if (url.startsWith(SCHEME)) {
// If this is a URL in our SCHEME, call the accpetsURL method of the wrapped driver
// If this is a URL in our SCHEME, call the acceptsURL method of the wrapped driver
return getWrappedDriver().acceptsURL(unwrapUrl(url));
} else if (url.startsWith("jdbc:")) {
// For any other JDBC URL, return false
return false;
} else {
// We accept a secret ID as the URL so if the config is set, and it's not a JDBC URL, return true
return true;
Expand Down Expand Up @@ -342,8 +345,8 @@ private Connection connectWithSecret(String unwrappedUrl, Properties info, Strin

@Override
public Connection connect(String url, Properties info) throws SQLException {
if (url == null) {
throw new SQLException("url cannot be null.");
if (!acceptsURL(url)) {
return null;
}

String unwrappedUrl = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package com.amazonaws.secretsmanager.sql;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
Expand Down Expand Up @@ -180,6 +181,12 @@ public void test_acceptsURL_returnsTrue_correctURL() {
assertEquals(1, DummyDriver.acceptsURLCallCount);
}

@Test
public void test_acceptsURL_returnsFalse_JdbcUrl() {
assertNotThrows(() -> assertFalse(sut.acceptsURL("jdbc:expectedUrl")));
assertEquals(0, DummyDriver.acceptsURLCallCount);
}

@Test
public void test_acceptsURL_returnsTrue_secretId() {
assertNotThrows(() -> assertTrue(sut.acceptsURL("someSecretId")));
Expand Down Expand Up @@ -216,6 +223,12 @@ public void test_connect_works_valid_url() {
assertEquals(1, DummyDriver.connectCallCount);
}

@Test
public void test_connect_jdbc_returnsNull() throws SQLException {
Connection conn = sut.connect("jdbc:expectedUrl", null);
assertEquals(conn, null);
}

@Test
public void test_connect_works_secretId() {
Properties props = new Properties();
Expand Down

0 comments on commit 2823ced

Please sign in to comment.