@webex/webex-core 3.12.0-webex-services-ready.4 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.repo-context.json +653 -0
  2. package/.sdd/manifest.json +605 -0
  3. package/AGENTS.md +209 -0
  4. package/dist/config.js +30 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/index.js +14 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/interceptors/catalog-url.js +87 -0
  9. package/dist/interceptors/catalog-url.js.map +1 -0
  10. package/dist/interceptors/payload-transformer.js +25 -4
  11. package/dist/interceptors/payload-transformer.js.map +1 -1
  12. package/dist/lib/batcher.js +1 -1
  13. package/dist/lib/credentials/credentials.js +56 -1
  14. package/dist/lib/credentials/credentials.js.map +1 -1
  15. package/dist/lib/credentials/token.js +1 -1
  16. package/dist/lib/services/service-catalog.js +102 -8
  17. package/dist/lib/services/service-catalog.js.map +1 -1
  18. package/dist/lib/services/services.js +84 -48
  19. package/dist/lib/services/services.js.map +1 -1
  20. package/dist/lib/services-v2/service-catalog.js +8 -1
  21. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  22. package/dist/lib/services-v2/services-v2.js +90 -50
  23. package/dist/lib/services-v2/services-v2.js.map +1 -1
  24. package/dist/lib/static-asset-loader.js +153 -0
  25. package/dist/lib/static-asset-loader.js.map +1 -0
  26. package/dist/plugins/logger.js +1 -1
  27. package/dist/webex-core.js +11 -3
  28. package/dist/webex-core.js.map +1 -1
  29. package/docs/adr/index.md +32 -0
  30. package/docs/architecture.md +298 -0
  31. package/docs/getting-started.md +96 -0
  32. package/docs/index.md +55 -0
  33. package/docs/specs/README.md +76 -0
  34. package/package.json +13 -13
  35. package/schemas/repo-context.schema.json +796 -0
  36. package/src/config.js +32 -0
  37. package/src/docs/README.md +732 -0
  38. package/src/index.js +2 -0
  39. package/src/interceptors/catalog-url.js +66 -0
  40. package/src/interceptors/docs/README.md +658 -0
  41. package/src/interceptors/payload-transformer.js +23 -1
  42. package/src/lib/credentials/credentials.js +43 -0
  43. package/src/lib/credentials/docs/README.md +846 -0
  44. package/src/lib/services/docs/README.md +737 -0
  45. package/src/lib/services/service-catalog.js +106 -6
  46. package/src/lib/services/services.js +77 -32
  47. package/src/lib/services-v2/docs/README.md +751 -0
  48. package/src/lib/services-v2/service-catalog.ts +10 -1
  49. package/src/lib/services-v2/services-v2.ts +86 -33
  50. package/src/lib/static-asset-loader.ts +128 -0
  51. package/src/lib/storage/docs/README.md +646 -0
  52. package/src/webex-core.js +8 -0
  53. package/test/integration/spec/services/services.js +148 -113
  54. package/test/integration/spec/services-v2/services-v2.js +134 -99
  55. package/test/unit/spec/credentials/credentials.js +114 -1
  56. package/test/unit/spec/interceptors/catalog-url.js +224 -0
  57. package/test/unit/spec/interceptors/payload-transformer.js +119 -1
  58. package/test/unit/spec/services/service-catalog.js +275 -0
  59. package/test/unit/spec/services/services.js +161 -2
  60. package/test/unit/spec/services-v2/service-catalog.ts +41 -0
  61. package/test/unit/spec/services-v2/services-v2.ts +279 -2
  62. package/test/unit/spec/static-asset-loader.ts +224 -0
  63. package/test/unit/spec/webex-core.js +77 -1
@@ -5,7 +5,7 @@
5
5
  import '@webex/internal-plugin-device';
6
6
 
7
7
  import {assert} from '@webex/test-helper-chai';
8
- import {flaky} from '@webex/test-helper-mocha';
8
+ import {flaky, retryOn429} from '@webex/test-helper-mocha';
9
9
  import WebexCore, {
10
10
  ServiceCatalogV2,
11
11
  ServiceDetail,
@@ -354,7 +354,10 @@ describe('webex-core', () => {
354
354
  // Before init settles, webex.ready must be false because services.ready
355
355
  // is a dependency and starts false in the gated path.
356
356
  assert.isFalse(gatedWebex.internal.services.ready, 'services.ready should start false');
357
- assert.isFalse(gatedWebex.ready, 'webex.ready should not fire while services.ready is false');
357
+ assert.isFalse(
358
+ gatedWebex.ready,
359
+ 'webex.ready should not fire while services.ready is false'
360
+ );
358
361
 
359
362
  // Wait up to 30s for services init to complete and flip ready.
360
363
  await new Promise((resolve, reject) => {
@@ -374,7 +377,10 @@ describe('webex-core', () => {
374
377
  });
375
378
  });
376
379
 
377
- assert.isTrue(gatedWebex.internal.services.ready, 'services.ready should flip true after init settles');
380
+ assert.isTrue(
381
+ gatedWebex.internal.services.ready,
382
+ 'services.ready should flip true after init settles'
383
+ );
378
384
  assert.isTrue(gatedWebex.ready, 'webex.ready should fire once services.ready flips');
379
385
  });
380
386
  });
@@ -826,18 +832,22 @@ describe('webex-core', () => {
826
832
  }));
827
833
 
828
834
  it('validates an authorized user and webex instance', () =>
829
- services.validateUser({email: webexUser.email}).then((r) => {
830
- assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
831
- assert.equal(r.activated, true);
832
- assert.equal(r.exists, true);
833
- }));
835
+ retryOn429(() =>
836
+ services.validateUser({email: webexUser.email}).then((r) => {
837
+ assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
838
+ assert.equal(r.activated, true);
839
+ assert.equal(r.exists, true);
840
+ })
841
+ ));
834
842
 
835
843
  it('validates an authorized EU user and webex instance', () =>
836
- servicesEU.validateUser({email: webexUserEU.email}).then((r) => {
837
- assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
838
- assert.equal(r.activated, true);
839
- assert.equal(r.exists, true);
840
- }));
844
+ retryOn429(() =>
845
+ servicesEU.validateUser({email: webexUserEU.email}).then((r) => {
846
+ assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
847
+ assert.equal(r.activated, true);
848
+ assert.equal(r.exists, true);
849
+ })
850
+ ));
841
851
 
842
852
  it("returns a rejected promise if the provided email isn't valid", () =>
843
853
  unauthServices
@@ -850,113 +860,134 @@ describe('webex-core', () => {
850
860
  }));
851
861
 
852
862
  it('validates a non-existing user', () =>
853
- unauthServices
854
- .validateUser({email: createActivationEmail()})
855
- .then((r) => {
863
+ retryOn429(() =>
864
+ unauthServices.validateUser({email: createActivationEmail()}).then((r) => {
856
865
  assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
857
866
  assert.equal(r.activated, false);
858
867
  assert.equal(r.exists, false);
859
- }));
868
+ })
869
+ ));
860
870
 
861
871
  it('validates new user with activationOptions suppressEmail false', () =>
862
- unauthServices
863
- .validateUser({
864
- email: createActivationEmail(),
865
- activationOptions: {suppressEmail: false},
866
- })
867
- .then((r) => {
868
- assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
869
- assert.equal(r.activated, false);
870
- assert.equal(r.exists, false);
871
- assert.equal(r.user.verificationEmailTriggered, true);
872
- }));
872
+ retryOn429(() =>
873
+ unauthServices
874
+ .validateUser({
875
+ email: createActivationEmail(),
876
+ activationOptions: {suppressEmail: false},
877
+ })
878
+ .then((r) => {
879
+ assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
880
+ assert.equal(r.activated, false);
881
+ assert.equal(r.exists, false);
882
+ assert.equal(r.user.verificationEmailTriggered, true);
883
+ })
884
+ ));
873
885
 
874
886
  it('validates new user with activationOptions suppressEmail true', () =>
875
- unauthServices
876
- .validateUser({
877
- email: createActivationEmail(),
878
- activationOptions: {suppressEmail: true},
879
- })
880
- .then((r) => {
881
- assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
882
- assert.equal(r.activated, false);
883
- assert.equal(r.exists, false);
884
- assert.equal(r.user.verificationEmailTriggered, false);
885
- }));
887
+ retryOn429(() =>
888
+ unauthServices
889
+ .validateUser({
890
+ email: createActivationEmail(),
891
+ activationOptions: {suppressEmail: true},
892
+ })
893
+ .then((r) => {
894
+ assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
895
+ assert.equal(r.activated, false);
896
+ assert.equal(r.exists, false);
897
+ assert.equal(r.user.verificationEmailTriggered, false);
898
+ })
899
+ ));
886
900
 
887
901
  it('validates an inactive user', () => {
888
902
  const inactive = 'webex.web.client+nonactivated@gmail.com';
889
903
 
890
- return unauthServices
891
- .validateUser({email: inactive, activationOptions: {suppressEmail: true}})
892
- .then((r) => {
893
- assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
894
- assert.equal(r.activated, false, 'activated');
895
- assert.equal(r.exists, true, 'exists');
896
- })
897
- .catch(() => {
898
- assert(true);
899
- });
904
+ return retryOn429(() =>
905
+ unauthServices
906
+ .validateUser({email: inactive, activationOptions: {suppressEmail: true}})
907
+ .then((r) => {
908
+ assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
909
+ assert.equal(r.activated, false, 'activated');
910
+ assert.equal(r.exists, true, 'exists');
911
+ })
912
+ ).catch(() => {
913
+ assert(true);
914
+ });
900
915
  });
901
916
 
902
917
  it('validates an existing user', () =>
903
- unauthServices.validateUser({email: webexUser.email}).then((r) => {
904
- assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
905
- assert.equal(r.activated, true);
906
- assert.equal(r.exists, true);
907
- }));
918
+ retryOn429(() =>
919
+ unauthServices.validateUser({email: webexUser.email}).then((r) => {
920
+ assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
921
+ assert.equal(r.activated, true);
922
+ assert.equal(r.exists, true);
923
+ })
924
+ ));
908
925
 
909
926
  it('validates an existing EU user', () =>
910
- unauthServices.validateUser({email: webexUserEU.email}).then((r) => {
911
- assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
912
- assert.equal(r.activated, true);
913
- assert.equal(r.exists, true);
914
- }));
927
+ retryOn429(() =>
928
+ unauthServices.validateUser({email: webexUserEU.email}).then((r) => {
929
+ assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']);
930
+ assert.equal(r.activated, true);
931
+ assert.equal(r.exists, true);
932
+ })
933
+ ));
915
934
 
916
935
  it('sends the prelogin user id as undefined when not specified', () => {
917
936
  const requestStub = sandbox.spy(unauthServices, 'request');
918
937
 
919
- return unauthServices
920
- .validateUser({
921
- email: createActivationEmail(),
922
- activationOptions: {suppressEmail: true},
923
- })
924
- .then(() => {
925
- assert.isUndefined(getActivationRequest(requestStub).headers['x-prelogin-userid']);
926
- });
938
+ return retryOn429(() => {
939
+ requestStub.resetHistory();
940
+
941
+ return unauthServices
942
+ .validateUser({
943
+ email: createActivationEmail(),
944
+ activationOptions: {suppressEmail: true},
945
+ })
946
+ .then(() => {
947
+ assert.isUndefined(getActivationRequest(requestStub).headers['x-prelogin-userid']);
948
+ });
949
+ });
927
950
  });
928
951
 
929
952
  it('sends the prelogin user id as provided when specified', () => {
930
953
  const requestStub = sandbox.spy(unauthServices, 'request');
931
954
  const preloginUserId = uuid.v4();
932
955
 
933
- return unauthServices
934
- .validateUser({
935
- email: createActivationEmail(),
936
- activationOptions: {suppressEmail: true},
937
- preloginUserId,
938
- })
939
- .then(() => {
940
- assert.strictEqual(
941
- getActivationRequest(requestStub).headers['x-prelogin-userid'],
942
- preloginUserId
943
- );
944
- });
956
+ return retryOn429(() => {
957
+ requestStub.resetHistory();
958
+
959
+ return unauthServices
960
+ .validateUser({
961
+ email: createActivationEmail(),
962
+ activationOptions: {suppressEmail: true},
963
+ preloginUserId,
964
+ })
965
+ .then(() => {
966
+ assert.strictEqual(
967
+ getActivationRequest(requestStub).headers['x-prelogin-userid'],
968
+ preloginUserId
969
+ );
970
+ });
971
+ });
945
972
  });
946
973
 
947
974
  it('uses the license service by default', () => {
948
975
  const requestStub = sandbox.spy(unauthServices, 'request');
949
976
 
950
- return unauthServices
951
- .validateUser({
952
- email: createActivationEmail(),
953
- activationOptions: {suppressEmail: true},
954
- })
955
- .then(() => {
956
- const request = getActivationRequest(requestStub, false);
957
- assert.strictEqual(request.service, 'license');
958
- assert.strictEqual(request.resource, 'users/activations');
959
- });
977
+ return retryOn429(() => {
978
+ requestStub.resetHistory();
979
+
980
+ return unauthServices
981
+ .validateUser({
982
+ email: createActivationEmail(),
983
+ activationOptions: {suppressEmail: true},
984
+ })
985
+ .then(() => {
986
+ const request = getActivationRequest(requestStub, false);
987
+ assert.strictEqual(request.service, 'license');
988
+ assert.strictEqual(request.resource, 'users/activations');
989
+ });
990
+ });
960
991
  });
961
992
 
962
993
  it('uses the user-onboarding service when useUserOnboardingServiceForActivations config is true', () => {
@@ -970,16 +1001,20 @@ describe('webex-core', () => {
970
1001
  const userOnboardingServices = userOnboardingWebex.internal.services;
971
1002
  const requestStub = sandbox.spy(userOnboardingServices, 'request');
972
1003
 
973
- return userOnboardingServices
974
- .validateUser({
975
- email: createActivationEmail(),
976
- activationOptions: {suppressEmail: true},
977
- })
978
- .then(() => {
979
- const request = getActivationRequest(requestStub, true);
980
- assert.strictEqual(request.service, 'user-onboarding');
981
- assert.strictEqual(request.resource, 'api/v1/users/activations');
982
- });
1004
+ return retryOn429(() => {
1005
+ requestStub.resetHistory();
1006
+
1007
+ return userOnboardingServices
1008
+ .validateUser({
1009
+ email: createActivationEmail(),
1010
+ activationOptions: {suppressEmail: true},
1011
+ })
1012
+ .then(() => {
1013
+ const request = getActivationRequest(requestStub, true);
1014
+ assert.strictEqual(request.service, 'user-onboarding');
1015
+ assert.strictEqual(request.resource, 'api/v1/users/activations');
1016
+ });
1017
+ });
983
1018
  });
984
1019
  });
985
1020
 
@@ -7,7 +7,7 @@ import {assert} from '@webex/test-helper-chai';
7
7
  import sinon from 'sinon';
8
8
  import MockWebex from '@webex/test-helper-mock-webex';
9
9
  import {Credentials, Token, grantErrors} from '@webex/webex-core';
10
- import {inBrowser} from '@webex/common';
10
+ import {inBrowser, base64} from '@webex/common';
11
11
  import FakeTimers from '@sinonjs/fake-timers';
12
12
  import {skipInBrowser} from '@webex/test-helper-mocha';
13
13
  import Logger from '@webex/plugin-logger';
@@ -506,6 +506,88 @@ describe('webex-core', () => {
506
506
  expect(() => credentials.extractOrgIdFromUserToken()).toThrow());
507
507
  });
508
508
 
509
+ describe('#extractUserIdFromToken()', () => {
510
+ let credentials;
511
+ let webex;
512
+
513
+ beforeEach(() => {
514
+ webex = new MockWebex();
515
+ credentials = new Credentials(undefined, {parent: webex});
516
+ });
517
+
518
+ const buildToken = (payload) =>
519
+ `header.${base64.toBase64Url(JSON.stringify(payload))}.signature`;
520
+
521
+ it('should return the cis_uuid from the provided token', () => {
522
+ const token = buildToken({cis_uuid: 'my-user-id'});
523
+
524
+ assert.equal(credentials.extractUserIdFromToken(token), 'my-user-id');
525
+ });
526
+
527
+ it('should throw if the token does not contain a cis_uuid', () => {
528
+ const token = buildToken({foo: 'bar'});
529
+
530
+ expect(() => credentials.extractUserIdFromToken(token)).toThrow(
531
+ 'the provided token does not contain a user ID'
532
+ );
533
+ });
534
+
535
+ it('should throw when provided an unparseable token', () =>
536
+ expect(() => credentials.extractUserIdFromToken('not-a-valid-token')).toThrow());
537
+
538
+ it('should throw when no token is provided', () =>
539
+ expect(() => credentials.extractUserIdFromToken()).toThrow());
540
+ });
541
+
542
+ describe('#getUserId()', () => {
543
+ let credentials;
544
+ let webex;
545
+
546
+ const buildToken = (userId) =>
547
+ `header.${base64.toBase64Url(JSON.stringify({cis_uuid: userId}))}.signature`;
548
+
549
+ beforeEach(() => {
550
+ webex = new MockWebex();
551
+ credentials = new Credentials(undefined, {parent: webex});
552
+ });
553
+
554
+ it('should return the userId from the supertoken', () => {
555
+ credentials.supertoken = makeToken(webex, {
556
+ access_token: buildToken('supertoken-user-id'),
557
+ });
558
+
559
+ assert.equal(credentials.getUserId(), 'supertoken-user-id');
560
+ });
561
+
562
+ it('should fall back to a user token when the supertoken has no userId', () => {
563
+ credentials.supertoken = makeToken(webex, {access_token: 'AT'});
564
+ credentials.userTokens.add(
565
+ makeToken(webex, {access_token: buildToken('user-token-user-id'), scope: 'scope1'})
566
+ );
567
+
568
+ assert.equal(credentials.getUserId(), 'user-token-user-id');
569
+ });
570
+
571
+ it('should prefer the supertoken over the user tokens', () => {
572
+ credentials.supertoken = makeToken(webex, {
573
+ access_token: buildToken('supertoken-user-id'),
574
+ });
575
+ credentials.userTokens.add(
576
+ makeToken(webex, {access_token: buildToken('user-token-user-id'), scope: 'scope1'})
577
+ );
578
+
579
+ assert.equal(credentials.getUserId(), 'supertoken-user-id');
580
+ });
581
+
582
+ it('should throw if no available token contains a userId', () => {
583
+ credentials.supertoken = makeToken(webex, {access_token: 'AT'});
584
+
585
+ expect(() => credentials.getUserId()).toThrow(
586
+ 'could not extract the user ID from any available token'
587
+ );
588
+ });
589
+ });
590
+
509
591
  describe('#initialize()', () => {
510
592
  it('turns a portal auth string into a configuration object', () => {
511
593
  const webex = new MockWebex();
@@ -630,6 +712,37 @@ describe('webex-core', () => {
630
712
  });
631
713
  });
632
714
 
715
+ describe('#getClientToken()', () => {
716
+ it('requests a client token without bypassing catalog URL validation', async () => {
717
+ const webex = new MockWebex();
718
+ const credentials = new Credentials(undefined, {parent: webex});
719
+ const uri = 'https://idbroker.webex.com/idb/oauth2/v1/access_token';
720
+ const scope = 'spark:all';
721
+
722
+ webex.request.resolves({body: {access_token: 'AT', token_type: 'Bearer'}});
723
+
724
+ const token = await credentials.getClientToken({uri, scope});
725
+
726
+ assert.calledOnceWithExactly(webex.request, {
727
+ method: 'POST',
728
+ uri,
729
+ form: {
730
+ grant_type: 'client_credentials',
731
+ scope,
732
+ self_contained_token: true,
733
+ },
734
+ auth: {
735
+ user: 'fake',
736
+ pass: 'fake',
737
+ sendImmediately: true,
738
+ },
739
+ shouldRefreshAccessToken: false,
740
+ });
741
+ assert.instanceOf(token, Token);
742
+ assert.equal(token.access_token, 'AT');
743
+ });
744
+ });
745
+
633
746
  describe('#getUserToken()', () => {
634
747
  it('resolves with the supertoken if the supertoken matches the requested scopes', () => {
635
748
  const webex = new MockWebex();
@@ -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
+ });