Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/api/objectDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ function objectDeleteInternal(authInfo, request, log, isExpiration, cb) {
request,
true,
null,
overheadField,
log,
isExpiration
? 's3:LifecycleExpiration:DeleteMarkerCreated'
Expand Down
27 changes: 2 additions & 25 deletions tests/unit/api/bucketPutVersioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { bucketPut } = require('../../../lib/api/bucketPut');
const bucketPutVersioning = require('../../../lib/api/bucketPutVersioning');
const bucketPutReplication = require('../../../lib/api/bucketPutReplication');

const { cleanup, DummyRequestLogger, makeAuthInfo } = require('../helpers');
const { cleanup, DummyRequestLogger, makeAuthInfo, replicationTestUtils } = require('../helpers');
const metadata = require('../../../lib/metadata/wrapper');

const xmlEnableVersioning =
Expand All @@ -29,19 +29,6 @@ const locConstraintNonVersioned =
'<LocationConstraint>withoutversioning</LocationConstraint>' +
'</CreateBucketConfiguration>';

const xmlReplicationConfiguration =
'<ReplicationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' +
'<Role>arn:aws:iam::account-id:role/src-resource</Role>' +
'<Rule>' +
'<Prefix></Prefix>' +
'<Status>Enabled</Status>' +
'<Destination>' +
'<Bucket>arn:aws:s3:::destination-bucket</Bucket>' +
'<StorageClass>us-east-2</StorageClass>' +
'</Destination>' +
'</Rule>' +
'</ReplicationConfiguration>';

const externalVersioningErrorMessage =
'We do not currently support putting a versioned object to a location-constraint of type Azure or GCP.';

Expand All @@ -59,16 +46,6 @@ function _getPutBucketRequest(xml) {
return request;
}

function _putReplicationRequest(xml) {
const request = {
bucketName,
headers: { host: `${bucketName}.s3.amazonaws.com` },
url: '/?replication',
};
request.post = xml;
return request;
}

function _putVersioningRequest(xml) {
const request = {
bucketName,
Expand Down Expand Up @@ -126,7 +103,7 @@ describe('bucketPutVersioning API', () => {
},
// Put the replication config on the bucket.
next => {
const request = _putReplicationRequest(xmlReplicationConfiguration);
const request = replicationTestUtils.createBucketPutReplicationReq(bucketName);
bucketPutReplication(authInfo, request, log, next);
},
// Attempt to suspend versioning.
Expand Down
32 changes: 31 additions & 1 deletion tests/unit/api/objectDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const services = require('../../../lib/services');
const { bucketPut } = require('../../../lib/api/bucketPut');
const bucketPutACL = require('../../../lib/api/bucketPutACL');
const constants = require('../../../constants');
const { cleanup, DummyRequestLogger, makeAuthInfo, versioningTestUtils } = require('../helpers');
const { cleanup, DummyRequestLogger, makeAuthInfo, versioningTestUtils, replicationTestUtils } = require('../helpers');
const objectPut = require('../../../lib/api/objectPut');
const { objectDelete, objectDeleteInternal } = require('../../../lib/api/objectDelete');
const objectGet = require('../../../lib/api/objectGet');
Expand All @@ -17,6 +17,7 @@ const metadataswitch = require('../metadataswitch');
const { fakeMetadataArchive } = require('../../functional/aws-node-sdk/test/utils/init');
const bucketPutNotification = require('../../../lib/api/bucketPutNotification');
const bucketPutVersioning = require('../../../lib/api/bucketPutVersioning');
const bucketPutReplication = require('../../../lib/api/bucketPutReplication');

const any = sinon.match.any;
const originalDeleteObject = services.deleteObject;
Expand Down Expand Up @@ -301,6 +302,35 @@ describe('objectDelete API', () => {
});
});

it('should delete an object in an NFS bucket with replication', done => {
const testNFSBucketPutRequest = new DummyRequest({
bucketName,
namespace,
headers: { 'x-scal-nfs-enabled': 'true' },
url: `/${bucketName}`,
});
async.series(
[
next => bucketPut(authInfo, testNFSBucketPutRequest, log, next),
next =>
bucketPutReplication(
authInfo,
replicationTestUtils.createBucketPutReplicationReq(bucketName),
log,
next,
),
next => objectPut(authInfo, testPutObjectRequest, undefined, log, next),
next => objectDelete(authInfo, testDeleteRequest, log, next),
next =>
objectGet(authInfo, testGetObjectRequest, false, log, err => {
assert.strictEqual(err.is.NoSuchKey, true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare the error message instead of err.is.NoSuchKey, so a failure shows the actual error. If the object was not deleted, err is null and err.is throws a TypeError instead of a clear assertion failure.

Suggested change
assert.strictEqual(err.is.NoSuchKey, true);
assert.strictEqual(err?.message, 'NoSuchKey');

next();
}),
],
done,
);
});

it('should log when expiration is trying to delete a master version', done => {
const warnStub = sinon.stub(log, 'warn');
const testBucketPutVersionRequest = new DummyRequest({
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,26 @@ const versioningTestUtils = {
},
};

const replicationTestUtils = {
createBucketPutReplicationReq: bucketName => ({
bucketName,
headers: { host: `${bucketName}.s3.amazonaws.com` },
url: '/?replication',
post:
'<ReplicationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' +
'<Role>arn:aws:iam::account-id:role/src-resource</Role>' +
'<Rule>' +
'<Prefix></Prefix>' +
'<Status>Enabled</Status>' +
'<Destination>' +
'<Bucket>arn:aws:s3:::destination-bucket</Bucket>' +
'<StorageClass>us-east-2</StorageClass>' +
'</Destination>' +
'</Rule>' +
'</ReplicationConfiguration>',
}),
};

class TaggingConfigTester {
constructor() {
this._tags = { k1: 'v1', k2: 'v2' };
Expand Down Expand Up @@ -552,6 +572,7 @@ module.exports = {
CorsConfigTester,
objectLockTestUtils,
versioningTestUtils,
replicationTestUtils,
TaggingConfigTester,
AccessControlPolicy,
createRequestContext,
Expand Down
Loading