Skip to content

Commit

Permalink
NC | put bucket policy invalid body error fix
Browse files Browse the repository at this point in the history
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
  • Loading branch information
romayalon committed May 8, 2024
1 parent 63ce0da commit 21ef7d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/endpoint/s3/ops/s3_put_bucket_policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function put_bucket_policy(req) {
module.exports = {
handler: put_bucket_policy,
body: {
invalid_error: S3Error.MalformedPolicyNotAJSON,
type: 'json',
},
reply: {
Expand Down
8 changes: 8 additions & 0 deletions src/endpoint/s3/s3_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ S3Error.MalformedPolicy = Object.freeze({
http_code: 400,
detail: '...', // will be overridden from rpc_data, see handle_error in s3_rest.js
});

S3Error.MalformedPolicyNotAJSON = Object.freeze({
code: 'MalformedPolicy',
message: 'Policies must be valid JSON and the first byte must be \'{\'',
http_code: 400,
detail: '...', // will be overridden from rpc_data, see handle_error in s3_rest.js
});

S3Error.NoSuchObjectLockConfiguration = Object.freeze({
code: 'NoSuchObjectLockConfiguration',
message: 'The specified object does not have a ObjectLock configuration',
Expand Down
17 changes: 17 additions & 0 deletions src/test/unit_tests/test_s3_bucket_policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,23 @@ mocha.describe('s3_bucket_policy', function() {
}
}
});

mocha.it('should not allow invalid json', async function() {
const self = this; // eslint-disable-line no-invalid-this
self.timeout(15000);
const s3_policy = "this is not a json";
try {
await s3_owner.putBucketPolicy({
Bucket: BKT,
Policy: s3_policy
});
assert.fail('Test was suppose to fail on ' + S3Error.MalformedPolicy.code);
} catch (err) {
if (err.Code !== S3Error.MalformedPolicy.code) {
throw err;
}
}
});
});

mocha.describe('get-bucket-policy status should work', async function() {
Expand Down

0 comments on commit 21ef7d4

Please sign in to comment.