akamai-edgegrid 3.3.0 → 3.4.1
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 +16 -0
- package/README.md +56 -0
- package/package.json +2 -2
- package/src/api.js +4 -3
- package/src/auth.js +0 -1
- package/src/edgerc.js +5 -0
- package/src/helpers.js +4 -1
- package/test/src/api_test.js +145 -8
- package/test/src/edgerc_test.js +65 -3
- package/test/src/helpers_test.js +119 -0
- package/test/test.js +18 -3
- package/test/test_data.json +12 -1
- package/test/test_edgerc +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# RELEASE NOTES
|
|
2
2
|
|
|
3
|
+
## 3.4.1 (May 09, 2023)
|
|
4
|
+
|
|
5
|
+
#### IMPROVEMENTS:
|
|
6
|
+
* Update various dependencies
|
|
7
|
+
|
|
8
|
+
## 3.4.0 (Jan 26, 2023)
|
|
9
|
+
|
|
10
|
+
#### IMPROVEMENTS:
|
|
11
|
+
* 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))
|
|
12
|
+
* Add default Accept header (related to [PR#43](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/43)
|
|
13
|
+
and [I#33](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/33))
|
|
14
|
+
* Add README section explaining how to use proxy (related to [PR#35](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/35)
|
|
15
|
+
and [I#59](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/59))
|
|
16
|
+
* Add README section explaining how to change request encoding (related to [PR#58](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/58))
|
|
17
|
+
* Update various dependencies
|
|
18
|
+
|
|
3
19
|
## 3.3.0 (Nov 08, 2022)
|
|
4
20
|
|
|
5
21
|
#### IMPROVEMENTS:
|
package/README.md
CHANGED
|
@@ -150,6 +150,62 @@ eg.auth({
|
|
|
150
150
|
// https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/papi/v1/cpcodes?contractId=ctr_1234&groupId=grp_1234
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
+
### Encoding
|
|
154
|
+
|
|
155
|
+
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.
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
const fs = require('fs');
|
|
159
|
+
|
|
160
|
+
eg.auth({
|
|
161
|
+
path : `/invoicing-api/v2/contracts/${contractId}/invoices/${invoiceNumber}/files/${fileName}`,
|
|
162
|
+
method: 'GET',
|
|
163
|
+
responseType: 'arraybuffer', // Important
|
|
164
|
+
}).send((err, response) => {
|
|
165
|
+
if (err) {
|
|
166
|
+
return console.log(err);
|
|
167
|
+
}
|
|
168
|
+
fs.writeFile(`./${fileName}`, response.data, 'binary', (err) => {
|
|
169
|
+
if (err){
|
|
170
|
+
return console.log(err);
|
|
171
|
+
}
|
|
172
|
+
console.log('File was saved!');
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Proxy
|
|
178
|
+
To use edgegrid with proxy, you can configure it with `proxy` field:
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
eg.auth({
|
|
182
|
+
path : `/papi/v1/cpcodes`,
|
|
183
|
+
method: 'GET',
|
|
184
|
+
proxy: {
|
|
185
|
+
host: 'my.proxy.com',
|
|
186
|
+
protocol: "https",
|
|
187
|
+
port: 3128,
|
|
188
|
+
auth: {
|
|
189
|
+
username: 'my-user',
|
|
190
|
+
password: 'my-password'
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}).send((err, response) => {
|
|
194
|
+
if (err) {
|
|
195
|
+
return console.log(err);
|
|
196
|
+
}
|
|
197
|
+
console.log('Success!');
|
|
198
|
+
// Do something with response
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
or use environment variable:
|
|
203
|
+
|
|
204
|
+
```shell
|
|
205
|
+
$ export https_proxy=https://username:password@host:port
|
|
206
|
+
$ node myapp.js
|
|
207
|
+
```
|
|
208
|
+
|
|
153
209
|
### Debug
|
|
154
210
|
|
|
155
211
|
With EdgeGrid you can enable debugging either as part of the EdgeGrid instantiation object
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akamai-edgegrid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"mocha-junit-reporter": "^2.1.0",
|
|
35
35
|
"nock": "^13.2.2",
|
|
36
36
|
"nyc": "^15.1.0",
|
|
37
|
-
"tsd": "^0.
|
|
37
|
+
"tsd": "^0.28.1"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/api.js
CHANGED
|
@@ -57,9 +57,10 @@ EdgeGrid.prototype.auth = function (req) {
|
|
|
57
57
|
body: ''
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
req.headers = helpers.extendHeaders(req.headers)
|
|
60
|
+
req.headers = helpers.extendHeaders(req.headers);
|
|
61
61
|
|
|
62
|
-
let isTarball = req.body instanceof Uint8Array &&
|
|
62
|
+
let isTarball = req.body instanceof Uint8Array &&
|
|
63
|
+
(req.headers['Content-Type'] === 'application/gzip' || req.headers['Content-Type'] === 'application/tar+gzip');
|
|
63
64
|
|
|
64
65
|
// Convert body object to properly formatted string
|
|
65
66
|
if (req.body) {
|
|
@@ -77,7 +78,7 @@ EdgeGrid.prototype.auth = function (req) {
|
|
|
77
78
|
this.config.access_token,
|
|
78
79
|
this.config.host
|
|
79
80
|
);
|
|
80
|
-
if (req.headers['Accept'] === 'application/gzip') {
|
|
81
|
+
if (req.headers['Accept'] === 'application/gzip' || req.headers['Accept'] === 'application/tar+gzip') {
|
|
81
82
|
this.request["responseType"] = 'arraybuffer';
|
|
82
83
|
}
|
|
83
84
|
return this;
|
package/src/auth.js
CHANGED
|
@@ -59,7 +59,6 @@ function makeURL(host, path, queryStringObj) {
|
|
|
59
59
|
|
|
60
60
|
module.exports = {
|
|
61
61
|
generateAuth: function (request, clientToken, clientSecret, accessToken, host, maxBody, guid, timestamp) {
|
|
62
|
-
maxBody = maxBody || 131072;
|
|
63
62
|
guid = guid || uuid.v4();
|
|
64
63
|
timestamp = timestamp || helpers.createTimestamp();
|
|
65
64
|
|
package/src/edgerc.js
CHANGED
|
@@ -41,6 +41,8 @@ function getSection(lines, sectionName) {
|
|
|
41
41
|
|
|
42
42
|
function validatedConfig(config) {
|
|
43
43
|
|
|
44
|
+
config.max_body = config.max_body || 131072
|
|
45
|
+
|
|
44
46
|
if (!(config.host && config.access_token &&
|
|
45
47
|
config.client_secret && config.client_token)) {
|
|
46
48
|
let errorMessage = "";
|
|
@@ -78,6 +80,9 @@ function buildObj(configs) {
|
|
|
78
80
|
index = config.indexOf('=');
|
|
79
81
|
if (index > -1 && !isComment) {
|
|
80
82
|
key = config.substr(0, index);
|
|
83
|
+
if (key.startsWith("max-body")) {
|
|
84
|
+
key = key.replace('-', '_')
|
|
85
|
+
}
|
|
81
86
|
val = config.substring(index + 1);
|
|
82
87
|
// remove inline comments
|
|
83
88
|
parsedValue = val.replace(/^\s*(['"])((?:\\\1|.)*?)\1\s*(?:;.*)?$/, "$2");
|
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) {
|
|
@@ -124,6 +124,9 @@ module.exports = {
|
|
|
124
124
|
if (!headers.hasOwnProperty('Content-Type')) {
|
|
125
125
|
headers['Content-Type'] = "application/json";
|
|
126
126
|
}
|
|
127
|
+
if (!headers.hasOwnProperty('Accept')) {
|
|
128
|
+
headers['Accept'] = "application/json";
|
|
129
|
+
}
|
|
127
130
|
|
|
128
131
|
let userAgents = [headers['User-Agent']];
|
|
129
132
|
if (process.env['AKAMAI_CLI'] && process.env['AKAMAI_CLI_VERSION']) {
|
package/test/src/api_test.js
CHANGED
|
@@ -23,7 +23,8 @@ describe('Api', function () {
|
|
|
23
23
|
'clientToken',
|
|
24
24
|
'clientSecret',
|
|
25
25
|
'accessToken',
|
|
26
|
-
'base.com'
|
|
26
|
+
'base.com',
|
|
27
|
+
false,
|
|
27
28
|
);
|
|
28
29
|
});
|
|
29
30
|
|
|
@@ -89,7 +90,98 @@ describe('Api', function () {
|
|
|
89
90
|
assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net');
|
|
90
91
|
});
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
it('reports the max-body from the edgerc associated with the specified section', function() {
|
|
94
|
+
assert.equal(this.api.config.max_body, 131072);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('when it is instantiated with an object with custom `max-body` value', function () {
|
|
98
|
+
beforeEach(function () {
|
|
99
|
+
this.api = new Api({
|
|
100
|
+
path: path.resolve(__dirname, '../test_edgerc'),
|
|
101
|
+
section: 'custom:max-body'
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('reports the client token from the edgerc associated with the specified section with custom `max-body`', function () {
|
|
106
|
+
assert.strictEqual(this.api.config.client_token, 'sectionClientToken');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('reports the client secret from the edgerc associated with the specified section with custom `max-body`', function () {
|
|
110
|
+
assert.strictEqual(this.api.config.client_secret, 'sectionClientSecret');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('reports the access token from the edgerc associated with the specified section with custom `max-body`', function () {
|
|
114
|
+
assert.strictEqual(this.api.config.access_token, 'sectionAccessToken');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('reports the API host from the edgerc associated with the specified section with custom `max-body`', function () {
|
|
118
|
+
assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('reports the max-body from the edgerc associated with the specified section with custom `max-body`', function () {
|
|
122
|
+
assert.equal(this.api.config.max_body, 4096);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('when it is instantiated with an object with custom `max_body` value', function () {
|
|
127
|
+
beforeEach(function () {
|
|
128
|
+
this.api = new Api({
|
|
129
|
+
path: path.resolve(__dirname, '../test_edgerc'),
|
|
130
|
+
section: 'custom:max_body'
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('reports the client token from the edgerc associated with the specified section with custom `max_body`', function () {
|
|
135
|
+
assert.strictEqual(this.api.config.client_token, 'sectionClientToken');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('reports the client secret from the edgerc associated with the specified section with custom `max_body`', function () {
|
|
139
|
+
assert.strictEqual(this.api.config.client_secret, 'sectionClientSecret');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('reports the access token from the edgerc associated with the specified section with custom `max_body`', function () {
|
|
143
|
+
assert.strictEqual(this.api.config.access_token, 'sectionAccessToken');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('reports the API host from the edgerc associated with the specified section with custom `max_body`', function () {
|
|
147
|
+
assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('reports the max-body from the edgerc associated with the specified section with custom `max_body`', function () {
|
|
151
|
+
assert.equal(this.api.config.max_body, 8192);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('when it is instantiated with an object without specified `max_body` value', function () {
|
|
156
|
+
beforeEach(function () {
|
|
157
|
+
this.api = new Api({
|
|
158
|
+
path: path.resolve(__dirname, '../test_edgerc'),
|
|
159
|
+
section: 'no-max-body'
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('reports the client token from the edgerc associated with the specified section without specified `max_body`', function () {
|
|
164
|
+
assert.strictEqual(this.api.config.client_token, 'sectionClientToken');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('reports the client secret from the edgerc associated with the specified section without specified `max_body`', function () {
|
|
168
|
+
assert.strictEqual(this.api.config.client_secret, 'sectionClientSecret');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('reports the access token from the edgerc associated with the specified section without specified `max_body`', function () {
|
|
172
|
+
assert.strictEqual(this.api.config.access_token, 'sectionAccessToken');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('reports the API host from the edgerc associated with the specified section without specified `max_body`', function () {
|
|
176
|
+
assert.strictEqual(this.api.config.host, 'https://sectionexample.luna.akamaiapis.net');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('reports the max-body from the edgerc associated with the specified section without specified `max_body`', function () {
|
|
180
|
+
assert.equal(this.api.config.max_body, 131072);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('when it is instantiated with an object that does not specify a section', function () {
|
|
93
185
|
beforeEach(function () {
|
|
94
186
|
this.api = new Api({
|
|
95
187
|
path: path.resolve(__dirname, '../test_edgerc')
|
|
@@ -111,6 +203,10 @@ describe('Api', function () {
|
|
|
111
203
|
it('reports the API host from the edgerc associated with the default section', function () {
|
|
112
204
|
assert.strictEqual(this.api.config.host, 'https://example.luna.akamaiapis.net');
|
|
113
205
|
});
|
|
206
|
+
|
|
207
|
+
it('reports the max-body from the edgerc associated with the default section', function() {
|
|
208
|
+
assert.equal(this.api.config.max_body, 131072);
|
|
209
|
+
});
|
|
114
210
|
});
|
|
115
211
|
|
|
116
212
|
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 () {
|
|
|
126
222
|
assert.strictEqual(this.api.config.client_token, "clientToken");
|
|
127
223
|
assert.strictEqual(this.api.config.client_secret, "clientSecret");
|
|
128
224
|
assert.strictEqual(this.api.config.access_token, "accessToken");
|
|
225
|
+
assert.strictEqual(this.api.config.max_body, 131072);
|
|
129
226
|
});
|
|
130
227
|
});
|
|
131
228
|
|
|
@@ -175,6 +272,10 @@ describe('Api', function () {
|
|
|
175
272
|
assert.strictEqual(this.api.request.headers['Content-Type'], 'application/json');
|
|
176
273
|
});
|
|
177
274
|
|
|
275
|
+
it('ensures a default Accept of application/json', function () {
|
|
276
|
+
assert.strictEqual(this.api.request.headers['Accept'], 'application/json');
|
|
277
|
+
});
|
|
278
|
+
|
|
178
279
|
it('ensures a default GET method', function () {
|
|
179
280
|
assert.strictEqual(this.api.request.method, 'GET');
|
|
180
281
|
});
|
|
@@ -189,7 +290,7 @@ describe('Api', function () {
|
|
|
189
290
|
|
|
190
291
|
it('ensures no User-Agent is added when AkamaiCLI env variables not set', function () {
|
|
191
292
|
assert.ok(!this.api.request.headers.hasOwnProperty('User-Agent'));
|
|
192
|
-
})
|
|
293
|
+
});
|
|
193
294
|
});
|
|
194
295
|
|
|
195
296
|
describe('when more specific request options are passed', function () {
|
|
@@ -202,7 +303,8 @@ describe('Api', function () {
|
|
|
202
303
|
},
|
|
203
304
|
somethingArbitrary: 'someValue',
|
|
204
305
|
headers: {
|
|
205
|
-
'User-Agent': 'testUserAgent'
|
|
306
|
+
'User-Agent': 'testUserAgent',
|
|
307
|
+
'Accept': 'text/html'
|
|
206
308
|
}
|
|
207
309
|
});
|
|
208
310
|
});
|
|
@@ -231,14 +333,20 @@ describe('Api', function () {
|
|
|
231
333
|
it('ensures provided User-Agent header is preserved', function () {
|
|
232
334
|
assert.strictEqual(this.api.request.headers['User-Agent'], 'testUserAgent');
|
|
233
335
|
});
|
|
336
|
+
|
|
337
|
+
it('ensures provided Accept header is preserved', function () {
|
|
338
|
+
assert.strictEqual(this.api.request.headers['Accept'], 'text/html');
|
|
339
|
+
});
|
|
234
340
|
});
|
|
235
341
|
|
|
236
342
|
describe("when gzip response format is expected", function () {
|
|
237
343
|
beforeEach(function () {
|
|
238
344
|
this.api.auth({
|
|
239
345
|
path: '/foo',
|
|
346
|
+
body: 'someBody',
|
|
240
347
|
headers: {
|
|
241
|
-
'Accept': `application/gzip
|
|
348
|
+
'Accept': `application/gzip`,
|
|
349
|
+
'Content-Type': `application/gzip`
|
|
242
350
|
}
|
|
243
351
|
});
|
|
244
352
|
});
|
|
@@ -251,8 +359,37 @@ describe('Api', function () {
|
|
|
251
359
|
assert.strictEqual(this.api.request.method, 'GET');
|
|
252
360
|
});
|
|
253
361
|
|
|
254
|
-
it('ensures
|
|
255
|
-
assert.strictEqual(this.api.request.body, '');
|
|
362
|
+
it('ensures the specified body is not modified', function () {
|
|
363
|
+
assert.strictEqual(this.api.request.body, 'someBody');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('should return response as buffer', function () {
|
|
367
|
+
assert.strictEqual(this.api.request["responseType"], "arraybuffer");
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
describe("when tar+gzip response format is expected", function () {
|
|
372
|
+
beforeEach(function () {
|
|
373
|
+
this.api.auth({
|
|
374
|
+
path: '/foo',
|
|
375
|
+
body: 'someBody',
|
|
376
|
+
headers: {
|
|
377
|
+
'Accept': `application/tar+gzip`,
|
|
378
|
+
'Content-Type': `application/tar+gzip`
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('adds an Authorization header to the request it is passed', function () {
|
|
384
|
+
assert.strictEqual(typeof this.api.request.headers.Authorization === 'string', true);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('ensures a default GET method', function () {
|
|
388
|
+
assert.strictEqual(this.api.request.method, 'GET');
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('ensures the specified body is not modified', function () {
|
|
392
|
+
assert.strictEqual(this.api.request.body, 'someBody');
|
|
256
393
|
});
|
|
257
394
|
|
|
258
395
|
it('should return response as buffer', function () {
|
|
@@ -273,7 +410,7 @@ describe('Api', function () {
|
|
|
273
410
|
process.env['AKAMAI_CLI_VERSION'] = '';
|
|
274
411
|
process.env['AKAMAI_CLI_COMMAND'] = '';
|
|
275
412
|
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '';
|
|
276
|
-
})
|
|
413
|
+
});
|
|
277
414
|
|
|
278
415
|
describe("when no User-Agent set in the request", function () {
|
|
279
416
|
beforeEach(function () {
|
package/test/src/edgerc_test.js
CHANGED
|
@@ -23,7 +23,7 @@ describe('edgerc', function () {
|
|
|
23
23
|
process.env['AKAMAI_CLIENT_SECRET'] = '';
|
|
24
24
|
process.env['AKAMAI_ACCESS_TOKEN'] = '';
|
|
25
25
|
});
|
|
26
|
-
describe('the parsed
|
|
26
|
+
describe('the parsed edgerc file it returns', function () {
|
|
27
27
|
describe('when it is not passed a second argument indicating config section', function () {
|
|
28
28
|
beforeEach(function () {
|
|
29
29
|
this.config = edgerc(path.resolve(__dirname, '../test_edgerc'));
|
|
@@ -44,6 +44,10 @@ describe('edgerc', function () {
|
|
|
44
44
|
it('reports the default access_token', function () {
|
|
45
45
|
assert.strictEqual(this.config.access_token, 'accessToken');
|
|
46
46
|
});
|
|
47
|
+
|
|
48
|
+
it('reports the default max_body', function () {
|
|
49
|
+
assert.equal(this.config.max_body, 131072);
|
|
50
|
+
});
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
describe('when it is passed a second argument indicating config section', function () {
|
|
@@ -66,6 +70,62 @@ describe('edgerc', function () {
|
|
|
66
70
|
it('reports the access_token associated with the section', function () {
|
|
67
71
|
assert.strictEqual(this.config.access_token, 'sectionAccessToken');
|
|
68
72
|
});
|
|
73
|
+
|
|
74
|
+
it('reports the max_body associated with the section', function () {
|
|
75
|
+
assert.equal(this.config.max_body, 131072);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('when it is passed a second argument indicating config section without specified max_body', function () {
|
|
80
|
+
beforeEach(function () {
|
|
81
|
+
this.config = edgerc(path.resolve(__dirname, '../test_edgerc'), 'no-max-body');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('reports the host associated with the section without specified max_body', function () {
|
|
85
|
+
assert.strictEqual(this.config.host, 'https://sectionexample.luna.akamaiapis.net');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('reports the client_token associated with the section without specified max_body', function () {
|
|
89
|
+
assert.strictEqual(this.config.client_token, 'sectionClientToken');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('reports the client_secret associated with the section without specified max_body', function () {
|
|
93
|
+
assert.strictEqual(this.config.client_secret, 'sectionClientSecret');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('reports the access_token associated with the section without specified max_body', function () {
|
|
97
|
+
assert.strictEqual(this.config.access_token, 'sectionAccessToken');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('reports the max_body associated with the section without specified max_body', function () {
|
|
101
|
+
assert.equal(this.config.max_body, 131072);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('when it is passed a second argument indicating config section with custom `max_body` value', function () {
|
|
106
|
+
beforeEach(function () {
|
|
107
|
+
this.config = edgerc(path.resolve(__dirname, '../test_edgerc'), 'custom:max_body');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('reports the host associated with the section with with custom `max_body`', function () {
|
|
111
|
+
assert.strictEqual(this.config.host, 'https://sectionexample.luna.akamaiapis.net');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('reports the client_token associated with the section with with custom `max_body`', function () {
|
|
115
|
+
assert.strictEqual(this.config.client_token, 'sectionClientToken');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('reports the client_secret associated with the section with with custom `max_body`', function () {
|
|
119
|
+
assert.strictEqual(this.config.client_secret, 'sectionClientSecret');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('reports the access_token associated with the section with with custom `max_body`', function () {
|
|
123
|
+
assert.strictEqual(this.config.access_token, 'sectionAccessToken');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('reports the max_body associated with the section with with custom `max_body`', function () {
|
|
127
|
+
assert.equal(this.config.max_body, 8192);
|
|
128
|
+
});
|
|
69
129
|
});
|
|
70
130
|
|
|
71
131
|
describe('when the section contains a host with the "https://" protocal specified', function () {
|
|
@@ -116,8 +176,8 @@ describe('edgerc', function () {
|
|
|
116
176
|
this.config = edgerc();
|
|
117
177
|
});
|
|
118
178
|
|
|
119
|
-
it('has
|
|
120
|
-
assert.strictEqual(Object.keys(this.config).length,
|
|
179
|
+
it('has five configuration items', function () {
|
|
180
|
+
assert.strictEqual(Object.keys(this.config).length, 5);
|
|
121
181
|
});
|
|
122
182
|
|
|
123
183
|
it('has valid config values', function () {
|
|
@@ -125,6 +185,7 @@ describe('edgerc', function () {
|
|
|
125
185
|
assert.strictEqual(this.config.client_token, "clientToken");
|
|
126
186
|
assert.strictEqual(this.config.client_secret, "clientSecret");
|
|
127
187
|
assert.strictEqual(this.config.access_token, "accessToken");
|
|
188
|
+
assert.equal(this.config.max_body, 131072);
|
|
128
189
|
});
|
|
129
190
|
});
|
|
130
191
|
|
|
@@ -148,6 +209,7 @@ describe('edgerc', function () {
|
|
|
148
209
|
assert.strictEqual(this.config.client_token, "clientToken");
|
|
149
210
|
assert.strictEqual(this.config.client_secret, "clientSecret");
|
|
150
211
|
assert.strictEqual(this.config.access_token, "accessToken");
|
|
212
|
+
assert.equal(this.config.max_body, 131072);
|
|
151
213
|
});
|
|
152
214
|
});
|
|
153
215
|
});
|
package/test/src/helpers_test.js
CHANGED
|
@@ -124,4 +124,123 @@ describe('helpers', function () {
|
|
|
124
124
|
assert.strictEqual(helpers.resolveHome('some/path/testdir'), "some/path/testdir");
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
|
+
|
|
128
|
+
describe('#extendHeaders', function () {
|
|
129
|
+
describe('when Content-Type is not provided', function () {
|
|
130
|
+
it('should set application/json as default', function () {
|
|
131
|
+
headers = helpers.extendHeaders({})
|
|
132
|
+
assert.strictEqual(headers['Content-Type'], 'application/json')
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
describe('when Content-Type is provided', function () {
|
|
137
|
+
it('should preserve the value', function () {
|
|
138
|
+
contentType = 'text/html'
|
|
139
|
+
headers = helpers.extendHeaders({
|
|
140
|
+
'Content-Type': contentType
|
|
141
|
+
})
|
|
142
|
+
assert.strictEqual(headers['Content-Type'], contentType)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('when Accept is not provided', function () {
|
|
147
|
+
it('should set aapplication/json as default', function () {
|
|
148
|
+
headers = helpers.extendHeaders({})
|
|
149
|
+
assert.strictEqual(headers['Accept'], 'application/json')
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
describe('when Accept is provided', function () {
|
|
154
|
+
it('should preserve the value', function () {
|
|
155
|
+
accept = 'text/html'
|
|
156
|
+
headers = helpers.extendHeaders({
|
|
157
|
+
'Accept': accept
|
|
158
|
+
})
|
|
159
|
+
assert.strictEqual(headers['Accept'], accept)
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
describe('when akamai cli user agent env is not provided', function () {
|
|
164
|
+
describe('when user agent is set in headers', function () {
|
|
165
|
+
it('should preserve the value and not append anything', function () {
|
|
166
|
+
testAgent = 'testAgent/1.0.0'
|
|
167
|
+
headers = helpers.extendHeaders({
|
|
168
|
+
'User-Agent': testAgent
|
|
169
|
+
});
|
|
170
|
+
assert.strictEqual(headers['User-Agent'], testAgent)
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('when no user agent is set in headers', function () {
|
|
175
|
+
it('should do nothing', function () {
|
|
176
|
+
headers = helpers.extendHeaders({})
|
|
177
|
+
assert.equal(headers.hasOwnProperty('User-Agent'), false)
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('when akamai cli user agent env is provided', function () {
|
|
183
|
+
beforeEach(function () {
|
|
184
|
+
process.env['AKAMAI_CLI'] = 'AkamaiCLI';
|
|
185
|
+
process.env['AKAMAI_CLI_VERSION'] = '1.0.0';
|
|
186
|
+
process.env['AKAMAI_CLI_COMMAND'] = 'command';
|
|
187
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '0.0.1';
|
|
188
|
+
this.akamaiCLIAgent = 'AkamaiCLI/1.0.0 AkamaiCLI-command/0.0.1'
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
afterEach(function () {
|
|
192
|
+
process.env['AKAMAI_CLI'] = '';
|
|
193
|
+
process.env['AKAMAI_CLI_VERSION'] = '';
|
|
194
|
+
process.env['AKAMAI_CLI_COMMAND'] = '';
|
|
195
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '';
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe('when user agent is set in headers', function () {
|
|
199
|
+
it('should append akamaiCLI agent', function () {
|
|
200
|
+
testAgent = 'testAgent/1.0.0'
|
|
201
|
+
headers = helpers.extendHeaders({
|
|
202
|
+
'User-Agent': testAgent
|
|
203
|
+
});
|
|
204
|
+
expectedAgent = testAgent + " " + this.akamaiCLIAgent
|
|
205
|
+
assert.strictEqual(headers['User-Agent'], expectedAgent)
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('when no user agent is set in headers', function () {
|
|
210
|
+
describe('when both akamaiCLI and command env is set', function () {
|
|
211
|
+
it('should set two user agents', function () {
|
|
212
|
+
headers = helpers.extendHeaders({})
|
|
213
|
+
assert.strictEqual(headers['User-Agent'], this.akamaiCLIAgent)
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe("when only AkamaiCLI info is set", function () {
|
|
218
|
+
beforeEach(function () {
|
|
219
|
+
process.env['AKAMAI_CLI_COMMAND'] = '';
|
|
220
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '';
|
|
221
|
+
this.akamaiCLIAgent = 'AkamaiCLI/1.0.0'
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("should only set AkamaiCLI/version User-Agent", function () {
|
|
225
|
+
headers = helpers.extendHeaders({})
|
|
226
|
+
assert.strictEqual(headers['User-Agent'], this.akamaiCLIAgent);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("when only AkamaiCLI command info is set", function () {
|
|
231
|
+
beforeEach(function () {
|
|
232
|
+
process.env['AKAMAI_CLI'] = '';
|
|
233
|
+
process.env['AKAMAI_CLI_VERSION'] = '';
|
|
234
|
+
this.akamaiCLIAgent = 'AkamaiCLI-command/0.0.1'
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("should only set AkamaiCLI/version User-Agent", function () {
|
|
238
|
+
headers = helpers.extendHeaders({})
|
|
239
|
+
assert.strictEqual(headers['User-Agent'], this.akamaiCLIAgent);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
})
|
|
245
|
+
})
|
|
127
246
|
});
|
package/test/test.js
CHANGED
|
@@ -56,9 +56,24 @@ describe('Signature Generation', function () {
|
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
describe('Post uses passed-max-body', function() {
|
|
60
|
+
it('should return the expected string when the signing request is run.', function() {
|
|
61
|
+
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=";
|
|
62
|
+
const data = "datadatadatadatadatadatadatadata";
|
|
63
|
+
const request = {
|
|
64
|
+
//"url": "https://akaa-kax6r2oleojomqr3-q2i5ed3v35xfwe3j.luna.akamaiapis.net/billing-usage/v1/contractusagedata/contract/C-6JGLXF/6/2014",
|
|
65
|
+
"path": "testapi/v1/t3",
|
|
66
|
+
"method": "POST",
|
|
67
|
+
"body": data
|
|
68
|
+
};
|
|
69
|
+
test_auth = auth.generateAuth(request, client_token, client_secret, access_token, base_url, false, nonce, timestamp);
|
|
70
|
+
assert.equal(test_auth.headers.Authorization, expected_header);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
59
74
|
describe('POST inside limit', function () {
|
|
60
75
|
it('should return the expected string when the signing request is run.', function () {
|
|
61
|
-
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=
|
|
76
|
+
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=";
|
|
62
77
|
const data = "datadatadatadatadatadatadatadata";
|
|
63
78
|
const request = {
|
|
64
79
|
//"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 () {
|
|
|
73
88
|
|
|
74
89
|
describe('POST too large', function () {
|
|
75
90
|
it('should return the expected string when the signing request is run.', function () {
|
|
76
|
-
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=
|
|
91
|
+
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=";
|
|
77
92
|
const data = fs.readFileSync(path.resolve(__dirname, 'test_body_data.txt'));
|
|
78
93
|
|
|
79
94
|
const request = {
|
|
@@ -89,7 +104,7 @@ describe('Signature Generation', function () {
|
|
|
89
104
|
|
|
90
105
|
describe('POST length equals max_body', function () {
|
|
91
106
|
it('should return the expected string when the signing request is run.', function () {
|
|
92
|
-
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=
|
|
107
|
+
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=";
|
|
93
108
|
const data = "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd";
|
|
94
109
|
const request = {
|
|
95
110
|
//"url": "https://akaa-kax6r2oleojomqr3-q2i5ed3v35xfwe3j.luna.akamaiapis.net/billing-usage/v1/contractusagedata/contract/C-6JGLXF/6/2014",
|
package/test/test_data.json
CHANGED
|
@@ -27,6 +27,17 @@
|
|
|
27
27
|
}]
|
|
28
28
|
},
|
|
29
29
|
"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="
|
|
30
|
+
}, {
|
|
31
|
+
"testName": "Post uses passed-max-body",
|
|
32
|
+
"request": {
|
|
33
|
+
"method": "POST",
|
|
34
|
+
"path": "/testapi/v1/t3",
|
|
35
|
+
"data": "datadatadatadatadatadatadatadata",
|
|
36
|
+
"headers": [{
|
|
37
|
+
"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"
|
|
38
|
+
}]
|
|
39
|
+
},
|
|
40
|
+
"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="
|
|
30
41
|
}, {
|
|
31
42
|
"testName": "POST inside limit",
|
|
32
43
|
"request": {
|
|
@@ -37,7 +48,7 @@
|
|
|
37
48
|
"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"
|
|
38
49
|
}]
|
|
39
50
|
},
|
|
40
|
-
"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=
|
|
51
|
+
"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="
|
|
41
52
|
}, {
|
|
42
53
|
"testName": "POST too large",
|
|
43
54
|
"request": {
|
package/test/test_edgerc
CHANGED
|
@@ -12,6 +12,26 @@ client_secret = sectionClientSecret
|
|
|
12
12
|
access_token = sectionAccessToken
|
|
13
13
|
max-body = 131072
|
|
14
14
|
|
|
15
|
+
[custom:max-body]
|
|
16
|
+
host = sectionexample.luna.akamaiapis.net
|
|
17
|
+
client_token = sectionClientToken
|
|
18
|
+
client_secret = sectionClientSecret
|
|
19
|
+
access_token = sectionAccessToken
|
|
20
|
+
max-body = 4096
|
|
21
|
+
|
|
22
|
+
[custom:max_body]
|
|
23
|
+
host = sectionexample.luna.akamaiapis.net
|
|
24
|
+
client_token = sectionClientToken
|
|
25
|
+
client_secret = sectionClientSecret
|
|
26
|
+
access_token = sectionAccessToken
|
|
27
|
+
max_body = 8192
|
|
28
|
+
|
|
29
|
+
[no-max-body]
|
|
30
|
+
host = sectionexample.luna.akamaiapis.net
|
|
31
|
+
client_token = sectionClientToken
|
|
32
|
+
client_secret = sectionClientSecret
|
|
33
|
+
access_token = sectionAccessToken
|
|
34
|
+
|
|
15
35
|
[https]
|
|
16
36
|
host = https://example.luna.akamaiapis.net
|
|
17
37
|
client_token = sectionClientToken
|