Skip to content

Commit 90d6b97

Browse files
committed
🥅(CLDSRV-779) manage error on putBucketReplication properly
1 parent fad11cb commit 90d6b97

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 4

lib/api/apiUtils/bucket/getReplicationConfiguration.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ function getReplicationConfiguration(xml, log, cb) {
99
if (err) {
1010
return cb(err);
1111
}
12+
1213
const validator = new ReplicationConfiguration(result, log, config);
1314
const configErr = validator.parseConfiguration();
14-
return cb(configErr || null, validator.getReplicationConfiguration());
15+
16+
if (configErr) {
17+
return cb(configErr);
18+
}
19+
20+
return cb(null, validator.getReplicationConfiguration());
1521
});
1622
}
1723

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,61 @@ describe('aws-node-sdk test putBucketReplication configuration rules', () => {
377377
return checkError(config, 'MalformedXML', done);
378378
});
379379
});
380+
381+
describe('aws-node-sdk test putBucketReplication CORS', () => {
382+
let s3;
383+
const bucket = 'source-bucket-cors';
384+
385+
beforeEach(done => {
386+
const config = getConfig('default', { signatureVersion: 'v4' });
387+
s3 = new S3(config);
388+
series([
389+
next => s3.createBucket({ Bucket: bucket }, next),
390+
next => s3.putBucketVersioning({
391+
Bucket: bucket,
392+
VersioningConfiguration: { Status: 'Enabled' },
393+
}, next),
394+
next => s3.putBucketCors({
395+
Bucket: bucket,
396+
CORSConfiguration: {
397+
CORSRules: [{
398+
AllowedOrigins: ['*'],
399+
AllowedMethods: ['PUT'],
400+
AllowedHeaders: ['*'],
401+
}],
402+
},
403+
}, next),
404+
], done);
405+
});
406+
407+
afterEach(done => {
408+
series([
409+
next => s3.deleteBucketCors({ Bucket: bucket }, err => {
410+
if (err && err.code !== 'NoSuchCORSConfiguration') {
411+
return next(err);
412+
}
413+
return next();
414+
}),
415+
next => s3.deleteBucket({ Bucket: bucket }, next),
416+
], done);
417+
});
418+
419+
it('should return CORS headers on malformed XML error', done => {
420+
const replicationParams = {
421+
Bucket: bucket,
422+
ReplicationConfiguration: {
423+
Role: 'arn:aws:iam::account-id:role/src-resource,' +
424+
'arn:aws:iam::account-id:role/dest-resource',
425+
Rules: [],
426+
},
427+
};
428+
const request = s3.putBucketReplication(replicationParams);
429+
request.on('build', () => {
430+
request.httpRequest.headers.Origin = 'http://example.com';
431+
});
432+
request.send(err => {
433+
assertError(err, 'MalformedXML');
434+
done();
435+
});
436+
});
437+
});

0 commit comments

Comments
 (0)