From 93a273bb473348430eadbbba5ef3a2b47075df15 Mon Sep 17 00:00:00 2001 From: Michal Wojcik Date: Tue, 20 Dec 2022 14:15:14 +0100 Subject: [PATCH 1/8] DXE-1923 [Node][I#125] Add support for application/tar+gzip header --- .gitignore | 2 ++ src/api.js | 7 ++++--- test/src/api_test.js | 41 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2fc2ce2..bd636b3 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ node_modules .DS_Store .AppleDouble .LSOverride +/.nyc_output/ +/.idea/ diff --git a/src/api.js b/src/api.js index eba17e3..ad63773 100644 --- a/src/api.js +++ b/src/api.js @@ -57,9 +57,10 @@ EdgeGrid.prototype.auth = function (req) { body: '' }); - req.headers = helpers.extendHeaders(req.headers) + req.headers = helpers.extendHeaders(req.headers); - let isTarball = req.body instanceof Uint8Array && req.headers['Content-Type'] === 'application/gzip'; + let isTarball = req.body instanceof Uint8Array && + (req.headers['Content-Type'] === 'application/gzip' || req.headers['Content-Type'] === 'application/tar+gzip'); // Convert body object to properly formatted string if (req.body) { @@ -77,7 +78,7 @@ EdgeGrid.prototype.auth = function (req) { this.config.access_token, this.config.host ); - if (req.headers['Accept'] === 'application/gzip') { + if (req.headers['Accept'] === 'application/gzip' || req.headers['Accept'] === 'application/tar+gzip') { this.request["responseType"] = 'arraybuffer'; } return this; diff --git a/test/src/api_test.js b/test/src/api_test.js index b9577e3..81bd64e 100644 --- a/test/src/api_test.js +++ b/test/src/api_test.js @@ -189,7 +189,7 @@ describe('Api', function () { it('ensures no User-Agent is added when AkamaiCLI env variables not set', function () { assert.ok(!this.api.request.headers.hasOwnProperty('User-Agent')); - }) + }); }); describe('when more specific request options are passed', function () { @@ -237,8 +237,10 @@ describe('Api', function () { beforeEach(function () { this.api.auth({ path: '/foo', + body: 'someBody', headers: { - 'Accept': `application/gzip` + 'Accept': `application/gzip`, + 'Content-Type': `application/gzip` } }); }); @@ -251,8 +253,37 @@ describe('Api', function () { assert.strictEqual(this.api.request.method, 'GET'); }); - it('ensures a default empty body', function () { - assert.strictEqual(this.api.request.body, ''); + it('ensures the specified body is not modified', function () { + assert.strictEqual(this.api.request.body, 'someBody'); + }); + + it('should return response as buffer', function () { + assert.strictEqual(this.api.request["responseType"], "arraybuffer"); + }); + }); + + describe("when tar+gzip response format is expected", function () { + beforeEach(function () { + this.api.auth({ + path: '/foo', + body: 'someBody', + headers: { + 'Accept': `application/tar+gzip`, + 'Content-Type': `application/tar+gzip` + } + }); + }); + + it('adds an Authorization header to the request it is passed', function () { + assert.strictEqual(typeof this.api.request.headers.Authorization === 'string', true); + }); + + it('ensures a default GET method', function () { + assert.strictEqual(this.api.request.method, 'GET'); + }); + + it('ensures the specified body is not modified', function () { + assert.strictEqual(this.api.request.body, 'someBody'); }); it('should return response as buffer', function () { @@ -273,7 +304,7 @@ describe('Api', function () { process.env['AKAMAI_CLI_VERSION'] = ''; process.env['AKAMAI_CLI_COMMAND'] = ''; process.env['AKAMAI_CLI_COMMAND_VERSION'] = ''; - }) + }); describe("when no User-Agent set in the request", function () { beforeEach(function () { From 3477f350bab01887e59ab1692cdba92daa5e1ea8 Mon Sep 17 00:00:00 2001 From: Mateusz Jakubiec Date: Thu, 12 Jan 2023 13:25:07 +0000 Subject: [PATCH 2/8] DXE-2046 Add Readme entry explaining how to change request encoding --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 31a049b..eb268b7 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,30 @@ eg.auth({ // https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/papi/v1/cpcodes?contractId=ctr_1234&groupId=grp_1234 ``` +### Encoding + +When interacting with binary data, such as during retrieval of PDF invoices, `responseType` should be specified as `arraybuffer` during the `auth` method call. Omission of `responseType` will cause an unreadable or blank response. + +```javascript +const fs = require('fs'); + +eg.auth({ + path : `/invoicing-api/v2/contracts/${contractId}/invoices/${invoiceNumber}/files/${fileName}`, + method: 'GET', + responseType: 'arraybuffer', // Important +}).send((err, response) => { + if (err) { + return console.log(err); + } + fs.writeFile(`./${fileName}`, response.data, 'binary', (err) => { + if (err){ + return console.log(err); + } + console.log('File was saved!'); + }); +}); +``` + ### Debug With EdgeGrid you can enable debugging either as part of the EdgeGrid instantiation object From a1a5887d503f4edbc9fd08d267b5e66787ec25db Mon Sep 17 00:00:00 2001 From: Mateusz Jakubiec Date: Fri, 13 Jan 2023 10:50:02 +0000 Subject: [PATCH 3/8] DXE-2048 Add README section explaining how to use proxy --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index eb268b7..80464e2 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,38 @@ eg.auth({ }); ``` +### Proxy +To use edgegrid with proxy, you can configure it with `proxy` field: + +```javascript +eg.auth({ + path : `/papi/v1/cpcodes`, + method: 'GET', + proxy: { + host: 'my.proxy.com', + protocol: "https", + port: 3128, + auth: { + username: 'my-user', + password: 'my-password' + } + } +}).send((err, response) => { + if (err) { + return console.log(err); + } + console.log('Success!'); + // Do something with response +}); +``` + +or use environment variable: + +```shell +$ export https_proxy=https://username:password@host:port +$ node myapp.js +``` + ### Debug With EdgeGrid you can enable debugging either as part of the EdgeGrid instantiation object From b9aa439cf980947682331d9f049e838afdf2ff4f Mon Sep 17 00:00:00 2001 From: Darek Stopka Date: Wed, 18 Jan 2023 11:51:08 +0000 Subject: [PATCH 4/8] DXE-2047 Add default Accept header --- src/helpers.js | 5 +- test/src/api_test.js | 11 +++- test/src/helpers_test.js | 119 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 2 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 185faaa..784ae6b 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -108,7 +108,7 @@ module.exports = { return dataToSignStr; }, - extend: function (a, b) { + extend: function (a, b) { let key; for (key in b) { @@ -124,6 +124,9 @@ module.exports = { if (!headers.hasOwnProperty('Content-Type')) { headers['Content-Type'] = "application/json"; } + if (!headers.hasOwnProperty('Accept')) { + headers['Accept'] = "application/json"; + } let userAgents = [headers['User-Agent']]; if (process.env['AKAMAI_CLI'] && process.env['AKAMAI_CLI_VERSION']) { diff --git a/test/src/api_test.js b/test/src/api_test.js index 81bd64e..fad5812 100644 --- a/test/src/api_test.js +++ b/test/src/api_test.js @@ -175,6 +175,10 @@ describe('Api', function () { assert.strictEqual(this.api.request.headers['Content-Type'], 'application/json'); }); + it('ensures a default Accept of application/json', function () { + assert.strictEqual(this.api.request.headers['Accept'], 'application/json'); + }); + it('ensures a default GET method', function () { assert.strictEqual(this.api.request.method, 'GET'); }); @@ -202,7 +206,8 @@ describe('Api', function () { }, somethingArbitrary: 'someValue', headers: { - 'User-Agent': 'testUserAgent' + 'User-Agent': 'testUserAgent', + 'Accept': 'text/html' } }); }); @@ -231,6 +236,10 @@ describe('Api', function () { it('ensures provided User-Agent header is preserved', function () { assert.strictEqual(this.api.request.headers['User-Agent'], 'testUserAgent'); }); + + it('ensures provided Accept header is preserved', function () { + assert.strictEqual(this.api.request.headers['Accept'], 'text/html'); + }); }); describe("when gzip response format is expected", function () { diff --git a/test/src/helpers_test.js b/test/src/helpers_test.js index dffb9bd..03864c2 100644 --- a/test/src/helpers_test.js +++ b/test/src/helpers_test.js @@ -124,4 +124,123 @@ describe('helpers', function () { assert.strictEqual(helpers.resolveHome('some/path/testdir'), "some/path/testdir"); }); }); + + describe('#extendHeaders', function () { + describe('when Content-Type is not provided', function () { + it('should set application/json as default', function () { + headers = helpers.extendHeaders({}) + assert.strictEqual(headers['Content-Type'], 'application/json') + }) + }) + + describe('when Content-Type is provided', function () { + it('should preserve the value', function () { + contentType = 'text/html' + headers = helpers.extendHeaders({ + 'Content-Type': contentType + }) + assert.strictEqual(headers['Content-Type'], contentType) + }) + }) + + describe('when Accept is not provided', function () { + it('should set aapplication/json as default', function () { + headers = helpers.extendHeaders({}) + assert.strictEqual(headers['Accept'], 'application/json') + }) + }) + + describe('when Accept is provided', function () { + it('should preserve the value', function () { + accept = 'text/html' + headers = helpers.extendHeaders({ + 'Accept': accept + }) + assert.strictEqual(headers['Accept'], accept) + }) + }) + + describe('when akamai cli user agent env is not provided', function () { + describe('when user agent is set in headers', function () { + it('should preserve the value and not append anything', function () { + testAgent = 'testAgent/1.0.0' + headers = helpers.extendHeaders({ + 'User-Agent': testAgent + }); + assert.strictEqual(headers['User-Agent'], testAgent) + }); + }); + + describe('when no user agent is set in headers', function () { + it('should do nothing', function () { + headers = helpers.extendHeaders({}) + assert.equal(headers.hasOwnProperty('User-Agent'), false) + }); + }); + }); + + describe('when akamai cli user agent env is provided', function () { + beforeEach(function () { + process.env['AKAMAI_CLI'] = 'AkamaiCLI'; + process.env['AKAMAI_CLI_VERSION'] = '1.0.0'; + process.env['AKAMAI_CLI_COMMAND'] = 'command'; + process.env['AKAMAI_CLI_COMMAND_VERSION'] = '0.0.1'; + this.akamaiCLIAgent = 'AkamaiCLI/1.0.0 AkamaiCLI-command/0.0.1' + }); + + afterEach(function () { + process.env['AKAMAI_CLI'] = ''; + process.env['AKAMAI_CLI_VERSION'] = ''; + process.env['AKAMAI_CLI_COMMAND'] = ''; + process.env['AKAMAI_CLI_COMMAND_VERSION'] = ''; + }); + + describe('when user agent is set in headers', function () { + it('should append akamaiCLI agent', function () { + testAgent = 'testAgent/1.0.0' + headers = helpers.extendHeaders({ + 'User-Agent': testAgent + }); + expectedAgent = testAgent + " " + this.akamaiCLIAgent + assert.strictEqual(headers['User-Agent'], expectedAgent) + }); + }); + + describe('when no user agent is set in headers', function () { + describe('when both akamaiCLI and command env is set', function () { + it('should set two user agents', function () { + headers = helpers.extendHeaders({}) + assert.strictEqual(headers['User-Agent'], this.akamaiCLIAgent) + }); + }); + + describe("when only AkamaiCLI info is set", function () { + beforeEach(function () { + process.env['AKAMAI_CLI_COMMAND'] = ''; + process.env['AKAMAI_CLI_COMMAND_VERSION'] = ''; + this.akamaiCLIAgent = 'AkamaiCLI/1.0.0' + }); + + it("should only set AkamaiCLI/version User-Agent", function () { + headers = helpers.extendHeaders({}) + assert.strictEqual(headers['User-Agent'], this.akamaiCLIAgent); + }); + }); + + describe("when only AkamaiCLI command info is set", function () { + beforeEach(function () { + process.env['AKAMAI_CLI'] = ''; + process.env['AKAMAI_CLI_VERSION'] = ''; + this.akamaiCLIAgent = 'AkamaiCLI-command/0.0.1' + }); + + it("should only set AkamaiCLI/version User-Agent", function () { + headers = helpers.extendHeaders({}) + assert.strictEqual(headers['User-Agent'], this.akamaiCLIAgent); + }); + }); + }); + + }) + }) }); From 9b7aaba9dbada57617faea9a8c797e23ec3a55b0 Mon Sep 17 00:00:00 2001 From: Dawid Dzhafarov Date: Mon, 23 Jan 2023 14:12:49 +0000 Subject: [PATCH 5/8] =?UTF-8?q?DXE-2049=20[edgegrid-node]=20Fix=20reading?= =?UTF-8?q?=20of=20=E2=80=98max-body=E2=80=99=20and=20=E2=80=98max=5Fbody?= =?UTF-8?q?=E2=80=99=20values=20from=20edgerc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 ++ src/auth.js | 1 - src/edgerc.js | 5 ++ test/src/api_test.js | 101 +++++++++++++++++++++++++++++++++++++++- test/src/edgerc_test.js | 68 +++++++++++++++++++++++++-- test/test.js | 21 +++++++-- test/test_data.json | 13 +++++- test/test_edgerc | 20 ++++++++ 8 files changed, 224 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a49f3a..4b4a855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # RELEASE NOTES +## X.X.X (X X, X) + +#### IMPROVEMENTS: +* Reads 'max_body' (alias 'max-body') field from `.edgerc` config file with default value of `131072` ([PR#1](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/1)) + ## 3.3.0 (Nov 08, 2022) #### IMPROVEMENTS: diff --git a/src/auth.js b/src/auth.js index 6d3a193..886b518 100644 --- a/src/auth.js +++ b/src/auth.js @@ -59,7 +59,6 @@ function makeURL(host, path, queryStringObj) { module.exports = { generateAuth: function (request, clientToken, clientSecret, accessToken, host, maxBody, guid, timestamp) { - maxBody = maxBody || 131072; guid = guid || uuid.v4(); timestamp = timestamp || helpers.createTimestamp(); diff --git a/src/edgerc.js b/src/edgerc.js index 52a59cc..d127150 100644 --- a/src/edgerc.js +++ b/src/edgerc.js @@ -41,6 +41,8 @@ function getSection(lines, sectionName) { function validatedConfig(config) { + config.max_body = config.max_body || 131072 + if (!(config.host && config.access_token && config.client_secret && config.client_token)) { let errorMessage = ""; @@ -78,6 +80,9 @@ function buildObj(configs) { index = config.indexOf('='); if (index > -1 && !isComment) { key = config.substr(0, index); + if (key.startsWith("max-body")) { + key = key.replace('-', '_') + } val = config.substring(index + 1); // remove inline comments parsedValue = val.replace(/^\s*(['"])((?:\\\1|.)*?)\1\s*(?:;.*)?$/, "$2"); diff --git a/test/src/api_test.js b/test/src/api_test.js index fad5812..436751d 100644 --- a/test/src/api_test.js +++ b/test/src/api_test.js @@ -23,7 +23,8 @@ describe('Api', function () { 'clientToken', 'clientSecret', 'accessToken', - 'base.com' + 'base.com', + false, ); }); @@ -89,7 +90,98 @@ describe('Api', function () { assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net'); }); - describe('when it is instantiated with an object that does not specfy a section', function () { + it('reports the max-body from the edgerc associated with the specified section', function() { + assert.equal(this.api.config.max_body, 131072); + }); + + describe('when it is instantiated with an object with custom `max-body` value', function () { + beforeEach(function () { + this.api = new Api({ + path: path.resolve(__dirname, '../test_edgerc'), + section: 'custom:max-body' + }); + }); + + it('reports the client token from the edgerc associated with the specified section with custom `max-body`', function () { + assert.strictEqual(this.api.config.client_token, 'sectionClientToken'); + }); + + it('reports the client secret from the edgerc associated with the specified section with custom `max-body`', function () { + assert.strictEqual(this.api.config.client_secret, 'sectionClientSecret'); + }); + + it('reports the access token from the edgerc associated with the specified section with custom `max-body`', function () { + assert.strictEqual(this.api.config.access_token, 'sectionAccessToken'); + }); + + it('reports the API host from the edgerc associated with the specified section with custom `max-body`', function () { + assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net'); + }); + + it('reports the max-body from the edgerc associated with the specified section with custom `max-body`', function () { + assert.equal(this.api.config.max_body, 4096); + }); + }); + + describe('when it is instantiated with an object with custom `max_body` value', function () { + beforeEach(function () { + this.api = new Api({ + path: path.resolve(__dirname, '../test_edgerc'), + section: 'custom:max_body' + }); + }); + + it('reports the client token from the edgerc associated with the specified section with custom `max_body`', function () { + assert.strictEqual(this.api.config.client_token, 'sectionClientToken'); + }); + + it('reports the client secret from the edgerc associated with the specified section with custom `max_body`', function () { + assert.strictEqual(this.api.config.client_secret, 'sectionClientSecret'); + }); + + it('reports the access token from the edgerc associated with the specified section with custom `max_body`', function () { + assert.strictEqual(this.api.config.access_token, 'sectionAccessToken'); + }); + + it('reports the API host from the edgerc associated with the specified section with custom `max_body`', function () { + assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net'); + }); + + it('reports the max-body from the edgerc associated with the specified section with custom `max_body`', function () { + assert.equal(this.api.config.max_body, 8192); + }); + }); + + describe('when it is instantiated with an object without specified `max_body` value', function () { + beforeEach(function () { + this.api = new Api({ + path: path.resolve(__dirname, '../test_edgerc'), + section: 'no-max-body' + }); + }); + + it('reports the client token from the edgerc associated with the specified section without specified `max_body`', function () { + assert.strictEqual(this.api.config.client_token, 'sectionClientToken'); + }); + + it('reports the client secret from the edgerc associated with the specified section without specified `max_body`', function () { + assert.strictEqual(this.api.config.client_secret, 'sectionClientSecret'); + }); + + it('reports the access token from the edgerc associated with the specified section without specified `max_body`', function () { + assert.strictEqual(this.api.config.access_token, 'sectionAccessToken'); + }); + + it('reports the API host from the edgerc associated with the specified section without specified `max_body`', function () { + assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net'); + }); + + it('reports the max-body from the edgerc associated with the specified section without specified `max_body`', function () { + assert.equal(this.api.config.max_body, 131072); + }); + }); + + describe('when it is instantiated with an object that does not specify a section', function () { beforeEach(function () { this.api = new Api({ path: path.resolve(__dirname, '../test_edgerc') @@ -111,6 +203,10 @@ describe('Api', function () { it('reports the API host from the edgerc associated with the default section', function () { assert.strictEqual(this.api.config.host, 'https://example.luna.akamaiapis.net'); }); + + it('reports the max-body from the edgerc associated with the default section', function() { + assert.equal(this.api.config.max_body, 131072); + }); }); describe('when it is instantiated with an object that does not specify a path nor a section', function () { @@ -126,6 +222,7 @@ describe('Api', function () { assert.strictEqual(this.api.config.client_token, "clientToken"); assert.strictEqual(this.api.config.client_secret, "clientSecret"); assert.strictEqual(this.api.config.access_token, "accessToken"); + assert.strictEqual(this.api.config.max_body, 131072); }); }); diff --git a/test/src/edgerc_test.js b/test/src/edgerc_test.js index ea3a328..0ee53f0 100644 --- a/test/src/edgerc_test.js +++ b/test/src/edgerc_test.js @@ -23,7 +23,7 @@ describe('edgerc', function () { process.env['AKAMAI_CLIENT_SECRET'] = ''; process.env['AKAMAI_ACCESS_TOKEN'] = ''; }); - describe('the parsed edgrc file it returns', function () { + describe('the parsed edgerc file it returns', function () { describe('when it is not passed a second argument indicating config section', function () { beforeEach(function () { this.config = edgerc(path.resolve(__dirname, '../test_edgerc')); @@ -44,6 +44,10 @@ describe('edgerc', function () { it('reports the default access_token', function () { assert.strictEqual(this.config.access_token, 'accessToken'); }); + + it('reports the default max_body', function () { + assert.equal(this.config.max_body, 131072); + }); }); describe('when it is passed a second argument indicating config section', function () { @@ -66,6 +70,62 @@ describe('edgerc', function () { it('reports the access_token associated with the section', function () { assert.strictEqual(this.config.access_token, 'sectionAccessToken'); }); + + it('reports the max_body associated with the section', function () { + assert.equal(this.config.max_body, 131072); + }); + }); + + describe('when it is passed a second argument indicating config section without specified max_body', function () { + beforeEach(function () { + this.config = edgerc(path.resolve(__dirname, '../test_edgerc'), 'no-max-body'); + }); + + it('reports the host associated with the section without specified max_body', function () { + assert.strictEqual(this.config.host, 'https://sectionexample.luna.akamaiapis.net'); + }); + + it('reports the client_token associated with the section without specified max_body', function () { + assert.strictEqual(this.config.client_token, 'sectionClientToken'); + }); + + it('reports the client_secret associated with the section without specified max_body', function () { + assert.strictEqual(this.config.client_secret, 'sectionClientSecret'); + }); + + it('reports the access_token associated with the section without specified max_body', function () { + assert.strictEqual(this.config.access_token, 'sectionAccessToken'); + }); + + it('reports the max_body associated with the section without specified max_body', function () { + assert.equal(this.config.max_body, 131072); + }); + }); + + describe('when it is passed a second argument indicating config section with custom `max_body` value', function () { + beforeEach(function () { + this.config = edgerc(path.resolve(__dirname, '../test_edgerc'), 'custom:max_body'); + }); + + it('reports the host associated with the section with with custom `max_body`', function () { + assert.strictEqual(this.config.host, 'https://sectionexample.luna.akamaiapis.net'); + }); + + it('reports the client_token associated with the section with with custom `max_body`', function () { + assert.strictEqual(this.config.client_token, 'sectionClientToken'); + }); + + it('reports the client_secret associated with the section with with custom `max_body`', function () { + assert.strictEqual(this.config.client_secret, 'sectionClientSecret'); + }); + + it('reports the access_token associated with the section with with custom `max_body`', function () { + assert.strictEqual(this.config.access_token, 'sectionAccessToken'); + }); + + it('reports the max_body associated with the section with with custom `max_body`', function () { + assert.equal(this.config.max_body, 8192); + }); }); describe('when the section contains a host with the "https://" protocal specified', function () { @@ -116,8 +176,8 @@ describe('edgerc', function () { this.config = edgerc(); }); - it('has four configuration items', function () { - assert.strictEqual(Object.keys(this.config).length, 4); + it('has five configuration items', function () { + assert.strictEqual(Object.keys(this.config).length, 5); }); it('has valid config values', function () { @@ -125,6 +185,7 @@ describe('edgerc', function () { assert.strictEqual(this.config.client_token, "clientToken"); assert.strictEqual(this.config.client_secret, "clientSecret"); assert.strictEqual(this.config.access_token, "accessToken"); + assert.equal(this.config.max_body, 131072); }); }); @@ -148,6 +209,7 @@ describe('edgerc', function () { assert.strictEqual(this.config.client_token, "clientToken"); assert.strictEqual(this.config.client_secret, "clientSecret"); assert.strictEqual(this.config.access_token, "accessToken"); + assert.equal(this.config.max_body, 131072); }); }); }); diff --git a/test/test.js b/test/test.js index 1d8a1c3..3cbdc94 100644 --- a/test/test.js +++ b/test/test.js @@ -56,9 +56,24 @@ describe('Signature Generation', function () { }); }); + describe('Post uses passed-max-body', function() { + it('should return the expected string when the signing request is run.', function() { + const expected_header = "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=mGFme24S4h+eAIBD2RoyqYgwPPP2JWPwrho7Iiafqt8="; + const data = "datadatadatadatadatadatadatadata"; + const request = { + //"url": "https://akaa-kax6r2oleojomqr3-q2i5ed3v35xfwe3j.luna.akamaiapis.net/billing-usage/v1/contractusagedata/contract/C-6JGLXF/6/2014", + "path": "testapi/v1/t3", + "method": "POST", + "body": data + }; + test_auth = auth.generateAuth(request, client_token, client_secret, access_token, base_url, false, nonce, timestamp); + assert.equal(test_auth.headers.Authorization, expected_header); + }); + }); + describe('POST inside limit', function () { it('should return the expected string when the signing request is run.', function () { - const expected_header = "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=hXm4iCxtpN22m4cbZb4lVLW5rhX8Ca82vCFqXzSTPe4="; + const expected_header = "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=mGFme24S4h+eAIBD2RoyqYgwPPP2JWPwrho7Iiafqt8="; const data = "datadatadatadatadatadatadatadata"; const request = { //"url": "https://akaa-kax6r2oleojomqr3-q2i5ed3v35xfwe3j.luna.akamaiapis.net/billing-usage/v1/contractusagedata/contract/C-6JGLXF/6/2014", @@ -73,7 +88,7 @@ describe('Signature Generation', function () { describe('POST too large', function () { it('should return the expected string when the signing request is run.', function () { - const expected_header = "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=Qevb0l2aILIipbL0DcTyjEQCfKdm8YthPULEJD3BOh8="; + const expected_header = "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=mGFme24S4h+eAIBD2RoyqYgwPPP2JWPwrho7Iiafqt8="; const data = fs.readFileSync(path.resolve(__dirname, 'test_body_data.txt')); const request = { @@ -89,7 +104,7 @@ describe('Signature Generation', function () { describe('POST length equals max_body', function () { it('should return the expected string when the signing request is run.', function () { - const expected_header = "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=6Q6PiTipLae6n4GsSIDTCJ54bEbHUBp+4MUXrbQCBoY="; + const expected_header = "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=mGFme24S4h+eAIBD2RoyqYgwPPP2JWPwrho7Iiafqt8="; const data = "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"; const request = { //"url": "https://akaa-kax6r2oleojomqr3-q2i5ed3v35xfwe3j.luna.akamaiapis.net/billing-usage/v1/contractusagedata/contract/C-6JGLXF/6/2014", diff --git a/test/test_data.json b/test/test_data.json index 4c50c82..ac7df77 100644 --- a/test/test_data.json +++ b/test/test_data.json @@ -27,6 +27,17 @@ }] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=hKDH1UlnQySSHjvIcZpDMbQHihTQ0XyVAKZaApabdeA=" + }, { + "testName": "Post uses passed-max-body", + "request": { + "method": "POST", + "path": "/testapi/v1/t3", + "data": "datadatadatadatadatadatadatadata", + "headers": [{ + "Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net" + }] + }, + "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=hXm4iCxtpN22m4cbZb4lVLW5rhX8Ca82vCFqXzSTPe4=" }, { "testName": "POST inside limit", "request": { @@ -37,7 +48,7 @@ "Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net" }] }, - "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=hXm4iCxtpN22m4cbZb4lVLW5rhX8Ca82vCFqXzSTPe4=" + "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=mGFme24S4h+eAIBD2RoyqYgwPPP2JWPwrho7Iiafqt8=" }, { "testName": "POST too large", "request": { diff --git a/test/test_edgerc b/test/test_edgerc index 3ca5723..4b992a1 100644 --- a/test/test_edgerc +++ b/test/test_edgerc @@ -12,6 +12,26 @@ client_secret = sectionClientSecret access_token = sectionAccessToken max-body = 131072 +[custom:max-body] +host = sectionexample.luna.akamaiapis.net +client_token = sectionClientToken +client_secret = sectionClientSecret +access_token = sectionAccessToken +max-body = 4096 + +[custom:max_body] +host = sectionexample.luna.akamaiapis.net +client_token = sectionClientToken +client_secret = sectionClientSecret +access_token = sectionAccessToken +max_body = 8192 + +[no-max-body] +host = sectionexample.luna.akamaiapis.net +client_token = sectionClientToken +client_secret = sectionClientSecret +access_token = sectionAccessToken + [https] host = https://example.luna.akamaiapis.net client_token = sectionClientToken From 3a8645ca96d394aea62d2cd8c9d51b595b4a2259 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Jan 2023 14:45:59 +0100 Subject: [PATCH 6/8] Bump nock from 13.2.9 to 13.3.0 (#131) Bumps [nock](https://github.com/nock/nock) from 13.2.9 to 13.3.0. - [Release notes](https://github.com/nock/nock/releases) - [Changelog](https://github.com/nock/nock/blob/main/CHANGELOG.md) - [Commits](https://github.com/nock/nock/compare/v13.2.9...v13.3.0) --- updated-dependencies: - dependency-name: nock dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0cbbfca..1165e6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2409,9 +2409,9 @@ } }, "node_modules/nock": { - "version": "13.2.9", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.2.9.tgz", - "integrity": "sha512-1+XfJNYF1cjGB+TKMWi29eZ0b82QOvQs2YoLNzbpWGqFMtRQHTa57osqdGj4FrFPgkO4D4AZinzUJR9VvW3QUA==", + "version": "13.3.0", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.3.0.tgz", + "integrity": "sha512-HHqYQ6mBeiMc+N038w8LkMpDCRquCHWeNmN3v6645P3NhN2+qXOBqvPqo7Rt1VyCMzKhJ733wZqw5B7cQVFNPg==", "dev": true, "dependencies": { "debug": "^4.1.0", @@ -5311,9 +5311,9 @@ "dev": true }, "nock": { - "version": "13.2.9", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.2.9.tgz", - "integrity": "sha512-1+XfJNYF1cjGB+TKMWi29eZ0b82QOvQs2YoLNzbpWGqFMtRQHTa57osqdGj4FrFPgkO4D4AZinzUJR9VvW3QUA==", + "version": "13.3.0", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.3.0.tgz", + "integrity": "sha512-HHqYQ6mBeiMc+N038w8LkMpDCRquCHWeNmN3v6645P3NhN2+qXOBqvPqo7Rt1VyCMzKhJ733wZqw5B7cQVFNPg==", "dev": true, "requires": { "debug": "^4.1.0", From 1523ff4174febe8001f7edb6f9f782f03e4570e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Jan 2023 14:46:52 +0100 Subject: [PATCH 7/8] Bump json5 from 2.2.1 to 2.2.3 (#130) Bumps [json5](https://github.com/json5/json5) from 2.2.1 to 2.2.3. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v2.2.1...v2.2.3) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1165e6c..e12a9af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1860,9 +1860,9 @@ "dev": true }, "node_modules/json5": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", - "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, "bin": { "json5": "lib/cli.js" @@ -4912,9 +4912,9 @@ "dev": true }, "json5": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", - "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true }, "jsonfile": { From aa614576aabef15fcc2227183b01afb60d45d01c Mon Sep 17 00:00:00 2001 From: Michal Wojcik Date: Tue, 24 Jan 2023 09:05:16 +0100 Subject: [PATCH 8/8] DXE-2065 Release Edgegrid-node 3.4.0 --- CHANGELOG.md | 8 +++++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b4a855..707ff28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # RELEASE NOTES -## X.X.X (X X, X) +## 3.4.0 (Jan 26, 2023) #### IMPROVEMENTS: * Reads 'max_body' (alias 'max-body') field from `.edgerc` config file with default value of `131072` ([PR#1](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/1)) +* Add default Accept header (related to [PR#43](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/43) + and [I#33](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/33)) +* Add README section explaining how to use proxy (related to [PR#35](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/35) + and [I#59](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/59)) +* Add README section explaining how to change request encoding (related to [PR#58](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/58)) +* Update various dependencies ## 3.3.0 (Nov 08, 2022) diff --git a/package-lock.json b/package-lock.json index e12a9af..f623490 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "akamai-edgegrid", - "version": "3.3.0", + "version": "3.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "akamai-edgegrid", - "version": "3.3.0", + "version": "3.4.0", "license": "Apache-2.0", "dependencies": { "axios": "^1.1.2", diff --git a/package.json b/package.json index b08871c..2dac16c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "akamai-edgegrid", - "version": "3.3.0", + "version": "3.4.0", "description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js", "main": "index.js", "scripts": {