diff --git a/extensions/lifecycle/tasks/LifecycleDeleteObjectTask.js b/extensions/lifecycle/tasks/LifecycleDeleteObjectTask.js index 9f41b86c5..592b911bb 100644 --- a/extensions/lifecycle/tasks/LifecycleDeleteObjectTask.js +++ b/extensions/lifecycle/tasks/LifecycleDeleteObjectTask.js @@ -104,24 +104,12 @@ class LifecycleDeleteObjectTask extends BackbeatTask { } _getS3Action(actionType, accountId) { - let reqMethod; if (actionType === 'deleteObject') { const backbeatClient = this.getBackbeatClient(accountId); - if (!backbeatClient) { - return null; - } - // Zenko supports the "deleteObjectFromExpiration" API, which - // sets the proper originOp in the metadata to trigger a - // nortification when an object gets expired. - if (typeof backbeatClient.deleteObjectFromExpiration === 'function') { - return backbeatClient.deleteObjectFromExpiration.bind(backbeatClient); - } - reqMethod = 'deleteObject'; - } else { - reqMethod = 'abortMultipartUpload'; + return backbeatClient?.deleteObjectFromExpiration?.bind(backbeatClient); } const client = this.getS3Client(accountId); - return client[reqMethod].bind(client); + return client?.abortMultipartUpload?.bind(client); } _executeDelete(entry, startTime, log, done) { diff --git a/tests/unit/lifecycle/LifecycleDeleteObjectTask.spec.js b/tests/unit/lifecycle/LifecycleDeleteObjectTask.spec.js index 45b6132fa..f85b10196 100644 --- a/tests/unit/lifecycle/LifecycleDeleteObjectTask.spec.js +++ b/tests/unit/lifecycle/LifecycleDeleteObjectTask.spec.js @@ -260,7 +260,7 @@ describe('LifecycleDeleteObjectTask', () => { }); }); - it('should expire object using the deleteObjectFromExpiration method if supported', done => { + it('should expire object using the deleteObjectFromExpiration method', done => { const entry = ActionQueueEntry.create('deleteObject') .setAttribute('target.owner', 'testowner') .setAttribute('target.bucket', 'testbucket') @@ -278,54 +278,52 @@ describe('LifecycleDeleteObjectTask', () => { }); }); - it('should expire object using the deleteObject method when not in Zenko', done => { - backbeatClient = new BackbeatClientMock({ isS3c: true }); - sinon.stub(task, 'getBackbeatClient').returns(backbeatClient); - const entry = ActionQueueEntry.create('deleteObject') + it('should abort an MPU using the abortMultipartUpload method', done => { + const entry = ActionQueueEntry.create('deleteMPU') .setAttribute('target.owner', 'testowner') .setAttribute('target.bucket', 'testbucket') .setAttribute('target.accountId', 'testid') .setAttribute('target.key', 'testkey') .setAttribute('target.version', 'testversion') + .setAttribute('details.UploadId', 'someUploadId') .setAttribute('details.lastModified', '2022-05-13T17:51:31.261Z'); s3Client.setResponse(null, {}); backbeatClient.setResponse(null, {}); task.processActionEntry(entry, err => { assert.ifError(err); - assert.strictEqual(s3Client.calls.deleteObject, 1); + assert.strictEqual(s3Client.calls.abortMultipartUpload, 1); + assert.strictEqual(s3Client.calls.deleteObject, 0); assert.strictEqual(backbeatClient.times.deleteObjectFromExpiration, 0); done(); }); }); - it('should abort an MPU using the abortMultipartUpload method', done => { - const entry = ActionQueueEntry.create('deleteMPU') + it('should return an error when it can\'t get the BackbeatClient', done => { + sinon.stub(task, 'getBackbeatClient').returns(null); + const entry = ActionQueueEntry.create('deleteObject') .setAttribute('target.owner', 'testowner') .setAttribute('target.bucket', 'testbucket') .setAttribute('target.accountId', 'testid') .setAttribute('target.key', 'testkey') .setAttribute('target.version', 'testversion') - .setAttribute('details.UploadId', 'someUploadId') .setAttribute('details.lastModified', '2022-05-13T17:51:31.261Z'); s3Client.setResponse(null, {}); backbeatClient.setResponse(null, {}); task.processActionEntry(entry, err => { - assert.ifError(err); - assert.strictEqual(s3Client.calls.abortMultipartUpload, 1); - assert.strictEqual(s3Client.calls.deleteObject, 0); - assert.strictEqual(backbeatClient.times.deleteObjectFromExpiration, 0); + assert(err); done(); }); }); - it('should return an error when it can\'t get the BackbeatClient', done => { - sinon.stub(task, 'getBackbeatClient').returns(null); - const entry = ActionQueueEntry.create('deleteObject') + it('should return an error when it can\'t get the S3 client', done => { + sinon.stub(task, 'getS3Client').returns(null); + const entry = ActionQueueEntry.create('deleteMPU') .setAttribute('target.owner', 'testowner') .setAttribute('target.bucket', 'testbucket') .setAttribute('target.accountId', 'testid') .setAttribute('target.key', 'testkey') .setAttribute('target.version', 'testversion') + .setAttribute('details.UploadId', 'someUploadId') .setAttribute('details.lastModified', '2022-05-13T17:51:31.261Z'); s3Client.setResponse(null, {}); backbeatClient.setResponse(null, {});