@webex/webex-core 3.12.0-next.9 → 3.12.0-task-refactor.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -764,7 +764,6 @@ describe('webex-core', () => {
764
764
  );
765
765
  });
766
766
  });
767
-
768
767
  describe('#isValidHost', () => {
769
768
  beforeEach(() => {
770
769
  // Setting up a mock services list
@@ -814,253 +813,5 @@ describe('webex-core', () => {
814
813
  assert.isFalse(services.isValidHost([]));
815
814
  });
816
815
  });
817
-
818
- describe('#isIntegrationEnvironment', () => {
819
- it('returns true when u2c URL contains "intb"', () => {
820
- services.webex.config = {
821
- services: {
822
- discovery: {
823
- u2c: 'https://u2c-intb.ciscospark.com/u2c/api/v1',
824
- },
825
- },
826
- };
827
- assert.isTrue(services.isIntegrationEnvironment());
828
- });
829
-
830
- it('returns false when u2c URL does not contain "intb" (production)', () => {
831
- services.webex.config = {
832
- services: {
833
- discovery: {
834
- u2c: 'https://u2c.wbx2.com/u2c/api/v1',
835
- },
836
- },
837
- };
838
- assert.isFalse(services.isIntegrationEnvironment());
839
- });
840
-
841
- it('returns false when u2c URL is for FedRAMP', () => {
842
- services.webex.config = {
843
- services: {
844
- discovery: {
845
- u2c: 'https://u2c.gov.ciscospark.com/u2c/api/v1',
846
- },
847
- },
848
- };
849
- assert.isFalse(services.isIntegrationEnvironment());
850
- });
851
-
852
- it('returns false when u2c URL is undefined', () => {
853
- services.webex.config = {
854
- services: {
855
- discovery: {
856
- u2c: undefined,
857
- },
858
- },
859
- };
860
- assert.isFalse(services.isIntegrationEnvironment());
861
- });
862
-
863
- it('returns false when config is not available', () => {
864
- services.webex.config = undefined;
865
- assert.isFalse(services.isIntegrationEnvironment());
866
- });
867
- });
868
-
869
- describe('U2C catalog cache behavior (v2)', () => {
870
- const CATALOG_CACHE_KEY_V2 = 'services.v2.u2cHostMap';
871
- let windowBackup;
872
- let localStorageBackup;
873
-
874
- const makeLocalStorageShim = () => {
875
- const store = new Map<string, string>();
876
- return {
877
- getItem: (k: string) => (store.has(k) ? store.get(k) : null),
878
- setItem: (k: string, v: string) => store.set(k, v),
879
- removeItem: (k: string) => store.delete(k),
880
- _store: store,
881
- };
882
- };
883
-
884
- beforeEach(() => {
885
- // Stub window.localStorage
886
- windowBackup = global.window;
887
- if (!global.window) global.window = {} as Window & typeof globalThis;
888
- localStorageBackup = global.window.localStorage;
889
- global.window.localStorage = makeLocalStorageShim();
890
- // Enable U2C caching feature flag for tests that depend on cache writes/reads
891
- services.webex.config = services.webex.config || {};
892
- services.webex.config.calling = {...(services.webex.config.calling || {}), cacheU2C: true};
893
- // Ensure code under test uses our shim via util method
894
- sinon.stub(services, '_getLocalStorageSafe').returns(global.window.localStorage);
895
- // default current env
896
- services.webex.config = services.webex.config || {};
897
- services.webex.config.services = services.webex.config.services || {discovery: {}};
898
- services.webex.config.services.discovery.u2c =
899
- services.webex.config.services.discovery.u2c || 'https://u2c.wbx2.com/u2c/api/v1';
900
- services.webex.config.fedramp =
901
- typeof services.webex.config.fedramp === 'boolean'
902
- ? services.webex.config.fedramp
903
- : false;
904
- });
905
-
906
- afterEach(() => {
907
- global.window.localStorage = localStorageBackup || undefined;
908
- if (!windowBackup) {
909
- delete global.window;
910
- } else {
911
- global.window = windowBackup;
912
- }
913
- // Restore util stub if present
914
- if (services._getLocalStorageSafe && services._getLocalStorageSafe.restore) {
915
- services._getLocalStorageSafe.restore();
916
- }
917
- });
918
-
919
- it('stores selection metadata and env on cache write for preauth', async () => {
920
- // Arrange env
921
- services.webex.config.services.discovery.u2c = 'https://u2c.wbx2.com/u2c/api/v1';
922
- services.webex.config.fedramp = false;
923
-
924
- // Act
925
- await services._cacheCatalog(
926
- 'preauth',
927
- {services: [], timestamp: Date.now().toString()},
928
- {selectionType: 'orgId', selectionValue: 'urn:EXAMPLE:org'}
929
- );
930
-
931
- // Assert
932
- const raw = window.localStorage.getItem(CATALOG_CACHE_KEY_V2);
933
- assert.isString(raw);
934
- const parsed = JSON.parse(raw as string);
935
- assert.deepEqual(parsed.env, {
936
- fedramp: false,
937
- u2cDiscoveryUrl: 'https://u2c.wbx2.com/u2c/api/v1',
938
- });
939
- assert.isObject(parsed.preauth);
940
- assert.deepEqual(parsed.preauth.meta, {
941
- selectionType: 'orgId',
942
- selectionValue: 'urn:EXAMPLE:org',
943
- });
944
- });
945
-
946
- it('warms preauth from cache when selection meta matches intended orgId', async () => {
947
- // Arrange current env and credentials
948
- services.webex.config.services.discovery.u2c = 'https://u2c.wbx2.com/u2c/api/v1';
949
- services.webex.config.fedramp = false;
950
- services.webex.credentials = {
951
- canAuthorize: true,
952
- getOrgId: sinon.stub().returns('urn:EXAMPLE:org'),
953
- };
954
- // Seed cache
955
- window.localStorage.setItem(
956
- CATALOG_CACHE_KEY_V2,
957
- JSON.stringify({
958
- cachedAt: Date.now(),
959
- env: {fedramp: false, u2cDiscoveryUrl: 'https://u2c.wbx2.com/u2c/api/v1'},
960
- preauth: {
961
- hostMap: {services: [], timestamp: '1'},
962
- meta: {selectionType: 'orgId', selectionValue: 'urn:EXAMPLE:org'},
963
- },
964
- })
965
- );
966
- // Spy updateServiceGroups
967
- const spy = sinon.spy(services._getCatalog(), 'updateServiceGroups');
968
-
969
- // Act
970
- const warmed = await services._loadCatalogFromCache();
971
-
972
- // Assert
973
- assert.isTrue(warmed);
974
- assert.isTrue(
975
- spy.calledWith('preauth', [], '1'),
976
- 'expected preauth to be warmed when selection matches'
977
- );
978
- spy.restore && spy.restore();
979
- });
980
-
981
- it('does not warm preauth when selection meta is proximity mode', async () => {
982
- // Arrange env
983
- services.webex.config.services.discovery.u2c = 'https://u2c.wbx2.com/u2c/api/v1';
984
- services.webex.config.fedramp = false;
985
- window.localStorage.setItem(
986
- CATALOG_CACHE_KEY_V2,
987
- JSON.stringify({
988
- cachedAt: Date.now(),
989
- env: {fedramp: false, u2cDiscoveryUrl: 'https://u2c.wbx2.com/u2c/api/v1'},
990
- preauth: {
991
- hostMap: {services: [], timestamp: '1'},
992
- meta: {selectionType: 'mode', selectionValue: 'DEFAULT_BY_PROXIMITY'},
993
- },
994
- })
995
- );
996
- const spy = sinon.spy(services._getCatalog(), 'updateServiceGroups');
997
-
998
- // Act
999
- const warmed = await services._loadCatalogFromCache();
1000
-
1001
- // Assert: overall warm-up succeeds, but preauth is skipped
1002
- assert.isTrue(warmed);
1003
- assert.isFalse(
1004
- spy.calledWith('preauth', sinon.match.any, sinon.match.any),
1005
- 'expected preauth not to be warmed for proximity mode'
1006
- );
1007
- spy.restore && spy.restore();
1008
- });
1009
-
1010
- it('does not warm preauth when selection meta mismatches intended selection', async () => {
1011
- // Arrange env and credentials
1012
- services.webex.config.services.discovery.u2c = 'https://u2c.wbx2.com/u2c/api/v1';
1013
- services.webex.config.fedramp = false;
1014
- services.webex.credentials = {
1015
- canAuthorize: true,
1016
- getOrgId: sinon.stub().returns('urn:EXAMPLE:org'),
1017
- };
1018
- window.localStorage.setItem(
1019
- CATALOG_CACHE_KEY_V2,
1020
- JSON.stringify({
1021
- cachedAt: Date.now(),
1022
- env: {fedramp: false, u2cDiscoveryUrl: 'https://u2c.wbx2.com/u2c/api/v1'},
1023
- preauth: {
1024
- hostMap: {services: [], timestamp: '1'},
1025
- meta: {selectionType: 'orgId', selectionValue: 'urn:DIFF:org'},
1026
- },
1027
- })
1028
- );
1029
- const spy = sinon.spy(services._getCatalog(), 'updateServiceGroups');
1030
-
1031
- const warmed = await services._loadCatalogFromCache();
1032
-
1033
- assert.isTrue(warmed);
1034
- assert.isFalse(
1035
- spy.calledWith('preauth', sinon.match.any, sinon.match.any),
1036
- 'expected preauth not to be warmed on selection mismatch'
1037
- );
1038
- spy.restore && spy.restore();
1039
- });
1040
-
1041
- it('skips warm entirely when environment fingerprint mismatches', async () => {
1042
- // Cached env differs from current env
1043
- services.webex.config.services.discovery.u2c = 'https://u2c.current.com/u2c/api/v1';
1044
- services.webex.config.fedramp = false;
1045
- window.localStorage.setItem(
1046
- CATALOG_CACHE_KEY_V2,
1047
- JSON.stringify({
1048
- cachedAt: Date.now(),
1049
- env: {fedramp: false, u2cDiscoveryUrl: 'https://u2c.cached.com/u2c/api/v1'},
1050
- preauth: {
1051
- hostMap: {services: [], timestamp: '1'},
1052
- meta: {selectionType: 'orgId', selectionValue: 'urn:EXAMPLE:org'},
1053
- },
1054
- })
1055
- );
1056
- const spy = sinon.spy(services._getCatalog(), 'updateServiceGroups');
1057
-
1058
- const warmed = await services._loadCatalogFromCache();
1059
-
1060
- assert.isFalse(warmed, 'env mismatch should skip warm and return false');
1061
- assert.isFalse(spy.called, 'no group should be warmed on env mismatch');
1062
- spy.restore && spy.restore();
1063
- });
1064
- });
1065
816
  });
1066
817
  });