@@ -6,9 +6,16 @@ import { Readable } from 'stream';
66import { mockClient } from 'aws-sdk-client-mock' ;
77import {
88 CopyObjectCommand ,
9- DeleteObjectCommand , GetObjectCommand , HeadObjectCommand , ListObjectsV2Command , PutObjectCommand , S3Client ,
9+ DeleteObjectCommand ,
10+ GetObjectCommand ,
11+ HeadObjectCommand ,
12+ ListObjectsV2Command ,
13+ ListObjectVersionsCommand ,
14+ PutObjectCommand ,
15+ S3Client ,
1016} from '@aws-sdk/client-s3' ;
1117import { sdkStreamMixin } from '@smithy/util-stream' ;
18+ import * as s3RequestPresigner from '@aws-sdk/s3-request-presigner/dist-cjs/getSignedUrl' ;
1219
1320import { v4 } from 'uuid' ;
1421import Connector from '../../../src/connectors/s3' ;
@@ -27,6 +34,55 @@ describe('connectors/s3.js', () => {
2734 sinon . restore ( ) ;
2835 } ) ;
2936
37+ it ( 'should get a signed url' , async ( ) => {
38+ // const spy = sinon.spy(() => 'https://123/456');
39+ // mockS3.on(PutObjectCommand).callsFake(spy);
40+ const spy = sinon . stub ( s3RequestPresigner , 'getSignedUrl' ) . resolves ( 'https://123/456' ) ;
41+
42+ const data = await new Connector ( { debug : debug ( 's3' ) } )
43+ . getSignedUrl ( 'putObject' , '1/2' ) ;
44+ expect ( spy ) . to . have . been . calledOnce ;
45+ // expect(spy).to.have.been.calledWith('putObject', {
46+ // Bucket: 'b1',
47+ // Key: '1/2',
48+ // });
49+ expect ( data ) . to . equal ( 'https://123/456' ) ;
50+ } ) ;
51+
52+ it ( 'should get a signed url for putObject' , async ( ) => {
53+ // const spy = sinon.spy(() => 'https://123/456');
54+ // mockS3.on(PutObjectCommand).callsFake(spy);
55+ const spy = sinon . stub ( s3RequestPresigner , 'getSignedUrl' ) . resolves ( 'https://123/456' ) ;
56+
57+ const data = await new Connector ( { debug : debug ( 's3' ) , bucketName : 'b1' } )
58+ . getSignedUrl ( 'putObject' , '1/2' ) ;
59+
60+ expect ( spy ) . to . have . been . calledOnce ;
61+ // expect(spy).to.have.been.calledWith('putObject', {
62+ // Bucket: 'b1',
63+ // Key: '1/2',
64+ // // ContentType: 'application/pdf',
65+ // // ACL: 'private',
66+ // });
67+ expect ( data ) . to . equal ( 'https://123/456' ) ;
68+ } ) ;
69+
70+ it ( 'should get a signed url for getObject' , async ( ) => {
71+ // const spy = sinon.spy(() => 'https://123/456');
72+ // mockS3.on(GetObjectCommand).callsFake(spy);
73+ const spy = sinon . stub ( s3RequestPresigner , 'getSignedUrl' ) . resolves ( 'https://123/456' ) ;
74+
75+ const data = await new Connector ( { debug : debug ( 's3' ) , bucketName : 'b1' } )
76+ . getSignedUrl ( 'getObject' , '1/2' ) ;
77+
78+ expect ( spy ) . to . have . been . calledOnce ;
79+ // expect(spy).to.have.been.calledWith('getObject', {
80+ // Bucket: 'b1',
81+ // Key: '1/2',
82+ // });
83+ expect ( data ) . to . equal ( 'https://123/456' ) ;
84+ } ) ;
85+
3086 it ( 'should reuse client per pipeline' , ( ) => {
3187 const client1 = Connector . getClient ( 'test1' , debug ( 'test' ) ) ;
3288 const client2 = Connector . getClient ( 'test1' , debug ( 'test' ) ) ;
@@ -161,6 +217,29 @@ describe('connectors/s3.js', () => {
161217 expect ( data ) . to . deep . equal ( { DeleteMarker : false } ) ;
162218 } ) ;
163219
220+ it ( 'should list object versions' , async ( ) => {
221+ const spy = sinon . spy ( ( ) => [ { VersionId : 'v1' } ] ) ;
222+ mockS3 . on ( ListObjectVersionsCommand ) . callsFake ( spy ) ;
223+
224+ const inputParams = {
225+ Prefix : 'k1' ,
226+ limit : 20 ,
227+ } ;
228+
229+ const data = await new Connector ( { debug : debug ( 's3' ) , bucketName : 'b1' } )
230+ . listObjectVersions ( inputParams ) ;
231+
232+ expect ( spy ) . to . have . been . calledWith ( {
233+ Bucket : 'b1' ,
234+ Prefix : 'k1' ,
235+ MaxKeys : 20 ,
236+ } ) ;
237+ expect ( data ) . to . deep . equal ( {
238+ last : undefined ,
239+ data : [ { VersionId : 'v1' } ] ,
240+ } ) ;
241+ } ) ;
242+
164243 it ( 'should list objects' , async ( ) => {
165244 const spy = sinon . spy ( ( ) => ( {
166245 IsTruncated : false ,
0 commit comments