-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S3 Presign #62
Comments
I looked at it and I think mocking it is not (easily) possible right now with the lib. Presign is done by a middleware. The mocking lib does not mock middlewares, but only client I think the way to go is to mock the whole Feel free to submit a PR for this! |
Yeah so at the moment my strategy has been to mock |
Yeah, this functionality would be great. |
An alternative solution is to mock your URL command to return a |
The best solution I've found is from the referenced issue: const presigner = require('@aws-sdk/s3-request-presigner/dist-cjs/getSignedUrl') // eslint-disable-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
sinon.stub(presigner, 'getSignedUrl').resolves('https://s3.amazonaws.com/path/to/object') |
I get an error with this (sinon.stub)
|
This is how I've done using jest:
Thanks for the simple solution @jhecking 🙌 |
This works great, but you need to expose (fake) AWS credentials, or otherwise it will complain.
|
Similar behaviour can be achieved for const postPresigner = require('@aws-sdk/s3-presigned-post/dist-cjs/createPresignedPost.js')
jest.spyOn(postPresigner, 'createPresignedPost').mockResolvedValue({ url: 'mockValue',
fields: {
key: 'mockValue',
Policy: 'mockValue',
'X-Amz-Signature': 'mockValue',
'X-Amz-Security-Token': 'mockValue',
bucket: 'mockValue',
'X-Amz-Algorithm': 'mockValue',
'X-Amz-Credential': 'mockValue',
'X-Amz-Date': 'mockValue',
} }) |
Thank you. I had to change it, but your approach helped me. My solution: jest.mock("@aws-sdk/s3-request-presigner", () => {
return {
getSignedUrl: jest.fn().mockResolvedValueOnce(signedUrlMockValue),
};
}); |
This solution doesn't work anymore starting from SDK v3.495.0 unfortunately. |
Is there any PR open to support getSignedUrl mock ? I am completely blocked as work around discussed above as well not working with new version of sdk |
If someone wants to create a PR, I will gladly review it. |
For those still struggling with this issue even today, you can workaround it with reimporting getSignedUrl to your own module like described in here https://stackoverflow.com/questions/72616800/trying-to-stub-a-function-results-in-descriptor-for-property-is-non-configurable/72793194#72793194 |
S3 presign is done using a helper library
@aws-sdk/s3-request-presigner
this seems like something that would need a helper library or additional documentation to mock properly.It would be good to see a way to mock presign requests. I'm happy to help with this.
The text was updated successfully, but these errors were encountered: