Skip to content

Commit 8266a66

Browse files
committed
Add test to ensure that the AWS S3 client receives getObject as the operation in the getSignedUrl function
Signed-off-by: Daniel San <[email protected]>
1 parent d761881 commit 8266a66

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

spec/test.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,17 @@ describe('S3Adapter tests', () => {
340340
it('should get using the baseUrl and amazon using presigned URL', () => {
341341
options.presignedUrl = true;
342342
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
343+
const originalS3Client = s3._s3Client;
344+
let getSignedUrlOperation = '';
345+
s3._s3Client = {
346+
getSignedUrl: (operation, params, callback) => {
347+
getSignedUrlOperation = operation;
348+
return originalS3Client.getSignedUrl(operation, params, callback);
349+
},
350+
};
343351

344352
const fileLocation = s3.getFileLocation(testConfig, 'test.png');
353+
expect(getSignedUrlOperation).toBe('getObject');
345354
expect(fileLocation).toMatch(/^http:\/\/example.com\/files\/foo\/bar\/test.png\?/);
346355
expect(fileLocation).toMatch(/X-Amz-Credential=accessKey%2F\d{8}%2Fus-east-1%2Fs3%2Faws4_request/);
347356
expect(fileLocation).toMatch(/X-Amz-Date=\d{8}T\d{6}Z/);
@@ -373,8 +382,17 @@ describe('S3Adapter tests', () => {
373382
delete options.baseUrl;
374383
options.presignedUrl = true;
375384
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
385+
const originalS3Client = s3._s3Client;
386+
let getSignedUrlOperation = '';
387+
s3._s3Client = {
388+
getSignedUrl: (operation, params, callback) => {
389+
getSignedUrlOperation = operation;
390+
return originalS3Client.getSignedUrl(operation, params, callback);
391+
},
392+
};
376393

377394
const fileLocation = s3.getFileLocation(testConfig, 'test.png');
395+
expect(getSignedUrlOperation).toBe('getObject');
378396
expect(fileLocation).toMatch(/^https:\/\/my-bucket.s3.amazonaws.com\/foo\/bar\/test.png\?/);
379397
expect(fileLocation).toMatch(/X-Amz-Credential=accessKey%2F\d{8}%2Fus-east-1%2Fs3%2Faws4_request/);
380398
expect(fileLocation).toMatch(/X-Amz-Date=\d{8}T\d{6}Z/);

0 commit comments

Comments
 (0)