@webex/webex-core 2.59.3-next.1 → 2.59.4
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/.eslintrc.js +6 -6
- package/README.md +79 -79
- package/babel.config.js +3 -3
- package/dist/config.js +24 -24
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +56 -56
- package/dist/credentials-config.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptors/auth.js +28 -28
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/interceptors/default-options.js +24 -24
- package/dist/interceptors/default-options.js.map +1 -1
- package/dist/interceptors/embargo.js +9 -9
- package/dist/interceptors/embargo.js.map +1 -1
- package/dist/interceptors/network-timing.js +19 -19
- package/dist/interceptors/network-timing.js.map +1 -1
- package/dist/interceptors/payload-transformer.js +19 -19
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/interceptors/rate-limit.js +40 -40
- package/dist/interceptors/rate-limit.js.map +1 -1
- package/dist/interceptors/redirect.js +13 -13
- package/dist/interceptors/redirect.js.map +1 -1
- package/dist/interceptors/request-event.js +23 -23
- package/dist/interceptors/request-event.js.map +1 -1
- package/dist/interceptors/request-logger.js +13 -13
- package/dist/interceptors/request-logger.js.map +1 -1
- package/dist/interceptors/request-timing.js +23 -23
- package/dist/interceptors/request-timing.js.map +1 -1
- package/dist/interceptors/response-logger.js +19 -19
- package/dist/interceptors/response-logger.js.map +1 -1
- package/dist/interceptors/user-agent.js +29 -29
- package/dist/interceptors/user-agent.js.map +1 -1
- package/dist/interceptors/webex-tracking-id.js +15 -15
- package/dist/interceptors/webex-tracking-id.js.map +1 -1
- package/dist/interceptors/webex-user-agent.js +13 -13
- package/dist/interceptors/webex-user-agent.js.map +1 -1
- package/dist/lib/batcher.js +83 -83
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +103 -103
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/grant-errors.js +17 -17
- package/dist/lib/credentials/grant-errors.js.map +1 -1
- package/dist/lib/credentials/index.js +2 -2
- package/dist/lib/credentials/index.js.map +1 -1
- package/dist/lib/credentials/scope.js +11 -11
- package/dist/lib/credentials/scope.js.map +1 -1
- package/dist/lib/credentials/token-collection.js +2 -2
- package/dist/lib/credentials/token-collection.js.map +1 -1
- package/dist/lib/credentials/token.js +145 -145
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/page.js +49 -49
- package/dist/lib/page.js.map +1 -1
- 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 +9 -9
- package/dist/lib/services/interceptors/server-error.js.map +1 -1
- package/dist/lib/services/interceptors/service.js +24 -24
- package/dist/lib/services/interceptors/service.js.map +1 -1
- package/dist/lib/services/metrics.js.map +1 -1
- package/dist/lib/services/service-catalog.js +104 -104
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/service-fed-ramp.js.map +1 -1
- package/dist/lib/services/service-host.js +134 -134
- package/dist/lib/services/service-host.js.map +1 -1
- package/dist/lib/services/service-registry.js +175 -175
- package/dist/lib/services/service-registry.js.map +1 -1
- package/dist/lib/services/service-state.js +38 -38
- package/dist/lib/services/service-state.js.map +1 -1
- package/dist/lib/services/service-url.js +31 -31
- package/dist/lib/services/service-url.js.map +1 -1
- package/dist/lib/services/services.js +245 -245
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/stateless-webex-plugin.js +28 -28
- package/dist/lib/stateless-webex-plugin.js.map +1 -1
- package/dist/lib/storage/decorators.js +27 -27
- package/dist/lib/storage/decorators.js.map +1 -1
- package/dist/lib/storage/errors.js +4 -4
- package/dist/lib/storage/errors.js.map +1 -1
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/make-webex-plugin-store.js +44 -44
- package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
- package/dist/lib/storage/make-webex-store.js +40 -40
- package/dist/lib/storage/make-webex-store.js.map +1 -1
- package/dist/lib/storage/memory-store-adapter.js +9 -9
- package/dist/lib/storage/memory-store-adapter.js.map +1 -1
- package/dist/lib/webex-core-plugin-mixin.js +13 -13
- package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-http-error.js +9 -9
- package/dist/lib/webex-http-error.js.map +1 -1
- package/dist/lib/webex-internal-core-plugin-mixin.js +13 -13
- package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-plugin.js +36 -36
- package/dist/lib/webex-plugin.js.map +1 -1
- package/dist/plugins/logger.js +9 -9
- package/dist/plugins/logger.js.map +1 -1
- package/dist/webex-core.js +104 -104
- package/dist/webex-core.js.map +1 -1
- package/dist/webex-internal-core.js +12 -12
- package/dist/webex-internal-core.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +19 -20
- package/process +1 -1
- package/src/config.js +90 -90
- package/src/credentials-config.js +212 -212
- package/src/index.js +62 -62
- package/src/interceptors/auth.js +186 -186
- package/src/interceptors/default-options.js +55 -55
- package/src/interceptors/embargo.js +43 -43
- package/src/interceptors/network-timing.js +54 -54
- package/src/interceptors/payload-transformer.js +55 -55
- package/src/interceptors/rate-limit.js +169 -169
- package/src/interceptors/redirect.js +106 -106
- package/src/interceptors/request-event.js +93 -93
- package/src/interceptors/request-logger.js +78 -78
- package/src/interceptors/request-timing.js +65 -65
- package/src/interceptors/response-logger.js +98 -98
- package/src/interceptors/user-agent.js +77 -77
- package/src/interceptors/webex-tracking-id.js +73 -73
- package/src/interceptors/webex-user-agent.js +79 -79
- package/src/lib/batcher.js +307 -307
- package/src/lib/credentials/credentials.js +552 -552
- package/src/lib/credentials/grant-errors.js +92 -92
- package/src/lib/credentials/index.js +16 -16
- package/src/lib/credentials/scope.js +34 -34
- package/src/lib/credentials/token-collection.js +17 -17
- package/src/lib/credentials/token.js +559 -559
- package/src/lib/page.js +159 -159
- package/src/lib/services/constants.js +9 -9
- package/src/lib/services/index.js +26 -26
- package/src/lib/services/interceptors/server-error.js +48 -48
- package/src/lib/services/interceptors/service.js +101 -101
- package/src/lib/services/metrics.js +4 -4
- package/src/lib/services/service-catalog.js +435 -435
- package/src/lib/services/service-fed-ramp.js +4 -4
- package/src/lib/services/service-host.js +267 -267
- package/src/lib/services/service-registry.js +465 -465
- package/src/lib/services/service-state.js +78 -78
- package/src/lib/services/service-url.js +124 -124
- package/src/lib/services/services.js +1018 -1018
- package/src/lib/stateless-webex-plugin.js +98 -98
- package/src/lib/storage/decorators.js +220 -220
- package/src/lib/storage/errors.js +15 -15
- package/src/lib/storage/index.js +10 -10
- package/src/lib/storage/make-webex-plugin-store.js +211 -211
- package/src/lib/storage/make-webex-store.js +140 -140
- package/src/lib/storage/memory-store-adapter.js +79 -79
- package/src/lib/webex-core-plugin-mixin.js +114 -114
- package/src/lib/webex-http-error.js +61 -61
- package/src/lib/webex-internal-core-plugin-mixin.js +107 -107
- package/src/lib/webex-plugin.js +222 -222
- package/src/plugins/logger.js +60 -60
- package/src/webex-core.js +745 -745
- package/src/webex-internal-core.js +46 -46
- package/test/integration/spec/credentials/credentials.js +139 -139
- package/test/integration/spec/credentials/token.js +102 -102
- package/test/integration/spec/services/service-catalog.js +838 -838
- package/test/integration/spec/services/services.js +1221 -1221
- package/test/integration/spec/webex-core.js +178 -178
- package/test/unit/spec/_setup.js +44 -44
- package/test/unit/spec/credentials/credentials.js +1017 -1017
- package/test/unit/spec/credentials/token.js +441 -441
- package/test/unit/spec/interceptors/auth.js +521 -521
- package/test/unit/spec/interceptors/default-options.js +84 -84
- package/test/unit/spec/interceptors/embargo.js +144 -144
- package/test/unit/spec/interceptors/network-timing.js +49 -49
- package/test/unit/spec/interceptors/payload-transformer.js +155 -155
- package/test/unit/spec/interceptors/rate-limit.js +302 -302
- package/test/unit/spec/interceptors/redirect.js +102 -102
- package/test/unit/spec/interceptors/request-timing.js +92 -92
- package/test/unit/spec/interceptors/user-agent.js +76 -76
- package/test/unit/spec/interceptors/webex-tracking-id.js +76 -76
- package/test/unit/spec/interceptors/webex-user-agent.js +159 -159
- package/test/unit/spec/lib/batcher.js +330 -330
- package/test/unit/spec/lib/page.js +148 -148
- package/test/unit/spec/lib/webex-plugin.js +48 -48
- package/test/unit/spec/services/interceptors/server-error.js +204 -204
- package/test/unit/spec/services/interceptors/service.js +188 -188
- package/test/unit/spec/services/service-catalog.js +194 -194
- package/test/unit/spec/services/service-host.js +260 -260
- package/test/unit/spec/services/service-registry.js +747 -747
- package/test/unit/spec/services/service-state.js +60 -60
- package/test/unit/spec/services/service-url.js +258 -258
- package/test/unit/spec/services/services.js +348 -348
- package/test/unit/spec/storage/persist.js +50 -50
- package/test/unit/spec/storage/storage-adapter.js +12 -12
- package/test/unit/spec/storage/wait-for-value.js +81 -81
- package/test/unit/spec/webex-core.js +253 -253
- package/test/unit/spec/webex-internal-core.js +91 -91
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {assert} from '@webex/test-helper-chai';
|
|
6
|
-
import {DefaultOptionsInterceptor} from '@webex/webex-core';
|
|
7
|
-
|
|
8
|
-
describe('webex-core', () => {
|
|
9
|
-
describe('Interceptors', () => {
|
|
10
|
-
describe('DefaultOptionsInterceptor', () => {
|
|
11
|
-
describe('#onRequest()', () => {
|
|
12
|
-
it('interceptor ok when defaultRequestOptions is undefined', () => {
|
|
13
|
-
const interceptor = Reflect.apply(
|
|
14
|
-
DefaultOptionsInterceptor.create,
|
|
15
|
-
{
|
|
16
|
-
config: {
|
|
17
|
-
appVersion: '1.0.0',
|
|
18
|
-
// defaultRequestOptions omitted/undefined here
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
[]
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const options = {
|
|
25
|
-
existingOption: 'bar',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
interceptor.onRequest(options);
|
|
29
|
-
assert.property(options, 'existingOption');
|
|
30
|
-
assert.equal(options.existingOption, 'bar');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('add default options to existing options', () => {
|
|
34
|
-
const interceptor = Reflect.apply(
|
|
35
|
-
DefaultOptionsInterceptor.create,
|
|
36
|
-
{
|
|
37
|
-
config: {
|
|
38
|
-
defaultRequestOptions: {
|
|
39
|
-
myNewOption1: 'foo1',
|
|
40
|
-
myNewOption2: 'foo2',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
[]
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const options = {
|
|
48
|
-
existingOption: 'bar',
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
interceptor.onRequest(options);
|
|
52
|
-
assert.property(options, 'myNewOption1');
|
|
53
|
-
assert.equal(options.myNewOption1, 'foo1');
|
|
54
|
-
assert.property(options, 'myNewOption2');
|
|
55
|
-
assert.equal(options.myNewOption2, 'foo2');
|
|
56
|
-
assert.property(options, 'existingOption');
|
|
57
|
-
assert.equal(options.existingOption, 'bar');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('default option does not override existing option', () => {
|
|
61
|
-
const interceptor = Reflect.apply(
|
|
62
|
-
DefaultOptionsInterceptor.create,
|
|
63
|
-
{
|
|
64
|
-
config: {
|
|
65
|
-
defaultRequestOptions: {
|
|
66
|
-
existingOption: 'foo',
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
[]
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const options = {
|
|
74
|
-
existingOption: 'bar',
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
interceptor.onRequest(options);
|
|
78
|
-
assert.property(options, 'existingOption');
|
|
79
|
-
assert.equal(options.existingOption, 'bar');
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import {DefaultOptionsInterceptor} from '@webex/webex-core';
|
|
7
|
+
|
|
8
|
+
describe('webex-core', () => {
|
|
9
|
+
describe('Interceptors', () => {
|
|
10
|
+
describe('DefaultOptionsInterceptor', () => {
|
|
11
|
+
describe('#onRequest()', () => {
|
|
12
|
+
it('interceptor ok when defaultRequestOptions is undefined', () => {
|
|
13
|
+
const interceptor = Reflect.apply(
|
|
14
|
+
DefaultOptionsInterceptor.create,
|
|
15
|
+
{
|
|
16
|
+
config: {
|
|
17
|
+
appVersion: '1.0.0',
|
|
18
|
+
// defaultRequestOptions omitted/undefined here
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
[]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const options = {
|
|
25
|
+
existingOption: 'bar',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
interceptor.onRequest(options);
|
|
29
|
+
assert.property(options, 'existingOption');
|
|
30
|
+
assert.equal(options.existingOption, 'bar');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('add default options to existing options', () => {
|
|
34
|
+
const interceptor = Reflect.apply(
|
|
35
|
+
DefaultOptionsInterceptor.create,
|
|
36
|
+
{
|
|
37
|
+
config: {
|
|
38
|
+
defaultRequestOptions: {
|
|
39
|
+
myNewOption1: 'foo1',
|
|
40
|
+
myNewOption2: 'foo2',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
[]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const options = {
|
|
48
|
+
existingOption: 'bar',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interceptor.onRequest(options);
|
|
52
|
+
assert.property(options, 'myNewOption1');
|
|
53
|
+
assert.equal(options.myNewOption1, 'foo1');
|
|
54
|
+
assert.property(options, 'myNewOption2');
|
|
55
|
+
assert.equal(options.myNewOption2, 'foo2');
|
|
56
|
+
assert.property(options, 'existingOption');
|
|
57
|
+
assert.equal(options.existingOption, 'bar');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('default option does not override existing option', () => {
|
|
61
|
+
const interceptor = Reflect.apply(
|
|
62
|
+
DefaultOptionsInterceptor.create,
|
|
63
|
+
{
|
|
64
|
+
config: {
|
|
65
|
+
defaultRequestOptions: {
|
|
66
|
+
existingOption: 'foo',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
[]
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const options = {
|
|
74
|
+
existingOption: 'bar',
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
interceptor.onRequest(options);
|
|
78
|
+
assert.property(options, 'existingOption');
|
|
79
|
+
assert.equal(options.existingOption, 'bar');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
import chai from 'chai';
|
|
2
|
-
import chaiAsPromised from 'chai-as-promised';
|
|
3
|
-
import sinon from 'sinon';
|
|
4
|
-
import {EmbargoInterceptor, WebexHttpError} from '@webex/webex-core';
|
|
5
|
-
|
|
6
|
-
const {assert} = chai;
|
|
7
|
-
|
|
8
|
-
chai.use(chaiAsPromised);
|
|
9
|
-
sinon.assert.expose(chai.assert, {prefix: ''});
|
|
10
|
-
|
|
11
|
-
describe('webex-core', () => {
|
|
12
|
-
describe('EmbargoInterceptor', () => {
|
|
13
|
-
let interceptor;
|
|
14
|
-
|
|
15
|
-
beforeAll(() => {
|
|
16
|
-
interceptor = new EmbargoInterceptor();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('#onResponseError()', () => {
|
|
20
|
-
let credentialsClear;
|
|
21
|
-
let loggerInfo;
|
|
22
|
-
let loggerMessage;
|
|
23
|
-
let options;
|
|
24
|
-
let reason;
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
options = {
|
|
28
|
-
uri: 'http://not-a-url.com/embargoed',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
interceptor.webex = {
|
|
32
|
-
credentials: {
|
|
33
|
-
clear: sinon.spy(),
|
|
34
|
-
},
|
|
35
|
-
internal: {},
|
|
36
|
-
logger: {
|
|
37
|
-
info: sinon.spy(),
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
credentialsClear = interceptor.webex.credentials.clear;
|
|
42
|
-
loggerInfo = interceptor.webex.logger.info;
|
|
43
|
-
loggerMessage = [
|
|
44
|
-
'Received `HTTP 451 Unavailable For Legal Reasons`, ',
|
|
45
|
-
'discarding credentials and device registration',
|
|
46
|
-
].join('');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('when the reason does have a \'451\' status code', () => {
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
reason = new WebexHttpError.InternalServerError({
|
|
52
|
-
message: 'test message',
|
|
53
|
-
statusCode: 451,
|
|
54
|
-
options: {
|
|
55
|
-
url: 'http://not-a-url.com/',
|
|
56
|
-
headers: {
|
|
57
|
-
trackingId: 'tid',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should return a rejected promise with the reason', () =>
|
|
64
|
-
assert
|
|
65
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
66
|
-
.then((error) => assert.equal(reason, error)));
|
|
67
|
-
|
|
68
|
-
it('should clear credentials', () =>
|
|
69
|
-
assert
|
|
70
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
71
|
-
.then(() => assert.called(credentialsClear)));
|
|
72
|
-
|
|
73
|
-
it('should present an appropriate logger message', () =>
|
|
74
|
-
assert
|
|
75
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
76
|
-
.then(() => assert.calledWith(loggerInfo, loggerMessage)));
|
|
77
|
-
|
|
78
|
-
describe('when the device plugin is mounted', () => {
|
|
79
|
-
let deviceClear;
|
|
80
|
-
|
|
81
|
-
beforeEach(() => {
|
|
82
|
-
interceptor.webex.internal.device = {
|
|
83
|
-
clear: sinon.spy(),
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
deviceClear = interceptor.webex.internal.device.clear;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should clear the device', () =>
|
|
90
|
-
assert
|
|
91
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
92
|
-
.then(() => assert.called(deviceClear)));
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('when the reason does not have a \'451\' status code', () => {
|
|
97
|
-
beforeEach(() => {
|
|
98
|
-
reason = new WebexHttpError.InternalServerError({
|
|
99
|
-
message: 'test message',
|
|
100
|
-
statusCode: 452,
|
|
101
|
-
options: {
|
|
102
|
-
url: 'http://not-a-url.com/',
|
|
103
|
-
headers: {
|
|
104
|
-
trackingId: 'tid',
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should return a rejected promise with the reason', () =>
|
|
111
|
-
assert
|
|
112
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
113
|
-
.then((error) => assert.equal(reason, error)));
|
|
114
|
-
|
|
115
|
-
it('should not clear credentials', () =>
|
|
116
|
-
assert
|
|
117
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
118
|
-
.then(() => assert.notCalled(credentialsClear)));
|
|
119
|
-
|
|
120
|
-
it('should not present any logger message', () =>
|
|
121
|
-
assert
|
|
122
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
123
|
-
.then(() => assert.notCalled(loggerInfo)));
|
|
124
|
-
|
|
125
|
-
describe('when the device plugin is mounted', () => {
|
|
126
|
-
let deviceClear;
|
|
127
|
-
|
|
128
|
-
beforeEach(() => {
|
|
129
|
-
interceptor.webex.internal.device = {
|
|
130
|
-
clear: sinon.spy(),
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
deviceClear = interceptor.webex.internal.device.clear;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should not clear the device', () =>
|
|
137
|
-
assert
|
|
138
|
-
.isRejected(interceptor.onResponseError(options, reason))
|
|
139
|
-
.then(() => assert.notCalled(deviceClear)));
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import {EmbargoInterceptor, WebexHttpError} from '@webex/webex-core';
|
|
5
|
+
|
|
6
|
+
const {assert} = chai;
|
|
7
|
+
|
|
8
|
+
chai.use(chaiAsPromised);
|
|
9
|
+
sinon.assert.expose(chai.assert, {prefix: ''});
|
|
10
|
+
|
|
11
|
+
describe('webex-core', () => {
|
|
12
|
+
describe('EmbargoInterceptor', () => {
|
|
13
|
+
let interceptor;
|
|
14
|
+
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
interceptor = new EmbargoInterceptor();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('#onResponseError()', () => {
|
|
20
|
+
let credentialsClear;
|
|
21
|
+
let loggerInfo;
|
|
22
|
+
let loggerMessage;
|
|
23
|
+
let options;
|
|
24
|
+
let reason;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
options = {
|
|
28
|
+
uri: 'http://not-a-url.com/embargoed',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interceptor.webex = {
|
|
32
|
+
credentials: {
|
|
33
|
+
clear: sinon.spy(),
|
|
34
|
+
},
|
|
35
|
+
internal: {},
|
|
36
|
+
logger: {
|
|
37
|
+
info: sinon.spy(),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
credentialsClear = interceptor.webex.credentials.clear;
|
|
42
|
+
loggerInfo = interceptor.webex.logger.info;
|
|
43
|
+
loggerMessage = [
|
|
44
|
+
'Received `HTTP 451 Unavailable For Legal Reasons`, ',
|
|
45
|
+
'discarding credentials and device registration',
|
|
46
|
+
].join('');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('when the reason does have a \'451\' status code', () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
reason = new WebexHttpError.InternalServerError({
|
|
52
|
+
message: 'test message',
|
|
53
|
+
statusCode: 451,
|
|
54
|
+
options: {
|
|
55
|
+
url: 'http://not-a-url.com/',
|
|
56
|
+
headers: {
|
|
57
|
+
trackingId: 'tid',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should return a rejected promise with the reason', () =>
|
|
64
|
+
assert
|
|
65
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
66
|
+
.then((error) => assert.equal(reason, error)));
|
|
67
|
+
|
|
68
|
+
it('should clear credentials', () =>
|
|
69
|
+
assert
|
|
70
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
71
|
+
.then(() => assert.called(credentialsClear)));
|
|
72
|
+
|
|
73
|
+
it('should present an appropriate logger message', () =>
|
|
74
|
+
assert
|
|
75
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
76
|
+
.then(() => assert.calledWith(loggerInfo, loggerMessage)));
|
|
77
|
+
|
|
78
|
+
describe('when the device plugin is mounted', () => {
|
|
79
|
+
let deviceClear;
|
|
80
|
+
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
interceptor.webex.internal.device = {
|
|
83
|
+
clear: sinon.spy(),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
deviceClear = interceptor.webex.internal.device.clear;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should clear the device', () =>
|
|
90
|
+
assert
|
|
91
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
92
|
+
.then(() => assert.called(deviceClear)));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('when the reason does not have a \'451\' status code', () => {
|
|
97
|
+
beforeEach(() => {
|
|
98
|
+
reason = new WebexHttpError.InternalServerError({
|
|
99
|
+
message: 'test message',
|
|
100
|
+
statusCode: 452,
|
|
101
|
+
options: {
|
|
102
|
+
url: 'http://not-a-url.com/',
|
|
103
|
+
headers: {
|
|
104
|
+
trackingId: 'tid',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should return a rejected promise with the reason', () =>
|
|
111
|
+
assert
|
|
112
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
113
|
+
.then((error) => assert.equal(reason, error)));
|
|
114
|
+
|
|
115
|
+
it('should not clear credentials', () =>
|
|
116
|
+
assert
|
|
117
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
118
|
+
.then(() => assert.notCalled(credentialsClear)));
|
|
119
|
+
|
|
120
|
+
it('should not present any logger message', () =>
|
|
121
|
+
assert
|
|
122
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
123
|
+
.then(() => assert.notCalled(loggerInfo)));
|
|
124
|
+
|
|
125
|
+
describe('when the device plugin is mounted', () => {
|
|
126
|
+
let deviceClear;
|
|
127
|
+
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
interceptor.webex.internal.device = {
|
|
130
|
+
clear: sinon.spy(),
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
deviceClear = interceptor.webex.internal.device.clear;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should not clear the device', () =>
|
|
137
|
+
assert
|
|
138
|
+
.isRejected(interceptor.onResponseError(options, reason))
|
|
139
|
+
.then(() => assert.notCalled(deviceClear)));
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {assert} from '@webex/test-helper-chai';
|
|
6
|
-
import {NetworkTimingInterceptor} from '@webex/webex-core';
|
|
7
|
-
|
|
8
|
-
describe('webex-core', () => {
|
|
9
|
-
describe('Interceptors', () => {
|
|
10
|
-
describe('NetworkTimingInterceptor', () => {
|
|
11
|
-
let interceptor;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
interceptor = NetworkTimingInterceptor.create();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('#onRequest()', () => {
|
|
18
|
-
it('adds a $timings object to options if one is not already there', () => {
|
|
19
|
-
const options = {};
|
|
20
|
-
|
|
21
|
-
interceptor.onRequest(options);
|
|
22
|
-
assert.property(options, '$timings');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('adds a networkStart time to options.$timings', () => {
|
|
26
|
-
const options = {};
|
|
27
|
-
|
|
28
|
-
interceptor.onRequest(options);
|
|
29
|
-
assert.property(options, '$timings');
|
|
30
|
-
assert.property(options.$timings, 'networkStart');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('#onResponse', () => {
|
|
35
|
-
it('adds a networkEnd time to options.$timings', () => {
|
|
36
|
-
const options = {
|
|
37
|
-
$timings: {
|
|
38
|
-
networkStart: Date.now() - 100,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
interceptor.onResponse(options);
|
|
43
|
-
assert.property(options, '$timings');
|
|
44
|
-
assert.property(options.$timings, 'networkEnd');
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import {NetworkTimingInterceptor} from '@webex/webex-core';
|
|
7
|
+
|
|
8
|
+
describe('webex-core', () => {
|
|
9
|
+
describe('Interceptors', () => {
|
|
10
|
+
describe('NetworkTimingInterceptor', () => {
|
|
11
|
+
let interceptor;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
interceptor = NetworkTimingInterceptor.create();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('#onRequest()', () => {
|
|
18
|
+
it('adds a $timings object to options if one is not already there', () => {
|
|
19
|
+
const options = {};
|
|
20
|
+
|
|
21
|
+
interceptor.onRequest(options);
|
|
22
|
+
assert.property(options, '$timings');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('adds a networkStart time to options.$timings', () => {
|
|
26
|
+
const options = {};
|
|
27
|
+
|
|
28
|
+
interceptor.onRequest(options);
|
|
29
|
+
assert.property(options, '$timings');
|
|
30
|
+
assert.property(options.$timings, 'networkStart');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('#onResponse', () => {
|
|
35
|
+
it('adds a networkEnd time to options.$timings', () => {
|
|
36
|
+
const options = {
|
|
37
|
+
$timings: {
|
|
38
|
+
networkStart: Date.now() - 100,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
interceptor.onResponse(options);
|
|
43
|
+
assert.property(options, '$timings');
|
|
44
|
+
assert.property(options.$timings, 'networkEnd');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|