Search in sources :

Example 36 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project fernet-java8 by l0s.

the class SecretsManagerTest method verifyAssertDoesNothing.

@Test
public final void verifyAssertDoesNothing() {
    // given
    final GetSecretValueRequest request = new GetSecretValueRequest();
    request.setSecretId("secret");
    request.setVersionStage("AWSCURRENT");
    given(delegate.getSecretValue(eq(request))).willReturn(new GetSecretValueResult());
    // when
    manager.assertCurrentStageExists("secret");
// then (nothing)
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) Test(org.junit.Test)

Example 37 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project fernet-java8 by l0s.

the class SecretsManagerTest method verifyGetSecretVersionRetrievesBinary.

@Test
public final void verifyGetSecretVersionRetrievesBinary() throws UnsupportedEncodingException {
    // given
    final GetSecretValueRequest request = new GetSecretValueRequest();
    request.setSecretId("secret");
    request.setVersionId("version");
    final GetSecretValueResult response = new GetSecretValueResult();
    response.setSecretBinary(ByteBuffer.wrap("expected".getBytes("UTF-8")));
    given(delegate.getSecretValue(eq(request))).willReturn(response);
    // when
    final ByteBuffer result = manager.getSecretVersion("secret", "version");
    // then
    final byte[] buffer = new byte[result.remaining()];
    result.get(buffer);
    assertEquals("expected", new String(buffer, "UTF-8"));
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 38 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project fernet-java8 by l0s.

the class SecretsManager method getSecretStage.

/**
 * Retrieve a specific stage of the secret.
 *
 * @param secretId the ARN of the secret
 * @param stage the stage of the secret to retrieve
 * @return the Fernet key or keys in binary form
 */
public ByteBuffer getSecretStage(final String secretId, final Stage stage) {
    final GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest();
    getSecretValueRequest.setSecretId(secretId);
    getSecretValueRequest.setVersionStage(stage.getAwsName());
    final GetSecretValueResult result = getDelegate().getSecretValue(getSecretValueRequest);
    return result.getSecretBinary();
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)

Example 39 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project JAQU-CAZ-Payments-API by InformedSolutions.

the class CredentialRetrievalManagerTest method canGetApiKeyWithOptionalWhitespaces.

@ParameterizedTest
@ValueSource(strings = { "testApiKey", " testApiKey", "testApiKey ", " testApiKey   " })
void canGetApiKeyWithOptionalWhitespaces(String apiKey) throws JsonProcessingException {
    UUID cleanAirZoneId = UUID.randomUUID();
    ObjectNode node = objectMapper.createObjectNode();
    node.put(cleanAirZoneId.toString().replace("-", ""), apiKey);
    GetSecretValueResult getSecretValueResponse = mock(GetSecretValueResult.class);
    Mockito.when(client.getSecretValue(Mockito.any(GetSecretValueRequest.class))).thenReturn(getSecretValueResponse);
    Mockito.when(getSecretValueResponse.getSecretString()).thenReturn(objectMapper.writeValueAsString(node));
    Optional<String> result = credentialRetrievalManager.getCardApiKey(cleanAirZoneId);
    assertTrue(result.isPresent());
    assertThat(result).contains("testApiKey");
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) UUID(java.util.UUID) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project JAQU-CAZ-Payments-API by InformedSolutions.

the class CredentialRetrievalManagerTest method mockAccessTokenForCaz.

@SneakyThrows
private void mockAccessTokenForCaz(UUID cazId, String accessToken) {
    GetSecretValueResult getSecretValueResponse = mock(GetSecretValueResult.class);
    Mockito.when(client.getSecretValue(Mockito.any(GetSecretValueRequest.class))).thenReturn(getSecretValueResponse);
    Mockito.when(getSecretValueResponse.getSecretString()).thenReturn(objectMapper.writeValueAsString(Collections.singletonMap(cazId.toString().replace("-", ""), accessToken)));
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) SneakyThrows(lombok.SneakyThrows)

Aggregations

GetSecretValueResult (com.amazonaws.services.secretsmanager.model.GetSecretValueResult)60 GetSecretValueRequest (com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)51 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)25 Before (org.junit.Before)21 JdbcConnectionFactory (com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory)18 JdbcCredentialProvider (com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider)18 AmazonAthena (com.amazonaws.services.athena.AmazonAthena)17 FederatedIdentity (com.amazonaws.athena.connector.lambda.security.FederatedIdentity)16 Connection (java.sql.Connection)13 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)8 AmazonS3 (com.amazonaws.services.s3.AmazonS3)6 DatabaseConnectionConfig (com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Map (java.util.Map)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 QueryStatusChecker (com.amazonaws.athena.connector.lambda.QueryStatusChecker)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IOException (java.io.IOException)3