@webex/webex-core 2.60.1-next.9 → 2.60.2
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/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +2 -1
- package/dist/credentials-config.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/interceptors/auth.js +3 -4
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/interceptors/default-options.js +3 -4
- package/dist/interceptors/default-options.js.map +1 -1
- package/dist/interceptors/embargo.js +3 -4
- package/dist/interceptors/embargo.js.map +1 -1
- package/dist/interceptors/network-timing.js +3 -4
- package/dist/interceptors/network-timing.js.map +1 -1
- package/dist/interceptors/payload-transformer.js +3 -4
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/interceptors/rate-limit.js +3 -4
- package/dist/interceptors/rate-limit.js.map +1 -1
- package/dist/interceptors/redirect.js +6 -7
- package/dist/interceptors/redirect.js.map +1 -1
- package/dist/interceptors/request-event.js +8 -9
- package/dist/interceptors/request-event.js.map +1 -1
- package/dist/interceptors/request-logger.js +15 -12
- package/dist/interceptors/request-logger.js.map +1 -1
- package/dist/interceptors/request-timing.js +3 -4
- package/dist/interceptors/request-timing.js.map +1 -1
- package/dist/interceptors/response-logger.js +10 -10
- package/dist/interceptors/response-logger.js.map +1 -1
- package/dist/interceptors/user-agent.js +7 -8
- package/dist/interceptors/user-agent.js.map +1 -1
- package/dist/interceptors/webex-tracking-id.js +3 -4
- package/dist/interceptors/webex-tracking-id.js.map +1 -1
- package/dist/interceptors/webex-user-agent.js +8 -9
- package/dist/interceptors/webex-user-agent.js.map +1 -1
- package/dist/lib/batcher.js +5 -8
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +35 -73
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/grant-errors.js +5 -5
- package/dist/lib/credentials/grant-errors.js.map +1 -1
- package/dist/lib/credentials/scope.js +5 -26
- package/dist/lib/credentials/scope.js.map +1 -1
- package/dist/lib/credentials/token-collection.js +2 -1
- package/dist/lib/credentials/token-collection.js.map +1 -1
- package/dist/lib/credentials/token.js +10 -14
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/page.js +2 -1
- package/dist/lib/page.js.map +1 -1
- package/dist/lib/services/constants.js +6 -3
- package/dist/lib/services/constants.js.map +1 -1
- package/dist/lib/services/index.js +2 -2
- package/dist/lib/services/index.js.map +1 -1
- package/dist/lib/services/interceptors/server-error.js +3 -4
- package/dist/lib/services/interceptors/server-error.js.map +1 -1
- package/dist/lib/services/interceptors/service.js +5 -8
- package/dist/lib/services/interceptors/service.js.map +1 -1
- package/dist/lib/services/metrics.js +2 -1
- package/dist/lib/services/metrics.js.map +1 -1
- package/dist/lib/services/service-catalog.js +5 -5
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/service-fed-ramp.js +2 -1
- package/dist/lib/services/service-fed-ramp.js.map +1 -1
- package/dist/lib/services/service-host.js +2 -1
- package/dist/lib/services/service-host.js.map +1 -1
- package/dist/lib/services/service-registry.js +4 -3
- package/dist/lib/services/service-registry.js.map +1 -1
- package/dist/lib/services/service-state.js +2 -1
- package/dist/lib/services/service-state.js.map +1 -1
- package/dist/lib/services/service-url.js +2 -1
- package/dist/lib/services/service-url.js.map +1 -1
- package/dist/lib/services/services.js +9 -7
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/stateless-webex-plugin.js +2 -1
- package/dist/lib/stateless-webex-plugin.js.map +1 -1
- package/dist/lib/storage/decorators.js +16 -18
- package/dist/lib/storage/decorators.js.map +1 -1
- package/dist/lib/storage/errors.js +5 -5
- package/dist/lib/storage/errors.js.map +1 -1
- package/dist/lib/storage/make-webex-plugin-store.js +10 -8
- package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
- package/dist/lib/storage/make-webex-store.js.map +1 -1
- package/dist/lib/storage/memory-store-adapter.js +2 -1
- package/dist/lib/storage/memory-store-adapter.js.map +1 -1
- package/dist/lib/webex-core-plugin-mixin.js +14 -13
- package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-http-error.js +3 -4
- package/dist/lib/webex-http-error.js.map +1 -1
- package/dist/lib/webex-internal-core-plugin-mixin.js +14 -13
- package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-plugin.js +8 -5
- package/dist/lib/webex-plugin.js.map +1 -1
- package/dist/plugins/logger.js +3 -2
- package/dist/plugins/logger.js.map +1 -1
- package/dist/webex-core.js +38 -37
- package/dist/webex-core.js.map +1 -1
- package/dist/webex-internal-core.js +2 -1
- package/dist/webex-internal-core.js.map +1 -1
- package/package.json +20 -21
- package/src/lib/credentials/credentials.js +40 -82
- package/src/lib/credentials/scope.js +5 -24
- package/src/lib/credentials/token.js +1 -9
- package/src/lib/services/interceptors/service.js +2 -2
- package/src/lib/services/service-catalog.js +1 -3
- package/src/lib/services/services.js +0 -1
- package/src/webex-core.js +1 -13
- package/test/unit/spec/credentials/credentials.js +13 -169
- package/test/unit/spec/credentials/token.js +1 -11
- package/test/unit/spec/interceptors/auth.js +0 -3
- package/test/unit/spec/interceptors/webex-user-agent.js +6 -6
- package/test/unit/spec/services/interceptors/service.js +3 -9
- package/test/unit/spec/webex-core.js +0 -12
- package/dist/lib/constants.js +0 -13
- package/dist/lib/constants.js.map +0 -1
- package/src/lib/constants.js +0 -6
- package/test/unit/spec/credentials/scope.js +0 -80
|
@@ -11,7 +11,6 @@ import {inBrowser} 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';
|
|
14
|
-
import Metrics, {config} from '@webex/internal-plugin-metrics';
|
|
15
14
|
|
|
16
15
|
/* eslint camelcase: [0] */
|
|
17
16
|
|
|
@@ -60,35 +59,6 @@ describe('webex-core', () => {
|
|
|
60
59
|
});
|
|
61
60
|
});
|
|
62
61
|
|
|
63
|
-
describe('#isUnverifiedGuest', () => {
|
|
64
|
-
let credentials;
|
|
65
|
-
let webex;
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
//generate the webex instance
|
|
68
|
-
webex = new MockWebex();
|
|
69
|
-
credentials = new Credentials(undefined, {parent: webex});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should have #isUnverifiedGuest', () => {
|
|
73
|
-
assert.exists(credentials.isUnverifiedGuest);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should get the user status and return as a boolean', () => {
|
|
77
|
-
credentials.set('supertoken', 'AT');
|
|
78
|
-
assert.isFalse(credentials.isUnverifiedGuest);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should get guest user ', () => {
|
|
82
|
-
credentials.set('supertoken', 'eyJhbGciOiJSUzI1NiJ9.eyJ1c2VyX3R5cGUiOiJndWVzdCJ9');
|
|
83
|
-
assert.isTrue(credentials.isUnverifiedGuest);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should get login user ', () => {
|
|
87
|
-
credentials.set('supertoken', 'dGhpc2lzbm90YXJlYWx1c2VydG9rZW4=');
|
|
88
|
-
assert.isFalse(credentials.isUnverifiedGuest);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
62
|
describe('#canAuthorize', () => {
|
|
93
63
|
it('indicates if the current state has enough information to populate an auth header, even if a token refresh or token downscope is required', () => {
|
|
94
64
|
const webex = new MockWebex();
|
|
@@ -447,11 +417,7 @@ describe('webex-core', () => {
|
|
|
447
417
|
});
|
|
448
418
|
|
|
449
419
|
it('schedules a refreshTimer', () => {
|
|
450
|
-
const webex = new MockWebex(
|
|
451
|
-
children: {
|
|
452
|
-
metrics: Metrics,
|
|
453
|
-
},
|
|
454
|
-
});
|
|
420
|
+
const webex = new MockWebex();
|
|
455
421
|
const supertoken = makeToken(webex, {
|
|
456
422
|
access_token: 'ST',
|
|
457
423
|
refresh_token: 'RT',
|
|
@@ -464,7 +430,6 @@ describe('webex-core', () => {
|
|
|
464
430
|
});
|
|
465
431
|
|
|
466
432
|
sinon.stub(supertoken, 'refresh').returns(Promise.resolve(supertoken2));
|
|
467
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
468
433
|
const credentials = new Credentials(supertoken, {parent: webex});
|
|
469
434
|
|
|
470
435
|
webex.trigger('change:config');
|
|
@@ -499,19 +464,7 @@ describe('webex-core', () => {
|
|
|
499
464
|
});
|
|
500
465
|
|
|
501
466
|
describe('#getUserToken()', () => {
|
|
502
|
-
it('resolves with the supertoken if the supertoken matches the requested scopes'
|
|
503
|
-
const webex = new MockWebex();
|
|
504
|
-
const credentials = new Credentials(undefined, {parent: webex});
|
|
505
|
-
|
|
506
|
-
webex.trigger('change:config');
|
|
507
|
-
const st = makeToken(webex, {access_token: 'ST', scope: 'scope1'});
|
|
508
|
-
|
|
509
|
-
credentials.set({
|
|
510
|
-
supertoken: st,
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
return credentials.getUserToken('scope1').then((result) => assert.deepEqual(result, st));
|
|
514
|
-
});
|
|
467
|
+
// it('resolves with the supertoken if the supertoken matches the requested scopes');
|
|
515
468
|
|
|
516
469
|
it('resolves with the token identified by the specified scopes', () => {
|
|
517
470
|
const webex = new MockWebex();
|
|
@@ -539,25 +492,6 @@ describe('webex-core', () => {
|
|
|
539
492
|
]);
|
|
540
493
|
});
|
|
541
494
|
|
|
542
|
-
it('uses the supertoken.scope instead of the config.scope for downscope', () => {
|
|
543
|
-
const webex = new MockWebex();
|
|
544
|
-
const credentials = new Credentials(undefined, {parent: webex});
|
|
545
|
-
|
|
546
|
-
webex.trigger('change:config');
|
|
547
|
-
const st = makeToken(webex, {access_token: 'ST', scope: 'scope1 spark:kms'});
|
|
548
|
-
|
|
549
|
-
credentials.set({
|
|
550
|
-
supertoken: st,
|
|
551
|
-
scope: 'invalidScope scope1',
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
sinon.stub(credentials, 'downscope').returns(Promise.resolve());
|
|
555
|
-
|
|
556
|
-
return credentials.getUserToken().then(() => {
|
|
557
|
-
assert.calledWith(credentials.downscope, 'scope1');
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
|
|
561
495
|
describe('when no matching token is found', () => {
|
|
562
496
|
it('downscopes the supertoken', () => {
|
|
563
497
|
const webex = new MockWebex();
|
|
@@ -595,13 +529,13 @@ describe('webex-core', () => {
|
|
|
595
529
|
it('resolves with a token containing all but the kms scopes', () => {
|
|
596
530
|
const webex = new MockWebex();
|
|
597
531
|
|
|
532
|
+
webex.config.credentials.scope = 'scope1 spark:kms';
|
|
598
533
|
const credentials = new Credentials(undefined, {parent: webex});
|
|
599
534
|
|
|
600
535
|
webex.trigger('change:config');
|
|
601
536
|
|
|
602
537
|
credentials.supertoken = makeToken(webex, {
|
|
603
538
|
access_token: 'ST',
|
|
604
|
-
scope: 'scope1 spark:kms',
|
|
605
539
|
});
|
|
606
540
|
|
|
607
541
|
// const t2 = makeToken(webex, {
|
|
@@ -628,11 +562,9 @@ describe('webex-core', () => {
|
|
|
628
562
|
const webex = new MockWebex({
|
|
629
563
|
children: {
|
|
630
564
|
logger: Logger,
|
|
631
|
-
metrics: Metrics,
|
|
632
565
|
},
|
|
633
566
|
});
|
|
634
567
|
|
|
635
|
-
webex.config.metrics = config.metrics;
|
|
636
568
|
webex.config.credentials.scope = 'scope1 spark:kms';
|
|
637
569
|
const credentials = new Credentials(undefined, {parent: webex});
|
|
638
570
|
|
|
@@ -642,11 +574,9 @@ describe('webex-core', () => {
|
|
|
642
574
|
access_token: 'ST',
|
|
643
575
|
});
|
|
644
576
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
sinon.stub(credentials.logger, 'warn').callsFake(() => {});
|
|
649
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
577
|
+
sinon
|
|
578
|
+
.stub(credentials.supertoken, 'downscope')
|
|
579
|
+
.returns(Promise.reject(new Error('downscope failed')));
|
|
650
580
|
|
|
651
581
|
const t1 = makeToken(webex, {
|
|
652
582
|
access_token: 'AT1',
|
|
@@ -657,27 +587,14 @@ describe('webex-core', () => {
|
|
|
657
587
|
userTokens: [t1],
|
|
658
588
|
});
|
|
659
589
|
|
|
660
|
-
return credentials
|
|
661
|
-
|
|
662
|
-
assert.
|
|
663
|
-
credentials.logger.warn,
|
|
664
|
-
'credentials: failed to downscope supertoken to "scope2"'
|
|
665
|
-
);
|
|
666
|
-
assert.calledWith(
|
|
667
|
-
webex.internal.metrics.submitClientMetrics,
|
|
668
|
-
'JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED',
|
|
669
|
-
{fields: {failReason, requestedScope: 'scope2'}}
|
|
670
|
-
);
|
|
671
|
-
});
|
|
590
|
+
return credentials
|
|
591
|
+
.getUserToken('scope2')
|
|
592
|
+
.then((t) => assert.equal(t.access_token, credentials.supertoken.access_token));
|
|
672
593
|
});
|
|
673
594
|
});
|
|
674
595
|
|
|
675
596
|
it('is blocked while a token refresh is inflight', () => {
|
|
676
|
-
const webex = new MockWebex(
|
|
677
|
-
children: {
|
|
678
|
-
metrics: Metrics,
|
|
679
|
-
},
|
|
680
|
-
});
|
|
597
|
+
const webex = new MockWebex();
|
|
681
598
|
|
|
682
599
|
webex.config.credentials.scope = 'scope1 spark:kms';
|
|
683
600
|
const credentials = new Credentials(undefined, {parent: webex});
|
|
@@ -703,7 +620,6 @@ describe('webex-core', () => {
|
|
|
703
620
|
const at2 = makeToken(webex, {access_token: 'ST2ATD'});
|
|
704
621
|
|
|
705
622
|
sinon.stub(supertoken2, 'downscope').returns(Promise.resolve(at2));
|
|
706
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
707
623
|
|
|
708
624
|
return Promise.all([
|
|
709
625
|
credentials.refresh(),
|
|
@@ -835,24 +751,18 @@ describe('webex-core', () => {
|
|
|
835
751
|
|
|
836
752
|
describe('#refresh()', () => {
|
|
837
753
|
it('refreshes and downscopes the supertoken, and revokes previous tokens', () => {
|
|
838
|
-
const webex = new MockWebex(
|
|
839
|
-
children: {
|
|
840
|
-
metrics: Metrics,
|
|
841
|
-
},
|
|
842
|
-
});
|
|
754
|
+
const webex = new MockWebex();
|
|
843
755
|
const credentials = new Credentials(undefined, {parent: webex});
|
|
844
756
|
|
|
845
757
|
webex.trigger('change:config');
|
|
846
758
|
const st = makeToken(webex, {
|
|
847
759
|
access_token: 'ST',
|
|
848
760
|
refresh_token: 'RT',
|
|
849
|
-
scope: 'scope1 scope2',
|
|
850
761
|
});
|
|
851
762
|
|
|
852
763
|
const st2 = makeToken(webex, {
|
|
853
764
|
access_token: 'ST2',
|
|
854
765
|
refresh_token: 'RT2',
|
|
855
|
-
scope: 'scope1 scope2',
|
|
856
766
|
});
|
|
857
767
|
|
|
858
768
|
const t1 = makeToken(webex, {
|
|
@@ -869,7 +779,6 @@ describe('webex-core', () => {
|
|
|
869
779
|
sinon.stub(st, 'refresh').returns(Promise.resolve(st2));
|
|
870
780
|
sinon.stub(t1, 'revoke').returns(Promise.resolve());
|
|
871
781
|
sinon.spy(credentials, 'scheduleRefresh');
|
|
872
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
873
782
|
|
|
874
783
|
credentials.set({
|
|
875
784
|
supertoken: st,
|
|
@@ -889,11 +798,7 @@ describe('webex-core', () => {
|
|
|
889
798
|
});
|
|
890
799
|
|
|
891
800
|
it('refreshes and downscopes the supertoken even if revocation of previous token fails', () => {
|
|
892
|
-
const webex = new MockWebex(
|
|
893
|
-
children: {
|
|
894
|
-
metrics: Metrics,
|
|
895
|
-
},
|
|
896
|
-
});
|
|
801
|
+
const webex = new MockWebex();
|
|
897
802
|
const credentials = new Credentials(undefined, {parent: webex});
|
|
898
803
|
|
|
899
804
|
webex.trigger('change:config');
|
|
@@ -905,7 +810,6 @@ describe('webex-core', () => {
|
|
|
905
810
|
const st2 = makeToken(webex, {
|
|
906
811
|
access_token: 'ST2',
|
|
907
812
|
refresh_token: 'RT2',
|
|
908
|
-
scope: 'scope1 scope2',
|
|
909
813
|
});
|
|
910
814
|
|
|
911
815
|
const t1 = makeToken(webex, {
|
|
@@ -922,7 +826,6 @@ describe('webex-core', () => {
|
|
|
922
826
|
sinon.stub(st, 'refresh').returns(Promise.resolve(st2));
|
|
923
827
|
sinon.stub(t1, 'revoke').returns(Promise.reject());
|
|
924
828
|
sinon.spy(credentials, 'scheduleRefresh');
|
|
925
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
926
829
|
|
|
927
830
|
credentials.set({
|
|
928
831
|
supertoken: st,
|
|
@@ -945,7 +848,6 @@ describe('webex-core', () => {
|
|
|
945
848
|
const webex = new MockWebex({
|
|
946
849
|
children: {
|
|
947
850
|
logger: Logger,
|
|
948
|
-
metrics: Metrics,
|
|
949
851
|
},
|
|
950
852
|
});
|
|
951
853
|
const credentials = new Credentials(undefined, {parent: webex});
|
|
@@ -954,11 +856,9 @@ describe('webex-core', () => {
|
|
|
954
856
|
const st = makeToken(webex, {
|
|
955
857
|
access_token: 'ST',
|
|
956
858
|
refresh_token: 'RT',
|
|
957
|
-
scope: '',
|
|
958
859
|
});
|
|
959
860
|
|
|
960
861
|
sinon.stub(st, 'refresh').returns(Promise.resolve(makeToken(webex, {access_token: 'ST2'})));
|
|
961
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
962
862
|
|
|
963
863
|
const t1 = makeToken(webex, {
|
|
964
864
|
access_token: 'AT1',
|
|
@@ -974,7 +874,7 @@ describe('webex-core', () => {
|
|
|
974
874
|
});
|
|
975
875
|
|
|
976
876
|
it('allows #getUserToken() to be revoked, but #getUserToken() promises will not resolve until the suport token has been refreshed', () => {
|
|
977
|
-
const webex = new MockWebex(
|
|
877
|
+
const webex = new MockWebex();
|
|
978
878
|
const credentials = new Credentials(undefined, {parent: webex});
|
|
979
879
|
|
|
980
880
|
webex.trigger('change:config');
|
|
@@ -1000,7 +900,6 @@ describe('webex-core', () => {
|
|
|
1000
900
|
|
|
1001
901
|
sinon.stub(st1, 'refresh').returns(Promise.resolve(st2));
|
|
1002
902
|
sinon.stub(st2, 'downscope').returns(Promise.resolve(t2));
|
|
1003
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
1004
903
|
|
|
1005
904
|
credentials.set({
|
|
1006
905
|
supertoken: st1,
|
|
@@ -1057,61 +956,6 @@ describe('webex-core', () => {
|
|
|
1057
956
|
assert.calledWith(triggerSpy, sinon.match('client:InvalidRequestError'));
|
|
1058
957
|
});
|
|
1059
958
|
});
|
|
1060
|
-
|
|
1061
|
-
it('exclude invalid scopes from user token, log and call metrics when fetched supertoken scope mismatch with the configured scope', () => {
|
|
1062
|
-
const webex = new MockWebex({
|
|
1063
|
-
children: {
|
|
1064
|
-
logger: Logger,
|
|
1065
|
-
metrics: Metrics,
|
|
1066
|
-
},
|
|
1067
|
-
});
|
|
1068
|
-
const credentials = new Credentials(undefined, {parent: webex});
|
|
1069
|
-
|
|
1070
|
-
webex.trigger('change:config');
|
|
1071
|
-
const st = makeToken(webex, {
|
|
1072
|
-
access_token: 'ST',
|
|
1073
|
-
refresh_token: 'RT',
|
|
1074
|
-
});
|
|
1075
|
-
|
|
1076
|
-
const st2 = makeToken(webex, {
|
|
1077
|
-
access_token: 'ST2',
|
|
1078
|
-
refresh_token: 'RT2',
|
|
1079
|
-
scope: 'scope1',
|
|
1080
|
-
});
|
|
1081
|
-
|
|
1082
|
-
const userToken = makeToken(webex, {
|
|
1083
|
-
access_token: 'AT1',
|
|
1084
|
-
scope: 'scope1 invalidScope1',
|
|
1085
|
-
});
|
|
1086
|
-
|
|
1087
|
-
credentials.set({
|
|
1088
|
-
supertoken: st,
|
|
1089
|
-
userTokens: [userToken],
|
|
1090
|
-
});
|
|
1091
|
-
const invalidScopes = 'invalidScope1 invalidScope2';
|
|
1092
|
-
credentials.config.scope = `scope1 ${invalidScopes}`;
|
|
1093
|
-
|
|
1094
|
-
sinon.stub(st2, 'downscope').returns(Promise.resolve());
|
|
1095
|
-
sinon.stub(st, 'refresh').returns(Promise.resolve(st2));
|
|
1096
|
-
sinon.spy(credentials, 'downscope');
|
|
1097
|
-
sinon.spy(credentials, 'scheduleRefresh');
|
|
1098
|
-
|
|
1099
|
-
sinon.stub(credentials.logger, 'warn').callsFake(() => {});
|
|
1100
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
1101
|
-
|
|
1102
|
-
return credentials.refresh().then(() => {
|
|
1103
|
-
assert.calledWith(
|
|
1104
|
-
credentials.logger.warn,
|
|
1105
|
-
`credentials: "${invalidScopes}" scope(s) are invalid because not listed in the supertoken, they will be excluded from user token requests.`
|
|
1106
|
-
);
|
|
1107
|
-
assert.calledWith(
|
|
1108
|
-
webex.internal.metrics.submitClientMetrics,
|
|
1109
|
-
'JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH',
|
|
1110
|
-
{fields: {invalidScopes}}
|
|
1111
|
-
);
|
|
1112
|
-
assert.calledWith(credentials.downscope, 'scope1');
|
|
1113
|
-
});
|
|
1114
|
-
});
|
|
1115
959
|
});
|
|
1116
960
|
|
|
1117
961
|
describe('#scheduleRefresh()', () => {
|
|
@@ -166,21 +166,11 @@ describe('webex-core', () => {
|
|
|
166
166
|
);
|
|
167
167
|
});
|
|
168
168
|
|
|
169
|
-
it('rejects downscope when the new scope is not super set of the available scopes', () => {
|
|
170
|
-
const token = makeToken();
|
|
171
|
-
token.config.scope = 'scopeY scopeZ';
|
|
172
|
-
|
|
173
|
-
return assert.isRejected(
|
|
174
|
-
token.downscope('scopeX'),
|
|
175
|
-
/new scope \(scopeX\) is not subset of the available scopes \(scopeY scopeZ\)/
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
169
|
it('alphabetizes the requested scope', () => {
|
|
180
170
|
const token = makeToken();
|
|
181
171
|
|
|
182
172
|
webex.request.returns(Promise.resolve({body: {access_token: 'AT2'}}));
|
|
183
|
-
|
|
173
|
+
|
|
184
174
|
return token
|
|
185
175
|
.downscope('b a')
|
|
186
176
|
.then(() => assert.equal(webex.request.args[0][0].form.scope, 'a b'));
|
|
@@ -12,7 +12,6 @@ import Logger from '@webex/plugin-logger';
|
|
|
12
12
|
import MockWebex from '@webex/test-helper-mock-webex';
|
|
13
13
|
import {AuthInterceptor, config, Credentials, WebexHttpError, Token} from '@webex/webex-core';
|
|
14
14
|
import {cloneDeep, merge} from 'lodash';
|
|
15
|
-
import Metrics from '@webex/internal-plugin-metrics';
|
|
16
15
|
|
|
17
16
|
const {assert} = chai;
|
|
18
17
|
|
|
@@ -29,7 +28,6 @@ describe('webex-core', () => {
|
|
|
29
28
|
children: {
|
|
30
29
|
credentials: Credentials,
|
|
31
30
|
logger: Logger,
|
|
32
|
-
metrics: Metrics,
|
|
33
31
|
},
|
|
34
32
|
config: merge(cloneDeep(config), {credentials: {client_secret: 'fake'}}),
|
|
35
33
|
});
|
|
@@ -43,7 +41,6 @@ describe('webex-core', () => {
|
|
|
43
41
|
);
|
|
44
42
|
|
|
45
43
|
interceptor = Reflect.apply(AuthInterceptor.create, webex, []);
|
|
46
|
-
sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
|
|
47
44
|
});
|
|
48
45
|
|
|
49
46
|
describe('#onRequest()', () => {
|
|
@@ -27,7 +27,7 @@ describe('webex-core', () => {
|
|
|
27
27
|
assert.property(options.headers, 'spark-user-agent');
|
|
28
28
|
assert.equal(
|
|
29
29
|
options.headers['spark-user-agent'],
|
|
30
|
-
`webex-js-sdk
|
|
30
|
+
`webex-js-sdk/${pkg.version} (${typeof window === 'undefined' ? 'node' : 'web'})`
|
|
31
31
|
);
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -47,7 +47,7 @@ describe('webex-core', () => {
|
|
|
47
47
|
assert.property(options.headers, 'spark-user-agent');
|
|
48
48
|
assert.equal(
|
|
49
49
|
options.headers['spark-user-agent'],
|
|
50
|
-
`webex-js-sdk
|
|
50
|
+
`webex-js-sdk/${pkg.version} (${typeof window === 'undefined' ? 'node' : 'web'})`
|
|
51
51
|
);
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -74,7 +74,7 @@ describe('webex-core', () => {
|
|
|
74
74
|
assert.property(options.headers, 'spark-user-agent');
|
|
75
75
|
assert.equal(
|
|
76
76
|
options.headers['spark-user-agent'],
|
|
77
|
-
`webex-js-sdk
|
|
77
|
+
`webex-js-sdk/${pkg.version} (${
|
|
78
78
|
typeof window === 'undefined' ? 'node' : 'web'
|
|
79
79
|
}) sample/1.0.0`
|
|
80
80
|
);
|
|
@@ -104,7 +104,7 @@ describe('webex-core', () => {
|
|
|
104
104
|
assert.property(options.headers, 'spark-user-agent');
|
|
105
105
|
assert.equal(
|
|
106
106
|
options.headers['spark-user-agent'],
|
|
107
|
-
`webex-js-sdk
|
|
107
|
+
`webex-js-sdk/${pkg.version} (${
|
|
108
108
|
typeof window === 'undefined' ? 'node' : 'web'
|
|
109
109
|
}) sample/1.0.0 custom-label/1.0.0`
|
|
110
110
|
);
|
|
@@ -128,7 +128,7 @@ describe('webex-core', () => {
|
|
|
128
128
|
assert.property(options.headers, 'spark-user-agent');
|
|
129
129
|
assert.equal(
|
|
130
130
|
options.headers['spark-user-agent'],
|
|
131
|
-
`webex
|
|
131
|
+
`webex/${pkg.version} (${typeof window === 'undefined' ? 'node' : 'web'})`
|
|
132
132
|
);
|
|
133
133
|
});
|
|
134
134
|
|
|
@@ -149,7 +149,7 @@ describe('webex-core', () => {
|
|
|
149
149
|
assert.property(options.headers, 'spark-user-agent');
|
|
150
150
|
assert.equal(
|
|
151
151
|
options.headers['spark-user-agent'],
|
|
152
|
-
`webex
|
|
152
|
+
`webex/${pkg.version} (${typeof window === 'undefined' ? 'node' : 'web'})`
|
|
153
153
|
);
|
|
154
154
|
});
|
|
155
155
|
});
|
|
@@ -5,7 +5,6 @@ import chai from 'chai';
|
|
|
5
5
|
import chaiAsPromised from 'chai-as-promised';
|
|
6
6
|
import sinon from 'sinon';
|
|
7
7
|
import {ServiceInterceptor} from '@webex/webex-core';
|
|
8
|
-
import CONFIG from '../../../../../src/config';
|
|
9
8
|
|
|
10
9
|
const {assert} = chai;
|
|
11
10
|
|
|
@@ -27,7 +26,6 @@ describe('webex-core', () => {
|
|
|
27
26
|
service: 'example',
|
|
28
27
|
serviceUrl: 'https://www.example-service.com/',
|
|
29
28
|
uri: 'https://www.example-uri.com/',
|
|
30
|
-
waitForServiceTimeout: 11,
|
|
31
29
|
};
|
|
32
30
|
|
|
33
31
|
options = {};
|
|
@@ -112,7 +110,6 @@ describe('webex-core', () => {
|
|
|
112
110
|
|
|
113
111
|
options.service = fixture.service;
|
|
114
112
|
options.resource = fixture.resource;
|
|
115
|
-
options.timeout = fixture.waitForServiceTimeout;
|
|
116
113
|
});
|
|
117
114
|
|
|
118
115
|
it('should normalize the options', () =>
|
|
@@ -122,12 +119,9 @@ describe('webex-core', () => {
|
|
|
122
119
|
interceptor.onRequest(options).then(() => assert.called(interceptor.validateOptions)));
|
|
123
120
|
|
|
124
121
|
it('should attempt to collect the service url', () =>
|
|
125
|
-
interceptor
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
timeout: options.waitForServiceTimeout,
|
|
129
|
-
})
|
|
130
|
-
));
|
|
122
|
+
interceptor
|
|
123
|
+
.onRequest(options)
|
|
124
|
+
.then(() => assert.calledWith(waitForService, {name: options.service})));
|
|
131
125
|
|
|
132
126
|
describe('when the service url was collected successfully', () => {
|
|
133
127
|
it('should attempt to generate the full uri', () =>
|
|
@@ -54,18 +54,6 @@ describe('Webex', () => {
|
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
describe('#request', () => {
|
|
58
|
-
it('exists', () => {
|
|
59
|
-
assert.property(webex, 'request');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('#prepareFetchOptions', () => {
|
|
64
|
-
it('exists', () => {
|
|
65
|
-
assert.property(webex, 'prepareFetchOptions');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
57
|
describe('#initialize()', () => {
|
|
70
58
|
it('initializes without arguments', () => {
|
|
71
59
|
let webex;
|
package/dist/lib/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.METRICS = void 0;
|
|
8
|
-
// Metric to do with WDM registration
|
|
9
|
-
var METRICS = exports.METRICS = {
|
|
10
|
-
JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED: 'JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED',
|
|
11
|
-
JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH: 'JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH'
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["METRICS","exports","JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED","JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH"],"sources":["constants.js"],"sourcesContent":["// Metric to do with WDM registration\nexport const METRICS = {\n JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED: 'JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED',\n JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH:\n 'JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH',\n};\n"],"mappings":";;;;;;;AAAA;AACO,IAAMA,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG;EACrBE,mCAAmC,EAAE,qCAAqC;EAC1EC,+CAA+C,EAC7C;AACJ,CAAC"}
|
package/src/lib/constants.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {assert} from '@webex/test-helper-chai';
|
|
2
|
-
import {
|
|
3
|
-
sortScope,
|
|
4
|
-
filterScope,
|
|
5
|
-
diffScopes,
|
|
6
|
-
isGuestScope,
|
|
7
|
-
} from '@webex/webex-core/src/lib/credentials/scope';
|
|
8
|
-
|
|
9
|
-
describe('webex-core', () => {
|
|
10
|
-
describe('scope utils', () => {
|
|
11
|
-
describe('sortScope', () => {
|
|
12
|
-
[
|
|
13
|
-
{scope: undefined, expected: ''},
|
|
14
|
-
{scope: '', expected: ''},
|
|
15
|
-
{scope: 'a', expected: 'a'},
|
|
16
|
-
{scope: 'b c a', expected: 'a b c'},
|
|
17
|
-
].forEach(({scope, expected}) =>
|
|
18
|
-
it(`should sort "${scope}" alphabetically`, () => {
|
|
19
|
-
assert.equal(sortScope(scope), expected);
|
|
20
|
-
})
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('filterScope', () => {
|
|
25
|
-
[
|
|
26
|
-
{toFilter: 'a', scope: undefined, expected: ''},
|
|
27
|
-
{toFilter: 'a', scope: '', expected: ''},
|
|
28
|
-
{toFilter: 'a', scope: 'a', expected: ''},
|
|
29
|
-
{toFilter: 'a', scope: 'a b c', expected: 'b c'},
|
|
30
|
-
{toFilter: 'c', scope: 'a c b', expected: 'a b'},
|
|
31
|
-
].forEach(({toFilter, scope, expected}) =>
|
|
32
|
-
it(`should filter out ${toFilter} scope from ${scope} scope and sort the result`, () => {
|
|
33
|
-
assert.equal(filterScope(toFilter, scope), expected);
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
[
|
|
38
|
-
{toFilter: [], scope: 'a', expected: 'a'},
|
|
39
|
-
{toFilter: ['a', 'b'], scope: undefined, expected: ''},
|
|
40
|
-
{toFilter: ['a', 'b'], scope: '', expected: ''},
|
|
41
|
-
{toFilter: ['a', 'b'], scope: 'a', expected: ''},
|
|
42
|
-
{toFilter: ['a', 'b'], scope: 'a b c', expected: 'c'},
|
|
43
|
-
{toFilter: ['a', 'd'], scope: 'a c a b', expected: 'b c'},
|
|
44
|
-
].forEach(({toFilter, scope, expected}) =>
|
|
45
|
-
it(`should filter out ${toFilter} from ${scope} and sort the result`, () => {
|
|
46
|
-
assert.equal(filterScope(toFilter, scope), expected);
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('diffScopes', () => {
|
|
52
|
-
[
|
|
53
|
-
{scope1: undefined, scope2: undefined, expected: ''},
|
|
54
|
-
{scope1: undefined, scope2: '', expected: ''},
|
|
55
|
-
{scope1: '', scope2: undefined, expected: ''},
|
|
56
|
-
{scope1: '', scope2: '', expected: ''},
|
|
57
|
-
{scope1: 'a', scope2: 'a', expected: ''},
|
|
58
|
-
{scope1: 'a b c', scope2: 'a b c', expected: ''},
|
|
59
|
-
{scope1: undefined, scope2: 'a b c', expected: ''},
|
|
60
|
-
{scope1: 'a b c', scope2: 'a b c d', expected: ''},
|
|
61
|
-
].forEach(({scope1, scope2, expected}) =>
|
|
62
|
-
it(`should return an empty string, when all items in ${scope1} scope are contained in the ${scope2} scope`, () => {
|
|
63
|
-
assert.deepEqual(diffScopes(scope1, scope2), expected);
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
[
|
|
68
|
-
{scope1: 'a', scope2: undefined, expected: 'a'},
|
|
69
|
-
{scope1: 'a', scope2: 'b', expected: 'a'},
|
|
70
|
-
{scope1: 'a b c', scope2: 'a b', expected: 'c'},
|
|
71
|
-
{scope1: 'a b c d', scope2: 'a b c', expected: 'd'},
|
|
72
|
-
{scope1: 'a b c', scope2: undefined, expected: 'a b c'},
|
|
73
|
-
].forEach(({scope1, scope2, expected}) =>
|
|
74
|
-
it(`should return a string containing all items in the ${scope1} scope that are not in the ${scope2} scope`, () => {
|
|
75
|
-
assert.deepEqual(diffScopes(scope1, scope2), expected);
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|