@ama-sdk/core 12.1.8 → 12.1.11
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/cjs/clients/api-angular-client.js +13 -18
- package/cjs/clients/api-fetch-client.js +16 -21
- package/cjs/fwk/api.helpers.js +11 -11
- package/cjs/fwk/date.js +5 -5
- package/cjs/fwk/errors.js +7 -7
- package/cjs/fwk/mocks/alf-mock-adapter.js +58 -60
- package/cjs/fwk/mocks/base-mock-adapter.js +15 -19
- package/cjs/fwk/mocks/helpers.js +3 -3
- package/cjs/fwk/param-serialization.js +6 -6
- package/cjs/fwk/reviver.js +4 -4
- package/cjs/plugins/abort/abort.spec.js +83 -81
- package/cjs/plugins/additional-params/additional-params.request.js +18 -25
- package/cjs/plugins/additional-params/additional-params.spec.js +194 -186
- package/cjs/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
- package/cjs/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
- package/cjs/plugins/api-key/api-key.request.js +12 -19
- package/cjs/plugins/api-key/api-key.spec.js +50 -50
- package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +25 -36
- package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
- package/cjs/plugins/client-facts/client-facts.request.js +18 -25
- package/cjs/plugins/client-facts/client-facts.spec.js +218 -208
- package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
- package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
- package/cjs/plugins/custom-info/custom-info.spec.js +90 -90
- package/cjs/plugins/fetch-cache/fetch-cache.spec.js +100 -98
- package/cjs/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
- package/cjs/plugins/json-token/json-token.spec.js +109 -107
- package/cjs/plugins/keepalive/keepalive.request.js +7 -12
- package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +11 -23
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
- package/cjs/plugins/mock-intercept/mock-intercept.angular.js +94 -100
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/cjs/plugins/mock-intercept/mock-intercept.interface.js +3 -3
- package/cjs/plugins/mock-intercept/mock-intercept.request.js +12 -19
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +245 -237
- package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/cjs/plugins/pii-tokenizer/pii-tokenizer.request.js +19 -27
- package/cjs/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
- package/cjs/plugins/raw-response-info/raw-response-info.spec.js +67 -67
- package/cjs/plugins/retry/retry.fetch.js +18 -27
- package/cjs/plugins/retry/retry.spec.js +233 -225
- package/cjs/plugins/reviver/reviver.spec.js +88 -86
- package/cjs/plugins/session-id/session-id.spec.js +98 -94
- package/cjs/plugins/si-token/si-token.spec.js +27 -29
- package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
- package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
- package/cjs/plugins/timeout/timeout.fetch.js +16 -22
- package/cjs/plugins/timeout/timeout.spec.js +211 -205
- package/cjs/plugins/url-rewrite/url-rewrite.request.js +9 -16
- package/cjs/plugins/url-rewrite/url-rewrite.spec.js +48 -48
- package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
- package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
- package/cjs/utils/crypto.js +15 -27
- package/cjs/utils/generic-api.js +9 -14
- package/cjs/utils/json-token.js +19 -26
- package/cjs/utils/json-token.spec.js +495 -497
- package/cjs/utils/mime-types.js +3 -3
- package/esm2015/clients/api-angular-client.js +13 -18
- package/esm2015/clients/api-fetch-client.js +16 -21
- package/esm2015/fwk/mocks/alf-mock-adapter.js +58 -60
- package/esm2015/fwk/mocks/base-mock-adapter.js +15 -19
- package/esm2015/plugins/abort/abort.spec.js +83 -81
- package/esm2015/plugins/additional-params/additional-params.request.js +15 -22
- package/esm2015/plugins/additional-params/additional-params.spec.js +194 -186
- package/esm2015/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
- package/esm2015/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
- package/esm2015/plugins/api-key/api-key.request.js +12 -19
- package/esm2015/plugins/api-key/api-key.spec.js +50 -50
- package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +21 -32
- package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
- package/esm2015/plugins/client-facts/client-facts.request.js +15 -22
- package/esm2015/plugins/client-facts/client-facts.spec.js +218 -208
- package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
- package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
- package/esm2015/plugins/custom-info/custom-info.spec.js +90 -90
- package/esm2015/plugins/fetch-cache/fetch-cache.spec.js +100 -98
- package/esm2015/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
- package/esm2015/plugins/json-token/json-token.spec.js +109 -107
- package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
- package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +8 -20
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
- package/esm2015/plugins/mock-intercept/mock-intercept.angular.js +94 -100
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/esm2015/plugins/mock-intercept/mock-intercept.request.js +12 -19
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +245 -237
- package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/esm2015/plugins/pii-tokenizer/pii-tokenizer.request.js +15 -23
- package/esm2015/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
- package/esm2015/plugins/raw-response-info/raw-response-info.spec.js +67 -67
- package/esm2015/plugins/retry/retry.fetch.js +18 -27
- package/esm2015/plugins/retry/retry.spec.js +233 -225
- package/esm2015/plugins/reviver/reviver.spec.js +88 -86
- package/esm2015/plugins/session-id/session-id.spec.js +98 -94
- package/esm2015/plugins/si-token/si-token.spec.js +27 -29
- package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
- package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
- package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
- package/esm2015/plugins/timeout/timeout.spec.js +211 -205
- package/esm2015/plugins/url-rewrite/url-rewrite.request.js +9 -16
- package/esm2015/plugins/url-rewrite/url-rewrite.spec.js +48 -48
- package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
- package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
- package/esm2015/utils/crypto.js +8 -20
- package/esm2015/utils/generic-api.js +9 -14
- package/esm2015/utils/json-token.js +10 -17
- package/esm2015/utils/json-token.spec.js +495 -497
- package/package.json +6 -6
|
@@ -33,7 +33,7 @@ function _async_to_generator(fn) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function _ts_generator(thisArg, body) {
|
|
36
|
-
var f, y, t,
|
|
36
|
+
var f, y, t, _ = {
|
|
37
37
|
label: 0,
|
|
38
38
|
sent: function() {
|
|
39
39
|
if (t[0] & 1) throw t[1];
|
|
@@ -41,12 +41,8 @@ function _ts_generator(thisArg, body) {
|
|
|
41
41
|
},
|
|
42
42
|
trys: [],
|
|
43
43
|
ops: []
|
|
44
|
-
};
|
|
45
|
-
return g = {
|
|
46
|
-
next: verb(0),
|
|
47
|
-
"throw": verb(1),
|
|
48
|
-
"return": verb(2)
|
|
49
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
44
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
45
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
50
46
|
return this;
|
|
51
47
|
}), g;
|
|
52
48
|
function verb(n) {
|
|
@@ -59,7 +55,7 @@ function _ts_generator(thisArg, body) {
|
|
|
59
55
|
}
|
|
60
56
|
function step(op) {
|
|
61
57
|
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
-
while(_)try {
|
|
58
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
63
59
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
64
60
|
if (y = 0, t) op = [
|
|
65
61
|
op[0] & 2,
|
|
@@ -166,70 +162,344 @@ describe('BotProtectionFingerprint', function() {
|
|
|
166
162
|
global.window = windowBackup;
|
|
167
163
|
consoleMock.mockReset();
|
|
168
164
|
});
|
|
169
|
-
it('Should return undefined and log if no Protection object is received.',
|
|
170
|
-
|
|
165
|
+
it('Should return undefined and log if no Protection object is received.', function() {
|
|
166
|
+
return _async_to_generator(function() {
|
|
167
|
+
var promise;
|
|
168
|
+
return _ts_generator(this, function(_state) {
|
|
169
|
+
switch(_state.label){
|
|
170
|
+
case 0:
|
|
171
|
+
promise = retriever();
|
|
172
|
+
return [
|
|
173
|
+
4,
|
|
174
|
+
jest.runAllTimersAsync()
|
|
175
|
+
];
|
|
176
|
+
case 1:
|
|
177
|
+
_state.sent();
|
|
178
|
+
return [
|
|
179
|
+
4,
|
|
180
|
+
promise
|
|
181
|
+
];
|
|
182
|
+
case 2:
|
|
183
|
+
expect.apply(void 0, [
|
|
184
|
+
_state.sent()
|
|
185
|
+
]).toBeUndefined();
|
|
186
|
+
// eslint-disable-next-line no-console -- console.error is not called here
|
|
187
|
+
expect(console.error).toHaveBeenCalledTimes(1);
|
|
188
|
+
return [
|
|
189
|
+
2
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
})();
|
|
194
|
+
});
|
|
195
|
+
it('Should return undefined and log if no Protection object is received within configured timeout.', function() {
|
|
196
|
+
return _async_to_generator(function() {
|
|
197
|
+
var promise;
|
|
198
|
+
return _ts_generator(this, function(_state) {
|
|
199
|
+
switch(_state.label){
|
|
200
|
+
case 0:
|
|
201
|
+
registerEvent(protectionResolve, 100);
|
|
202
|
+
promise = retriever();
|
|
203
|
+
return [
|
|
204
|
+
4,
|
|
205
|
+
jest.runAllTimersAsync()
|
|
206
|
+
];
|
|
207
|
+
case 1:
|
|
208
|
+
_state.sent();
|
|
209
|
+
return [
|
|
210
|
+
4,
|
|
211
|
+
promise
|
|
212
|
+
];
|
|
213
|
+
case 2:
|
|
214
|
+
expect.apply(void 0, [
|
|
215
|
+
_state.sent()
|
|
216
|
+
]).toBeUndefined();
|
|
217
|
+
// eslint-disable-next-line no-console -- console.error is not called here
|
|
218
|
+
expect(console.error).toHaveBeenCalledTimes(1);
|
|
219
|
+
return [
|
|
220
|
+
2
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
})();
|
|
225
|
+
});
|
|
226
|
+
it('Should return undefined and log if token promise rejected.', function() {
|
|
227
|
+
return _async_to_generator(function() {
|
|
228
|
+
var promise;
|
|
229
|
+
return _ts_generator(this, function(_state) {
|
|
230
|
+
switch(_state.label){
|
|
231
|
+
case 0:
|
|
232
|
+
registerEvent(protectionReject);
|
|
233
|
+
promise = retriever();
|
|
234
|
+
return [
|
|
235
|
+
4,
|
|
236
|
+
jest.runAllTimersAsync()
|
|
237
|
+
];
|
|
238
|
+
case 1:
|
|
239
|
+
_state.sent();
|
|
240
|
+
return [
|
|
241
|
+
4,
|
|
242
|
+
promise
|
|
243
|
+
];
|
|
244
|
+
case 2:
|
|
245
|
+
expect.apply(void 0, [
|
|
246
|
+
_state.sent()
|
|
247
|
+
]).toBeUndefined();
|
|
248
|
+
// eslint-disable-next-line no-console -- console.error is not called here
|
|
249
|
+
expect(console.error).toHaveBeenCalledTimes(1);
|
|
250
|
+
return [
|
|
251
|
+
2
|
|
252
|
+
];
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
})();
|
|
256
|
+
});
|
|
257
|
+
it('Should return the token if everything happened within timeout values.', function() {
|
|
258
|
+
return _async_to_generator(function() {
|
|
259
|
+
var promise, newPromise;
|
|
260
|
+
return _ts_generator(this, function(_state) {
|
|
261
|
+
switch(_state.label){
|
|
262
|
+
case 0:
|
|
263
|
+
registerEvent(protectionResolve, 25);
|
|
264
|
+
promise = retriever();
|
|
265
|
+
return [
|
|
266
|
+
4,
|
|
267
|
+
jest.runAllTimersAsync()
|
|
268
|
+
];
|
|
269
|
+
case 1:
|
|
270
|
+
_state.sent();
|
|
271
|
+
return [
|
|
272
|
+
4,
|
|
273
|
+
promise
|
|
274
|
+
];
|
|
275
|
+
case 2:
|
|
276
|
+
expect.apply(void 0, [
|
|
277
|
+
_state.sent()
|
|
278
|
+
]).toBe(tokenValue);
|
|
279
|
+
tokenValue = 'newToken';
|
|
280
|
+
newPromise = retriever();
|
|
281
|
+
return [
|
|
282
|
+
4,
|
|
283
|
+
jest.runAllTimersAsync()
|
|
284
|
+
];
|
|
285
|
+
case 3:
|
|
286
|
+
_state.sent();
|
|
287
|
+
return [
|
|
288
|
+
4,
|
|
289
|
+
newPromise
|
|
290
|
+
];
|
|
291
|
+
case 4:
|
|
292
|
+
expect.apply(void 0, [
|
|
293
|
+
_state.sent()
|
|
294
|
+
]).toBe(tokenValue);
|
|
295
|
+
// eslint-disable-next-line no-console -- console.error is not called here
|
|
296
|
+
expect(console.error).not.toHaveBeenCalled();
|
|
297
|
+
return [
|
|
298
|
+
2
|
|
299
|
+
];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
})();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
describe('akamaiTelemetryRetrieverFactory', function() {
|
|
306
|
+
it('Should return undefined if bmak object doesn\'t exist.', function() {
|
|
307
|
+
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)()()).toBeUndefined();
|
|
308
|
+
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)({})()).toBeUndefined();
|
|
309
|
+
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)({
|
|
310
|
+
get_telemetry: 'test'
|
|
311
|
+
})()).toBeUndefined();
|
|
312
|
+
});
|
|
313
|
+
it('Should return telemetry', function() {
|
|
314
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- naming convention imposed by Akamai
|
|
315
|
+
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)({
|
|
316
|
+
get_telemetry: function() {
|
|
317
|
+
return 'telemetryValue';
|
|
318
|
+
}
|
|
319
|
+
})()).toBe('telemetryValue');
|
|
320
|
+
global.window = {};
|
|
321
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- naming convention imposed by Akamai
|
|
322
|
+
global.window.bmak = {
|
|
323
|
+
get_telemetry: function() {
|
|
324
|
+
return 'telemetryValue2';
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)()()).toBe('telemetryValue2');
|
|
328
|
+
global.window = undefined;
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
describe('Plug-in', function() {
|
|
333
|
+
var mockedRequest;
|
|
334
|
+
var mockedFingerprint;
|
|
335
|
+
var fingerprintRetriever;
|
|
336
|
+
var destinationHeaderName = 'test-header';
|
|
337
|
+
beforeEach(function() {
|
|
338
|
+
mockedFingerprint = undefined;
|
|
339
|
+
mockedRequest = {
|
|
340
|
+
method: 'get',
|
|
341
|
+
basePath: 'toto',
|
|
342
|
+
headers: new Headers()
|
|
343
|
+
};
|
|
344
|
+
fingerprintRetriever = jest.fn().mockImplementation(function() {
|
|
345
|
+
return mockedFingerprint;
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
it('Should add the fingerprint header if a fingerprint is found.', function() {
|
|
349
|
+
return _async_to_generator(function() {
|
|
350
|
+
var plugin, newRequest;
|
|
171
351
|
return _ts_generator(this, function(_state) {
|
|
172
352
|
switch(_state.label){
|
|
173
353
|
case 0:
|
|
174
|
-
|
|
354
|
+
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
355
|
+
destinationHeaderName: destinationHeaderName,
|
|
356
|
+
fingerprintRetriever: fingerprintRetriever,
|
|
357
|
+
pollerOptions: undefined,
|
|
358
|
+
pollOnlyOnce: false
|
|
359
|
+
}).load();
|
|
360
|
+
mockedFingerprint = 'fingerprint';
|
|
175
361
|
return [
|
|
176
362
|
4,
|
|
177
|
-
|
|
363
|
+
plugin.transform(mockedRequest)
|
|
364
|
+
];
|
|
365
|
+
case 1:
|
|
366
|
+
newRequest = _state.sent();
|
|
367
|
+
expect(newRequest.headers.get(destinationHeaderName)).toBe(mockedFingerprint);
|
|
368
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(1);
|
|
369
|
+
return [
|
|
370
|
+
2
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
})();
|
|
375
|
+
});
|
|
376
|
+
it('Should\' add the fingerprint header if no fingerprint is found with no poller.', function() {
|
|
377
|
+
return _async_to_generator(function() {
|
|
378
|
+
var plugin, newRequest;
|
|
379
|
+
return _ts_generator(this, function(_state) {
|
|
380
|
+
switch(_state.label){
|
|
381
|
+
case 0:
|
|
382
|
+
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
383
|
+
destinationHeaderName: destinationHeaderName,
|
|
384
|
+
fingerprintRetriever: fingerprintRetriever,
|
|
385
|
+
pollerOptions: undefined,
|
|
386
|
+
pollOnlyOnce: false
|
|
387
|
+
}).load();
|
|
388
|
+
return [
|
|
389
|
+
4,
|
|
390
|
+
plugin.transform(mockedRequest)
|
|
391
|
+
];
|
|
392
|
+
case 1:
|
|
393
|
+
newRequest = _state.sent();
|
|
394
|
+
expect(newRequest.headers.has(destinationHeaderName)).toBeFalsy();
|
|
395
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(1);
|
|
396
|
+
return [
|
|
397
|
+
2
|
|
398
|
+
];
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
})();
|
|
402
|
+
});
|
|
403
|
+
it('Should add the fingerprint header if there is no fingerprint after the configured poller has finished running.', function() {
|
|
404
|
+
return _async_to_generator(function() {
|
|
405
|
+
var plugin, newRequestPromise, newRequest;
|
|
406
|
+
return _ts_generator(this, function(_state) {
|
|
407
|
+
switch(_state.label){
|
|
408
|
+
case 0:
|
|
409
|
+
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
410
|
+
destinationHeaderName: destinationHeaderName,
|
|
411
|
+
fingerprintRetriever: fingerprintRetriever,
|
|
412
|
+
pollerOptions: {
|
|
413
|
+
maximumTries: 5,
|
|
414
|
+
delayBetweenTriesInMilliseconds: 250
|
|
415
|
+
},
|
|
416
|
+
pollOnlyOnce: false
|
|
417
|
+
}).load();
|
|
418
|
+
newRequestPromise = plugin.transform(mockedRequest);
|
|
419
|
+
return [
|
|
420
|
+
4,
|
|
421
|
+
jest.advanceTimersByTimeAsync(1000)
|
|
178
422
|
];
|
|
179
423
|
case 1:
|
|
180
424
|
_state.sent();
|
|
181
425
|
return [
|
|
182
426
|
4,
|
|
183
|
-
|
|
427
|
+
newRequestPromise
|
|
184
428
|
];
|
|
185
429
|
case 2:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// eslint-disable-next-line no-console -- console.error is not called here
|
|
190
|
-
expect(console.error).toHaveBeenCalledTimes(1);
|
|
430
|
+
newRequest = _state.sent();
|
|
431
|
+
expect(newRequest.headers.has(destinationHeaderName)).toBeFalsy();
|
|
432
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(5);
|
|
191
433
|
return [
|
|
192
434
|
2
|
|
193
435
|
];
|
|
194
436
|
}
|
|
195
437
|
});
|
|
196
|
-
}));
|
|
197
|
-
|
|
198
|
-
|
|
438
|
+
})();
|
|
439
|
+
});
|
|
440
|
+
it('Should add the fingerprint header if initially not found but added before the poller ended.', function() {
|
|
441
|
+
return _async_to_generator(function() {
|
|
442
|
+
var plugin, newRequestPromise, newRequest;
|
|
199
443
|
return _ts_generator(this, function(_state) {
|
|
200
444
|
switch(_state.label){
|
|
201
445
|
case 0:
|
|
202
|
-
|
|
203
|
-
|
|
446
|
+
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
447
|
+
destinationHeaderName: destinationHeaderName,
|
|
448
|
+
fingerprintRetriever: fingerprintRetriever,
|
|
449
|
+
pollerOptions: {
|
|
450
|
+
maximumTries: 5,
|
|
451
|
+
delayBetweenTriesInMilliseconds: 250
|
|
452
|
+
},
|
|
453
|
+
pollOnlyOnce: false
|
|
454
|
+
}).load();
|
|
455
|
+
setTimeout(function() {
|
|
456
|
+
return mockedFingerprint = 'fingerprint';
|
|
457
|
+
}, 350);
|
|
458
|
+
newRequestPromise = plugin.transform(mockedRequest);
|
|
204
459
|
return [
|
|
205
460
|
4,
|
|
206
|
-
jest.
|
|
461
|
+
jest.advanceTimersByTimeAsync(350)
|
|
207
462
|
];
|
|
208
463
|
case 1:
|
|
209
464
|
_state.sent();
|
|
465
|
+
mockedFingerprint = 'fingerprint';
|
|
210
466
|
return [
|
|
211
467
|
4,
|
|
212
|
-
|
|
468
|
+
jest.runAllTimersAsync()
|
|
213
469
|
];
|
|
214
470
|
case 2:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
471
|
+
_state.sent();
|
|
472
|
+
return [
|
|
473
|
+
4,
|
|
474
|
+
newRequestPromise
|
|
475
|
+
];
|
|
476
|
+
case 3:
|
|
477
|
+
newRequest = _state.sent();
|
|
478
|
+
expect(newRequest.headers.get(destinationHeaderName)).toBe(mockedFingerprint);
|
|
479
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(3);
|
|
220
480
|
return [
|
|
221
481
|
2
|
|
222
482
|
];
|
|
223
483
|
}
|
|
224
484
|
});
|
|
225
|
-
}));
|
|
226
|
-
|
|
227
|
-
|
|
485
|
+
})();
|
|
486
|
+
});
|
|
487
|
+
it('Should poll twice if configured.', function() {
|
|
488
|
+
return _async_to_generator(function() {
|
|
489
|
+
var plugin, promise;
|
|
228
490
|
return _ts_generator(this, function(_state) {
|
|
229
491
|
switch(_state.label){
|
|
230
492
|
case 0:
|
|
231
|
-
|
|
232
|
-
|
|
493
|
+
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
494
|
+
destinationHeaderName: destinationHeaderName,
|
|
495
|
+
fingerprintRetriever: fingerprintRetriever,
|
|
496
|
+
pollerOptions: {
|
|
497
|
+
maximumTries: 5,
|
|
498
|
+
delayBetweenTriesInMilliseconds: 250
|
|
499
|
+
},
|
|
500
|
+
pollOnlyOnce: false
|
|
501
|
+
}).load();
|
|
502
|
+
promise = plugin.transform(mockedRequest);
|
|
233
503
|
return [
|
|
234
504
|
4,
|
|
235
505
|
jest.runAllTimersAsync()
|
|
@@ -241,24 +511,45 @@ describe('BotProtectionFingerprint', function() {
|
|
|
241
511
|
promise
|
|
242
512
|
];
|
|
243
513
|
case 2:
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
514
|
+
_state.sent();
|
|
515
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(5);
|
|
516
|
+
promise = plugin.transform(mockedRequest);
|
|
517
|
+
return [
|
|
518
|
+
4,
|
|
519
|
+
jest.runAllTimersAsync()
|
|
520
|
+
];
|
|
521
|
+
case 3:
|
|
522
|
+
_state.sent();
|
|
523
|
+
return [
|
|
524
|
+
4,
|
|
525
|
+
promise
|
|
526
|
+
];
|
|
527
|
+
case 4:
|
|
528
|
+
_state.sent();
|
|
529
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(10);
|
|
249
530
|
return [
|
|
250
531
|
2
|
|
251
532
|
];
|
|
252
533
|
}
|
|
253
534
|
});
|
|
254
|
-
}));
|
|
255
|
-
|
|
256
|
-
|
|
535
|
+
})();
|
|
536
|
+
});
|
|
537
|
+
it('Shouldn\'t poll twice if configured.', function() {
|
|
538
|
+
return _async_to_generator(function() {
|
|
539
|
+
var plugin, promise;
|
|
257
540
|
return _ts_generator(this, function(_state) {
|
|
258
541
|
switch(_state.label){
|
|
259
542
|
case 0:
|
|
260
|
-
|
|
261
|
-
|
|
543
|
+
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
544
|
+
destinationHeaderName: destinationHeaderName,
|
|
545
|
+
fingerprintRetriever: fingerprintRetriever,
|
|
546
|
+
pollerOptions: {
|
|
547
|
+
maximumTries: 5,
|
|
548
|
+
delayBetweenTriesInMilliseconds: 250
|
|
549
|
+
},
|
|
550
|
+
pollOnlyOnce: true
|
|
551
|
+
}).load();
|
|
552
|
+
promise = plugin.transform(mockedRequest);
|
|
262
553
|
return [
|
|
263
554
|
4,
|
|
264
555
|
jest.runAllTimersAsync()
|
|
@@ -270,11 +561,9 @@ describe('BotProtectionFingerprint', function() {
|
|
|
270
561
|
promise
|
|
271
562
|
];
|
|
272
563
|
case 2:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
tokenValue = 'newToken';
|
|
277
|
-
newPromise = retriever();
|
|
564
|
+
_state.sent();
|
|
565
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(5);
|
|
566
|
+
promise = plugin.transform(mockedRequest);
|
|
278
567
|
return [
|
|
279
568
|
4,
|
|
280
569
|
jest.runAllTimersAsync()
|
|
@@ -283,290 +572,17 @@ describe('BotProtectionFingerprint', function() {
|
|
|
283
572
|
_state.sent();
|
|
284
573
|
return [
|
|
285
574
|
4,
|
|
286
|
-
|
|
575
|
+
promise
|
|
287
576
|
];
|
|
288
577
|
case 4:
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
]).toBe(tokenValue);
|
|
292
|
-
// eslint-disable-next-line no-console -- console.error is not called here
|
|
293
|
-
expect(console.error).not.toHaveBeenCalled();
|
|
578
|
+
_state.sent();
|
|
579
|
+
expect(fingerprintRetriever).toHaveBeenCalledTimes(6);
|
|
294
580
|
return [
|
|
295
581
|
2
|
|
296
582
|
];
|
|
297
583
|
}
|
|
298
584
|
});
|
|
299
|
-
}));
|
|
300
|
-
});
|
|
301
|
-
describe('akamaiTelemetryRetrieverFactory', function() {
|
|
302
|
-
it('Should return undefined if bmak object doesn\'t exist.', function() {
|
|
303
|
-
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)()()).toBeUndefined();
|
|
304
|
-
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)({})()).toBeUndefined();
|
|
305
|
-
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)({
|
|
306
|
-
get_telemetry: 'test'
|
|
307
|
-
})()).toBeUndefined();
|
|
308
|
-
});
|
|
309
|
-
it('Should return telemetry', function() {
|
|
310
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention -- naming convention imposed by Akamai
|
|
311
|
-
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)({
|
|
312
|
-
get_telemetry: function() {
|
|
313
|
-
return 'telemetryValue';
|
|
314
|
-
}
|
|
315
|
-
})()).toBe('telemetryValue');
|
|
316
|
-
global.window = {};
|
|
317
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention -- naming convention imposed by Akamai
|
|
318
|
-
global.window.bmak = {
|
|
319
|
-
get_telemetry: function() {
|
|
320
|
-
return 'telemetryValue2';
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
expect((0, _botprotectionfingerprintrequest.akamaiTelemetryRetrieverFactory)()()).toBe('telemetryValue2');
|
|
324
|
-
global.window = undefined;
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
describe('Plug-in', function() {
|
|
329
|
-
var mockedRequest;
|
|
330
|
-
var mockedFingerprint;
|
|
331
|
-
var fingerprintRetriever;
|
|
332
|
-
var destinationHeaderName = 'test-header';
|
|
333
|
-
beforeEach(function() {
|
|
334
|
-
mockedFingerprint = undefined;
|
|
335
|
-
mockedRequest = {
|
|
336
|
-
method: 'get',
|
|
337
|
-
basePath: 'toto',
|
|
338
|
-
headers: new Headers()
|
|
339
|
-
};
|
|
340
|
-
fingerprintRetriever = jest.fn().mockImplementation(function() {
|
|
341
|
-
return mockedFingerprint;
|
|
342
|
-
});
|
|
585
|
+
})();
|
|
343
586
|
});
|
|
344
|
-
it('Should add the fingerprint header if a fingerprint is found.', /*#__PURE__*/ _async_to_generator(function() {
|
|
345
|
-
var plugin, newRequest;
|
|
346
|
-
return _ts_generator(this, function(_state) {
|
|
347
|
-
switch(_state.label){
|
|
348
|
-
case 0:
|
|
349
|
-
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
350
|
-
destinationHeaderName: destinationHeaderName,
|
|
351
|
-
fingerprintRetriever: fingerprintRetriever,
|
|
352
|
-
pollerOptions: undefined,
|
|
353
|
-
pollOnlyOnce: false
|
|
354
|
-
}).load();
|
|
355
|
-
mockedFingerprint = 'fingerprint';
|
|
356
|
-
return [
|
|
357
|
-
4,
|
|
358
|
-
plugin.transform(mockedRequest)
|
|
359
|
-
];
|
|
360
|
-
case 1:
|
|
361
|
-
newRequest = _state.sent();
|
|
362
|
-
expect(newRequest.headers.get(destinationHeaderName)).toBe(mockedFingerprint);
|
|
363
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(1);
|
|
364
|
-
return [
|
|
365
|
-
2
|
|
366
|
-
];
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}));
|
|
370
|
-
it('Should\' add the fingerprint header if no fingerprint is found with no poller.', /*#__PURE__*/ _async_to_generator(function() {
|
|
371
|
-
var plugin, newRequest;
|
|
372
|
-
return _ts_generator(this, function(_state) {
|
|
373
|
-
switch(_state.label){
|
|
374
|
-
case 0:
|
|
375
|
-
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
376
|
-
destinationHeaderName: destinationHeaderName,
|
|
377
|
-
fingerprintRetriever: fingerprintRetriever,
|
|
378
|
-
pollerOptions: undefined,
|
|
379
|
-
pollOnlyOnce: false
|
|
380
|
-
}).load();
|
|
381
|
-
return [
|
|
382
|
-
4,
|
|
383
|
-
plugin.transform(mockedRequest)
|
|
384
|
-
];
|
|
385
|
-
case 1:
|
|
386
|
-
newRequest = _state.sent();
|
|
387
|
-
expect(newRequest.headers.has(destinationHeaderName)).toBeFalsy();
|
|
388
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(1);
|
|
389
|
-
return [
|
|
390
|
-
2
|
|
391
|
-
];
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
}));
|
|
395
|
-
it('Should add the fingerprint header if there is no fingerprint after the configured poller has finished running.', /*#__PURE__*/ _async_to_generator(function() {
|
|
396
|
-
var plugin, newRequestPromise, newRequest;
|
|
397
|
-
return _ts_generator(this, function(_state) {
|
|
398
|
-
switch(_state.label){
|
|
399
|
-
case 0:
|
|
400
|
-
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
401
|
-
destinationHeaderName: destinationHeaderName,
|
|
402
|
-
fingerprintRetriever: fingerprintRetriever,
|
|
403
|
-
pollerOptions: {
|
|
404
|
-
maximumTries: 5,
|
|
405
|
-
delayBetweenTriesInMilliseconds: 250
|
|
406
|
-
},
|
|
407
|
-
pollOnlyOnce: false
|
|
408
|
-
}).load();
|
|
409
|
-
newRequestPromise = plugin.transform(mockedRequest);
|
|
410
|
-
return [
|
|
411
|
-
4,
|
|
412
|
-
jest.advanceTimersByTimeAsync(1000)
|
|
413
|
-
];
|
|
414
|
-
case 1:
|
|
415
|
-
_state.sent();
|
|
416
|
-
return [
|
|
417
|
-
4,
|
|
418
|
-
newRequestPromise
|
|
419
|
-
];
|
|
420
|
-
case 2:
|
|
421
|
-
newRequest = _state.sent();
|
|
422
|
-
expect(newRequest.headers.has(destinationHeaderName)).toBeFalsy();
|
|
423
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(5);
|
|
424
|
-
return [
|
|
425
|
-
2
|
|
426
|
-
];
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
}));
|
|
430
|
-
it('Should add the fingerprint header if initially not found but added before the poller ended.', /*#__PURE__*/ _async_to_generator(function() {
|
|
431
|
-
var plugin, newRequestPromise, newRequest;
|
|
432
|
-
return _ts_generator(this, function(_state) {
|
|
433
|
-
switch(_state.label){
|
|
434
|
-
case 0:
|
|
435
|
-
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
436
|
-
destinationHeaderName: destinationHeaderName,
|
|
437
|
-
fingerprintRetriever: fingerprintRetriever,
|
|
438
|
-
pollerOptions: {
|
|
439
|
-
maximumTries: 5,
|
|
440
|
-
delayBetweenTriesInMilliseconds: 250
|
|
441
|
-
},
|
|
442
|
-
pollOnlyOnce: false
|
|
443
|
-
}).load();
|
|
444
|
-
setTimeout(function() {
|
|
445
|
-
return mockedFingerprint = 'fingerprint';
|
|
446
|
-
}, 350);
|
|
447
|
-
newRequestPromise = plugin.transform(mockedRequest);
|
|
448
|
-
return [
|
|
449
|
-
4,
|
|
450
|
-
jest.advanceTimersByTimeAsync(350)
|
|
451
|
-
];
|
|
452
|
-
case 1:
|
|
453
|
-
_state.sent();
|
|
454
|
-
mockedFingerprint = 'fingerprint';
|
|
455
|
-
return [
|
|
456
|
-
4,
|
|
457
|
-
jest.runAllTimersAsync()
|
|
458
|
-
];
|
|
459
|
-
case 2:
|
|
460
|
-
_state.sent();
|
|
461
|
-
return [
|
|
462
|
-
4,
|
|
463
|
-
newRequestPromise
|
|
464
|
-
];
|
|
465
|
-
case 3:
|
|
466
|
-
newRequest = _state.sent();
|
|
467
|
-
expect(newRequest.headers.get(destinationHeaderName)).toBe(mockedFingerprint);
|
|
468
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(3);
|
|
469
|
-
return [
|
|
470
|
-
2
|
|
471
|
-
];
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
}));
|
|
475
|
-
it('Should poll twice if configured.', /*#__PURE__*/ _async_to_generator(function() {
|
|
476
|
-
var plugin, promise;
|
|
477
|
-
return _ts_generator(this, function(_state) {
|
|
478
|
-
switch(_state.label){
|
|
479
|
-
case 0:
|
|
480
|
-
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
481
|
-
destinationHeaderName: destinationHeaderName,
|
|
482
|
-
fingerprintRetriever: fingerprintRetriever,
|
|
483
|
-
pollerOptions: {
|
|
484
|
-
maximumTries: 5,
|
|
485
|
-
delayBetweenTriesInMilliseconds: 250
|
|
486
|
-
},
|
|
487
|
-
pollOnlyOnce: false
|
|
488
|
-
}).load();
|
|
489
|
-
promise = plugin.transform(mockedRequest);
|
|
490
|
-
return [
|
|
491
|
-
4,
|
|
492
|
-
jest.runAllTimersAsync()
|
|
493
|
-
];
|
|
494
|
-
case 1:
|
|
495
|
-
_state.sent();
|
|
496
|
-
return [
|
|
497
|
-
4,
|
|
498
|
-
promise
|
|
499
|
-
];
|
|
500
|
-
case 2:
|
|
501
|
-
_state.sent();
|
|
502
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(5);
|
|
503
|
-
promise = plugin.transform(mockedRequest);
|
|
504
|
-
return [
|
|
505
|
-
4,
|
|
506
|
-
jest.runAllTimersAsync()
|
|
507
|
-
];
|
|
508
|
-
case 3:
|
|
509
|
-
_state.sent();
|
|
510
|
-
return [
|
|
511
|
-
4,
|
|
512
|
-
promise
|
|
513
|
-
];
|
|
514
|
-
case 4:
|
|
515
|
-
_state.sent();
|
|
516
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(10);
|
|
517
|
-
return [
|
|
518
|
-
2
|
|
519
|
-
];
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}));
|
|
523
|
-
it('Shouldn\'t poll twice if configured.', /*#__PURE__*/ _async_to_generator(function() {
|
|
524
|
-
var plugin, promise;
|
|
525
|
-
return _ts_generator(this, function(_state) {
|
|
526
|
-
switch(_state.label){
|
|
527
|
-
case 0:
|
|
528
|
-
plugin = new _botprotectionfingerprintrequest.BotProtectionFingerprintRequest({
|
|
529
|
-
destinationHeaderName: destinationHeaderName,
|
|
530
|
-
fingerprintRetriever: fingerprintRetriever,
|
|
531
|
-
pollerOptions: {
|
|
532
|
-
maximumTries: 5,
|
|
533
|
-
delayBetweenTriesInMilliseconds: 250
|
|
534
|
-
},
|
|
535
|
-
pollOnlyOnce: true
|
|
536
|
-
}).load();
|
|
537
|
-
promise = plugin.transform(mockedRequest);
|
|
538
|
-
return [
|
|
539
|
-
4,
|
|
540
|
-
jest.runAllTimersAsync()
|
|
541
|
-
];
|
|
542
|
-
case 1:
|
|
543
|
-
_state.sent();
|
|
544
|
-
return [
|
|
545
|
-
4,
|
|
546
|
-
promise
|
|
547
|
-
];
|
|
548
|
-
case 2:
|
|
549
|
-
_state.sent();
|
|
550
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(5);
|
|
551
|
-
promise = plugin.transform(mockedRequest);
|
|
552
|
-
return [
|
|
553
|
-
4,
|
|
554
|
-
jest.runAllTimersAsync()
|
|
555
|
-
];
|
|
556
|
-
case 3:
|
|
557
|
-
_state.sent();
|
|
558
|
-
return [
|
|
559
|
-
4,
|
|
560
|
-
promise
|
|
561
|
-
];
|
|
562
|
-
case 4:
|
|
563
|
-
_state.sent();
|
|
564
|
-
expect(fingerprintRetriever).toHaveBeenCalledTimes(6);
|
|
565
|
-
return [
|
|
566
|
-
2
|
|
567
|
-
];
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
}));
|
|
571
587
|
});
|
|
572
588
|
});
|