Skip to content

Commit 3e3da3c

Browse files
authored
Merge pull request #8874 from jackyalbo/jacky-cors-fixes
Fix id parse for s3_put_bucket_cors
2 parents 464e7b7 + a020726 commit 3e3da3c

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/endpoint/s3/ops/s3_put_bucket_cors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function put_bucket_cors(req) {
1313
allowed_methods: rule.AllowedMethod,
1414
allowed_origins: rule.AllowedOrigin,
1515
expose_headers: rule.ExposeHeader,
16-
id: rule.ID,
16+
id: rule.ID?.[0],
1717
max_age_seconds: rule.MaxAgeSeconds && parseInt(rule.MaxAgeSeconds, 10),
1818
}, _.isUndefined)
1919
);

src/test/unit_tests/test_s3_ops.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,59 @@ mocha.describe('s3_ops', function() {
461461
});
462462
});
463463

464+
mocha.describe('bucket-cors', function() {
465+
466+
mocha.before(async function() {
467+
await s3.createBucket({ Bucket: "cors-bucket" });
468+
});
469+
470+
mocha.it('should put and get bucket cors with ID', async function() {
471+
472+
// put bucket cors
473+
const params = {
474+
Bucket: "cors-bucket",
475+
CORSConfiguration: {
476+
CORSRules: [{
477+
ID: 'rule1',
478+
AllowedOrigins: ["http://www.example.com"],
479+
AllowedHeaders: ["*"],
480+
AllowedMethods: ["PUT", "POST", "DELETE"],
481+
ExposeHeaders: ["x-amz-server-side-encryption"]
482+
}]
483+
}
484+
};
485+
await s3.putBucketCors(params);
486+
487+
// get bucket CORS
488+
const res = await s3.getBucketCors({ Bucket: "cors-bucket" });
489+
assert.deepEqual(res.CORSRules, params.CORSConfiguration.CORSRules);
490+
});
491+
492+
mocha.it('should put and get bucket cors with max age seconds', async function() {
493+
494+
// put bucket cors
495+
const params = {
496+
Bucket: "cors-bucket",
497+
CORSConfiguration: {
498+
CORSRules: [{
499+
AllowedOrigins: ["http://www.example.com"],
500+
AllowedMethods: ["PUT", "POST", "DELETE"],
501+
MaxAgeSeconds: 1500,
502+
}]
503+
}
504+
};
505+
await s3.putBucketCors(params);
506+
507+
// get bucket CORS
508+
const res = await s3.getBucketCors({ Bucket: "cors-bucket" });
509+
assert.deepEqual(res.CORSRules, params.CORSConfiguration.CORSRules);
510+
});
511+
512+
mocha.after(async function() {
513+
await s3.deleteBucket({ Bucket: "cors-bucket" });
514+
});
515+
});
516+
464517
async function test_object_ops(bucket_name, bucket_type, caching, remote_endpoint_options) {
465518

466519
const is_azure_namespace = is_namespace_blob_bucket(bucket_type, remote_endpoint_options && remote_endpoint_options.endpoint_type);

0 commit comments

Comments
 (0)