Skip to content

Commit

Permalink
Merge branch 'w/8.7/bugfix/CLDSRV-569/delete-bucket-encryption' into …
Browse files Browse the repository at this point in the history
…tmp/octopus/w/8.8/bugfix/CLDSRV-569/delete-bucket-encryption
  • Loading branch information
bert-e committed Oct 22, 2024
2 parents a73290c + cd57399 commit ec2e304
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/api/bucketDeleteEncryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function bucketDeleteEncryption(authInfo, request, log, callback) {
configuredMasterKeyId: sseConfig.configuredMasterKeyId,
};

const { isAccountEncryptionEnabled } = sseConfig;
if (isAccountEncryptionEnabled) {
updatedConfig.isAccountEncryptionEnabled = isAccountEncryptionEnabled;
}

bucket.setServerSideEncryption(updatedConfig);
return metadata.updateBucket(bucketName, bucket, log, err => next(err, bucket));
},
Expand Down
73 changes: 73 additions & 0 deletions tests/unit/api/bucketDeleteEncryption.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const assert = require('assert');
const sinon = require('sinon');

const { bucketPut } = require('../../../lib/api/bucketPut');
const bucketPutEncryption = require('../../../lib/api/bucketPutEncryption');
const bucketDeleteEncryption = require('../../../lib/api/bucketDeleteEncryption');
const { cleanup, DummyRequestLogger, makeAuthInfo } = require('../helpers');
const { templateSSEConfig, templateRequest, getSSEConfig } = require('../utils/bucketEncryption');
const inMemory = require('../../../lib/kms/in_memory/backend').backend;
const log = new DummyRequestLogger();
const authInfo = makeAuthInfo('accessKey1');
const bucketName = 'bucketname';
Expand Down Expand Up @@ -216,4 +218,75 @@ describe('bucketDeleteEncryption API', () => {
});
});
});

describe('bucketDeleteEncryption API with account level encryption', () => {
beforeEach(() => {
sinon.stub(inMemory, 'supportsDefaultKeyPerAccount').value(true);
});

afterEach(() => {
sinon.restore();
});

it('should keep isAccountEncryptionEnabled after deleting AES256 bucket encryption', done => {
const post = templateSSEConfig({ algorithm: 'AES256' });
bucketPutEncryption(authInfo, templateRequest(bucketName, { post }), log, err => {
assert.ifError(err);
return getSSEConfig(bucketName, log, (err, sseInfo) => {
assert.ifError(err);
assert.strictEqual(sseInfo.isAccountEncryptionEnabled, true);
bucketDeleteEncryption(authInfo, templateRequest(bucketName, {}), log, err => {
assert.ifError(err);
return getSSEConfig(bucketName, log, (err, sseInfoAfterDeletion) => {
assert.ifError(err);
assert.strictEqual(sseInfoAfterDeletion.isAccountEncryptionEnabled, true);
done();
});
});
});
});
});

it('should keep isAccountEncryptionEnabled after deleting aws:kms bucket encryption', done => {
const post = templateSSEConfig({ algorithm: 'aws:kms' });
bucketPutEncryption(authInfo, templateRequest(bucketName, { post }), log, err => {
assert.ifError(err);
return getSSEConfig(bucketName, log, (err, sseInfo) => {
assert.ifError(err);
assert.strictEqual(sseInfo.isAccountEncryptionEnabled, true);
bucketDeleteEncryption(authInfo, templateRequest(bucketName, {}), log, err => {
assert.ifError(err);
return getSSEConfig(bucketName, log, (err, sseInfoAfterDeletion) => {
assert.ifError(err);
assert.strictEqual(sseInfoAfterDeletion.isAccountEncryptionEnabled, true);
done();
});
});
});
});
});

it('should keep isAccountEncryptionEnabled after deleting aws:kms and key id bucket encryption', done => {
const postAES256 = templateSSEConfig({ algorithm: 'AES256' });
bucketPutEncryption(authInfo, templateRequest(bucketName, { post: postAES256 }), log, err => {
assert.ifError(err);
const post = templateSSEConfig({ algorithm: 'aws:kms', keyId: '123' });
bucketPutEncryption(authInfo, templateRequest(bucketName, { post }), log, err => {
assert.ifError(err);
return getSSEConfig(bucketName, log, (err, sseInfo) => {
assert.ifError(err);
assert.strictEqual(sseInfo.isAccountEncryptionEnabled, true);
bucketDeleteEncryption(authInfo, templateRequest(bucketName, {}), log, err => {
assert.ifError(err);
return getSSEConfig(bucketName, log, (err, sseInfoAfterDeletion) => {
assert.ifError(err);
assert.strictEqual(sseInfoAfterDeletion.isAccountEncryptionEnabled, true);
done();
});
});
});
});
});
});
});
});

0 comments on commit ec2e304

Please sign in to comment.