akamai-edgegrid 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +9 -6
- package/src/api.js +3 -10
- package/src/helpers.js +22 -1
- package/test/src/api_test.js +83 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akamai-edgegrid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "EDGEGRID_ENV=test ./node_modules/.bin/mocha $(find test -name '*.js')"
|
|
7
|
+
"test": "EDGEGRID_ENV=test ./node_modules/.bin/mocha $(find test -name '*.js')",
|
|
8
|
+
"ci": "EDGEGRID_ENV=test MOCHA_FILE=./test/tests.xml nyc --reporter cobertura --report-dir test/coverage/ ./node_modules/.bin/mocha --reporter mocha-junit-reporter --reporter-options jenkinsMode=true --reporter-options antMode=true $(find test -name '*.js')"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -24,13 +25,15 @@
|
|
|
24
25
|
],
|
|
25
26
|
"license": "Apache-2.0",
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"axios": "^
|
|
28
|
+
"axios": "^1.1.2",
|
|
28
29
|
"log4js": "^6.4.0",
|
|
29
|
-
"uuid": "^
|
|
30
|
+
"uuid": "^9.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"mocha": "^
|
|
33
|
+
"mocha": "^10.0.0",
|
|
34
|
+
"mocha-junit-reporter": "^2.1.0",
|
|
33
35
|
"nock": "^13.2.2",
|
|
34
|
-
"
|
|
36
|
+
"nyc": "^15.1.0",
|
|
37
|
+
"tsd": "^0.24.1"
|
|
35
38
|
}
|
|
36
39
|
}
|
package/src/api.js
CHANGED
|
@@ -48,24 +48,17 @@ const EdgeGrid = function (client_token, client_secret, access_token, host, debu
|
|
|
48
48
|
* @return EdgeGrid object (self)
|
|
49
49
|
*/
|
|
50
50
|
EdgeGrid.prototype.auth = function (req) {
|
|
51
|
-
let headers = {
|
|
52
|
-
'Content-Type': "application/json"
|
|
53
|
-
};
|
|
54
|
-
if (process.env['AKAMAI_CLI'] && process.env['AKAMAI_CLI_VERSION']) {
|
|
55
|
-
headers['User-Agent'] = (headers['User-Agent'] ? headers['User-Agent'] + " " : "") + `AkamaiCLI/${process.env['AKAMAI_CLI_VERSION']}`;
|
|
56
|
-
}
|
|
57
|
-
if (process.env['AKAMAI_CLI_COMMAND'] && process.env['AKAMAI_CLI_COMMAND_VERSION']) {
|
|
58
|
-
headers['User-Agent'] = (headers['User-Agent'] ? headers['User-Agent'] + " " : "") + `AkamaiCLI-${process.env['AKAMAI_CLI_COMMAND']}/${process.env['AKAMAI_CLI_COMMAND_VERSION']}`;
|
|
59
|
-
}
|
|
60
51
|
req = helpers.extend(req, {
|
|
61
52
|
baseURL: this.config.host,
|
|
62
53
|
url: req.path,
|
|
63
54
|
method: 'GET',
|
|
64
|
-
headers:
|
|
55
|
+
headers: {},
|
|
65
56
|
maxRedirects: 0,
|
|
66
57
|
body: ''
|
|
67
58
|
});
|
|
68
59
|
|
|
60
|
+
req.headers = helpers.extendHeaders(req.headers)
|
|
61
|
+
|
|
69
62
|
let isTarball = req.body instanceof Uint8Array && req.headers['Content-Type'] === 'application/gzip';
|
|
70
63
|
|
|
71
64
|
// Convert body object to properly formatted string
|
package/src/helpers.js
CHANGED
|
@@ -108,7 +108,7 @@ module.exports = {
|
|
|
108
108
|
return dataToSignStr;
|
|
109
109
|
},
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
extend: function (a, b) {
|
|
112
112
|
let key;
|
|
113
113
|
|
|
114
114
|
for (key in b) {
|
|
@@ -120,6 +120,27 @@ module.exports = {
|
|
|
120
120
|
return a;
|
|
121
121
|
},
|
|
122
122
|
|
|
123
|
+
extendHeaders: function (headers) {
|
|
124
|
+
if (!headers.hasOwnProperty('Content-Type')) {
|
|
125
|
+
headers['Content-Type'] = "application/json";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let userAgents = [headers['User-Agent']];
|
|
129
|
+
if (process.env['AKAMAI_CLI'] && process.env['AKAMAI_CLI_VERSION']) {
|
|
130
|
+
userAgents.push(`AkamaiCLI/${process.env['AKAMAI_CLI_VERSION']}`);
|
|
131
|
+
}
|
|
132
|
+
if (process.env['AKAMAI_CLI_COMMAND'] && process.env['AKAMAI_CLI_COMMAND_VERSION']) {
|
|
133
|
+
userAgents.push(`AkamaiCLI-${process.env['AKAMAI_CLI_COMMAND']}/${process.env['AKAMAI_CLI_COMMAND_VERSION']}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
userAgents = userAgents.filter(v => v)
|
|
137
|
+
if (userAgents.length > 0) {
|
|
138
|
+
headers['User-Agent'] = userAgents.join(' ')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return headers;
|
|
142
|
+
},
|
|
143
|
+
|
|
123
144
|
isRedirect: function (statusCode) {
|
|
124
145
|
return [
|
|
125
146
|
300, 301, 302, 303, 307
|
package/test/src/api_test.js
CHANGED
|
@@ -186,6 +186,10 @@ describe('Api', function () {
|
|
|
186
186
|
it('ensures a url is properly declared', function () {
|
|
187
187
|
assert.strictEqual(this.api.request.url, 'https://base.com/foo');
|
|
188
188
|
});
|
|
189
|
+
|
|
190
|
+
it('ensures no User-Agent is added when AkamaiCLI env variables not set', function () {
|
|
191
|
+
assert.ok(!this.api.request.headers.hasOwnProperty('User-Agent'));
|
|
192
|
+
})
|
|
189
193
|
});
|
|
190
194
|
|
|
191
195
|
describe('when more specific request options are passed', function () {
|
|
@@ -196,7 +200,10 @@ describe('Api', function () {
|
|
|
196
200
|
body: {
|
|
197
201
|
foo: 'bar'
|
|
198
202
|
},
|
|
199
|
-
somethingArbitrary: 'someValue'
|
|
203
|
+
somethingArbitrary: 'someValue',
|
|
204
|
+
headers: {
|
|
205
|
+
'User-Agent': 'testUserAgent'
|
|
206
|
+
}
|
|
200
207
|
});
|
|
201
208
|
});
|
|
202
209
|
|
|
@@ -220,6 +227,10 @@ describe('Api', function () {
|
|
|
220
227
|
it('extends the default request options with any others specified', function () {
|
|
221
228
|
assert.strictEqual(this.api.request.somethingArbitrary, 'someValue');
|
|
222
229
|
});
|
|
230
|
+
|
|
231
|
+
it('ensures provided User-Agent header is preserved', function () {
|
|
232
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'testUserAgent');
|
|
233
|
+
});
|
|
223
234
|
});
|
|
224
235
|
|
|
225
236
|
describe("when gzip response format is expected", function () {
|
|
@@ -248,6 +259,77 @@ describe('Api', function () {
|
|
|
248
259
|
assert.strictEqual(this.api.request["responseType"], "arraybuffer");
|
|
249
260
|
});
|
|
250
261
|
});
|
|
262
|
+
|
|
263
|
+
describe("when akamai cli user agent is expected", function () {
|
|
264
|
+
beforeEach(function () {
|
|
265
|
+
process.env['AKAMAI_CLI'] = 'AkamaiCLI';
|
|
266
|
+
process.env['AKAMAI_CLI_VERSION'] = '1.0.0';
|
|
267
|
+
process.env['AKAMAI_CLI_COMMAND'] = 'command';
|
|
268
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '0.0.1';
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
afterEach(function () {
|
|
272
|
+
process.env['AKAMAI_CLI'] = '';
|
|
273
|
+
process.env['AKAMAI_CLI_VERSION'] = '';
|
|
274
|
+
process.env['AKAMAI_CLI_COMMAND'] = '';
|
|
275
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '';
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
describe("when no User-Agent set in the request", function () {
|
|
279
|
+
beforeEach(function () {
|
|
280
|
+
this.api.auth({
|
|
281
|
+
path: '/foo'
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("should set User-Agent", function () {
|
|
286
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'AkamaiCLI/1.0.0 AkamaiCLI-command/0.0.1');
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("when User-Agent is already in the request", function () {
|
|
291
|
+
beforeEach(function () {
|
|
292
|
+
this.api.auth({
|
|
293
|
+
path: '/foo',
|
|
294
|
+
headers: {
|
|
295
|
+
'User-Agent': 'testAgent'
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should append to already present User-Agent header", function () {
|
|
301
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'testAgent AkamaiCLI/1.0.0 AkamaiCLI-command/0.0.1');
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe("when only AkamaiCLI info is set", function () {
|
|
306
|
+
beforeEach(function () {
|
|
307
|
+
process.env['AKAMAI_CLI_COMMAND'] = '';
|
|
308
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '';
|
|
309
|
+
this.api.auth({
|
|
310
|
+
path: '/foo'
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("should only set AkamaiCLI/version User-Agent", function () {
|
|
315
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'AkamaiCLI/1.0.0');
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("when only AkamaiCLI command info is set", function () {
|
|
320
|
+
beforeEach(function () {
|
|
321
|
+
process.env['AKAMAI_CLI'] = '';
|
|
322
|
+
process.env['AKAMAI_CLI_VERSION'] = '';
|
|
323
|
+
this.api.auth({
|
|
324
|
+
path: '/foo'
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("should only set AkamaiCLI/version User-Agent", function () {
|
|
329
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'AkamaiCLI-command/0.0.1');
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
251
333
|
});
|
|
252
334
|
|
|
253
335
|
describe('#send', function () {
|