1
1
const async = require ( 'async' ) ;
2
+ const {
3
+ CreateBucketCommand,
4
+ PutObjectCommand,
5
+ DeleteObjectCommand,
6
+ DeleteBucketCommand,
7
+ } = require ( '@aws-sdk/client-s3' ) ;
2
8
3
9
const withV4 = require ( '../../support/withV4' ) ;
4
10
const BucketUtility = require ( '../../../lib/utility/bucket-util' ) ;
@@ -30,26 +36,34 @@ function testSuite() {
30
36
withV4 ( sigCfg => {
31
37
const bucketUtil = new BucketUtility ( 'default' , sigCfg ) ;
32
38
const s3 = bucketUtil . s3 ;
33
- beforeEach ( done => s3 . createBucket ( {
34
- Bucket : bucket ,
35
- CreateBucketConfiguration : {
36
- LocationConstraint : awsLocation ,
37
- } ,
38
- } , done ) ) ;
39
- afterEach ( done => {
40
- removeAllVersions ( { Bucket : bucket } , err => {
41
- if ( err ) {
42
- return done ( err ) ;
43
- }
44
- return s3 . deleteBucket ( { Bucket : bucket } , done ) ;
39
+
40
+ beforeEach ( done => {
41
+ const command = new CreateBucketCommand ( {
42
+ Bucket : bucket ,
43
+ CreateBucketConfiguration : {
44
+ LocationConstraint : awsLocation ,
45
+ } ,
45
46
} ) ;
47
+ s3 . send ( command )
48
+ . then ( ( ) => done ( ) )
49
+ . catch ( err => done ( err ) ) ;
50
+ } ) ;
51
+
52
+ afterEach ( async ( ) => {
53
+ await removeAllVersions ( { Bucket : bucket } ) ;
54
+ await s3 . send ( new DeleteBucketCommand ( { Bucket : bucket } ) ) ;
46
55
} ) ;
47
56
48
57
it ( 'versioning not configured: should put/get a tag set on the ' +
49
58
'latest version if no version is specified' , done => {
50
59
const key = `somekey-${ genUniqID ( ) } ` ;
51
60
async . waterfall ( [
52
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
61
+ next => {
62
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
63
+ s3 . send ( command )
64
+ . then ( data => next ( null , data ) )
65
+ . catch ( err => next ( err ) ) ;
66
+ } ,
53
67
( putData , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
54
68
expectedVersionId : false } , next ) ,
55
69
( versionId , next ) => getTaggingAndAssert ( s3 , { bucket, key,
@@ -63,7 +77,12 @@ function testSuite() {
63
77
'specific version if specified (null)' , done => {
64
78
const key = `somekey-${ genUniqID ( ) } ` ;
65
79
async . waterfall ( [
66
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
80
+ next => {
81
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
82
+ s3 . send ( command )
83
+ . then ( data => next ( null , data ) )
84
+ . catch ( err => next ( err ) ) ;
85
+ } ,
67
86
( putData , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
68
87
versionId : 'null' , expectedVersionId : false } , next ) ,
69
88
( versionId , next ) => getTaggingAndAssert ( s3 , { bucket, key,
@@ -110,7 +129,12 @@ function testSuite() {
110
129
const key = `somekey-${ genUniqID ( ) } ` ;
111
130
async . waterfall ( [
112
131
next => enableVersioning ( s3 , bucket , next ) ,
113
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
132
+ next => {
133
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
134
+ s3 . send ( command )
135
+ . then ( data => next ( null , data ) )
136
+ . catch ( err => next ( err ) ) ;
137
+ } ,
114
138
( putData , next ) => awsGetLatestVerId ( key , '' ,
115
139
( err , awsVid ) => next ( err , putData . VersionId , awsVid ) ) ,
116
140
( s3Vid , awsVid , next ) => putNullVersionsToAws ( s3 , bucket , key ,
@@ -131,7 +155,12 @@ function testSuite() {
131
155
const key = `somekey-${ genUniqID ( ) } ` ;
132
156
async . waterfall ( [
133
157
next => enableVersioning ( s3 , bucket , next ) ,
134
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
158
+ next => {
159
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
160
+ s3 . send ( command )
161
+ . then ( data => next ( null , data ) )
162
+ . catch ( err => next ( err ) ) ;
163
+ } ,
135
164
( putData , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
136
165
expectedVersionId : putData . VersionId } , next ) ,
137
166
( versionId , next ) => getTaggingAndAssert ( s3 , { bucket, key,
@@ -146,7 +175,12 @@ function testSuite() {
146
175
const key = `somekey-${ genUniqID ( ) } ` ;
147
176
async . waterfall ( [
148
177
next => enableVersioning ( s3 , bucket , next ) ,
149
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
178
+ next => {
179
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
180
+ s3 . send ( command )
181
+ . then ( data => next ( null , data ) )
182
+ . catch ( err => next ( err ) ) ;
183
+ } ,
150
184
( putData , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
151
185
versionId : putData . VersionId ,
152
186
expectedVersionId : putData . VersionId } , next ) ,
@@ -163,7 +197,12 @@ function testSuite() {
163
197
const key = `somekey-${ genUniqID ( ) } ` ;
164
198
async . waterfall ( [
165
199
next => enableVersioning ( s3 , bucket , next ) ,
166
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
200
+ next => {
201
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
202
+ s3 . send ( command )
203
+ . then ( data => next ( null , data ) )
204
+ . catch ( err => next ( err ) ) ;
205
+ } ,
167
206
( putData , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
168
207
versionId : putData . VersionId ,
169
208
expectedVersionId : putData . VersionId } , next ) ,
@@ -178,13 +217,25 @@ function testSuite() {
178
217
const key = `somekey-${ genUniqID ( ) } ` ;
179
218
async . waterfall ( [
180
219
next => enableVersioning ( s3 , bucket , next ) ,
181
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
220
+ next => {
221
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
222
+ s3 . send ( command )
223
+ . then ( data => next ( null , data ) )
224
+ . catch ( err => next ( err ) ) ;
225
+ } ,
182
226
( putData , next ) => awsGetLatestVerId ( key , '' ,
183
227
( err , awsVid ) => next ( err , putData . VersionId , awsVid ) ) ,
184
228
// put another version
185
- ( s3Vid , awsVid , next ) => s3 . putObject ( { Bucket : bucket ,
186
- Key : key , Body : someBody } ,
187
- err => next ( err , s3Vid , awsVid ) ) ,
229
+ ( s3Vid , awsVid , next ) => {
230
+ const command = new PutObjectCommand ( {
231
+ Bucket : bucket ,
232
+ Key : key ,
233
+ Body : someBody
234
+ } ) ;
235
+ s3 . send ( command )
236
+ . then ( ( ) => next ( null , s3Vid , awsVid ) )
237
+ . catch ( err => next ( err , s3Vid , awsVid ) ) ;
238
+ } ,
188
239
( s3Vid , awsVid , next ) => putTaggingAndAssert ( s3 , { bucket, key,
189
240
tags, versionId : s3Vid , expectedVersionId : s3Vid } , err =>
190
241
next ( err , s3Vid , awsVid ) ) ,
@@ -196,7 +247,6 @@ function testSuite() {
196
247
] , done ) ;
197
248
} ) ;
198
249
199
-
200
250
it ( 'versioning suspended then enabled: should put/get a tag set on ' +
201
251
'a specific version (null) if specified' , done => {
202
252
const key = `somekey-${ genUniqID ( ) } ` ;
@@ -222,12 +272,25 @@ function testSuite() {
222
272
done => {
223
273
const key = `somekey-${ genUniqID ( ) } ` ;
224
274
async . waterfall ( [
225
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
275
+ next => {
276
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
277
+ s3 . send ( command )
278
+ . then ( data => next ( null , data ) )
279
+ . catch ( err => next ( err ) ) ;
280
+ } ,
226
281
( putData , next ) => awsGetLatestVerId ( key , '' , next ) ,
227
282
( awsVid , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
228
283
expectedVersionId : false } , ( ) => next ( null , awsVid ) ) ,
229
- ( awsVid , next ) => awsS3 . deleteObject ( { Bucket : awsBucket ,
230
- Key : key , VersionId : awsVid } , next ) ,
284
+ ( awsVid , next ) => {
285
+ const command = new DeleteObjectCommand ( {
286
+ Bucket : awsBucket ,
287
+ Key : key ,
288
+ VersionId : awsVid
289
+ } ) ;
290
+ awsS3 . send ( command )
291
+ . then ( data => next ( null , data ) )
292
+ . catch ( err => next ( err ) ) ;
293
+ } ,
231
294
( delData , next ) => getTaggingAndAssert ( s3 , { bucket, key,
232
295
expectedTags : tags , expectedVersionId : false ,
233
296
getObject : false } , next ) ,
@@ -239,10 +302,23 @@ function testSuite() {
239
302
done => {
240
303
const key = `somekey-${ genUniqID ( ) } ` ;
241
304
async . waterfall ( [
242
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
305
+ next => {
306
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
307
+ s3 . send ( command )
308
+ . then ( data => next ( null , data ) )
309
+ . catch ( err => next ( err ) ) ;
310
+ } ,
243
311
( putData , next ) => awsGetLatestVerId ( key , '' , next ) ,
244
- ( awsVid , next ) => awsS3 . deleteObject ( { Bucket : awsBucket ,
245
- Key : key , VersionId : awsVid } , next ) ,
312
+ ( awsVid , next ) => {
313
+ const command = new DeleteObjectCommand ( {
314
+ Bucket : awsBucket ,
315
+ Key : key ,
316
+ VersionId : awsVid
317
+ } ) ;
318
+ awsS3 . send ( command )
319
+ . then ( data => next ( null , data ) )
320
+ . catch ( err => next ( err ) ) ;
321
+ } ,
246
322
( delData , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
247
323
expectedError : 'ServiceUnavailable' } , next ) ,
248
324
] , done ) ;
@@ -254,14 +330,27 @@ function testSuite() {
254
330
const key = `somekey-${ genUniqID ( ) } ` ;
255
331
async . waterfall ( [
256
332
next => enableVersioning ( s3 , bucket , next ) ,
257
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
333
+ next => {
334
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
335
+ s3 . send ( command )
336
+ . then ( data => next ( null , data ) )
337
+ . catch ( err => next ( err ) ) ;
338
+ } ,
258
339
( putData , next ) => awsGetLatestVerId ( key , '' ,
259
340
( err , awsVid ) => next ( err , putData . VersionId , awsVid ) ) ,
260
341
( s3Vid , awsVid , next ) => putTaggingAndAssert ( s3 , { bucket, key,
261
342
tags, versionId : s3Vid , expectedVersionId : s3Vid } ,
262
343
( ) => next ( null , s3Vid , awsVid ) ) ,
263
- ( s3Vid , awsVid , next ) => awsS3 . deleteObject ( { Bucket : awsBucket ,
264
- Key : key , VersionId : awsVid } , err => next ( err , s3Vid ) ) ,
344
+ ( s3Vid , awsVid , next ) => {
345
+ const command = new DeleteObjectCommand ( {
346
+ Bucket : awsBucket ,
347
+ Key : key ,
348
+ VersionId : awsVid
349
+ } ) ;
350
+ awsS3 . send ( command )
351
+ . then ( ( ) => next ( null , s3Vid ) )
352
+ . catch ( err => next ( err , s3Vid ) ) ;
353
+ } ,
265
354
( s3Vid , next ) => getTaggingAndAssert ( s3 , { bucket, key,
266
355
versionId : s3Vid , expectedTags : tags ,
267
356
expectedVersionId : s3Vid , getObject : false } , next ) ,
@@ -273,11 +362,24 @@ function testSuite() {
273
362
done => {
274
363
const key = `somekey-${ genUniqID ( ) } ` ;
275
364
async . waterfall ( [
276
- next => s3 . putObject ( { Bucket : bucket , Key : key } , next ) ,
365
+ next => {
366
+ const command = new PutObjectCommand ( { Bucket : bucket , Key : key } ) ;
367
+ s3 . send ( command )
368
+ . then ( data => next ( null , data ) )
369
+ . catch ( err => next ( err ) ) ;
370
+ } ,
277
371
( putData , next ) => awsGetLatestVerId ( key , '' ,
278
372
( err , awsVid ) => next ( err , putData . VersionId , awsVid ) ) ,
279
- ( s3Vid , awsVid , next ) => awsS3 . deleteObject ( { Bucket : awsBucket ,
280
- Key : key , VersionId : awsVid } , err => next ( err , s3Vid ) ) ,
373
+ ( s3Vid , awsVid , next ) => {
374
+ const command = new DeleteObjectCommand ( {
375
+ Bucket : awsBucket ,
376
+ Key : key ,
377
+ VersionId : awsVid
378
+ } ) ;
379
+ awsS3 . send ( command )
380
+ . then ( ( ) => next ( null , s3Vid ) )
381
+ . catch ( err => next ( err , s3Vid ) ) ;
382
+ } ,
281
383
( s3Vid , next ) => putTaggingAndAssert ( s3 , { bucket, key, tags,
282
384
versionId : s3Vid , expectedError :
283
385
'ServiceUnavailable' } , next ) ,
0 commit comments