Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/w/8.6/bugfix/CLDSRV-508-fix-buck…
Browse files Browse the repository at this point in the history
…et-tagging' into w/8.7/bugfix/CLDSRV-508-fix-bucket-tagging
  • Loading branch information
williamlardier committed Feb 20, 2024
2 parents 3186a97 + a28b141 commit 2f2f91d
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/api/bucketDeleteTagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ function bucketDeleteTagging(authInfo, request, log, callback) {
authInfo,
bucketName,
requestType: request.apiMethods || 'bucketDeleteTagging',
request,
};

let bucket = null;
return waterfall([
next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log,
(err, b) => {
if (err) {
return next(err);
}
bucket = b;
bucket.setTags([]);
return next(err);
return next();
}),
next => metadata.updateBucket(bucket.getName(), bucket, log, next),
], err => {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/bucketGetTagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const escapeForXml = s3middleware.escapeForXml;
function tagsToXml(tags) {
const xml = [];

xml.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Tagging><TagSet>');
xml.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Tagging> <TagSet>');

tags.forEach(tag => {
xml.push('<Tag>');
Expand All @@ -46,7 +46,7 @@ function tagsToXml(tags) {
xml.push('</Tag>');
});

xml.push('</TagSet></Tagging>');
xml.push('</TagSet> </Tagging>');

return xml.join('');
}
Expand Down
1 change: 1 addition & 0 deletions lib/api/bucketPutTagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function bucketPutTagging(authInfo, request, log, callback) {
authInfo,
bucketName,
requestType: request.apiMethods || 'bucketPutTagging',
request,
};
let bucket = null;
return waterfall([
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenko/cloudserver",
"version": "8.7.45",
"version": "8.7.46",
"description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol",
"main": "index.js",
"engines": {
Expand Down
74 changes: 74 additions & 0 deletions tests/unit/api/bucketDeleteTagging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const assert = require('assert');

const { bucketPut } = require('../../../lib/api/bucketPut');
const { cleanup,
DummyRequestLogger,
makeAuthInfo,
TaggingConfigTester }
= require('../helpers');
const bucketPutTagging = require('../../../lib/api/bucketPutTagging');
const bucketGetTagging = require('../../../lib/api/bucketGetTagging');
const bucketDeleteTagging = require('../../../lib/api/bucketDeleteTagging');
const log = new DummyRequestLogger();
const authInfo = makeAuthInfo('accessKey1');
const bucketName = 'bucketGetTaggingTest';

const testBucketPutRequest = {
bucketName,
headers: { host: `${bucketName}.s3.amazonaws.com` },
url: '/',
actionImplicitDenies: false,
};

describe('deleteBucketTagging API', () => {
beforeEach(done => {
cleanup();
bucketPut(authInfo, testBucketPutRequest, log, done);
});

afterEach(() => cleanup());

it('should delete tags resource', done => {
const taggingUtil = new TaggingConfigTester();
const testBucketPutTaggingRequest = taggingUtil
.createBucketTaggingRequest('PUT', bucketName);
bucketPutTagging(authInfo, testBucketPutTaggingRequest, log, err => {
assert.strictEqual(err, undefined);

const testBucketGetTaggingRequest = taggingUtil
.createBucketTaggingRequest('GET', bucketName);
return bucketGetTagging(authInfo, testBucketGetTaggingRequest, log,
(err, xml) => {
assert.ifError(err);
assert.strictEqual(xml, taggingUtil.constructXml());
const testBucketDeleteTaggingRequest = taggingUtil
.createBucketTaggingRequest('DELETE', bucketName);
return bucketDeleteTagging(authInfo, testBucketDeleteTaggingRequest,
log, err => {
assert.ifError(err);
return bucketGetTagging(authInfo, testBucketGetTaggingRequest,
log, err => {
assert(err.NoSuchTagSet);
return done();
});
});
});
});
});

it('should return access denied if the authorization check fails', done => {
const taggingUtil = new TaggingConfigTester();
const testBucketPutTaggingRequest = taggingUtil
.createBucketTaggingRequest('PUT', bucketName);
bucketPutTagging(authInfo, testBucketPutTaggingRequest, log, err => {
assert.ifError(err);
const testBucketDeleteTaggingRequest = taggingUtil
.createBucketTaggingRequest('DELETE', bucketName, null, true);
return bucketDeleteTagging(authInfo, testBucketDeleteTaggingRequest,
log, err => {
assert(err.AccessDenied);
return done();
});
});
});
});
67 changes: 67 additions & 0 deletions tests/unit/api/bucketGetTagging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const assert = require('assert');

const { bucketPut } = require('../../../lib/api/bucketPut');
const { cleanup,
DummyRequestLogger,
makeAuthInfo,
TaggingConfigTester,
} = require('../helpers');
const bucketPutTagging = require('../../../lib/api/bucketPutTagging');
const bucketGetTagging = require('../../../lib/api/bucketGetTagging');
const log = new DummyRequestLogger();
const authInfo = makeAuthInfo('accessKey1');
const bucketName = 'bucketGetTaggingTest';

const testBucketPutRequest = {
bucketName,
headers: { host: `${bucketName}.s3.amazonaws.com` },
url: '/',
actionImplicitDenies: false,
};

describe('getBucketTagging API', () => {
beforeEach(done => {
cleanup();
bucketPut(authInfo, testBucketPutRequest, log, done);
});

afterEach(() => cleanup());

it('should return tags resource', done => {
const taggingUtil = new TaggingConfigTester();
const testBucketPutTaggingRequest = taggingUtil
.createBucketTaggingRequest('PUT', bucketName);
bucketPutTagging(authInfo, testBucketPutTaggingRequest, log, err => {
assert.strictEqual(err, undefined);
const testBucketGetTaggingRequest = taggingUtil
.createBucketTaggingRequest('GET', bucketName);
return bucketGetTagging(authInfo, testBucketGetTaggingRequest, log,
(err, xml) => {
if (err) {
process.stdout.write(`Err getting object tagging ${err}`);
return done(err);
}
assert.strictEqual(xml, taggingUtil.constructXml());
return done();
});
});
});

it('should return access denied if the authorization check fails', done => {
const taggingUtil = new TaggingConfigTester();
const testBucketPutTaggingRequest = taggingUtil
.createBucketTaggingRequest('PUT', bucketName);
bucketPutTagging(authInfo, testBucketPutTaggingRequest, log, err => {
assert.strictEqual(err, undefined);
const testBucketGetTaggingRequest = taggingUtil
.createBucketTaggingRequest('GET', bucketName, true);
const badAuthInfo = makeAuthInfo('accessKey2');
return bucketGetTagging(badAuthInfo, testBucketGetTaggingRequest, log,
err => {
assert.strictEqual(err.AccessDenied, true);
return done();
});
});
});
});

53 changes: 53 additions & 0 deletions tests/unit/api/bucketPutTagging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const assert = require('assert');

const { bucketPut } = require('../../../lib/api/bucketPut');
const { cleanup,
DummyRequestLogger,
makeAuthInfo,
TaggingConfigTester,
} = require('../helpers');
const bucketPutTagging = require('../../../lib/api/bucketPutTagging');
const log = new DummyRequestLogger();
const authInfo = makeAuthInfo('accessKey1');
const bucketName = 'bucketGetTaggingTest';

const testBucketPutRequest = {
bucketName,
headers: { host: `${bucketName}.s3.amazonaws.com` },
url: '/',
actionImplicitDenies: false,
};

describe('putBucketTagging API', () => {
beforeEach(done => {
cleanup();
bucketPut(authInfo, testBucketPutRequest, log, done);
});

afterEach(() => cleanup());

it('should set tags resource', done => {
const taggingUtil = new TaggingConfigTester();
const testBucketPutTaggingRequest = taggingUtil
.createBucketTaggingRequest('PUT', bucketName);
bucketPutTagging(authInfo, testBucketPutTaggingRequest, log, err => {
if (err) {
process.stdout.write(`Err putting object tagging ${err}`);
return done(err);
}
assert.strictEqual(err, undefined);
return done();
});
});

it('should return access denied if the authorization check fails', done => {
const taggingUtil = new TaggingConfigTester();
const testBucketPutTaggingRequest = taggingUtil
.createBucketTaggingRequest('PUT', bucketName);
const authInfo = makeAuthInfo('accessKey2');
bucketPutTagging(authInfo, testBucketPutTaggingRequest, log, err => {
assert(err.AccessDenied);
return done();
});
});
});
18 changes: 18 additions & 0 deletions tests/unit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ class TaggingConfigTester {
}
return request;
}

createBucketTaggingRequest(method, bucketName, body, implicitDeny = false) {
const request = {
bucketName,
headers: {
host: `${bucketName}.s3.amazonaws.com`,
},
url: '/?tagging',
query: { tagging: '' },
actionImplicitDenies: implicitDeny,
};
if (method === 'PUT') {
request.post = body || this.constructXml();
request.headers['content-md5'] = crypto.createHash('md5')
.update(request.post, 'utf8').digest('base64');
}
return request;
}
}

class AccessControlPolicy {
Expand Down

0 comments on commit 2f2f91d

Please sign in to comment.