From 5443e36b56fecbd90f547ceb16679c027128c972 Mon Sep 17 00:00:00 2001 From: Steeve Payraudeau <16964532+steevepay@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:40:08 +0400 Subject: [PATCH] Fix bucket alias --- CHANGELOG.md | 3 +++ package.json | 2 +- s3.js | 2 +- tests/s3.test.js | 35 +++++++++++------------------------ 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40e0b81..1204b15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v1.0.2 +- Fixed Bucket aliases generating a false AWS4 signature + ### v1.0.1 - Remove unused code - Update documentation diff --git a/package.json b/package.json index be3040a..471a932 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tiny-storage-client", - "version": "1.0.1", + "version": "1.0.2", "description": "Tiny node client to request distributed AWS S3 or the OpenStack Swift Object Storage.", "main": "index.js", "scripts": { diff --git a/s3.js b/s3.js index 745af3d..27d5180 100644 --- a/s3.js +++ b/s3.js @@ -276,7 +276,7 @@ function request (method, path, options, callback) { /** REQUIRED FOR AWS4 SIGNATURE */ service: 's3', hostname: _activeStorage.url, - path: `${path}${_urlParams ?? ''}`, + path: `${_path}${_urlParams ?? ''}`, region: _activeStorage.region, protocol: 'https:' }, { diff --git a/tests/s3.test.js b/tests/s3.test.js index 62186c3..9c2e59f 100644 --- a/tests/s3.test.js +++ b/tests/s3.test.js @@ -17,7 +17,7 @@ const fileXml = fs.readFileSync(fileXmlPath).toString(); const _listObjectsResponseXML = fs.readFileSync(path.join(__dirname, "./assets", 'listObjects.response.xml')); const _listObjectsResponseJSON = require('./assets/listObjects.response.json'); -describe.only('S3 SDK', function () { +describe('S3 SDK', function () { beforeEach(function() { storage = s3([{ @@ -94,27 +94,6 @@ describe.only('S3 SDK', function () { }); }) - describe('request - CALLBACK', function() { - - describe("REQUEST MAIN STORAGE", function () { - - }); - - describe("SWITCH TO CHILD STORAGE", function () { - }); - - }); - - describe('request - STREAM', function() { - - describe("REQUEST MAIN STORAGE", function () { - }); - - describe("SWITCH TO CHILD STORAGE", function () { - }); - - }); - describe('headBucket', function() { describe("REQUEST MAIN STORAGE", function () { @@ -590,10 +569,18 @@ describe.only('S3 SDK', function () { 'x-amz-request-id': '318BC8BC148832E5', 'x-amz-id-2': 'eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran' } - const nockRequest = nock(url1S3) + const nockRequest = nock(url1S3, { + reqheaders: { + 'x-amz-content-sha256': () => true, + 'x-amz-date': () => true, + 'authorization': () => true, + 'host': () => true + } + }) .defaultReplyHeaders(_header) .get('/invoices-gra-1234/file.docx') - .reply(200, () => { + .reply(200, (uri, body) => { + console.log(uri); return fileTxt; }); storage.downloadFile('invoices', 'file.docx', function (err, resp) {