@webex/webex-core 3.12.0 → 3.13.0-next.10
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/.repo-context.json +653 -0
- package/.sdd/manifest.json +615 -0
- package/AGENTS.md +209 -0
- package/README.md +6 -3
- package/dist/config.js +46 -1
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +21 -1
- package/dist/credentials-config.js.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/interceptors/auth.js +10 -1
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/interceptors/catalog-url.js +87 -0
- package/dist/interceptors/catalog-url.js.map +1 -0
- package/dist/interceptors/payload-transformer.js +25 -4
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/lib/batcher.js +23 -7
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +117 -5
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/token.js +23 -9
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/domains.js +90 -0
- package/dist/lib/domains.js.map +1 -0
- package/dist/lib/interceptors/service.js +5 -1
- package/dist/lib/interceptors/service.js.map +1 -1
- package/dist/lib/services/catalog-auth.js +114 -0
- package/dist/lib/services/catalog-auth.js.map +1 -0
- package/dist/lib/services/service-catalog.js +108 -18
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/services.js +287 -40
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/services-v2/service-catalog.js +14 -13
- package/dist/lib/services-v2/service-catalog.js.map +1 -1
- package/dist/lib/services-v2/services-v2.js +294 -44
- package/dist/lib/services-v2/services-v2.js.map +1 -1
- package/dist/lib/static-asset-loader.js +153 -0
- package/dist/lib/static-asset-loader.js.map +1 -0
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +11 -3
- package/dist/webex-core.js.map +1 -1
- package/docs/adr/index.md +32 -0
- package/docs/architecture.md +298 -0
- package/docs/getting-started.md +96 -0
- package/docs/index.md +55 -0
- package/docs/specs/README.md +76 -0
- package/package.json +13 -13
- package/schemas/repo-context.schema.json +796 -0
- package/src/config.js +50 -1
- package/src/credentials-config.js +22 -0
- package/src/docs/README.md +732 -0
- package/src/index.js +2 -0
- package/src/interceptors/auth.js +14 -1
- package/src/interceptors/catalog-url.js +66 -0
- package/src/interceptors/docs/README.md +658 -0
- package/src/interceptors/payload-transformer.js +23 -1
- package/src/lib/batcher.js +25 -10
- package/src/lib/credentials/credentials.js +106 -4
- package/src/lib/credentials/docs/README.md +847 -0
- package/src/lib/credentials/token.js +15 -8
- package/src/lib/domains.ts +94 -0
- package/src/lib/interceptors/service.js +11 -3
- package/src/lib/services/catalog-auth.js +112 -0
- package/src/lib/services/docs/README.md +737 -0
- package/src/lib/services/service-catalog.js +112 -16
- package/src/lib/services/services.js +274 -24
- package/src/lib/services-v2/docs/README.md +751 -0
- package/src/lib/services-v2/service-catalog.ts +16 -12
- package/src/lib/services-v2/services-v2.ts +282 -26
- package/src/lib/static-asset-loader.ts +128 -0
- package/src/lib/storage/docs/README.md +646 -0
- package/src/webex-core.js +8 -0
- package/test/fixtures/activation-email.ts +22 -0
- package/test/integration/spec/credentials/credentials.js +3 -1
- package/test/integration/spec/credentials/token.js +8 -0
- package/test/integration/spec/services/service-catalog.js +5 -0
- package/test/integration/spec/services/services.js +183 -112
- package/test/integration/spec/services-v2/services-v2.js +169 -98
- package/test/integration/spec/unit-browser/token.js +7 -2
- package/test/unit/spec/credentials/credentials.js +326 -3
- package/test/unit/spec/credentials/token.js +259 -6
- package/test/unit/spec/interceptors/auth.js +92 -1
- package/test/unit/spec/interceptors/catalog-url.js +224 -0
- package/test/unit/spec/interceptors/payload-transformer.js +119 -1
- package/test/unit/spec/lib/batcher.js +56 -0
- package/test/unit/spec/services/interceptors/service.js +35 -1
- package/test/unit/spec/services/service-catalog.js +368 -11
- package/test/unit/spec/services/services.js +783 -10
- package/test/unit/spec/services-v2/service-catalog.ts +134 -11
- package/test/unit/spec/services-v2/services-v2.ts +825 -10
- package/test/unit/spec/static-asset-loader.ts +224 -0
- package/test/unit/spec/webex-core.js +77 -1
|
@@ -150,7 +150,7 @@ describe('webex-core', () => {
|
|
|
150
150
|
|
|
151
151
|
describe('#downscope()', () => {
|
|
152
152
|
it('requires an access token', () => {
|
|
153
|
-
const token = makeToken();
|
|
153
|
+
const token = makeToken({scope: 'scopeA scopeB'});
|
|
154
154
|
|
|
155
155
|
token.unset('access_token');
|
|
156
156
|
|
|
@@ -158,7 +158,7 @@ describe('webex-core', () => {
|
|
|
158
158
|
});
|
|
159
159
|
|
|
160
160
|
it('requires an unexpired access token', () => {
|
|
161
|
-
const token = makeToken({expires: Date.now() - 10000});
|
|
161
|
+
const token = makeToken({expires: Date.now() - 10000, scope: 'scopeA scopeB'});
|
|
162
162
|
|
|
163
163
|
return assert.isRejected(
|
|
164
164
|
token.downscope('spark:kms'),
|
|
@@ -167,6 +167,15 @@ describe('webex-core', () => {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
it('rejects downscope when the new scope is not super set of the available scopes', () => {
|
|
170
|
+
const token = makeToken({scope: 'scopeA scopeB'});
|
|
171
|
+
|
|
172
|
+
return assert.isRejected(
|
|
173
|
+
token.downscope('scopeX'),
|
|
174
|
+
/new scope \(scopeX\) is not subset of the available scopes \(scopeA scopeB\)/
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('rejects downscope when the new scope is not super set of the available scopes - config fallback', () => {
|
|
170
179
|
const token = makeToken();
|
|
171
180
|
token.config.scope = 'scopeY scopeZ';
|
|
172
181
|
|
|
@@ -176,11 +185,54 @@ describe('webex-core', () => {
|
|
|
176
185
|
);
|
|
177
186
|
});
|
|
178
187
|
|
|
179
|
-
it('
|
|
188
|
+
it("uses the token's scope instead of the configured scope for downscope", () => {
|
|
189
|
+
const token = makeToken({scope: 'scopeX scopeY'});
|
|
190
|
+
|
|
191
|
+
token.config.scope = 'scopeY';
|
|
192
|
+
webex.request.returns(Promise.resolve({body: {access_token: 'AT2'}}));
|
|
193
|
+
|
|
194
|
+
return token.downscope('scopeX').then(() => {
|
|
195
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
uri: token.config.tokenUrl,
|
|
198
|
+
addAuthHeader: false,
|
|
199
|
+
form: {
|
|
200
|
+
grant_type: 'urn:cisco:oauth:grant-type:scope-reduction',
|
|
201
|
+
token: 'AT',
|
|
202
|
+
scope: 'scopeX',
|
|
203
|
+
client_id: token.config.client_id,
|
|
204
|
+
self_contained_token: true,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("falls back to the configured scope for downscope", () => {
|
|
180
211
|
const token = makeToken();
|
|
181
212
|
|
|
213
|
+
token.config.scope = 'scopeX scopeY';
|
|
214
|
+
webex.request.returns(Promise.resolve({body: {access_token: 'AT2'}}));
|
|
215
|
+
|
|
216
|
+
return token.downscope('scopeX').then(() => {
|
|
217
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
uri: token.config.tokenUrl,
|
|
220
|
+
addAuthHeader: false,
|
|
221
|
+
form: {
|
|
222
|
+
grant_type: 'urn:cisco:oauth:grant-type:scope-reduction',
|
|
223
|
+
token: 'AT',
|
|
224
|
+
scope: 'scopeX',
|
|
225
|
+
client_id: token.config.client_id,
|
|
226
|
+
self_contained_token: true,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('alphabetizes the requested scope', () => {
|
|
233
|
+
const token = makeToken({scope: 'a b c'});
|
|
234
|
+
|
|
182
235
|
webex.request.returns(Promise.resolve({body: {access_token: 'AT2'}}));
|
|
183
|
-
token.config.scope = 'a b c';
|
|
184
236
|
return token
|
|
185
237
|
.downscope('b a')
|
|
186
238
|
.then(() => assert.equal(webex.request.args[0][0].form.scope, 'a b'));
|
|
@@ -269,12 +321,13 @@ describe('webex-core', () => {
|
|
|
269
321
|
|
|
270
322
|
describe('#refresh()', () => {
|
|
271
323
|
browserOnly(it)('refreshes the access_token', () => {
|
|
272
|
-
const token = makeToken();
|
|
324
|
+
const token = makeToken({scope: 'scope1'});
|
|
273
325
|
|
|
274
326
|
webex.config.credentials.refreshCallback = sinon.stub().returns(
|
|
275
327
|
Promise.resolve({
|
|
276
328
|
access_token: 'AT2',
|
|
277
329
|
expires_in: 10000,
|
|
330
|
+
scope: 'scope1',
|
|
278
331
|
token_type: 'Fake',
|
|
279
332
|
})
|
|
280
333
|
);
|
|
@@ -285,17 +338,23 @@ describe('webex-core', () => {
|
|
|
285
338
|
|
|
286
339
|
return token.refresh().then((token2) => {
|
|
287
340
|
assert.equal(token2.access_token, 'AT2');
|
|
341
|
+
assert.equal(token2.scope, 'scope1');
|
|
342
|
+
assert.calledOnceWithExactly(webex.config.credentials.refreshCallback, webex, token, {
|
|
343
|
+
scope: undefined,
|
|
344
|
+
upgradeScope: undefined,
|
|
345
|
+
});
|
|
288
346
|
});
|
|
289
347
|
});
|
|
290
348
|
|
|
291
349
|
nodeOnly(it)('refreshes the access_token', () => {
|
|
292
|
-
const token = makeToken();
|
|
350
|
+
const token = makeToken({scope: 'scope1'});
|
|
293
351
|
|
|
294
352
|
webex.request.onCall(0).returns(
|
|
295
353
|
Promise.resolve({
|
|
296
354
|
body: {
|
|
297
355
|
access_token: 'AT2',
|
|
298
356
|
expires_in: 10000,
|
|
357
|
+
scope: 'scope1',
|
|
299
358
|
token_type: 'Fake',
|
|
300
359
|
},
|
|
301
360
|
})
|
|
@@ -303,6 +362,200 @@ describe('webex-core', () => {
|
|
|
303
362
|
|
|
304
363
|
return token.refresh().then((token2) => {
|
|
305
364
|
assert.equal(token2.access_token, 'AT2');
|
|
365
|
+
assert.equal(token2.scope, 'scope1');
|
|
366
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
367
|
+
method: 'POST',
|
|
368
|
+
uri: token.config.tokenUrl,
|
|
369
|
+
form: {
|
|
370
|
+
grant_type: 'refresh_token',
|
|
371
|
+
redirect_uri: token.config.redirect_uri,
|
|
372
|
+
refresh_token: 'RT',
|
|
373
|
+
},
|
|
374
|
+
auth: {
|
|
375
|
+
user: token.config.client_id,
|
|
376
|
+
pass: token.config.client_secret,
|
|
377
|
+
sendImmediately: true,
|
|
378
|
+
},
|
|
379
|
+
shouldRefreshAccessToken: false,
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
browserOnly(it)('refreshes the access_token with scope upgrade', () => {
|
|
385
|
+
const token = makeToken({scope: 'scope1'});
|
|
386
|
+
|
|
387
|
+
webex.config.credentials.refreshCallback = sinon.stub().returns(
|
|
388
|
+
Promise.resolve({
|
|
389
|
+
access_token: 'AT2',
|
|
390
|
+
expires_in: 10000,
|
|
391
|
+
scope: 'scope1 scope2',
|
|
392
|
+
token_type: 'Fake',
|
|
393
|
+
})
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
// FIXME this next line should be necessary. we need a better way to
|
|
397
|
+
// do config
|
|
398
|
+
token.trigger('change:config');
|
|
399
|
+
|
|
400
|
+
return token.refresh({upgradeScope: 'scope1 scope2'}).then((token2) => {
|
|
401
|
+
assert.equal(token2.access_token, 'AT2');
|
|
402
|
+
assert.equal(token2.scope, 'scope1 scope2');
|
|
403
|
+
assert.calledOnceWithExactly(webex.config.credentials.refreshCallback, webex, token, {
|
|
404
|
+
scope: undefined,
|
|
405
|
+
upgradeScope: 'scope1 scope2',
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
nodeOnly(it)('refreshes the access_token with scope upgrade', () => {
|
|
411
|
+
const token = makeToken({scope: 'scope1'});
|
|
412
|
+
|
|
413
|
+
webex.request.onCall(0).returns(
|
|
414
|
+
Promise.resolve({
|
|
415
|
+
body: {
|
|
416
|
+
access_token: 'AT2',
|
|
417
|
+
expires_in: 10000,
|
|
418
|
+
scope: 'scope1 scope2',
|
|
419
|
+
token_type: 'Fake',
|
|
420
|
+
},
|
|
421
|
+
})
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
return token.refresh({upgradeScope: 'scope1 scope2'}).then((token2) => {
|
|
425
|
+
assert.equal(token2.access_token, 'AT2');
|
|
426
|
+
assert.equal(token2.scope, 'scope1 scope2');
|
|
427
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
428
|
+
method: 'POST',
|
|
429
|
+
uri: token.config.tokenUrl,
|
|
430
|
+
form: {
|
|
431
|
+
grant_type: 'refresh_token',
|
|
432
|
+
redirect_uri: token.config.redirect_uri,
|
|
433
|
+
refresh_token: 'RT',
|
|
434
|
+
upgrade_scope: 'scope1 scope2',
|
|
435
|
+
},
|
|
436
|
+
auth: {
|
|
437
|
+
user: token.config.client_id,
|
|
438
|
+
pass: token.config.client_secret,
|
|
439
|
+
sendImmediately: true,
|
|
440
|
+
},
|
|
441
|
+
shouldRefreshAccessToken: false,
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
browserOnly(it)('refreshes the access_token with an explicit scope', () => {
|
|
447
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
448
|
+
|
|
449
|
+
webex.config.credentials.refreshCallback = sinon.stub().resolves({
|
|
450
|
+
access_token: 'AT2',
|
|
451
|
+
expires_in: 10000,
|
|
452
|
+
scope: 'scope1',
|
|
453
|
+
token_type: 'Fake',
|
|
454
|
+
});
|
|
455
|
+
token.trigger('change:config');
|
|
456
|
+
|
|
457
|
+
return token.refresh({scope: 'scope1'}).then((token2) => {
|
|
458
|
+
assert.equal(token2.access_token, 'AT2');
|
|
459
|
+
assert.equal(token2.scope, 'scope1');
|
|
460
|
+
assert.calledOnceWithExactly(webex.config.credentials.refreshCallback, webex, token, {
|
|
461
|
+
scope: 'scope1',
|
|
462
|
+
upgradeScope: undefined,
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
nodeOnly(it)('refreshes the access_token with an explicit scope', () => {
|
|
468
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
469
|
+
|
|
470
|
+
webex.request.resolves({
|
|
471
|
+
body: {
|
|
472
|
+
access_token: 'AT2',
|
|
473
|
+
expires_in: 10000,
|
|
474
|
+
scope: 'scope1',
|
|
475
|
+
token_type: 'Fake',
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
return token.refresh({scope: 'scope1'}).then((token2) => {
|
|
480
|
+
assert.equal(token2.access_token, 'AT2');
|
|
481
|
+
assert.equal(token2.scope, 'scope1');
|
|
482
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
483
|
+
method: 'POST',
|
|
484
|
+
uri: token.config.tokenUrl,
|
|
485
|
+
form: {
|
|
486
|
+
grant_type: 'refresh_token',
|
|
487
|
+
redirect_uri: token.config.redirect_uri,
|
|
488
|
+
refresh_token: 'RT',
|
|
489
|
+
scope: 'scope1',
|
|
490
|
+
},
|
|
491
|
+
auth: {
|
|
492
|
+
user: token.config.client_id,
|
|
493
|
+
pass: token.config.client_secret,
|
|
494
|
+
sendImmediately: true,
|
|
495
|
+
},
|
|
496
|
+
shouldRefreshAccessToken: false,
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
[
|
|
502
|
+
{
|
|
503
|
+
description: 'prefers the returned scope over an explicit scope',
|
|
504
|
+
options: {scope: 'scope1 scope2'},
|
|
505
|
+
responseScope: 'scope1',
|
|
506
|
+
expectedScope: 'scope1',
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
description: 'uses the explicit scope when the response omits scope',
|
|
510
|
+
options: {scope: 'scope1'},
|
|
511
|
+
responseScope: undefined,
|
|
512
|
+
expectedScope: 'scope1',
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
description:
|
|
516
|
+
'retains the old scope when neither the request nor response supplies scope',
|
|
517
|
+
options: {},
|
|
518
|
+
responseScope: undefined,
|
|
519
|
+
expectedScope: 'scope1 scope2',
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
description: 'does not assume an upgrade succeeded when the response omits scope',
|
|
523
|
+
options: {upgradeScope: 'scope1 scope2 scope3'},
|
|
524
|
+
responseScope: undefined,
|
|
525
|
+
expectedScope: 'scope1 scope2',
|
|
526
|
+
},
|
|
527
|
+
].forEach(({description, options, responseScope, expectedScope}) => {
|
|
528
|
+
browserOnly(it)(description, () => {
|
|
529
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
530
|
+
|
|
531
|
+
webex.config.credentials.refreshCallback = sinon.stub().resolves({
|
|
532
|
+
access_token: 'AT2',
|
|
533
|
+
expires_in: 10000,
|
|
534
|
+
scope: responseScope,
|
|
535
|
+
token_type: 'Fake',
|
|
536
|
+
});
|
|
537
|
+
token.trigger('change:config');
|
|
538
|
+
|
|
539
|
+
return token.refresh(options).then((token2) => {
|
|
540
|
+
assert.equal(token2.scope, expectedScope);
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
nodeOnly(it)(description, () => {
|
|
545
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
546
|
+
|
|
547
|
+
webex.request.resolves({
|
|
548
|
+
body: {
|
|
549
|
+
access_token: 'AT2',
|
|
550
|
+
expires_in: 10000,
|
|
551
|
+
scope: responseScope,
|
|
552
|
+
token_type: 'Fake',
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
return token.refresh(options).then((token2) => {
|
|
557
|
+
assert.equal(token2.scope, expectedScope);
|
|
558
|
+
});
|
|
306
559
|
});
|
|
307
560
|
});
|
|
308
561
|
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
AuthInterceptor,
|
|
15
15
|
config,
|
|
16
16
|
Credentials,
|
|
17
|
+
Services,
|
|
18
|
+
ServicesV2,
|
|
17
19
|
WebexHttpError,
|
|
18
20
|
Token,
|
|
19
21
|
serviceConstants,
|
|
@@ -237,7 +239,7 @@ describe('webex-core', () => {
|
|
|
237
239
|
beforeEach(() => {
|
|
238
240
|
services = {
|
|
239
241
|
hydra: 'https://hydra-a.wbx.com',
|
|
240
|
-
u2c: 'https://u2c.
|
|
242
|
+
u2c: 'https://u2c.svc.webex.com/u2c/api/v1',
|
|
241
243
|
example: 'https://service.example.com',
|
|
242
244
|
};
|
|
243
245
|
|
|
@@ -380,6 +382,60 @@ describe('webex-core', () => {
|
|
|
380
382
|
});
|
|
381
383
|
});
|
|
382
384
|
|
|
385
|
+
describe('#onRequest() against a real service catalog', () => {
|
|
386
|
+
// The cases above stub `isAllowedDomainUrl`, so they answer the
|
|
387
|
+
// allowed-domain question themselves and cannot show that the catalog
|
|
388
|
+
// matcher is reached by the code that attaches the token. These use a
|
|
389
|
+
// real catalog and real allowed-domain methods.
|
|
390
|
+
[
|
|
391
|
+
{name: 'Services', Constructor: Services},
|
|
392
|
+
{name: 'ServicesV2', Constructor: ServicesV2},
|
|
393
|
+
].forEach(({name, Constructor}) => {
|
|
394
|
+
describe(name, () => {
|
|
395
|
+
let getUserToken;
|
|
396
|
+
|
|
397
|
+
beforeEach(() => {
|
|
398
|
+
const services = new Constructor(undefined, {parent: webex});
|
|
399
|
+
|
|
400
|
+
services._getCatalog().setAllowedDomains(['webex.com']);
|
|
401
|
+
// the catalog holds no services, so a url that is not covered by
|
|
402
|
+
// an allowed domain has nothing else to authorize it
|
|
403
|
+
services.waitForService = sinon.stub().rejects(new Error('no such service'));
|
|
404
|
+
|
|
405
|
+
webex.internal.services = services;
|
|
406
|
+
getUserToken = sinon.spy(webex.credentials, 'getUserToken');
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
afterEach(() => {
|
|
410
|
+
getUserToken.restore();
|
|
411
|
+
delete webex.internal.services;
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('adds the authorization header for a url under an allowed domain', () =>
|
|
415
|
+
interceptor
|
|
416
|
+
.onRequest({uri: 'https://api.webex.com/resource', headers: {}})
|
|
417
|
+
.then((options) => {
|
|
418
|
+
assert.equal(
|
|
419
|
+
options.headers.authorization,
|
|
420
|
+
webex.credentials.supertoken.toString()
|
|
421
|
+
);
|
|
422
|
+
assert.calledOnce(getUserToken);
|
|
423
|
+
}));
|
|
424
|
+
|
|
425
|
+
[
|
|
426
|
+
'https://notwebex.com/resource',
|
|
427
|
+
'https://webex.com.unrelated.example/resource',
|
|
428
|
+
].forEach((uri) => {
|
|
429
|
+
it(`does not add the authorization header for ${uri}`, () =>
|
|
430
|
+
interceptor.onRequest({uri, headers: {}}).then((options) => {
|
|
431
|
+
assert.notProperty(options.headers, 'authorization');
|
|
432
|
+
assert.notCalled(getUserToken);
|
|
433
|
+
}));
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
383
439
|
describe('#onResponseError()', () => {
|
|
384
440
|
describe('when the server responds with 401', () => {
|
|
385
441
|
nodeOnly(it)('refreshes the access token and replays the request', () => {
|
|
@@ -491,6 +547,41 @@ describe('webex-core', () => {
|
|
|
491
547
|
});
|
|
492
548
|
});
|
|
493
549
|
|
|
550
|
+
it('marks a refresh 403 after a 401 with the original catalog status', () => {
|
|
551
|
+
webex.config.credentials.refreshCallback = sinon.stub();
|
|
552
|
+
webex.credentials.supertoken = new Token(
|
|
553
|
+
{
|
|
554
|
+
access_token: 'ST1',
|
|
555
|
+
refresh_token: 'RT1',
|
|
556
|
+
},
|
|
557
|
+
{parent: webex}
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
const refreshError = new Error('forbidden');
|
|
561
|
+
|
|
562
|
+
refreshError.statusCode = 403;
|
|
563
|
+
sinon.stub(webex.credentials, 'refresh').rejects(refreshError);
|
|
564
|
+
|
|
565
|
+
const err = new WebexHttpError.Unauthorized({
|
|
566
|
+
statusCode: 401,
|
|
567
|
+
options: {
|
|
568
|
+
headers: {
|
|
569
|
+
trackingid: 'blarg',
|
|
570
|
+
},
|
|
571
|
+
uri: `${config.services.discovery.hydra}/ping`,
|
|
572
|
+
},
|
|
573
|
+
body: {
|
|
574
|
+
error: 'fake error',
|
|
575
|
+
},
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
return assert.isRejected(interceptor.onResponseError(err.options, err)).then((err2) => {
|
|
579
|
+
assert.equal(err2, refreshError);
|
|
580
|
+
assert.equal(err2.statusCode, 403);
|
|
581
|
+
assert.equal(err2.catalogAuthStatus, 401);
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
|
|
494
585
|
it('does not refresh if shouldRefreshAccessToken was false', () => {
|
|
495
586
|
webex.config.credentials.refreshCallback = sinon.stub().returns(
|
|
496
587
|
Promise.resolve({
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import chai from 'chai';
|
|
6
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
7
|
+
import sinon from 'sinon';
|
|
8
|
+
import {CatalogUrlInterceptor} from '@webex/webex-core';
|
|
9
|
+
|
|
10
|
+
const {assert} = chai;
|
|
11
|
+
|
|
12
|
+
chai.use(chaiAsPromised);
|
|
13
|
+
sinon.assert.expose(chai.assert, {prefix: ''});
|
|
14
|
+
|
|
15
|
+
describe('webex-core', () => {
|
|
16
|
+
describe('Interceptors', () => {
|
|
17
|
+
describe('CatalogUrlInterceptor', () => {
|
|
18
|
+
let interceptor;
|
|
19
|
+
let webex;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
webex = {
|
|
23
|
+
config: {
|
|
24
|
+
services: {},
|
|
25
|
+
},
|
|
26
|
+
internal: {
|
|
27
|
+
services: {
|
|
28
|
+
getServiceFromUrl: sinon.stub(),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
logger: {
|
|
32
|
+
warn: sinon.stub(),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
interceptor = Reflect.apply(CatalogUrlInterceptor.create, webex, []);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('#onRequest()', () => {
|
|
40
|
+
it('allows catalog URLs', async () => {
|
|
41
|
+
const options = {uri: 'https://conv-a.wbx2.com/conversation/api/v1/messages'};
|
|
42
|
+
webex.internal.services.getServiceFromUrl.returns({name: 'conversation'});
|
|
43
|
+
|
|
44
|
+
const result = await interceptor.onRequest(options);
|
|
45
|
+
|
|
46
|
+
assert.deepEqual(result, options);
|
|
47
|
+
assert.calledOnceWithExactly(webex.internal.services.getServiceFromUrl, options.uri);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('blocks non-catalog URLs with error', async () => {
|
|
51
|
+
const options = {uri: 'https://evil.attacker.com/steal-data'};
|
|
52
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
53
|
+
|
|
54
|
+
await assert.isRejected(
|
|
55
|
+
interceptor.onRequest(options),
|
|
56
|
+
/Request blocked: URL not in service catalog/
|
|
57
|
+
);
|
|
58
|
+
assert.calledOnce(webex.internal.services.getServiceFromUrl);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('service parameter bypass', () => {
|
|
62
|
+
it('skips validation when service has not been resolved to a URL', async () => {
|
|
63
|
+
const options = {
|
|
64
|
+
service: 'conversation',
|
|
65
|
+
resource: '/messages',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const result = await interceptor.onRequest(options);
|
|
69
|
+
|
|
70
|
+
assert.deepEqual(result, options);
|
|
71
|
+
assert.notCalled(webex.internal.services.getServiceFromUrl);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('blocks a non-catalog URL when service is also present', async () => {
|
|
75
|
+
const options = {
|
|
76
|
+
service: 'conversation',
|
|
77
|
+
resource: '/messages',
|
|
78
|
+
uri: 'https://attacker.com/steal',
|
|
79
|
+
headers: {authorization: 'Bearer token'},
|
|
80
|
+
};
|
|
81
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
82
|
+
|
|
83
|
+
await assert.isRejected(interceptor.onRequest(options), /Request blocked/);
|
|
84
|
+
assert.calledOnceWithExactly(webex.internal.services.getServiceFromUrl, options.uri);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('url parameter support', () => {
|
|
89
|
+
it('validates options.url when options.uri is not present', async () => {
|
|
90
|
+
const options = {url: 'https://conv-a.wbx2.com/conversation/api/v1/messages'};
|
|
91
|
+
webex.internal.services.getServiceFromUrl.returns({name: 'conversation'});
|
|
92
|
+
|
|
93
|
+
const result = await interceptor.onRequest(options);
|
|
94
|
+
|
|
95
|
+
assert.deepEqual(result, options);
|
|
96
|
+
assert.calledOnceWithExactly(webex.internal.services.getServiceFromUrl, options.url);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('edge cases', () => {
|
|
101
|
+
it('allows request when no URL is present', async () => {
|
|
102
|
+
const options = {method: 'GET'};
|
|
103
|
+
|
|
104
|
+
const result = await interceptor.onRequest(options);
|
|
105
|
+
|
|
106
|
+
assert.deepEqual(result, options);
|
|
107
|
+
assert.notCalled(webex.internal.services.getServiceFromUrl);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('handles missing services plugin gracefully', async () => {
|
|
111
|
+
webex.internal = undefined;
|
|
112
|
+
const options = {uri: 'https://example.com/api'};
|
|
113
|
+
|
|
114
|
+
const result = await interceptor.onRequest(options);
|
|
115
|
+
|
|
116
|
+
assert.deepEqual(result, options);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('security scenarios', () => {
|
|
121
|
+
it('blocks Mercury-injected malicious URLs', async () => {
|
|
122
|
+
// This is the SSRF attack vector: Mercury event contains attacker URL
|
|
123
|
+
// that the flag plugin would POST to without validation
|
|
124
|
+
const options = {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
uri: 'https://attacker-controlled.com/exfiltrate',
|
|
127
|
+
body: {sensitiveData: 'secrets'},
|
|
128
|
+
};
|
|
129
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
130
|
+
|
|
131
|
+
await assert.isRejected(interceptor.onRequest(options), /Request blocked/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('allows legitimate activity service URLs', async () => {
|
|
135
|
+
const options = {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
uri: 'https://conv-a.wbx2.com/conversation/api/v1/activities/12345',
|
|
138
|
+
body: {verb: 'flag'},
|
|
139
|
+
};
|
|
140
|
+
webex.internal.services.getServiceFromUrl.returns({name: 'conversation'});
|
|
141
|
+
|
|
142
|
+
const result = await interceptor.onRequest(options);
|
|
143
|
+
|
|
144
|
+
assert.deepEqual(result, options);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('blocks URLs with similar-looking hostnames', async () => {
|
|
148
|
+
// Attacker might try to use a URL that looks similar to a catalog URL
|
|
149
|
+
const options = {
|
|
150
|
+
uri: 'https://conv-a.wbx2.com.attacker.com/api',
|
|
151
|
+
};
|
|
152
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
153
|
+
|
|
154
|
+
await assert.isRejected(interceptor.onRequest(options), /Request blocked/);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('allowedDomains support', () => {
|
|
159
|
+
beforeEach(() => {
|
|
160
|
+
// Add allowedDomains methods to mock
|
|
161
|
+
webex.internal.services.validateDomains = true;
|
|
162
|
+
webex.internal.services.hasAllowedDomains = sinon.stub();
|
|
163
|
+
webex.internal.services.isAllowedDomainUrl = sinon.stub();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('allows URLs in allowedDomains when not in catalog', async () => {
|
|
167
|
+
const options = {uri: 'https://cdn.example.com/files/encrypted-attachment.bin'};
|
|
168
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
169
|
+
webex.internal.services.hasAllowedDomains.returns(true);
|
|
170
|
+
webex.internal.services.isAllowedDomainUrl.returns(true);
|
|
171
|
+
|
|
172
|
+
const result = await interceptor.onRequest(options);
|
|
173
|
+
|
|
174
|
+
assert.deepEqual(result, options);
|
|
175
|
+
assert.calledOnceWithExactly(webex.internal.services.isAllowedDomainUrl, options.uri);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('blocks URLs not in catalog and not in allowedDomains', async () => {
|
|
179
|
+
const options = {uri: 'https://attacker.com/steal'};
|
|
180
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
181
|
+
webex.internal.services.hasAllowedDomains.returns(true);
|
|
182
|
+
webex.internal.services.isAllowedDomainUrl.returns(false);
|
|
183
|
+
|
|
184
|
+
await assert.isRejected(
|
|
185
|
+
interceptor.onRequest(options),
|
|
186
|
+
/Request blocked: URL not in service catalog or allowed domains/
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('blocks when validateDomains is false', async () => {
|
|
191
|
+
const options = {uri: 'https://cdn.example.com/files/attachment.bin'};
|
|
192
|
+
webex.internal.services.validateDomains = false;
|
|
193
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
194
|
+
webex.internal.services.hasAllowedDomains.returns(true);
|
|
195
|
+
webex.internal.services.isAllowedDomainUrl.returns(true);
|
|
196
|
+
|
|
197
|
+
await assert.isRejected(interceptor.onRequest(options), /Request blocked/);
|
|
198
|
+
assert.notCalled(webex.internal.services.isAllowedDomainUrl);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('blocks when no allowedDomains configured', async () => {
|
|
202
|
+
const options = {uri: 'https://cdn.example.com/files/attachment.bin'};
|
|
203
|
+
webex.internal.services.getServiceFromUrl.returns(undefined);
|
|
204
|
+
webex.internal.services.hasAllowedDomains.returns(false);
|
|
205
|
+
|
|
206
|
+
await assert.isRejected(interceptor.onRequest(options), /Request blocked/);
|
|
207
|
+
assert.notCalled(webex.internal.services.isAllowedDomainUrl);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('skips allowedDomains check when URL is in catalog', async () => {
|
|
211
|
+
const options = {uri: 'https://conv-a.wbx2.com/conversation/api/v1/messages'};
|
|
212
|
+
webex.internal.services.getServiceFromUrl.returns({name: 'conversation'});
|
|
213
|
+
|
|
214
|
+
const result = await interceptor.onRequest(options);
|
|
215
|
+
|
|
216
|
+
assert.deepEqual(result, options);
|
|
217
|
+
assert.notCalled(webex.internal.services.hasAllowedDomains);
|
|
218
|
+
assert.notCalled(webex.internal.services.isAllowedDomainUrl);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|