0

I need to unit test AWS secret manager that is in Java and am using Mockito and EasyMock to do that and whenever I call client.getSecretValue(), it is trowing the exception Code to be tested

AWSSecretsManagerClient client =
            (AWSSecretsManagerClient) 
AWSSecretsManagerClientBuilder.standard().withRegion(region).build();

    String secret = null, decodedBinarySecret = null;
    GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest().withSecretId(secretName);
    GetSecretValueResult getSecretValueResult = null;
    AWSSecrets awsSecrets = null;
    try {
        getSecretValueResult = client.getSecretValue(getSecretValueRequest);
    } catch (DecryptionFailureException e) {

Exception

 "com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), com.amazonaws.auth.profile.ProfileCredentialsProvider@28ce75ec: Unable to load credentials into profile [default]: AWS Access Key ID is not specified., WebIdentityTokenCredentialsProvider: To use assume role profiles the aws-java-sdk-sts module must be on the class path., com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@4db728df: Unable to load credentials from service endpoint]".

Can anybody help me with this?

Mark B
  • 183,023
  • 24
  • 297
  • 295
user3217014
  • 43
  • 1
  • 5
  • I don't see any use of "Mockito and EasyMock" in the code you posted. – Mark B Jul 17 '20 at 18:42
  • @Mark B, When I write unit test for the method that is calling this code, it is throwing the above exception, that is the reason to post this question – user3217014 Jul 17 '20 at 18:46

1 Answers1

0

You are creating an instance of GetSecretValueRequest instead of creating a mock for it.

Your test is trying to communicate with the real object thereby asking for your AWS credentials.

flyingfishcattle
  • 1,817
  • 3
  • 14
  • 25
king05
  • 1
  • 1