@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,60 +1,60 @@
|
|
|
1
|
-
import {assert} from '@webex/test-helper-chai';
|
|
2
|
-
import {serviceConstants, ServiceState} from '@webex/webex-core';
|
|
3
|
-
|
|
4
|
-
describe('webex-core', () => {
|
|
5
|
-
describe('ServiceState', () => {
|
|
6
|
-
let serviceState;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
serviceState = new ServiceState();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe('#constructor()', () => {
|
|
13
|
-
it('should create a collection of catalog states', () => {
|
|
14
|
-
assert.isTrue(
|
|
15
|
-
serviceConstants.SERVICE_CATALOGS.every((catalog) => !!serviceState[catalog])
|
|
16
|
-
);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should initialize states with false collecting values', () => {
|
|
20
|
-
assert.isTrue(
|
|
21
|
-
serviceConstants.SERVICE_CATALOGS.every(
|
|
22
|
-
(catalog) => serviceState[catalog].collecting === false
|
|
23
|
-
)
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('#setCollecting()', () => {
|
|
29
|
-
it('should set the collecting value of a catalog state to true', () => {
|
|
30
|
-
serviceState.setCollecting(serviceConstants.SERVICE_CATALOGS[0], true);
|
|
31
|
-
assert.isTrue(serviceState[serviceConstants.SERVICE_CATALOGS[0]].collecting);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should set the collecting value of a catalog state to false', () => {
|
|
35
|
-
serviceState.setCollecting(serviceConstants.SERVICE_CATALOGS[0], false);
|
|
36
|
-
assert.isFalse(serviceState[serviceConstants.SERVICE_CATALOGS[0]].collecting);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('#setReady()', () => {
|
|
41
|
-
it('should set the collecting value of a catalog state to true', () => {
|
|
42
|
-
serviceState.setReady(serviceConstants.SERVICE_CATALOGS[0], true);
|
|
43
|
-
assert.isTrue(serviceState[serviceConstants.SERVICE_CATALOGS[0]].ready);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should set the collecting value of a catalog state to false', () => {
|
|
47
|
-
serviceState.setReady(serviceConstants.SERVICE_CATALOGS[0], false);
|
|
48
|
-
assert.isFalse(serviceState[serviceConstants.SERVICE_CATALOGS[0]].ready);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('static methods', () => {
|
|
53
|
-
describe('#generateCatalogState()', () => {
|
|
54
|
-
it('returns an object with the correct keys', () => {
|
|
55
|
-
assert.containsAllKeys(ServiceState.generateCatalogState(), ['collecting', 'ready']);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
1
|
+
import {assert} from '@webex/test-helper-chai';
|
|
2
|
+
import {serviceConstants, ServiceState} from '@webex/webex-core';
|
|
3
|
+
|
|
4
|
+
describe('webex-core', () => {
|
|
5
|
+
describe('ServiceState', () => {
|
|
6
|
+
let serviceState;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
serviceState = new ServiceState();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('#constructor()', () => {
|
|
13
|
+
it('should create a collection of catalog states', () => {
|
|
14
|
+
assert.isTrue(
|
|
15
|
+
serviceConstants.SERVICE_CATALOGS.every((catalog) => !!serviceState[catalog])
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should initialize states with false collecting values', () => {
|
|
20
|
+
assert.isTrue(
|
|
21
|
+
serviceConstants.SERVICE_CATALOGS.every(
|
|
22
|
+
(catalog) => serviceState[catalog].collecting === false
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('#setCollecting()', () => {
|
|
29
|
+
it('should set the collecting value of a catalog state to true', () => {
|
|
30
|
+
serviceState.setCollecting(serviceConstants.SERVICE_CATALOGS[0], true);
|
|
31
|
+
assert.isTrue(serviceState[serviceConstants.SERVICE_CATALOGS[0]].collecting);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should set the collecting value of a catalog state to false', () => {
|
|
35
|
+
serviceState.setCollecting(serviceConstants.SERVICE_CATALOGS[0], false);
|
|
36
|
+
assert.isFalse(serviceState[serviceConstants.SERVICE_CATALOGS[0]].collecting);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('#setReady()', () => {
|
|
41
|
+
it('should set the collecting value of a catalog state to true', () => {
|
|
42
|
+
serviceState.setReady(serviceConstants.SERVICE_CATALOGS[0], true);
|
|
43
|
+
assert.isTrue(serviceState[serviceConstants.SERVICE_CATALOGS[0]].ready);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should set the collecting value of a catalog state to false', () => {
|
|
47
|
+
serviceState.setReady(serviceConstants.SERVICE_CATALOGS[0], false);
|
|
48
|
+
assert.isFalse(serviceState[serviceConstants.SERVICE_CATALOGS[0]].ready);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('static methods', () => {
|
|
53
|
+
describe('#generateCatalogState()', () => {
|
|
54
|
+
it('returns an object with the correct keys', () => {
|
|
55
|
+
assert.containsAllKeys(ServiceState.generateCatalogState(), ['collecting', 'ready']);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,258 +1,258 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {assert} from '@webex/test-helper-chai';
|
|
6
|
-
import MockWebex from '@webex/test-helper-mock-webex';
|
|
7
|
-
import {Services, ServiceUrl} from '@webex/webex-core';
|
|
8
|
-
|
|
9
|
-
/* eslint-disable no-underscore-dangle */
|
|
10
|
-
describe('webex-core', () => {
|
|
11
|
-
describe('ServiceUrl', () => {
|
|
12
|
-
let webex;
|
|
13
|
-
let serviceUrl;
|
|
14
|
-
let template;
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
webex = new MockWebex();
|
|
18
|
-
/* eslint-disable-next-line no-unused-vars */
|
|
19
|
-
const services = new Services(undefined, {parent: webex});
|
|
20
|
-
|
|
21
|
-
template = {
|
|
22
|
-
defaultUrl: 'https://example.com/api/v1',
|
|
23
|
-
hosts: [
|
|
24
|
-
{
|
|
25
|
-
host: 'example-host-p1.com',
|
|
26
|
-
priority: 1,
|
|
27
|
-
ttl: -1,
|
|
28
|
-
id: '1',
|
|
29
|
-
homeCluster: false,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
host: 'example-host-p2.com',
|
|
33
|
-
priority: 2,
|
|
34
|
-
ttl: -1,
|
|
35
|
-
id: '2',
|
|
36
|
-
homeCluster: false,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
host: 'example-host-p3.com',
|
|
40
|
-
priority: 3,
|
|
41
|
-
ttl: -1,
|
|
42
|
-
id: '3',
|
|
43
|
-
homeCluster: true,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
host: 'example-host-p4.com',
|
|
47
|
-
priority: 4,
|
|
48
|
-
ttl: -1,
|
|
49
|
-
id: '4',
|
|
50
|
-
homeCluster: true,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
host: 'example-host-p5.com',
|
|
54
|
-
priority: 5,
|
|
55
|
-
ttl: -1,
|
|
56
|
-
id: '5',
|
|
57
|
-
homeCluster: true,
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
name: 'example',
|
|
61
|
-
};
|
|
62
|
-
serviceUrl = new ServiceUrl({...template});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('#namespace', () => {
|
|
66
|
-
it('is accurate to plugin name', () => {
|
|
67
|
-
assert.equal(serviceUrl.namespace, 'ServiceUrl');
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('#defautUrl', () => {
|
|
72
|
-
it('is valid value', () => {
|
|
73
|
-
assert.typeOf(serviceUrl.defaultUrl, 'string');
|
|
74
|
-
assert.equal(serviceUrl.defaultUrl, 'https://example.com/api/v1');
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('#hosts', () => {
|
|
79
|
-
it('is valid value', () => {
|
|
80
|
-
assert.typeOf(serviceUrl.hosts, 'array');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('contains all appended hosts on construction', () => {
|
|
84
|
-
template.hosts.forEach((host) => {
|
|
85
|
-
assert.include([...serviceUrl.hosts], host);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('#name', () => {
|
|
91
|
-
it('is valid value', () => {
|
|
92
|
-
assert.typeOf(serviceUrl.name, 'string');
|
|
93
|
-
assert.equal(serviceUrl.name, 'example');
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('#_generateHostUrl()', () => {
|
|
98
|
-
it('returns a string', () => {
|
|
99
|
-
serviceUrl.hosts.forEach(({host}) => {
|
|
100
|
-
assert.typeOf(serviceUrl._generateHostUrl(host), 'string');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('replaces the host of a pass in url', () => {
|
|
105
|
-
serviceUrl.hosts.forEach(({host}) => {
|
|
106
|
-
assert.include(serviceUrl._generateHostUrl(host), `https://${host}/api/v1`);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('#_getHostUrls()', () => {
|
|
112
|
-
it('returns an array of objects with an updated url and priority', () => {
|
|
113
|
-
serviceUrl._getHostUrls().forEach((hu) => {
|
|
114
|
-
assert.hasAllKeys(hu, ['url', 'priority']);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('generates an array objects from current hosts', () => {
|
|
119
|
-
const hostUrls = serviceUrl._getHostUrls();
|
|
120
|
-
|
|
121
|
-
hostUrls.forEach((hu, i) => {
|
|
122
|
-
assert.equal(hu.url, serviceUrl._generateHostUrl(serviceUrl.hosts[i].host));
|
|
123
|
-
assert.equal(hu.priority, serviceUrl.hosts[i].priority);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('#_getPriorityHostUrl()', () => {
|
|
129
|
-
let highPriorityHost;
|
|
130
|
-
|
|
131
|
-
beforeEach(() => {
|
|
132
|
-
highPriorityHost = serviceUrl._generateHostUrl(
|
|
133
|
-
serviceUrl.hosts.reduce((o, c) => (o.priority > c.priority || !o.homeCluster ? c : o))
|
|
134
|
-
.host
|
|
135
|
-
);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('validates that the retrieved high priority host matches the manually retrieved high priority host', () => {
|
|
139
|
-
assert.equal(serviceUrl._getPriorityHostUrl(), highPriorityHost);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should reset the hosts when all have failed', () => {
|
|
143
|
-
serviceUrl.hosts.forEach((host) => {
|
|
144
|
-
/* eslint-disable-next-line no-param-reassign */
|
|
145
|
-
host.failed = true;
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
serviceUrl._getPriorityHostUrl();
|
|
149
|
-
|
|
150
|
-
const homeClusterUrls = serviceUrl.hosts.filter((host) => host.homeCluster);
|
|
151
|
-
|
|
152
|
-
assert.isTrue(homeClusterUrls.every((host) => !host.failed));
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('#failHost()', () => {
|
|
157
|
-
let host;
|
|
158
|
-
let hostUrl;
|
|
159
|
-
|
|
160
|
-
beforeEach(() => {
|
|
161
|
-
host = 'example-host-px.com';
|
|
162
|
-
hostUrl = 'https://example-host-px.com/api/v1';
|
|
163
|
-
serviceUrl.hosts.push({host, priority: 10, ttl: -1});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('marks a host as failed', () => {
|
|
167
|
-
serviceUrl.failHost(hostUrl);
|
|
168
|
-
|
|
169
|
-
const removedHost = serviceUrl.hosts.find((currentHost) => currentHost.host === host);
|
|
170
|
-
|
|
171
|
-
assert.isTrue(removedHost.failed);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('does not mark failed a host if the hostUrl is defaultUrl', () => {
|
|
175
|
-
// Remove here as countermeasure to beforeEach
|
|
176
|
-
serviceUrl.failHost(hostUrl);
|
|
177
|
-
|
|
178
|
-
const hostLength = serviceUrl.hosts.length;
|
|
179
|
-
const foundHost = serviceUrl.failHost(serviceUrl.defaultUrl);
|
|
180
|
-
|
|
181
|
-
assert.isTrue(foundHost);
|
|
182
|
-
assert.equal(hostLength, serviceUrl.hosts.length);
|
|
183
|
-
assert.isDefined(serviceUrl.defaultUrl);
|
|
184
|
-
assert.equal(serviceUrl.defaultUrl, template.defaultUrl);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('returns true if hostUrl was found', () => {
|
|
188
|
-
const removedHostResult = serviceUrl.failHost(hostUrl);
|
|
189
|
-
|
|
190
|
-
assert.isTrue(removedHostResult);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('returns false if hostUrl was not found', () => {
|
|
194
|
-
const removedHostResult = serviceUrl.failHost('https://someurl.com/api/vq');
|
|
195
|
-
|
|
196
|
-
assert.isFalse(removedHostResult);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe('#get()', () => {
|
|
201
|
-
it('returns a string', () => {
|
|
202
|
-
assert.typeOf(serviceUrl.get(), 'string');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
// This may be updated in a later PR if
|
|
206
|
-
// changes to federation before release occur.
|
|
207
|
-
it('returns the defaultUrl value', () => {
|
|
208
|
-
assert.equal(serviceUrl.get(), serviceUrl.defaultUrl);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('returns the highest priority host as url', () => {
|
|
212
|
-
const hpUrl = serviceUrl.get(true);
|
|
213
|
-
|
|
214
|
-
assert.equal(hpUrl, serviceUrl._getPriorityHostUrl());
|
|
215
|
-
assert.isDefined(serviceUrl.hosts.find((hostObj) => hpUrl.includes(hostObj.host)));
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
describe('when a clusterId is provided', () => {
|
|
219
|
-
let highPriorityHost;
|
|
220
|
-
let hosts;
|
|
221
|
-
let url;
|
|
222
|
-
|
|
223
|
-
describe('when the clusterId is a home cluster', () => {
|
|
224
|
-
beforeEach(() => {
|
|
225
|
-
hosts = serviceUrl.hosts.filter((host) => host.homeCluster);
|
|
226
|
-
|
|
227
|
-
highPriorityHost = hosts.reduce((current, next) =>
|
|
228
|
-
current.priority <= next.priority ? current : next
|
|
229
|
-
).host;
|
|
230
|
-
|
|
231
|
-
url = serviceUrl.get(true, hosts[0].id);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should return a url from the correct cluster', () => {
|
|
235
|
-
assert.isTrue(url.includes(highPriorityHost));
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe('when the clusterId is not a home cluster', () => {
|
|
240
|
-
beforeEach(() => {
|
|
241
|
-
hosts = serviceUrl.hosts.filter((host) => !host.homeCluster);
|
|
242
|
-
|
|
243
|
-
highPriorityHost = hosts.reduce((current, next) =>
|
|
244
|
-
current.priority <= next.priority ? current : next
|
|
245
|
-
).host;
|
|
246
|
-
|
|
247
|
-
url = serviceUrl.get(true, hosts[0].id);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it('should return a url from the correct cluster', () => {
|
|
251
|
-
assert.isTrue(url.includes(highPriorityHost));
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
/* eslint-enable no-underscore-dangle */
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
7
|
+
import {Services, ServiceUrl} from '@webex/webex-core';
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-underscore-dangle */
|
|
10
|
+
describe('webex-core', () => {
|
|
11
|
+
describe('ServiceUrl', () => {
|
|
12
|
+
let webex;
|
|
13
|
+
let serviceUrl;
|
|
14
|
+
let template;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
webex = new MockWebex();
|
|
18
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
19
|
+
const services = new Services(undefined, {parent: webex});
|
|
20
|
+
|
|
21
|
+
template = {
|
|
22
|
+
defaultUrl: 'https://example.com/api/v1',
|
|
23
|
+
hosts: [
|
|
24
|
+
{
|
|
25
|
+
host: 'example-host-p1.com',
|
|
26
|
+
priority: 1,
|
|
27
|
+
ttl: -1,
|
|
28
|
+
id: '1',
|
|
29
|
+
homeCluster: false,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
host: 'example-host-p2.com',
|
|
33
|
+
priority: 2,
|
|
34
|
+
ttl: -1,
|
|
35
|
+
id: '2',
|
|
36
|
+
homeCluster: false,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
host: 'example-host-p3.com',
|
|
40
|
+
priority: 3,
|
|
41
|
+
ttl: -1,
|
|
42
|
+
id: '3',
|
|
43
|
+
homeCluster: true,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
host: 'example-host-p4.com',
|
|
47
|
+
priority: 4,
|
|
48
|
+
ttl: -1,
|
|
49
|
+
id: '4',
|
|
50
|
+
homeCluster: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
host: 'example-host-p5.com',
|
|
54
|
+
priority: 5,
|
|
55
|
+
ttl: -1,
|
|
56
|
+
id: '5',
|
|
57
|
+
homeCluster: true,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
name: 'example',
|
|
61
|
+
};
|
|
62
|
+
serviceUrl = new ServiceUrl({...template});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('#namespace', () => {
|
|
66
|
+
it('is accurate to plugin name', () => {
|
|
67
|
+
assert.equal(serviceUrl.namespace, 'ServiceUrl');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('#defautUrl', () => {
|
|
72
|
+
it('is valid value', () => {
|
|
73
|
+
assert.typeOf(serviceUrl.defaultUrl, 'string');
|
|
74
|
+
assert.equal(serviceUrl.defaultUrl, 'https://example.com/api/v1');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('#hosts', () => {
|
|
79
|
+
it('is valid value', () => {
|
|
80
|
+
assert.typeOf(serviceUrl.hosts, 'array');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('contains all appended hosts on construction', () => {
|
|
84
|
+
template.hosts.forEach((host) => {
|
|
85
|
+
assert.include([...serviceUrl.hosts], host);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('#name', () => {
|
|
91
|
+
it('is valid value', () => {
|
|
92
|
+
assert.typeOf(serviceUrl.name, 'string');
|
|
93
|
+
assert.equal(serviceUrl.name, 'example');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('#_generateHostUrl()', () => {
|
|
98
|
+
it('returns a string', () => {
|
|
99
|
+
serviceUrl.hosts.forEach(({host}) => {
|
|
100
|
+
assert.typeOf(serviceUrl._generateHostUrl(host), 'string');
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('replaces the host of a pass in url', () => {
|
|
105
|
+
serviceUrl.hosts.forEach(({host}) => {
|
|
106
|
+
assert.include(serviceUrl._generateHostUrl(host), `https://${host}/api/v1`);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('#_getHostUrls()', () => {
|
|
112
|
+
it('returns an array of objects with an updated url and priority', () => {
|
|
113
|
+
serviceUrl._getHostUrls().forEach((hu) => {
|
|
114
|
+
assert.hasAllKeys(hu, ['url', 'priority']);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('generates an array objects from current hosts', () => {
|
|
119
|
+
const hostUrls = serviceUrl._getHostUrls();
|
|
120
|
+
|
|
121
|
+
hostUrls.forEach((hu, i) => {
|
|
122
|
+
assert.equal(hu.url, serviceUrl._generateHostUrl(serviceUrl.hosts[i].host));
|
|
123
|
+
assert.equal(hu.priority, serviceUrl.hosts[i].priority);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('#_getPriorityHostUrl()', () => {
|
|
129
|
+
let highPriorityHost;
|
|
130
|
+
|
|
131
|
+
beforeEach(() => {
|
|
132
|
+
highPriorityHost = serviceUrl._generateHostUrl(
|
|
133
|
+
serviceUrl.hosts.reduce((o, c) => (o.priority > c.priority || !o.homeCluster ? c : o))
|
|
134
|
+
.host
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('validates that the retrieved high priority host matches the manually retrieved high priority host', () => {
|
|
139
|
+
assert.equal(serviceUrl._getPriorityHostUrl(), highPriorityHost);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should reset the hosts when all have failed', () => {
|
|
143
|
+
serviceUrl.hosts.forEach((host) => {
|
|
144
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
145
|
+
host.failed = true;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
serviceUrl._getPriorityHostUrl();
|
|
149
|
+
|
|
150
|
+
const homeClusterUrls = serviceUrl.hosts.filter((host) => host.homeCluster);
|
|
151
|
+
|
|
152
|
+
assert.isTrue(homeClusterUrls.every((host) => !host.failed));
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('#failHost()', () => {
|
|
157
|
+
let host;
|
|
158
|
+
let hostUrl;
|
|
159
|
+
|
|
160
|
+
beforeEach(() => {
|
|
161
|
+
host = 'example-host-px.com';
|
|
162
|
+
hostUrl = 'https://example-host-px.com/api/v1';
|
|
163
|
+
serviceUrl.hosts.push({host, priority: 10, ttl: -1});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('marks a host as failed', () => {
|
|
167
|
+
serviceUrl.failHost(hostUrl);
|
|
168
|
+
|
|
169
|
+
const removedHost = serviceUrl.hosts.find((currentHost) => currentHost.host === host);
|
|
170
|
+
|
|
171
|
+
assert.isTrue(removedHost.failed);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('does not mark failed a host if the hostUrl is defaultUrl', () => {
|
|
175
|
+
// Remove here as countermeasure to beforeEach
|
|
176
|
+
serviceUrl.failHost(hostUrl);
|
|
177
|
+
|
|
178
|
+
const hostLength = serviceUrl.hosts.length;
|
|
179
|
+
const foundHost = serviceUrl.failHost(serviceUrl.defaultUrl);
|
|
180
|
+
|
|
181
|
+
assert.isTrue(foundHost);
|
|
182
|
+
assert.equal(hostLength, serviceUrl.hosts.length);
|
|
183
|
+
assert.isDefined(serviceUrl.defaultUrl);
|
|
184
|
+
assert.equal(serviceUrl.defaultUrl, template.defaultUrl);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('returns true if hostUrl was found', () => {
|
|
188
|
+
const removedHostResult = serviceUrl.failHost(hostUrl);
|
|
189
|
+
|
|
190
|
+
assert.isTrue(removedHostResult);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('returns false if hostUrl was not found', () => {
|
|
194
|
+
const removedHostResult = serviceUrl.failHost('https://someurl.com/api/vq');
|
|
195
|
+
|
|
196
|
+
assert.isFalse(removedHostResult);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('#get()', () => {
|
|
201
|
+
it('returns a string', () => {
|
|
202
|
+
assert.typeOf(serviceUrl.get(), 'string');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// This may be updated in a later PR if
|
|
206
|
+
// changes to federation before release occur.
|
|
207
|
+
it('returns the defaultUrl value', () => {
|
|
208
|
+
assert.equal(serviceUrl.get(), serviceUrl.defaultUrl);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('returns the highest priority host as url', () => {
|
|
212
|
+
const hpUrl = serviceUrl.get(true);
|
|
213
|
+
|
|
214
|
+
assert.equal(hpUrl, serviceUrl._getPriorityHostUrl());
|
|
215
|
+
assert.isDefined(serviceUrl.hosts.find((hostObj) => hpUrl.includes(hostObj.host)));
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('when a clusterId is provided', () => {
|
|
219
|
+
let highPriorityHost;
|
|
220
|
+
let hosts;
|
|
221
|
+
let url;
|
|
222
|
+
|
|
223
|
+
describe('when the clusterId is a home cluster', () => {
|
|
224
|
+
beforeEach(() => {
|
|
225
|
+
hosts = serviceUrl.hosts.filter((host) => host.homeCluster);
|
|
226
|
+
|
|
227
|
+
highPriorityHost = hosts.reduce((current, next) =>
|
|
228
|
+
current.priority <= next.priority ? current : next
|
|
229
|
+
).host;
|
|
230
|
+
|
|
231
|
+
url = serviceUrl.get(true, hosts[0].id);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should return a url from the correct cluster', () => {
|
|
235
|
+
assert.isTrue(url.includes(highPriorityHost));
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe('when the clusterId is not a home cluster', () => {
|
|
240
|
+
beforeEach(() => {
|
|
241
|
+
hosts = serviceUrl.hosts.filter((host) => !host.homeCluster);
|
|
242
|
+
|
|
243
|
+
highPriorityHost = hosts.reduce((current, next) =>
|
|
244
|
+
current.priority <= next.priority ? current : next
|
|
245
|
+
).host;
|
|
246
|
+
|
|
247
|
+
url = serviceUrl.get(true, hosts[0].id);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('should return a url from the correct cluster', () => {
|
|
251
|
+
assert.isTrue(url.includes(highPriorityHost));
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
/* eslint-enable no-underscore-dangle */
|