Skip to content

Commit a3b2dbe

Browse files
authored
Merge pull request #8927 from shirady/nc-get-bucket-encryption
NC | NSFS | Fix the `get_bucket_encryption` to Return Object
2 parents e776be7 + 811c88c commit a3b2dbe

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

docs/dev_guide/run_coretest_locally.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ Another option, which is less recommended, is to connect to postgres container a
5858
Notes:
5959
* For running `psql` commands you would need to install it on your machine (better with the matching version of postgres).
6060
* In case you already run postgres on your machine (not the mentioned container) it might raise some issues, better remove it (in MacOs using the Activity Monitor and search for postgres).
61+
Example: you stopped the docker run, and you tried to connect to postgres, but got an error (probably password authentication failed). As it expected to see the following message when we don't have a postgres container:
62+
63+
```
64+
psql: error: connection to server at "127.0.0.1", port 5432 failed: Connection refused
65+
Is the server running on that host and accepting TCP/IP connections?
66+
```
67+
6168
* In case a test failed with "error: database "coretest" already exists" it means that you probably forgot to drop the DB table, and you can stop (ctrl + c) and rerun the `docker run` command mentioned above and then run the test again.
6269
* If you want to run the test with higher debug level you can add the `NOOBAA_LOG_LEVEL=all`, for example: `NOOBAA_LOG_LEVEL=all ./node_modules/mocha/bin/mocha.js src/test/unit_tests/test_s3_bucket_policy.js` (notice that you can printings that are not only from `LOG`, `L0`, `WARN` and `ERROR`, for example: `L1`, `L2`, `L3`, etc.)
6370

src/sdk/bucketspace_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
594594
const { name } = params;
595595
dbg.log0('BucketSpaceFS.get_bucket_encryption: Bucket name', name);
596596
const bucket = await this.config_fs.get_bucket_by_name(name);
597-
return bucket.encryption;
597+
return { encryption: bucket.encryption };
598598
} catch (err) {
599599
throw translate_error_codes(err, entity_enum.BUCKET);
600600
}

src/test/unit_tests/test_bucketspace_fs.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,11 @@ mocha.describe('bucketspace_fs', function() {
722722
});
723723

724724
mocha.describe('bucket encryption operations', function() {
725+
mocha.it('get_bucket_encryption (return empty encryption)', async function() {
726+
const param = { name: test_bucket };
727+
const empty_encryption = await bucketspace_fs.get_bucket_encryption(param);
728+
assert.ok(empty_encryption.encryption === undefined);
729+
});
725730
mocha.it('put_bucket_encryption ', async function() {
726731
const encryption = {
727732
algorithm: 'AES256',
@@ -731,19 +736,19 @@ mocha.describe('bucketspace_fs', function() {
731736
await bucketspace_fs.put_bucket_encryption(param);
732737

733738
const output_encryption = await bucketspace_fs.get_bucket_encryption(param);
734-
assert.deepEqual(output_encryption, encryption);
739+
assert.deepEqual(output_encryption.encryption, encryption);
735740
});
736-
mocha.it('delete_bucket_encryption ', async function() {
741+
mocha.it('delete_bucket_encryption', async function() {
737742
const encryption = {
738743
algorithm: 'AES256',
739744
kms_key_id: 'kms-123'
740745
};
741746
const param = { name: test_bucket };
742747
const output_encryption = await bucketspace_fs.get_bucket_encryption(param);
743-
assert.deepEqual(output_encryption, encryption);
748+
assert.deepEqual(output_encryption.encryption, encryption);
744749
await bucketspace_fs.delete_bucket_encryption(param);
745750
const empty_encryption = await bucketspace_fs.get_bucket_encryption(param);
746-
assert.ok(empty_encryption === undefined);
751+
assert.ok(empty_encryption.encryption === undefined);
747752
});
748753
});
749754

src/test/unit_tests/test_nsfs_integration.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,14 @@ mocha.describe('bucket operations - namespace_fs', function() {
795795
const expected_payer = 'BucketOwner'; // this is the mock that we use
796796
assert.equal(res.Payer, expected_payer);
797797
});
798+
mocha.it('get bucket encryption (before put bucket encryption) - throws an error', async function() {
799+
try {
800+
await s3_correct_uid_default_nsr.getBucketEncryption({ Bucket: bucket_name});
801+
assert.fail('get bucket encryption when encryption not set should fail');
802+
} catch (err) {
803+
assert.strictEqual(err.Code, 'ServerSideEncryptionConfigurationNotFoundError');
804+
}
805+
});
798806

799807
mocha.it('delete multiple non existing objects without failing', async function() {
800808
const keys_to_delete = [

src/test/unit_tests/test_s3_ops.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ mocha.describe('s3_ops', function() {
116116
const expected_payer = 'BucketOwner'; // this is the mock that we use
117117
assert.equal(res.Payer, expected_payer);
118118
});
119+
mocha.it('should allow get_bucket_encryption (no put before the get)', async function() {
120+
const res = await s3.getBucketEncryption({ Bucket: BKT1 });
121+
const expected_response = {
122+
ServerSideEncryptionConfiguration: {
123+
Rules: [{
124+
ApplyServerSideEncryptionByDefault: {
125+
SSEAlgorithm: 'AES256'
126+
},
127+
BucketKeyEnabled: false
128+
}]
129+
}
130+
};
131+
assert.equal(res.$metadata.httpStatusCode, 200);
132+
const res_without_metadata = _.omit(res, '$metadata');
133+
assert.deepEqual(res_without_metadata, expected_response);
134+
});
119135
mocha.it('should enable bucket logging', async function() {
120136
await s3.createBucket({ Bucket: BKT2 });
121137
await s3.putBucketLogging({

0 commit comments

Comments
 (0)