单元测试AWS secret manager java

y0u0uwnf  于 2023-03-28  发布在  Java
关注(0)|答案(1)|浏览(146)

我需要对Java中的AWS secret manager进行单元测试,并且正在使用Mockito和EasyMock来执行此操作,每当我调用client.getSecretValue()时,它都会抛出异常待测试代码

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) {

例外情况

"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]".

有人能帮我一下吗?

js81xvg6

js81xvg61#

您正在创建GetSecretValueRequest的示例,而不是为其创建模拟。您的测试正在尝试与真实的对象通信,从而要求您提供aws凭据。

相关问题