@webex/webex-core 3.13.0-next.4 → 3.13.0-next.6
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 +1 -1
- package/.sdd/manifest.json +14 -4
- package/AGENTS.md +2 -2
- package/dist/interceptors/auth.js +10 -1
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/lib/batcher.js +1 -1
- package/dist/lib/credentials/credentials.js +1 -1
- package/dist/lib/credentials/token.js +1 -1
- 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/services.js +46 -3
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/services-v2/services-v2.js +40 -3
- package/dist/lib/services-v2/services-v2.js.map +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/docs/getting-started.md +2 -2
- package/package.json +13 -13
- package/src/interceptors/auth.js +14 -1
- package/src/lib/interceptors/service.js +11 -3
- package/src/lib/services/catalog-auth.js +112 -0
- package/src/lib/services/docs/README.md +4 -4
- package/src/lib/services/services.js +54 -2
- package/src/lib/services-v2/docs/README.md +4 -4
- package/src/lib/services-v2/services-v2.ts +48 -2
- package/test/unit/spec/interceptors/auth.js +35 -0
- package/test/unit/spec/services/interceptors/service.js +35 -1
- package/test/unit/spec/services/services.js +309 -0
- package/test/unit/spec/services-v2/services-v2.ts +227 -0
|
@@ -6,6 +6,7 @@ import {assert} from '@webex/test-helper-chai';
|
|
|
6
6
|
import MockWebex from '@webex/test-helper-mock-webex';
|
|
7
7
|
import sinon from 'sinon';
|
|
8
8
|
import {Services, ServiceRegistry, ServiceState} from '@webex/webex-core';
|
|
9
|
+
import grantErrors from '@webex/webex-core/dist/lib/credentials/grant-errors';
|
|
9
10
|
import {NewMetrics} from '@webex/internal-plugin-metrics';
|
|
10
11
|
|
|
11
12
|
const waitForAsync = () =>
|
|
@@ -611,6 +612,314 @@ describe('webex-core', () => {
|
|
|
611
612
|
|
|
612
613
|
sinon.assert.calledWith(services.collectPreauthCatalog, {orgId: 'orgId'});
|
|
613
614
|
sinon.assert.calledWith(services.logger.warn, 'services: cannot retrieve postauth catalog');
|
|
615
|
+
assert.isNull(services._getCatalogAuthFailure());
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it.each([
|
|
619
|
+
{statusField: 'statusCode', status: 401, reason: 'invalid_access_token'},
|
|
620
|
+
{statusField: 'status', status: 403, reason: 'access_denied'},
|
|
621
|
+
])(
|
|
622
|
+
'stores $reason when the postauth catalog fails with $status',
|
|
623
|
+
async ({statusField, status, reason}) => {
|
|
624
|
+
const error = new Error('catalog failed');
|
|
625
|
+
|
|
626
|
+
error[statusField] = status;
|
|
627
|
+
|
|
628
|
+
services.webex.credentials = {
|
|
629
|
+
getOrgId: sinon.stub().returns('orgId'),
|
|
630
|
+
canAuthorize: true,
|
|
631
|
+
};
|
|
632
|
+
services.collectPreauthCatalog = sinon.stub().resolves();
|
|
633
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
634
|
+
services.logger.error = sinon.stub();
|
|
635
|
+
|
|
636
|
+
await services.initServiceCatalogs();
|
|
637
|
+
|
|
638
|
+
assert.isTrue(services.initFailed);
|
|
639
|
+
sinon.assert.calledWith(services.logger.warn, 'services: cannot retrieve postauth catalog');
|
|
640
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {status, reason});
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
it.each([
|
|
645
|
+
{statusField: 'statusCode', status: 401, reason: 'invalid_access_token'},
|
|
646
|
+
{statusField: 'status', status: 403, reason: 'access_denied'},
|
|
647
|
+
])(
|
|
648
|
+
'keeps a stored $reason when a second init times out during the postauth fetch',
|
|
649
|
+
async ({statusField, status, reason}) => {
|
|
650
|
+
let rejectFetch;
|
|
651
|
+
const fetchPromise = new Promise((resolve, reject) => {
|
|
652
|
+
rejectFetch = reject;
|
|
653
|
+
});
|
|
654
|
+
const clock = sinon.useFakeTimers({toFake: ['setTimeout', 'clearTimeout']});
|
|
655
|
+
|
|
656
|
+
services.webex.credentials = {
|
|
657
|
+
getOrgId: sinon.stub().returns('orgId'),
|
|
658
|
+
canAuthorize: true,
|
|
659
|
+
supertoken: {access_token: 'token'},
|
|
660
|
+
};
|
|
661
|
+
services.collectPreauthCatalog = sinon.stub().resolves();
|
|
662
|
+
sinon.stub(services, '_fetchNewServiceHostmap').returns(fetchPromise);
|
|
663
|
+
|
|
664
|
+
try {
|
|
665
|
+
const firstInit = services.initServiceCatalogs();
|
|
666
|
+
|
|
667
|
+
await waitForAsync();
|
|
668
|
+
assert.isTrue(catalog.status.postauth.collecting);
|
|
669
|
+
|
|
670
|
+
const secondInit = services.initServiceCatalogs();
|
|
671
|
+
|
|
672
|
+
await waitForAsync();
|
|
673
|
+
assert.calledOnce(services._fetchNewServiceHostmap);
|
|
674
|
+
|
|
675
|
+
const error = new Error('catalog failed');
|
|
676
|
+
|
|
677
|
+
error[statusField] = status;
|
|
678
|
+
rejectFetch(error);
|
|
679
|
+
await firstInit;
|
|
680
|
+
|
|
681
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {status, reason});
|
|
682
|
+
|
|
683
|
+
clock.tick(60 * 1000);
|
|
684
|
+
await secondInit;
|
|
685
|
+
|
|
686
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {status, reason});
|
|
687
|
+
} finally {
|
|
688
|
+
clock.restore();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
);
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
describe('#updateServices catalog auth failure', () => {
|
|
695
|
+
const emptyHostmap = {
|
|
696
|
+
serviceLinks: {},
|
|
697
|
+
hostCatalog: {},
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
const recordAuthFailure = (status) => {
|
|
701
|
+
services._recordCatalogAuthFailure(
|
|
702
|
+
Object.assign(new Error('catalog failed'), {statusCode: status})
|
|
703
|
+
);
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
it.each([
|
|
707
|
+
{status: 401, reason: 'invalid_access_token'},
|
|
708
|
+
{status: 403, reason: 'access_denied'},
|
|
709
|
+
])(
|
|
710
|
+
'clears a stored $reason after a successful postauth update and reports a missing service as unknown',
|
|
711
|
+
async ({status}) => {
|
|
712
|
+
services.webex.config.services = {
|
|
713
|
+
servicesNotNeedValidation: [],
|
|
714
|
+
};
|
|
715
|
+
services.webex.internal.metrics = {
|
|
716
|
+
submitClientMetrics: sinon.stub(),
|
|
717
|
+
};
|
|
718
|
+
recordAuthFailure(status);
|
|
719
|
+
sinon.stub(services, '_fetchNewServiceHostmap').resolves(emptyHostmap);
|
|
720
|
+
|
|
721
|
+
await services.updateServices();
|
|
722
|
+
|
|
723
|
+
assert.isNull(services._getCatalogAuthFailure());
|
|
724
|
+
catalog.isReady = true;
|
|
725
|
+
|
|
726
|
+
try {
|
|
727
|
+
await services.waitForService({name: 'wcc-api-gateway'});
|
|
728
|
+
assert.fail('expected waitForService to reject');
|
|
729
|
+
} catch (error) {
|
|
730
|
+
assert.equal(
|
|
731
|
+
error.message,
|
|
732
|
+
"services: service 'wcc-api-gateway' was not found in any of the catalogs"
|
|
733
|
+
);
|
|
734
|
+
assert.isUndefined(error.reason);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
);
|
|
738
|
+
|
|
739
|
+
it.each([
|
|
740
|
+
{status: 401, reason: 'invalid_access_token'},
|
|
741
|
+
{status: 403, reason: 'access_denied'},
|
|
742
|
+
])(
|
|
743
|
+
'clears a stored $reason when waitForCatalog(postauth) reloads through updateServices',
|
|
744
|
+
async ({status}) => {
|
|
745
|
+
services.webex.credentials = {
|
|
746
|
+
supertoken: {
|
|
747
|
+
access_token: 'token',
|
|
748
|
+
},
|
|
749
|
+
};
|
|
750
|
+
catalog.status.preauth.ready = true;
|
|
751
|
+
catalog.status.postauth.ready = false;
|
|
752
|
+
catalog.status.postauth.collecting = false;
|
|
753
|
+
recordAuthFailure(status);
|
|
754
|
+
sinon.stub(services, 'initServiceCatalogs');
|
|
755
|
+
sinon.stub(services, '_fetchNewServiceHostmap').resolves(emptyHostmap);
|
|
756
|
+
|
|
757
|
+
await services.waitForCatalog('postauth');
|
|
758
|
+
|
|
759
|
+
assert.notCalled(services.initServiceCatalogs);
|
|
760
|
+
assert.isNull(services._getCatalogAuthFailure());
|
|
761
|
+
}
|
|
762
|
+
);
|
|
763
|
+
|
|
764
|
+
it.each([
|
|
765
|
+
{statusField: 'statusCode', status: 401, reason: 'invalid_access_token'},
|
|
766
|
+
{statusField: 'status', status: 403, reason: 'access_denied'},
|
|
767
|
+
])(
|
|
768
|
+
'stores $reason when a direct postauth update fails with $status',
|
|
769
|
+
async ({statusField, status, reason}) => {
|
|
770
|
+
const error = new Error('catalog failed');
|
|
771
|
+
|
|
772
|
+
error[statusField] = status;
|
|
773
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
774
|
+
sinon.spy(services, 'initServiceCatalogs');
|
|
775
|
+
|
|
776
|
+
try {
|
|
777
|
+
await services.updateServices();
|
|
778
|
+
assert.fail('expected updateServices to reject');
|
|
779
|
+
} catch (rejected) {
|
|
780
|
+
assert.equal(rejected, error);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
assert.notCalled(services.initServiceCatalogs);
|
|
784
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {status, reason});
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
|
|
788
|
+
it('stores invalid_access_token when a refresh 403 replaced a catalog 401', async () => {
|
|
789
|
+
const error = new Error('forbidden');
|
|
790
|
+
|
|
791
|
+
error.statusCode = 403;
|
|
792
|
+
error.catalogAuthStatus = 401;
|
|
793
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
794
|
+
|
|
795
|
+
try {
|
|
796
|
+
await services.updateServices();
|
|
797
|
+
assert.fail('expected updateServices to reject');
|
|
798
|
+
} catch (rejected) {
|
|
799
|
+
assert.equal(rejected, error);
|
|
800
|
+
assert.equal(rejected.statusCode, 403);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
804
|
+
status: 401,
|
|
805
|
+
reason: 'invalid_access_token',
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
it('stores invalid_access_token when a postauth update fails with InvalidGrantError', async () => {
|
|
810
|
+
const error = new grantErrors.InvalidGrantError({
|
|
811
|
+
body: {
|
|
812
|
+
error: 'invalid_grant',
|
|
813
|
+
error_description: 'The refresh token is invalid',
|
|
814
|
+
},
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
818
|
+
|
|
819
|
+
try {
|
|
820
|
+
await services.updateServices();
|
|
821
|
+
assert.fail('expected updateServices to reject');
|
|
822
|
+
} catch (rejected) {
|
|
823
|
+
assert.equal(rejected, error);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
827
|
+
status: 401,
|
|
828
|
+
reason: 'invalid_access_token',
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
it('stores invalid_access_token when a postauth update fails after the auth replay limit', async () => {
|
|
833
|
+
const error = new Error('Failed after 1 replay attempts');
|
|
834
|
+
|
|
835
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
836
|
+
|
|
837
|
+
try {
|
|
838
|
+
await services.updateServices();
|
|
839
|
+
assert.fail('expected updateServices to reject');
|
|
840
|
+
} catch (rejected) {
|
|
841
|
+
assert.equal(rejected, error);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
845
|
+
status: 401,
|
|
846
|
+
reason: 'invalid_access_token',
|
|
847
|
+
});
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
it('clears a stored auth failure when a postauth update fails with a statusless error', async () => {
|
|
851
|
+
const error = new Error('catalog failed');
|
|
852
|
+
|
|
853
|
+
recordAuthFailure(401);
|
|
854
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
855
|
+
|
|
856
|
+
try {
|
|
857
|
+
await services.updateServices();
|
|
858
|
+
assert.fail('expected updateServices to reject');
|
|
859
|
+
} catch (rejected) {
|
|
860
|
+
assert.equal(rejected, error);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
assert.isNull(services._getCatalogAuthFailure());
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
it.each([
|
|
867
|
+
{label: 'preauth', args: {from: 'limited', query: {orgId: 'urn:EXAMPLE:org'}}},
|
|
868
|
+
{label: 'signin', args: {from: 'signin', query: {email: 'user@example.com'}}},
|
|
869
|
+
])('leaves a postauth auth failure in place after a successful $label update', async ({args}) => {
|
|
870
|
+
recordAuthFailure(401);
|
|
871
|
+
sinon.stub(services, '_fetchNewServiceHostmap').resolves(emptyHostmap);
|
|
872
|
+
|
|
873
|
+
await services.updateServices(args);
|
|
874
|
+
|
|
875
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
876
|
+
status: 401,
|
|
877
|
+
reason: 'invalid_access_token',
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
describe('#waitForService', () => {
|
|
883
|
+
it('rejects with invalid_access_token when the postauth catalog failed with 401 and the service is missing', async () => {
|
|
884
|
+
services.webex.config.services = {
|
|
885
|
+
servicesNotNeedValidation: [],
|
|
886
|
+
};
|
|
887
|
+
services.webex.internal.metrics = {
|
|
888
|
+
submitClientMetrics: sinon.stub(),
|
|
889
|
+
};
|
|
890
|
+
services._recordCatalogAuthFailure(
|
|
891
|
+
Object.assign(new Error('unauthorized'), {statusCode: 401})
|
|
892
|
+
);
|
|
893
|
+
catalog.isReady = true;
|
|
894
|
+
|
|
895
|
+
try {
|
|
896
|
+
await services.waitForService({name: 'wcc-api-gateway'});
|
|
897
|
+
assert.fail('expected waitForService to reject');
|
|
898
|
+
} catch (error) {
|
|
899
|
+
assert.equal(error.reason, 'invalid_access_token');
|
|
900
|
+
assert.equal(error.statusCode, 401);
|
|
901
|
+
assert.equal(error.message, 'invalid_access_token');
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
it('rejects with access_denied when the postauth catalog failed with 403 and the service is missing', async () => {
|
|
906
|
+
services.webex.config.services = {
|
|
907
|
+
servicesNotNeedValidation: [],
|
|
908
|
+
};
|
|
909
|
+
services.webex.internal.metrics = {
|
|
910
|
+
submitClientMetrics: sinon.stub(),
|
|
911
|
+
};
|
|
912
|
+
services._recordCatalogAuthFailure(Object.assign(new Error('forbidden'), {statusCode: 403}));
|
|
913
|
+
catalog.isReady = true;
|
|
914
|
+
|
|
915
|
+
try {
|
|
916
|
+
await services.waitForService({name: 'wcc-api-gateway'});
|
|
917
|
+
assert.fail('expected waitForService to reject');
|
|
918
|
+
} catch (error) {
|
|
919
|
+
assert.equal(error.reason, 'access_denied');
|
|
920
|
+
assert.equal(error.statusCode, 403);
|
|
921
|
+
assert.equal(error.message, 'access_denied');
|
|
922
|
+
}
|
|
614
923
|
});
|
|
615
924
|
});
|
|
616
925
|
|
|
@@ -6,6 +6,7 @@ import {assert} from '@webex/test-helper-chai';
|
|
|
6
6
|
import MockWebex from '@webex/test-helper-mock-webex';
|
|
7
7
|
import sinon from 'sinon';
|
|
8
8
|
import {ServicesV2} from '@webex/webex-core';
|
|
9
|
+
import grantErrors from '@webex/webex-core/dist/lib/credentials/grant-errors';
|
|
9
10
|
import {NewMetrics} from '@webex/internal-plugin-metrics';
|
|
10
11
|
import {formattedServiceHostmapV2, serviceHostmapV2} from '../../../fixtures/host-catalog-v2';
|
|
11
12
|
import fedRampServices from '../../../../src/lib/services-v2/service-fed-ramp';
|
|
@@ -702,6 +703,232 @@ describe('webex-core', () => {
|
|
|
702
703
|
|
|
703
704
|
sinon.assert.calledWith(services.collectPreauthCatalog, {orgId: 'orgId'});
|
|
704
705
|
sinon.assert.calledWith(services.logger.warn, 'services: cannot retrieve postauth catalog');
|
|
706
|
+
assert.isNull(services._getCatalogAuthFailure());
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
it.each([
|
|
710
|
+
{statusField: 'statusCode', status: 401, reason: 'invalid_access_token'},
|
|
711
|
+
{statusField: 'status', status: 403, reason: 'access_denied'},
|
|
712
|
+
])(
|
|
713
|
+
'keeps a stored $reason when a second init times out during the postauth fetch',
|
|
714
|
+
async ({statusField, status, reason}) => {
|
|
715
|
+
let rejectFetch: (error: Error) => void = () => undefined;
|
|
716
|
+
const fetchPromise = new Promise((resolve, reject) => {
|
|
717
|
+
rejectFetch = reject;
|
|
718
|
+
});
|
|
719
|
+
const clock = sinon.useFakeTimers({toFake: ['setTimeout', 'clearTimeout']});
|
|
720
|
+
|
|
721
|
+
services.webex.credentials = {
|
|
722
|
+
getOrgId: sinon.stub().returns('orgId'),
|
|
723
|
+
canAuthorize: true,
|
|
724
|
+
supertoken: {access_token: 'token'},
|
|
725
|
+
};
|
|
726
|
+
services.collectPreauthCatalog = sinon.stub().resolves();
|
|
727
|
+
sinon.stub(services, '_fetchNewServiceHostmap').returns(fetchPromise);
|
|
728
|
+
|
|
729
|
+
try {
|
|
730
|
+
const firstInit = services.initServiceCatalogs();
|
|
731
|
+
|
|
732
|
+
await waitForAsync();
|
|
733
|
+
assert.isTrue(catalog.status.postauth.collecting);
|
|
734
|
+
|
|
735
|
+
const secondInit = services.initServiceCatalogs();
|
|
736
|
+
|
|
737
|
+
await waitForAsync();
|
|
738
|
+
assert.calledOnce(services._fetchNewServiceHostmap);
|
|
739
|
+
|
|
740
|
+
const error = Object.assign(new Error('catalog failed'), {[statusField]: status});
|
|
741
|
+
|
|
742
|
+
rejectFetch(error);
|
|
743
|
+
await firstInit;
|
|
744
|
+
|
|
745
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {status, reason});
|
|
746
|
+
|
|
747
|
+
clock.tick(60 * 1000);
|
|
748
|
+
await secondInit;
|
|
749
|
+
|
|
750
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {status, reason});
|
|
751
|
+
} finally {
|
|
752
|
+
clock.restore();
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
);
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
describe('#updateServices catalog auth failure', () => {
|
|
759
|
+
const emptyHostmap = {
|
|
760
|
+
services: [],
|
|
761
|
+
timestamp: '1',
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
const recordAuthFailure = (status: number) => {
|
|
765
|
+
services._recordCatalogAuthFailure(
|
|
766
|
+
Object.assign(new Error('catalog failed'), {statusCode: status})
|
|
767
|
+
);
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
const rejectMissingService = async (expected: {
|
|
771
|
+
message: string;
|
|
772
|
+
reason?: string;
|
|
773
|
+
statusCode?: number;
|
|
774
|
+
}) => {
|
|
775
|
+
services.webex.config.services = {
|
|
776
|
+
servicesNotNeedValidation: [],
|
|
777
|
+
};
|
|
778
|
+
services.webex.internal.metrics = {
|
|
779
|
+
submitClientMetrics: sinon.stub(),
|
|
780
|
+
};
|
|
781
|
+
catalog.isReady = true;
|
|
782
|
+
|
|
783
|
+
try {
|
|
784
|
+
await services.waitForService({name: 'wcc-api-gateway'});
|
|
785
|
+
assert.fail('expected waitForService to reject');
|
|
786
|
+
} catch (error) {
|
|
787
|
+
assert.equal(error.message, expected.message);
|
|
788
|
+
if (expected.reason) {
|
|
789
|
+
assert.equal(error.reason, expected.reason);
|
|
790
|
+
assert.equal(error.statusCode, expected.statusCode);
|
|
791
|
+
} else {
|
|
792
|
+
assert.isUndefined(error.reason);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
it.each([
|
|
798
|
+
{status: 401, reason: 'invalid_access_token'},
|
|
799
|
+
{status: 403, reason: 'access_denied'},
|
|
800
|
+
])(
|
|
801
|
+
'stores $reason when a postauth catalog update fails with $status and surfaces it for a missing service',
|
|
802
|
+
async ({status, reason}) => {
|
|
803
|
+
const error = Object.assign(new Error('catalog failed'), {statusCode: status});
|
|
804
|
+
|
|
805
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
806
|
+
|
|
807
|
+
try {
|
|
808
|
+
await services.updateServices();
|
|
809
|
+
assert.fail('expected updateServices to reject');
|
|
810
|
+
} catch (rejected) {
|
|
811
|
+
assert.equal(rejected, error);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {status, reason});
|
|
815
|
+
await rejectMissingService({message: reason, reason, statusCode: status});
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
|
|
819
|
+
it('stores invalid_access_token when a refresh 403 replaced a catalog 401', async () => {
|
|
820
|
+
const error = Object.assign(new Error('forbidden'), {
|
|
821
|
+
statusCode: 403,
|
|
822
|
+
catalogAuthStatus: 401,
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
826
|
+
|
|
827
|
+
try {
|
|
828
|
+
await services.updateServices();
|
|
829
|
+
assert.fail('expected updateServices to reject');
|
|
830
|
+
} catch (rejected) {
|
|
831
|
+
assert.equal(rejected, error);
|
|
832
|
+
assert.equal(rejected.statusCode, 403);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
836
|
+
status: 401,
|
|
837
|
+
reason: 'invalid_access_token',
|
|
838
|
+
});
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
it('stores invalid_access_token when a postauth update fails with InvalidGrantError', async () => {
|
|
842
|
+
const error = new grantErrors.InvalidGrantError({
|
|
843
|
+
body: {
|
|
844
|
+
error: 'invalid_grant',
|
|
845
|
+
error_description: 'The refresh token is invalid',
|
|
846
|
+
},
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
850
|
+
|
|
851
|
+
try {
|
|
852
|
+
await services.updateServices();
|
|
853
|
+
assert.fail('expected updateServices to reject');
|
|
854
|
+
} catch (rejected) {
|
|
855
|
+
assert.equal(rejected, error);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
859
|
+
status: 401,
|
|
860
|
+
reason: 'invalid_access_token',
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
it('stores invalid_access_token when a postauth update fails after the auth replay limit', async () => {
|
|
865
|
+
const error = new Error('Failed after 1 replay attempts');
|
|
866
|
+
|
|
867
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
868
|
+
|
|
869
|
+
try {
|
|
870
|
+
await services.updateServices();
|
|
871
|
+
assert.fail('expected updateServices to reject');
|
|
872
|
+
} catch (rejected) {
|
|
873
|
+
assert.equal(rejected, error);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
877
|
+
status: 401,
|
|
878
|
+
reason: 'invalid_access_token',
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
it('clears a stored auth failure when a postauth update fails with a statusless error', async () => {
|
|
883
|
+
const error = new Error('catalog failed');
|
|
884
|
+
|
|
885
|
+
recordAuthFailure(401);
|
|
886
|
+
sinon.stub(services, '_fetchNewServiceHostmap').rejects(error);
|
|
887
|
+
|
|
888
|
+
try {
|
|
889
|
+
await services.updateServices();
|
|
890
|
+
assert.fail('expected updateServices to reject');
|
|
891
|
+
} catch (rejected) {
|
|
892
|
+
assert.equal(rejected, error);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
assert.isNull(services._getCatalogAuthFailure());
|
|
896
|
+
await rejectMissingService({
|
|
897
|
+
message: "services: service 'wcc-api-gateway' was not found in any of the catalogs",
|
|
898
|
+
});
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
it.each([
|
|
902
|
+
{status: 401, reason: 'invalid_access_token'},
|
|
903
|
+
{status: 403, reason: 'access_denied'},
|
|
904
|
+
])(
|
|
905
|
+
'clears a stored $reason after a successful postauth update and reports a missing service as unknown',
|
|
906
|
+
async ({status}) => {
|
|
907
|
+
recordAuthFailure(status);
|
|
908
|
+
sinon.stub(services, '_fetchNewServiceHostmap').resolves(emptyHostmap);
|
|
909
|
+
|
|
910
|
+
await services.updateServices();
|
|
911
|
+
|
|
912
|
+
assert.isNull(services._getCatalogAuthFailure());
|
|
913
|
+
await rejectMissingService({
|
|
914
|
+
message: "services: service 'wcc-api-gateway' was not found in any of the catalogs",
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
);
|
|
918
|
+
|
|
919
|
+
it.each([
|
|
920
|
+
{label: 'preauth', args: {from: 'limited', query: {orgId: 'urn:EXAMPLE:org'}}},
|
|
921
|
+
{label: 'signin', args: {from: 'signin', query: {email: 'user@example.com'}}},
|
|
922
|
+
])('leaves a postauth auth failure in place after a successful $label update', async ({args}) => {
|
|
923
|
+
recordAuthFailure(401);
|
|
924
|
+
sinon.stub(services, '_fetchNewServiceHostmap').resolves(emptyHostmap);
|
|
925
|
+
|
|
926
|
+
await services.updateServices(args);
|
|
927
|
+
|
|
928
|
+
assert.deepEqual(services._getCatalogAuthFailure(), {
|
|
929
|
+
status: 401,
|
|
930
|
+
reason: 'invalid_access_token',
|
|
931
|
+
});
|
|
705
932
|
});
|
|
706
933
|
});
|
|
707
934
|
|