Trouble mocking Secrets Manager Client
See original GitHub issueChecklist
- I have read Caveats documentation and didn’t find a solution for this problem there.
Bug description
Mocking secrets manager client doesn’t work as the client first tries to validate a security token which is probably not using the mocked .send
command. Example below;
import { mockClient } from 'aws-sdk-client-mock';
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
const smMock = mockClient(new SecretsManagerClient({}));
smMock.on(GetSecretValueCommand)
.resolves({
SecretString: JSON.stringify({ my_secret_key: 'my_secret_value' })
});
This code throws:
ExpiredTokenException: The security token included in the request is expired
I’ve tried adding a .callsFake(() => console.log('Hit the mock'))
before the .resolves...
method and it’s not even getting that far (which supports the theory that the token validation doesn’t use send
).
Environment
- Node version: 16.4.1
- Typescript version: 4.3.5
- AWS SDK v3 Client mock version: 0.5.3
- AWS JS SDK libs and versions:
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Mocking Secrets Manager module for JavaScript jest unit tests
You create a mock constructor for the SecretsManager in the mock ... AWS.config.update({ region: "us-east-1", }); const client = new AWS.
Read more >Creating Mocks for an AWS Service - Nishant Kaushish
Mock functions for any AWS service to be used in unit tests ... Secrets Manager is an AWS service which allows us to...
Read more >Secret Manager client libraries - Documentation - Google Cloud
This page shows how to get started with the Cloud Client Libraries for the Secret Manager API. Read more about the client libraries...
Read more >secretsmanageriface - Amazon Web Services - Go SDK
Package secretsmanageriface provides an interface to enable mocking the AWS Secrets Manager service client for testing your code.
Read more >secretsmanageriface - Go Packages
Package secretsmanageriface provides an interface to enable mocking the AWS Secrets Manager service client for testing your code.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I run the test with both v3.28.0 and v3.34.0 of
@aws-sdk/client-secrets-manager
and it looks to work fine.The code you posted has a slight mistake - you either pass the client class to the
mockClient()
function, or the same instance that you want to mock.This works good for me:
Alternatively, if you want to mock only a single instance of the Client, you need to provide the same instance in the mock as you use later in code:
Please let me know if that solves your problem.
Hey, I was vacationing so sorry for the delay, but I will look into this in the next days.