Skip to content

Commit 071dee4

Browse files
committed
putBucketReplication additional tests migration
1 parent c3a42c0 commit 071dee4

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

tests/functional/aws-node-sdk/test/bucket/putBucketReplication.js

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const { errors } = require('arsenal');
33
const { S3Client,
44
CreateBucketCommand,
55
DeleteBucketCommand,
6+
DeleteBucketCorsCommand,
7+
PutBucketCorsCommand,
68
PutBucketReplicationCommand,
79
PutBucketVersioningCommand } = require('@aws-sdk/client-s3');
810
const { series } = require('async');
@@ -408,41 +410,38 @@ describe('aws-node-sdk test putBucketReplication CORS', () => {
408410
let s3;
409411
const bucket = 'source-bucket-cors';
410412

411-
beforeEach(done => {
413+
beforeEach(async () => {
412414
const config = getConfig('default', { signatureVersion: 'v4' });
413-
s3 = new S3(config);
414-
series([
415-
next => s3.createBucket({ Bucket: bucket }, next),
416-
next => s3.putBucketVersioning({
417-
Bucket: bucket,
418-
VersioningConfiguration: { Status: 'Enabled' },
419-
}, next),
420-
next => s3.putBucketCors({
421-
Bucket: bucket,
422-
CORSConfiguration: {
423-
CORSRules: [{
424-
AllowedOrigins: ['*'],
425-
AllowedMethods: ['PUT'],
426-
AllowedHeaders: ['*'],
427-
}],
428-
},
429-
}, next),
430-
], done);
415+
s3 = new S3Client(config);
416+
await s3.send(new CreateBucketCommand({ Bucket: bucket }));
417+
await s3.send(new PutBucketVersioningCommand({
418+
Bucket: bucket,
419+
VersioningConfiguration: { Status: 'Enabled' },
420+
}));
421+
await s3.send(new PutBucketCorsCommand({
422+
Bucket: bucket,
423+
CORSConfiguration: {
424+
CORSRules: [{
425+
AllowedOrigins: ['*'],
426+
AllowedMethods: ['PUT'],
427+
AllowedHeaders: ['*'],
428+
}],
429+
},
430+
}));
431431
});
432432

433-
afterEach(done => {
434-
series([
435-
next => s3.deleteBucketCors({ Bucket: bucket }, err => {
436-
if (err && err.code !== 'NoSuchCORSConfiguration') {
437-
return next(err);
438-
}
439-
return next();
440-
}),
441-
next => s3.deleteBucket({ Bucket: bucket }, next),
442-
], done);
433+
afterEach(async () => {
434+
try {
435+
await s3.send(new DeleteBucketCorsCommand({ Bucket: bucket }));
436+
} catch (err) {
437+
if (err.name !== 'NoSuchCORSConfiguration') {
438+
throw err;
439+
}
440+
}
441+
await s3.send(new DeleteBucketCommand({ Bucket: bucket }));
443442
});
444443

445-
it('should return malformed XML error in XML is invalid', done => {
444+
it('should return malformed XML error in XML is invalid', async () => {
446445
const replicationParams = {
447446
Bucket: bucket,
448447
ReplicationConfiguration: {
@@ -451,13 +450,26 @@ describe('aws-node-sdk test putBucketReplication CORS', () => {
451450
Rules: [],
452451
},
453452
};
454-
const request = s3.putBucketReplication(replicationParams);
455-
request.on('build', () => {
456-
request.httpRequest.headers.Origin = 'http://example.com';
457-
});
458-
request.send(err => {
453+
const command = new PutBucketReplicationCommand(replicationParams);
454+
command.middlewareStack.add(
455+
(next) => async args => {
456+
if (args.request && args.request.headers) {
457+
args.request.headers.Origin = 'http://example.com';
458+
}
459+
return next(args);
460+
},
461+
{
462+
name: 'injectOriginHeader',
463+
step: 'build',
464+
priority: 'high',
465+
}
466+
);
467+
468+
try {
469+
await s3.send(command);
470+
assert.fail('Expected MalformedXML error');
471+
} catch (err) {
459472
assertError(err, 'MalformedXML');
460-
done();
461-
});
473+
}
462474
});
463475
});

0 commit comments

Comments
 (0)