@ama-sdk/core 12.1.10 → 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.
Files changed (111) hide show
  1. package/cjs/clients/api-angular-client.js +13 -18
  2. package/cjs/clients/api-fetch-client.js +16 -21
  3. package/cjs/fwk/api.helpers.js +11 -11
  4. package/cjs/fwk/date.js +5 -5
  5. package/cjs/fwk/errors.js +7 -7
  6. package/cjs/fwk/mocks/alf-mock-adapter.js +58 -60
  7. package/cjs/fwk/mocks/base-mock-adapter.js +15 -19
  8. package/cjs/fwk/mocks/helpers.js +3 -3
  9. package/cjs/fwk/param-serialization.js +6 -6
  10. package/cjs/fwk/reviver.js +4 -4
  11. package/cjs/plugins/abort/abort.spec.js +83 -81
  12. package/cjs/plugins/additional-params/additional-params.request.js +18 -25
  13. package/cjs/plugins/additional-params/additional-params.spec.js +194 -186
  14. package/cjs/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
  15. package/cjs/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
  16. package/cjs/plugins/api-key/api-key.request.js +12 -19
  17. package/cjs/plugins/api-key/api-key.spec.js +50 -50
  18. package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +25 -36
  19. package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
  20. package/cjs/plugins/client-facts/client-facts.request.js +18 -25
  21. package/cjs/plugins/client-facts/client-facts.spec.js +218 -208
  22. package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
  23. package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
  24. package/cjs/plugins/custom-info/custom-info.spec.js +90 -90
  25. package/cjs/plugins/fetch-cache/fetch-cache.spec.js +100 -98
  26. package/cjs/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
  27. package/cjs/plugins/json-token/json-token.spec.js +109 -107
  28. package/cjs/plugins/keepalive/keepalive.request.js +7 -12
  29. package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
  30. package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +11 -23
  31. package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
  32. package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
  33. package/cjs/plugins/mock-intercept/mock-intercept.angular.js +94 -100
  34. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  35. package/cjs/plugins/mock-intercept/mock-intercept.interface.js +3 -3
  36. package/cjs/plugins/mock-intercept/mock-intercept.request.js +12 -19
  37. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +245 -237
  38. package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
  39. package/cjs/plugins/pii-tokenizer/pii-tokenizer.request.js +19 -27
  40. package/cjs/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
  41. package/cjs/plugins/raw-response-info/raw-response-info.spec.js +67 -67
  42. package/cjs/plugins/retry/retry.fetch.js +18 -27
  43. package/cjs/plugins/retry/retry.spec.js +233 -225
  44. package/cjs/plugins/reviver/reviver.spec.js +88 -86
  45. package/cjs/plugins/session-id/session-id.spec.js +98 -94
  46. package/cjs/plugins/si-token/si-token.spec.js +27 -29
  47. package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
  48. package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
  49. package/cjs/plugins/timeout/timeout.fetch.js +16 -22
  50. package/cjs/plugins/timeout/timeout.spec.js +211 -205
  51. package/cjs/plugins/url-rewrite/url-rewrite.request.js +9 -16
  52. package/cjs/plugins/url-rewrite/url-rewrite.spec.js +48 -48
  53. package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
  54. package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
  55. package/cjs/utils/crypto.js +15 -27
  56. package/cjs/utils/generic-api.js +9 -14
  57. package/cjs/utils/json-token.js +19 -26
  58. package/cjs/utils/json-token.spec.js +495 -497
  59. package/cjs/utils/mime-types.js +3 -3
  60. package/esm2015/clients/api-angular-client.js +13 -18
  61. package/esm2015/clients/api-fetch-client.js +16 -21
  62. package/esm2015/fwk/mocks/alf-mock-adapter.js +58 -60
  63. package/esm2015/fwk/mocks/base-mock-adapter.js +15 -19
  64. package/esm2015/plugins/abort/abort.spec.js +83 -81
  65. package/esm2015/plugins/additional-params/additional-params.request.js +15 -22
  66. package/esm2015/plugins/additional-params/additional-params.spec.js +194 -186
  67. package/esm2015/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
  68. package/esm2015/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
  69. package/esm2015/plugins/api-key/api-key.request.js +12 -19
  70. package/esm2015/plugins/api-key/api-key.spec.js +50 -50
  71. package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +21 -32
  72. package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
  73. package/esm2015/plugins/client-facts/client-facts.request.js +15 -22
  74. package/esm2015/plugins/client-facts/client-facts.spec.js +218 -208
  75. package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
  76. package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
  77. package/esm2015/plugins/custom-info/custom-info.spec.js +90 -90
  78. package/esm2015/plugins/fetch-cache/fetch-cache.spec.js +100 -98
  79. package/esm2015/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
  80. package/esm2015/plugins/json-token/json-token.spec.js +109 -107
  81. package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
  82. package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
  83. package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +8 -20
  84. package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
  85. package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
  86. package/esm2015/plugins/mock-intercept/mock-intercept.angular.js +94 -100
  87. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  88. package/esm2015/plugins/mock-intercept/mock-intercept.request.js +12 -19
  89. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +245 -237
  90. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
  91. package/esm2015/plugins/pii-tokenizer/pii-tokenizer.request.js +15 -23
  92. package/esm2015/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
  93. package/esm2015/plugins/raw-response-info/raw-response-info.spec.js +67 -67
  94. package/esm2015/plugins/retry/retry.fetch.js +18 -27
  95. package/esm2015/plugins/retry/retry.spec.js +233 -225
  96. package/esm2015/plugins/reviver/reviver.spec.js +88 -86
  97. package/esm2015/plugins/session-id/session-id.spec.js +98 -94
  98. package/esm2015/plugins/si-token/si-token.spec.js +27 -29
  99. package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
  100. package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
  101. package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
  102. package/esm2015/plugins/timeout/timeout.spec.js +211 -205
  103. package/esm2015/plugins/url-rewrite/url-rewrite.request.js +9 -16
  104. package/esm2015/plugins/url-rewrite/url-rewrite.spec.js +48 -48
  105. package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
  106. package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
  107. package/esm2015/utils/crypto.js +8 -20
  108. package/esm2015/utils/generic-api.js +9 -14
  109. package/esm2015/utils/json-token.js +10 -17
  110. package/esm2015/utils/json-token.spec.js +495 -497
  111. package/package.json +6 -6
@@ -46,7 +46,7 @@ function _define_property(obj, key, value) {
46
46
  return obj;
47
47
  }
48
48
  function _ts_generator(thisArg, body) {
49
- var f, y, t, g, _ = {
49
+ var f, y, t, _ = {
50
50
  label: 0,
51
51
  sent: function() {
52
52
  if (t[0] & 1) throw t[1];
@@ -54,12 +54,8 @@ function _ts_generator(thisArg, body) {
54
54
  },
55
55
  trys: [],
56
56
  ops: []
57
- };
58
- return g = {
59
- next: verb(0),
60
- "throw": verb(1),
61
- "return": verb(2)
62
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
57
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
58
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
63
59
  return this;
64
60
  }), g;
65
61
  function verb(n) {
@@ -72,7 +68,7 @@ function _ts_generator(thisArg, body) {
72
68
  }
73
69
  function step(op) {
74
70
  if (f) throw new TypeError("Generator is already executing.");
75
- while(_)try {
71
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
76
72
  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;
77
73
  if (y = 0, t) op = [
78
74
  op[0] & 2,
@@ -187,200 +183,212 @@ describe('JSON auth token request plugin', function() {
187
183
  afterAll(function() {
188
184
  global.sessionStorage = undefined;
189
185
  });
190
- it('should add a Bearer in the header', /*#__PURE__*/ _async_to_generator(function() {
191
- var _result_headers_get, plugin, result;
192
- return _ts_generator(this, function(_state) {
193
- switch(_state.label){
194
- case 0:
195
- plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
196
- return [
197
- 4,
198
- plugin.load().transform(options)
199
- ];
200
- case 1:
201
- result = _state.sent();
202
- expect(result.headers.has(authHeaderKey)).toBeTruthy();
203
- expect((_result_headers_get = result.headers.get(authHeaderKey)) === null || _result_headers_get === void 0 ? void 0 : _result_headers_get.startsWith(authHeaderPrefix)).toBeTruthy();
204
- return [
205
- 2
206
- ];
207
- }
208
- });
209
- }));
210
- it('should check that the jws token is well formatted', /*#__PURE__*/ _async_to_generator(function() {
211
- var plugin, result, token, tokenParts;
212
- return _ts_generator(this, function(_state) {
213
- switch(_state.label){
214
- case 0:
215
- plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
216
- return [
217
- 4,
218
- plugin.load().transform(options)
219
- ];
220
- case 1:
221
- result = _state.sent();
222
- token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
223
- tokenParts = token.split('.');
224
- expect(token).toBeDefined();
225
- expect(tokenParts.length).toEqual(3);
226
- return [
227
- 2
228
- ];
229
- }
230
- });
231
- }));
232
- it('should check that the header is properly set', /*#__PURE__*/ _async_to_generator(function() {
233
- var base64URLDecoder, plugin, result, token, tokenParts, header;
234
- return _ts_generator(this, function(_state) {
235
- switch(_state.label){
236
- case 0:
237
- base64URLDecoder = createBase64UrlDecoder();
238
- plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
239
- return [
240
- 4,
241
- plugin.load().transform(options)
242
- ];
243
- case 1:
244
- result = _state.sent();
245
- token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
246
- expect(token).toBeDefined();
247
- tokenParts = token.split('.');
248
- header = JSON.parse(base64URLDecoder(tokenParts[0]));
249
- expect(header.alg).toBeDefined();
250
- expect(header.alg).toEqual('HS256');
251
- expect(header.typ).toBeDefined();
252
- expect(header.typ).toEqual('JWT');
253
- return [
254
- 2
255
- ];
256
- }
257
- });
258
- }));
259
- it('should check that the payload is properly set', /*#__PURE__*/ _async_to_generator(function() {
260
- var base64URLDecoder, base64Decoder, plugin, result, token, tokenParts, payload, context;
261
- return _ts_generator(this, function(_state) {
262
- switch(_state.label){
263
- case 0:
264
- base64URLDecoder = createBase64UrlDecoder();
265
- base64Decoder = createBase64Decoder();
266
- plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
267
- return [
268
- 4,
269
- plugin.load().transform(options)
270
- ];
271
- case 1:
272
- result = _state.sent();
273
- token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
274
- expect(token).toBeDefined();
275
- tokenParts = token.split('.');
276
- payload = JSON.parse(base64URLDecoder(tokenParts[1]));
277
- expect(payload.jti).toBeDefined();
278
- expect(payload.iat).toBeDefined();
279
- expect(payload.exp).toBeDefined();
280
- expect(payload.iss).toBeDefined();
281
- expect(payload.iss).toEqual(jsonAuthTokenOptions.applicationId);
282
- expect(payload.context).toBeDefined();
283
- context = JSON.parse(base64Decoder(payload.context));
284
- expect(context.oid).toBeDefined();
285
- expect(context.oid).toEqual(jsonAuthTokenOptions.context.oid);
286
- return [
287
- 2
288
- ];
289
- }
290
- });
291
- }));
292
- it('should check the signature validity', /*#__PURE__*/ _async_to_generator(function() {
293
- var base64URLDecoder, base64UrlEncoder, plugin, result, token, tokenParts, header, payload, signature, secretKey, _, message, signCheck;
294
- return _ts_generator(this, function(_state) {
295
- switch(_state.label){
296
- case 0:
297
- base64URLDecoder = createBase64UrlDecoder();
298
- base64UrlEncoder = createBase64UrlEncoder();
299
- plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
300
- return [
301
- 4,
302
- plugin.load().transform(options)
303
- ];
304
- case 1:
305
- result = _state.sent();
306
- token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
307
- tokenParts = token.split('.');
308
- header = JSON.parse(base64URLDecoder(tokenParts[0]));
309
- payload = JSON.parse(base64URLDecoder(tokenParts[1]));
310
- signature = tokenParts[2];
311
- _ = jsonAuthTokenOptions.apiKey;
312
- return [
313
- 4,
314
- sha256(jsonAuthTokenOptions.secret + payload.jti + payload.iat + routePath)
315
- ];
316
- case 2:
317
- return [
318
- 4,
319
- sha256.apply(void 0, [
320
- _ + _state.sent()
321
- ])
322
- ];
323
- case 3:
324
- secretKey = _state.sent();
325
- message = "".concat(base64UrlEncoder(JSON.stringify(header)), ".").concat(base64UrlEncoder(JSON.stringify(payload)));
326
- return [
327
- 4,
328
- hmacSHA256(message, secretKey)
329
- ];
330
- case 4:
331
- signCheck = base64EncodeUrl.apply(void 0, [
332
- _state.sent()
333
- ]);
334
- expect(signature).toEqual(signCheck);
335
- return [
336
- 2
337
- ];
338
- }
339
- });
340
- }));
341
- it('should have same hmacSHA256 of node implementation', /*#__PURE__*/ _async_to_generator(function() {
342
- var base64URLDecoder, base64UrlEncoder, plugin, result, token, tokenParts, header, payload, secretKey, _, message;
343
- return _ts_generator(this, function(_state) {
344
- switch(_state.label){
345
- case 0:
346
- base64URLDecoder = createBase64UrlDecoder();
347
- base64UrlEncoder = createBase64UrlEncoder();
348
- plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
349
- return [
350
- 4,
351
- plugin.load().transform(options)
352
- ];
353
- case 1:
354
- result = _state.sent();
355
- token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
356
- tokenParts = token.split('.');
357
- header = JSON.parse(base64URLDecoder(tokenParts[0]));
358
- payload = JSON.parse(base64URLDecoder(tokenParts[1]));
359
- _ = jsonAuthTokenOptions.apiKey;
360
- return [
361
- 4,
362
- sha256(jsonAuthTokenOptions.secret + payload.jti + payload.iat + routePath)
363
- ];
364
- case 2:
365
- return [
366
- 4,
367
- sha256.apply(void 0, [
368
- _ + _state.sent()
369
- ])
370
- ];
371
- case 3:
372
- secretKey = _state.sent();
373
- message = "".concat(base64UrlEncoder(JSON.stringify(header)), ".").concat(base64UrlEncoder(JSON.stringify(payload)));
374
- return [
375
- 4,
376
- expect(hmacSHA256(message, secretKey)).resolves.toBe(hmacSHA256NodeImplementation(message, secretKey))
377
- ];
378
- case 4:
379
- _state.sent();
380
- return [
381
- 2
382
- ];
383
- }
384
- });
385
- }));
186
+ it('should add a Bearer in the header', function() {
187
+ return _async_to_generator(function() {
188
+ var _result_headers_get, plugin, result;
189
+ return _ts_generator(this, function(_state) {
190
+ switch(_state.label){
191
+ case 0:
192
+ plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
193
+ return [
194
+ 4,
195
+ plugin.load().transform(options)
196
+ ];
197
+ case 1:
198
+ result = _state.sent();
199
+ expect(result.headers.has(authHeaderKey)).toBeTruthy();
200
+ expect((_result_headers_get = result.headers.get(authHeaderKey)) === null || _result_headers_get === void 0 ? void 0 : _result_headers_get.startsWith(authHeaderPrefix)).toBeTruthy();
201
+ return [
202
+ 2
203
+ ];
204
+ }
205
+ });
206
+ })();
207
+ });
208
+ it('should check that the jws token is well formatted', function() {
209
+ return _async_to_generator(function() {
210
+ var plugin, result, token, tokenParts;
211
+ return _ts_generator(this, function(_state) {
212
+ switch(_state.label){
213
+ case 0:
214
+ plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
215
+ return [
216
+ 4,
217
+ plugin.load().transform(options)
218
+ ];
219
+ case 1:
220
+ result = _state.sent();
221
+ token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
222
+ tokenParts = token.split('.');
223
+ expect(token).toBeDefined();
224
+ expect(tokenParts.length).toEqual(3);
225
+ return [
226
+ 2
227
+ ];
228
+ }
229
+ });
230
+ })();
231
+ });
232
+ it('should check that the header is properly set', function() {
233
+ return _async_to_generator(function() {
234
+ var base64URLDecoder, plugin, result, token, tokenParts, header;
235
+ return _ts_generator(this, function(_state) {
236
+ switch(_state.label){
237
+ case 0:
238
+ base64URLDecoder = createBase64UrlDecoder();
239
+ plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
240
+ return [
241
+ 4,
242
+ plugin.load().transform(options)
243
+ ];
244
+ case 1:
245
+ result = _state.sent();
246
+ token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
247
+ expect(token).toBeDefined();
248
+ tokenParts = token.split('.');
249
+ header = JSON.parse(base64URLDecoder(tokenParts[0]));
250
+ expect(header.alg).toBeDefined();
251
+ expect(header.alg).toEqual('HS256');
252
+ expect(header.typ).toBeDefined();
253
+ expect(header.typ).toEqual('JWT');
254
+ return [
255
+ 2
256
+ ];
257
+ }
258
+ });
259
+ })();
260
+ });
261
+ it('should check that the payload is properly set', function() {
262
+ return _async_to_generator(function() {
263
+ var base64URLDecoder, base64Decoder, plugin, result, token, tokenParts, payload, context;
264
+ return _ts_generator(this, function(_state) {
265
+ switch(_state.label){
266
+ case 0:
267
+ base64URLDecoder = createBase64UrlDecoder();
268
+ base64Decoder = createBase64Decoder();
269
+ plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
270
+ return [
271
+ 4,
272
+ plugin.load().transform(options)
273
+ ];
274
+ case 1:
275
+ result = _state.sent();
276
+ token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
277
+ expect(token).toBeDefined();
278
+ tokenParts = token.split('.');
279
+ payload = JSON.parse(base64URLDecoder(tokenParts[1]));
280
+ expect(payload.jti).toBeDefined();
281
+ expect(payload.iat).toBeDefined();
282
+ expect(payload.exp).toBeDefined();
283
+ expect(payload.iss).toBeDefined();
284
+ expect(payload.iss).toEqual(jsonAuthTokenOptions.applicationId);
285
+ expect(payload.context).toBeDefined();
286
+ context = JSON.parse(base64Decoder(payload.context));
287
+ expect(context.oid).toBeDefined();
288
+ expect(context.oid).toEqual(jsonAuthTokenOptions.context.oid);
289
+ return [
290
+ 2
291
+ ];
292
+ }
293
+ });
294
+ })();
295
+ });
296
+ it('should check the signature validity', function() {
297
+ return _async_to_generator(function() {
298
+ var base64URLDecoder, base64UrlEncoder, plugin, result, token, tokenParts, header, payload, signature, secretKey, _, message, signCheck;
299
+ return _ts_generator(this, function(_state) {
300
+ switch(_state.label){
301
+ case 0:
302
+ base64URLDecoder = createBase64UrlDecoder();
303
+ base64UrlEncoder = createBase64UrlEncoder();
304
+ plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
305
+ return [
306
+ 4,
307
+ plugin.load().transform(options)
308
+ ];
309
+ case 1:
310
+ result = _state.sent();
311
+ token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
312
+ tokenParts = token.split('.');
313
+ header = JSON.parse(base64URLDecoder(tokenParts[0]));
314
+ payload = JSON.parse(base64URLDecoder(tokenParts[1]));
315
+ signature = tokenParts[2];
316
+ _ = jsonAuthTokenOptions.apiKey;
317
+ return [
318
+ 4,
319
+ sha256(jsonAuthTokenOptions.secret + payload.jti + payload.iat + routePath)
320
+ ];
321
+ case 2:
322
+ return [
323
+ 4,
324
+ sha256.apply(void 0, [
325
+ _ + _state.sent()
326
+ ])
327
+ ];
328
+ case 3:
329
+ secretKey = _state.sent();
330
+ message = "".concat(base64UrlEncoder(JSON.stringify(header)), ".").concat(base64UrlEncoder(JSON.stringify(payload)));
331
+ return [
332
+ 4,
333
+ hmacSHA256(message, secretKey)
334
+ ];
335
+ case 4:
336
+ signCheck = base64EncodeUrl.apply(void 0, [
337
+ _state.sent()
338
+ ]);
339
+ expect(signature).toEqual(signCheck);
340
+ return [
341
+ 2
342
+ ];
343
+ }
344
+ });
345
+ })();
346
+ });
347
+ it('should have same hmacSHA256 of node implementation', function() {
348
+ return _async_to_generator(function() {
349
+ var base64URLDecoder, base64UrlEncoder, plugin, result, token, tokenParts, header, payload, secretKey, _, message;
350
+ return _ts_generator(this, function(_state) {
351
+ switch(_state.label){
352
+ case 0:
353
+ base64URLDecoder = createBase64UrlDecoder();
354
+ base64UrlEncoder = createBase64UrlEncoder();
355
+ plugin = new MicroGatewayMiddlewareAuthenticationRequest(jsonAuthTokenOptions);
356
+ return [
357
+ 4,
358
+ plugin.load().transform(options)
359
+ ];
360
+ case 1:
361
+ result = _state.sent();
362
+ token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
363
+ tokenParts = token.split('.');
364
+ header = JSON.parse(base64URLDecoder(tokenParts[0]));
365
+ payload = JSON.parse(base64URLDecoder(tokenParts[1]));
366
+ _ = jsonAuthTokenOptions.apiKey;
367
+ return [
368
+ 4,
369
+ sha256(jsonAuthTokenOptions.secret + payload.jti + payload.iat + routePath)
370
+ ];
371
+ case 2:
372
+ return [
373
+ 4,
374
+ sha256.apply(void 0, [
375
+ _ + _state.sent()
376
+ ])
377
+ ];
378
+ case 3:
379
+ secretKey = _state.sent();
380
+ message = "".concat(base64UrlEncoder(JSON.stringify(header)), ".").concat(base64UrlEncoder(JSON.stringify(payload)));
381
+ return [
382
+ 4,
383
+ expect(hmacSHA256(message, secretKey)).resolves.toBe(hmacSHA256NodeImplementation(message, secretKey))
384
+ ];
385
+ case 4:
386
+ _state.sent();
387
+ return [
388
+ 2
389
+ ];
390
+ }
391
+ });
392
+ })();
393
+ });
386
394
  });