Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
.idea/
build
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

# IntelliJ
.idea/
*.iml

# VS Code
.vscode

# macOS
.DS_Store
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.12.262</version>
<version>1.12.264</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
Expand Down Expand Up @@ -114,6 +114,7 @@
</configuration>
<executions>
<execution>
<?m2e execute onConfiguration,onIncremental?>
<id>validate</id>
<phase>validate</phase>
<goals>
Expand All @@ -133,6 +134,7 @@
</configuration>
<executions>
<execution>
<?m2e execute onConfiguration,onIncremental?>
<id>analyze-compile</id>
<phase>compile</phase>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public SecretCacheObject(final String secretId,
public abstract int hashCode();
public abstract String toString();

protected <T extends AmazonWebServiceRequest> T updateUserAgent(T request) {
protected <U extends AmazonWebServiceRequest> U updateUserAgent(U request) {
request.getRequestClientOptions().appendUserAgent(VersionInfo.USER_AGENT);
return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private static void repeat(int number, IntConsumer c) {
public void exceptionSecretCacheTest() {
SecretCache sc = new SecretCache();
sc.getSecretString("");
sc.close();
}

@Test(expectedExceptions = {SdkClientException.class})
Expand All @@ -87,9 +88,11 @@ public void secretCacheConstructorTest() {
SecretCache sc2 = null;
try {
sc1 = new SecretCache((SecretCacheConfiguration)null);
sc1.close();
} catch (Exception e) {}
try {
sc2 = new SecretCache((AWSSecretsManagerClientBuilder)null);
sc2.close();
} catch (Exception e) {}
}

Expand Down Expand Up @@ -150,6 +153,7 @@ public Object get(final Object o) {
repeat(10, n -> Assert.assertEquals(sc.getSecretBinary(""),
ByteBuffer.wrap(secret.getBytes())));
Assert.assertEquals(hook.getCount(), 2);
sc.close();
}

@Test
Expand All @@ -172,6 +176,7 @@ public void secretCacheNullStagesTest() {

repeat(10, n -> Assert.assertEquals(sc.getSecretBinary(""),
ByteBuffer.wrap(secret.getBytes())));
sc.close();
}

@Test
Expand All @@ -198,6 +203,7 @@ public void basicSecretCacheRefreshNowTest() throws Throwable {
repeat(10, n -> Assert.assertEquals(sc.getSecretString(""), secret));
Mockito.verify(asm, Mockito.times(2)).describeSecret(Mockito.any());
Mockito.verify(asm, Mockito.times(1)).getSecretValue(Mockito.any());
sc.close();
}

@Test
Expand All @@ -221,6 +227,7 @@ public void basicSecretCacheByteBufferTest() {

repeat(10, n -> Assert.assertEquals(sc.getSecretBinary(""),
ByteBuffer.wrap(secret.getBytes())));
sc.close();
}

@Test
Expand All @@ -242,6 +249,7 @@ public void basicSecretCacheMultipleTest() {
// Verify that multiple requests did not call the API
Mockito.verify(asm, Mockito.times(2)).describeSecret(Mockito.any());
Mockito.verify(asm, Mockito.times(2)).getSecretValue(Mockito.any());
sc.close();
}

@Test
Expand Down Expand Up @@ -312,30 +320,30 @@ public void basicSecretCacheTestNoVersions() {
// Verify that multiple requests did not call the API
Mockito.verify(asm, Mockito.times(1)).describeSecret(Mockito.any());
Mockito.verify(asm, Mockito.times(0)).getSecretValue(Mockito.any());
sc.close();
}

@Test(expectedExceptions = {RuntimeException.class})
public void basicSecretCacheExceptionTest() {
final String secret = "basicSecretCacheExceptionTest";
Mockito.when(asm.describeSecret(Mockito.any())).thenThrow(new RuntimeException());
SecretCache sc = new SecretCache(asm);
sc.getSecretString("");
sc.close();
}

@Test
public void basicSecretCacheExceptionRefreshNowTest() throws Throwable {
final String secret = "basicSecretCacheExceptionTest";
Mockito.when(asm.describeSecret(Mockito.any())).thenThrow(new RuntimeException());
SecretCache sc = new SecretCache(asm);
Assert.assertFalse(sc.refreshNow(""));
Mockito.verify(asm, Mockito.times(1)).describeSecret(Mockito.any());
Assert.assertFalse(sc.refreshNow(""));
Mockito.verify(asm, Mockito.times(2)).describeSecret(Mockito.any());
sc.close();
}

@Test
public void basicSecretCacheExceptionRetryTest() throws Throwable {
final String secret = "basicSecretCacheExceptionTest";
final int retryCount = 10;
Mockito.when(asm.describeSecret(Mockito.any())).thenThrow(new RuntimeException());
SecretCache sc = new SecretCache(asm);
Expand All @@ -357,22 +365,23 @@ public void basicSecretCacheExceptionRetryTest() throws Throwable {
} catch (RuntimeException ex) {}
// The api call should have been retried after the delay.
Mockito.verify(asm, Mockito.times(2)).describeSecret(Mockito.any());
sc.close();
}

@Test
public void basicSecretCacheNullTest() {
final String secret = "basicSecretCacheNullTest";
Mockito.when(asm.describeSecret(Mockito.any())).thenReturn(null);
SecretCache sc = new SecretCache(asm);
Assert.assertNull(sc.getSecretString(""));
sc.close();
}

@Test
public void basicSecretCacheNullStagesTest() {
final String secret = "basicSecretCacheNullStagesTest";
Mockito.when(describeSecretResult.getVersionIdsToStages()).thenReturn(null);
SecretCache sc = new SecretCache(asm);
Assert.assertNull(sc.getSecretString(""));
sc.close();
}

@Test
Expand All @@ -390,6 +399,7 @@ public void basicSecretCacheVersionWithNullStageTest() {
// Verify that multiple requests did not call the API
Mockito.verify(asm, Mockito.times(1)).describeSecret(Mockito.any());
Mockito.verify(asm, Mockito.times(0)).getSecretValue(Mockito.any());
sc.close();
}

}