From 229e641f88182ebb3f0d10a9fd2c38dda7d59b44 Mon Sep 17 00:00:00 2001 From: williamlardier Date: Tue, 20 Feb 2024 12:42:18 +0100 Subject: [PATCH 1/4] CLDSRV-508: add missing parameters in buckjet tagging APIs --- lib/api/bucketDeleteTagging.js | 1 + lib/api/bucketPutTagging.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/api/bucketDeleteTagging.js b/lib/api/bucketDeleteTagging.js index ebea54b043..527b261395 100644 --- a/lib/api/bucketDeleteTagging.js +++ b/lib/api/bucketDeleteTagging.js @@ -27,6 +27,7 @@ async function bucketDeleteTagging(authInfo, request, log, callback) { authInfo, bucketName, requestType: request.apiMethods || 'bucketDeleteTagging', + request, }; try { diff --git a/lib/api/bucketPutTagging.js b/lib/api/bucketPutTagging.js index 18a5a58674..e0b0edc1b1 100644 --- a/lib/api/bucketPutTagging.js +++ b/lib/api/bucketPutTagging.js @@ -39,6 +39,7 @@ function bucketPutTagging(authInfo, request, log, callback) { authInfo, bucketName, requestType: request.apiMethods || 'bucketPutTagging', + request, }; let bucket = null; return waterfall([ From 4d343fe468cbdc26f2e6645e4bb0dee834fbb1f8 Mon Sep 17 00:00:00 2001 From: williamlardier Date: Tue, 20 Feb 2024 12:42:34 +0100 Subject: [PATCH 2/4] CLDSRV-508: standardize XML with object tagging API --- lib/api/bucketGetTagging.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/api/bucketGetTagging.js b/lib/api/bucketGetTagging.js index 9e9d48889c..080628efae 100644 --- a/lib/api/bucketGetTagging.js +++ b/lib/api/bucketGetTagging.js @@ -37,7 +37,7 @@ const escapeForXml = s3middleware.escapeForXml; function tagsToXml(tags) { const xml = []; - xml.push(''); + xml.push(' '); tags.forEach(tag => { xml.push(''); @@ -46,7 +46,7 @@ function tagsToXml(tags) { xml.push(''); }); - xml.push(''); + xml.push(' '); return xml.join(''); } From 34202eaa621129a2e2cca2fdc334767437a3afe2 Mon Sep 17 00:00:00 2001 From: williamlardier Date: Tue, 20 Feb 2024 12:44:07 +0100 Subject: [PATCH 3/4] CLDSRV-508: add tests for bucket tagging APIs --- tests/unit/api/bucketDeleteTagging.js | 74 +++++++++++++++++++++++++++ tests/unit/api/bucketGetTagging.js | 67 ++++++++++++++++++++++++ tests/unit/api/bucketPutTagging.js | 53 +++++++++++++++++++ tests/unit/helpers.js | 18 +++++++ 4 files changed, 212 insertions(+) create mode 100644 tests/unit/api/bucketDeleteTagging.js create mode 100644 tests/unit/api/bucketGetTagging.js create mode 100644 tests/unit/api/bucketPutTagging.js diff --git a/tests/unit/api/bucketDeleteTagging.js b/tests/unit/api/bucketDeleteTagging.js new file mode 100644 index 0000000000..7eeb98f1f8 --- /dev/null +++ b/tests/unit/api/bucketDeleteTagging.js @@ -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(); + }); + }); + }); +}); diff --git a/tests/unit/api/bucketGetTagging.js b/tests/unit/api/bucketGetTagging.js new file mode 100644 index 0000000000..a1c5f502db --- /dev/null +++ b/tests/unit/api/bucketGetTagging.js @@ -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(); + }); + }); + }); +}); + diff --git a/tests/unit/api/bucketPutTagging.js b/tests/unit/api/bucketPutTagging.js new file mode 100644 index 0000000000..1d95729c46 --- /dev/null +++ b/tests/unit/api/bucketPutTagging.js @@ -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(); + }); + }); +}); diff --git a/tests/unit/helpers.js b/tests/unit/helpers.js index f8ed6bac42..d4c017003d 100644 --- a/tests/unit/helpers.js +++ b/tests/unit/helpers.js @@ -442,6 +442,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 { From 46fe061895dba4dfa75d7d577b657902481bc5eb Mon Sep 17 00:00:00 2001 From: williamlardier Date: Tue, 20 Feb 2024 12:44:23 +0100 Subject: [PATCH 4/4] CLDSRV-508: bump project version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f723f93041..d35a06fb54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "s3", - "version": "7.70.44", + "version": "7.70.45", "description": "S3 connector", "main": "index.js", "engines": {