diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-10-28 15:14:38 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-10-28 15:20:25 +0100 |
commit | 94d7e79bcebda73213abdf1b162487a4fa021768 (patch) | |
tree | 9c1e0cab513d4cf3832a5dc3ad2bd95d4c6e2828 /vespa-athenz/src/test | |
parent | 9a6ee1f2287a679f31cb3706953dede231f13bb3 (diff) |
Move AwsCredentialsProvider to vespa-athenz
Diffstat (limited to 'vespa-athenz/src/test')
-rw-r--r-- | vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialProviderTest.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialProviderTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialProviderTest.java new file mode 100644 index 00000000000..3569f231814 --- /dev/null +++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/aws/AwsCredentialProviderTest.java @@ -0,0 +1,36 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.athenz.aws; + +import com.yahoo.vespa.athenz.api.AwsTemporaryCredentials; +import org.junit.Assert; +import org.junit.Test; + +import java.time.Clock; +import java.time.Duration; +import java.time.Instant; + +/** + * @author tokle + */ +public class AwsCredentialProviderTest { + + @Test + public void refreshes_correctly() { + Clock clock = Clock.systemUTC(); + // Does not require refresh when expires in 10 minutes + Assert.assertFalse(AwsCredentialsProvider.shouldRefresh(getCredentials(clock.instant().plus(Duration.ofMinutes(10))))); + + // Requires refresh when expires in 3 minutes + Assert.assertTrue(AwsCredentialsProvider.shouldRefresh(getCredentials(clock.instant().plus(Duration.ofMinutes(3))))); + + // Requires refresh when expired + Assert.assertTrue(AwsCredentialsProvider.shouldRefresh(getCredentials(clock.instant().minus(Duration.ofMinutes(1))))); + + // Refreshes when no credentials provided + Assert.assertTrue(AwsCredentialsProvider.shouldRefresh(null)); + } + + private AwsTemporaryCredentials getCredentials(Instant expiration) { + return new AwsTemporaryCredentials("accesskey", "secretaccesskey", "sessionToken", expiration); + } +} |