@webex/webex-core 3.8.1-next.3 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -87
- 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/services/services.js +1 -1
- package/dist/lib/services-v2/metrics.js.map +1 -1
- package/dist/lib/services-v2/service-catalog.js +10 -11
- package/dist/lib/services-v2/service-catalog.js.map +1 -1
- package/dist/lib/services-v2/service-host.js +300 -0
- package/dist/lib/services-v2/service-host.js.map +1 -0
- package/dist/lib/services-v2/service-registry.js +534 -0
- package/dist/lib/services-v2/service-registry.js.map +1 -0
- package/dist/lib/services-v2/service-state.js +97 -0
- package/dist/lib/services-v2/service-state.js.map +1 -0
- package/dist/lib/services-v2/service-url.js +119 -0
- package/dist/lib/services-v2/service-url.js.map +1 -0
- package/dist/lib/services-v2/services-v2.js +66 -55
- package/dist/lib/services-v2/services-v2.js.map +1 -1
- package/dist/lib/services-v2/types.js.map +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/dist/webex-core.js.map +1 -1
- package/package.json +13 -13
- package/src/lib/services-v2/service-catalog.ts +19 -20
- package/src/lib/services-v2/{services-v2.ts → services-v2.js} +93 -119
- package/src/lib/services-v2/types.ts +2 -62
- package/test/integration/spec/services/services.js +0 -11
- package/test/unit/spec/services-v2/services-v2.ts +436 -390
- package/test/integration/spec/services-v2/service-catalog.js +0 -667
- package/test/integration/spec/services-v2/services-v2.js +0 -1047
- /package/src/lib/services-v2/{metrics.ts → metrics.js} +0 -0
|
@@ -33,240 +33,287 @@ describe('webex-core', () => {
|
|
|
33
33
|
catalog = services._getCatalog();
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
describe('#initialize', () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('#initServiceCatalogs', () => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
});
|
|
36
|
+
// describe('#initialize', () => {
|
|
37
|
+
// it('initFailed is false when initialization succeeds and credentials are available', async () => {
|
|
38
|
+
// services.listenToOnce = sinon.stub();
|
|
39
|
+
// services.initServiceCatalogs = sinon.stub().returns(Promise.resolve());
|
|
40
|
+
// services.webex.credentials = {
|
|
41
|
+
// supertoken: {
|
|
42
|
+
// access_token: 'token',
|
|
43
|
+
// },
|
|
44
|
+
// };
|
|
45
|
+
|
|
46
|
+
// services.initialize();
|
|
47
|
+
|
|
48
|
+
// // call the onReady callback
|
|
49
|
+
// services.listenToOnce.getCall(1).args[2]();
|
|
50
|
+
// await waitForAsync();
|
|
51
|
+
|
|
52
|
+
// assert.isFalse(services.initFailed);
|
|
53
|
+
// });
|
|
54
|
+
|
|
55
|
+
// it('initFailed is false when initialization succeeds no credentials are available', async () => {
|
|
56
|
+
// services.listenToOnce = sinon.stub();
|
|
57
|
+
// services.collectPreauthCatalog = sinon.stub().returns(Promise.resolve());
|
|
58
|
+
|
|
59
|
+
// services.initialize();
|
|
60
|
+
|
|
61
|
+
// // call the onReady callback
|
|
62
|
+
// services.listenToOnce.getCall(1).args[2]();
|
|
63
|
+
// await waitForAsync();
|
|
64
|
+
|
|
65
|
+
// assert.isFalse(services.initFailed);
|
|
66
|
+
// });
|
|
67
|
+
|
|
68
|
+
// it.each([
|
|
69
|
+
// {error: new Error('failed'), expectedMessage: 'failed'},
|
|
70
|
+
// {error: undefined, expectedMessage: undefined},
|
|
71
|
+
// ])(
|
|
72
|
+
// 'sets initFailed to true when collectPreauthCatalog errors',
|
|
73
|
+
// async ({error, expectedMessage}) => {
|
|
74
|
+
// services.collectPreauthCatalog = sinon.stub().callsFake(() => {
|
|
75
|
+
// return Promise.reject(error);
|
|
76
|
+
// });
|
|
77
|
+
|
|
78
|
+
// services.listenToOnce = sinon.stub();
|
|
79
|
+
// services.logger.error = sinon.stub();
|
|
80
|
+
|
|
81
|
+
// services.initialize();
|
|
82
|
+
|
|
83
|
+
// // call the onReady callback
|
|
84
|
+
// services.listenToOnce.getCall(1).args[2]();
|
|
85
|
+
|
|
86
|
+
// await waitForAsync();
|
|
87
|
+
|
|
88
|
+
// assert.isTrue(services.initFailed);
|
|
89
|
+
// sinon.assert.calledWith(
|
|
90
|
+
// services.logger.error,
|
|
91
|
+
// `services: failed to init initial services when no credentials available, ${expectedMessage}`
|
|
92
|
+
// );
|
|
93
|
+
// }
|
|
94
|
+
// );
|
|
95
|
+
|
|
96
|
+
// it.each([
|
|
97
|
+
// {error: new Error('failed'), expectedMessage: 'failed'},
|
|
98
|
+
// {error: undefined, expectedMessage: undefined},
|
|
99
|
+
// ])(
|
|
100
|
+
// 'sets initFailed to true when initServiceCatalogs errors',
|
|
101
|
+
// async ({error, expectedMessage}) => {
|
|
102
|
+
// services.initServiceCatalogs = sinon.stub().callsFake(() => {
|
|
103
|
+
// return Promise.reject(error);
|
|
104
|
+
// });
|
|
105
|
+
// services.webex.credentials = {
|
|
106
|
+
// supertoken: {
|
|
107
|
+
// access_token: 'token',
|
|
108
|
+
// },
|
|
109
|
+
// };
|
|
110
|
+
|
|
111
|
+
// services.listenToOnce = sinon.stub();
|
|
112
|
+
// services.logger.error = sinon.stub();
|
|
113
|
+
|
|
114
|
+
// services.initialize();
|
|
115
|
+
|
|
116
|
+
// // call the onReady callback
|
|
117
|
+
// services.listenToOnce.getCall(1).args[2]();
|
|
118
|
+
|
|
119
|
+
// await waitForAsync();
|
|
120
|
+
|
|
121
|
+
// assert.isTrue(services.initFailed);
|
|
122
|
+
// sinon.assert.calledWith(
|
|
123
|
+
// services.logger.error,
|
|
124
|
+
// `services: failed to init initial services when credentials available, ${expectedMessage}`
|
|
125
|
+
// );
|
|
126
|
+
// }
|
|
127
|
+
// );
|
|
128
|
+
// });
|
|
129
|
+
|
|
130
|
+
// describe('#initServiceCatalogs', () => {
|
|
131
|
+
// it('does not set initFailed to true when updateServices succeeds', async () => {
|
|
132
|
+
// services.webex.credentials = {
|
|
133
|
+
// getOrgId: sinon.stub().returns('orgId'),
|
|
134
|
+
// canAuthorize: true,
|
|
135
|
+
// };
|
|
136
|
+
|
|
137
|
+
// services.collectPreauthCatalog = sinon.stub().callsFake(() => {
|
|
138
|
+
// return Promise.resolve();
|
|
139
|
+
// });
|
|
140
|
+
|
|
141
|
+
// services.updateServices = sinon.stub().callsFake(() => {
|
|
142
|
+
// return Promise.resolve();
|
|
143
|
+
// });
|
|
144
|
+
|
|
145
|
+
// services.logger.error = sinon.stub();
|
|
146
|
+
|
|
147
|
+
// await services.initServiceCatalogs();
|
|
148
|
+
|
|
149
|
+
// assert.isFalse(services.initFailed);
|
|
150
|
+
|
|
151
|
+
// sinon.assert.calledWith(services.collectPreauthCatalog, {orgId: 'orgId'});
|
|
152
|
+
// sinon.assert.notCalled(services.logger.warn);
|
|
153
|
+
// });
|
|
154
|
+
|
|
155
|
+
// it('sets initFailed to true when updateServices errors', async () => {
|
|
156
|
+
// const error = new Error('failed');
|
|
157
|
+
|
|
158
|
+
// services.webex.credentials = {
|
|
159
|
+
// getOrgId: sinon.stub().returns('orgId'),
|
|
160
|
+
// canAuthorize: true,
|
|
161
|
+
// };
|
|
162
|
+
|
|
163
|
+
// services.collectPreauthCatalog = sinon.stub().callsFake(() => {
|
|
164
|
+
// return Promise.resolve();
|
|
165
|
+
// });
|
|
166
|
+
|
|
167
|
+
// services.updateServices = sinon.stub().callsFake(() => {
|
|
168
|
+
// return Promise.reject(error);
|
|
169
|
+
// });
|
|
170
|
+
|
|
171
|
+
// services.logger.error = sinon.stub();
|
|
172
|
+
|
|
173
|
+
// await services.initServiceCatalogs();
|
|
174
|
+
|
|
175
|
+
// assert.isTrue(services.initFailed);
|
|
176
|
+
|
|
177
|
+
// sinon.assert.calledWith(services.collectPreauthCatalog, {orgId: 'orgId'});
|
|
178
|
+
// sinon.assert.calledWith(services.logger.warn, 'services: cannot retrieve postauth catalog');
|
|
179
|
+
// });
|
|
180
|
+
// });
|
|
181
|
+
|
|
182
|
+
// describe('class members', () => {
|
|
183
|
+
// describe('#registries', () => {
|
|
184
|
+
// it('should be a weakmap', () => {
|
|
185
|
+
// assert.instanceOf(services.registries, WeakMap);
|
|
186
|
+
// });
|
|
187
|
+
// });
|
|
188
|
+
|
|
189
|
+
// describe('#states', () => {
|
|
190
|
+
// it('should be a weakmap', () => {
|
|
191
|
+
// assert.instanceOf(services.states, WeakMap);
|
|
192
|
+
// });
|
|
193
|
+
// });
|
|
194
|
+
// });
|
|
195
|
+
|
|
196
|
+
// describe('class methods', () => {
|
|
197
|
+
// describe('#getRegistry', () => {
|
|
198
|
+
// it('should be a service registry', () => {
|
|
199
|
+
// assert.instanceOf(services.getRegistry(), ServiceRegistry);
|
|
200
|
+
// });
|
|
201
|
+
// });
|
|
202
|
+
|
|
203
|
+
// describe('#getState', () => {
|
|
204
|
+
// it('should be a service state', () => {
|
|
205
|
+
// assert.instanceOf(services.getState(), ServiceState);
|
|
206
|
+
// });
|
|
207
|
+
// });
|
|
208
|
+
// });
|
|
209
|
+
|
|
210
|
+
// describe('#namespace', () => {
|
|
211
|
+
// it('is accurate to plugin name', () => {
|
|
212
|
+
// assert.equal(services.namespace, 'Services');
|
|
213
|
+
// });
|
|
214
|
+
// });
|
|
215
|
+
|
|
216
|
+
// describe('#_catalogs', () => {
|
|
217
|
+
// it('is a weakmap', () => {
|
|
218
|
+
// assert.typeOf(services._catalogs, 'weakmap');
|
|
219
|
+
// });
|
|
220
|
+
// });
|
|
221
|
+
|
|
222
|
+
// describe('#validateDomains', () => {
|
|
223
|
+
// it('is a boolean', () => {
|
|
224
|
+
// assert.isBoolean(services.validateDomains);
|
|
225
|
+
// });
|
|
226
|
+
// });
|
|
227
|
+
|
|
228
|
+
// describe('#initFailed', () => {
|
|
229
|
+
// it('is a boolean', () => {
|
|
230
|
+
// assert.isFalse(services.initFailed);
|
|
231
|
+
// });
|
|
232
|
+
// });
|
|
233
|
+
|
|
234
|
+
// describe('#list()', () => {
|
|
235
|
+
// let serviceList;
|
|
236
|
+
|
|
237
|
+
// beforeEach(() => {
|
|
238
|
+
// serviceList = services.list();
|
|
239
|
+
// });
|
|
240
|
+
|
|
241
|
+
// it('must return an object', () => {
|
|
242
|
+
// assert.typeOf(serviceList, 'object');
|
|
243
|
+
// });
|
|
244
|
+
|
|
245
|
+
// it('returned list must be of shape {Record<string, string>}', () => {
|
|
246
|
+
// Object.keys(serviceList).forEach((key) => {
|
|
247
|
+
// assert.typeOf(key, 'string');
|
|
248
|
+
// assert.typeOf(serviceList[key], 'string');
|
|
249
|
+
// });
|
|
250
|
+
// });
|
|
251
|
+
// });
|
|
252
|
+
|
|
253
|
+
// describe('#fetchClientRegionInfo', () => {
|
|
254
|
+
// beforeEach(() => {
|
|
255
|
+
// services.webex.config = {
|
|
256
|
+
// services: {
|
|
257
|
+
// discovery: {
|
|
258
|
+
// sqdiscovery: 'https://test.ciscospark.com/v1/region',
|
|
259
|
+
// },
|
|
260
|
+
// },
|
|
261
|
+
// };
|
|
262
|
+
// });
|
|
263
|
+
|
|
264
|
+
// it('successfully resolves with undefined if fetch request failed', () => {
|
|
265
|
+
// webex.request = sinon.stub().returns(Promise.reject());
|
|
266
|
+
|
|
267
|
+
// return services.fetchClientRegionInfo().then((r) => {
|
|
268
|
+
// assert.isUndefined(r);
|
|
269
|
+
// });
|
|
270
|
+
// });
|
|
271
|
+
|
|
272
|
+
// it('successfully resolves with true if fetch request succeeds', () => {
|
|
273
|
+
// webex.request = sinon.stub().returns(Promise.resolve({body: true}));
|
|
274
|
+
|
|
275
|
+
// return services.fetchClientRegionInfo().then((r) => {
|
|
276
|
+
// assert.equal(r, true);
|
|
277
|
+
// assert.calledWith(webex.request, {
|
|
278
|
+
// uri: 'https://test.ciscospark.com/v1/region',
|
|
279
|
+
// addAuthHeader: false,
|
|
280
|
+
// headers: {'spark-user-agent': null},
|
|
281
|
+
// timeout: 5000,
|
|
282
|
+
// });
|
|
283
|
+
// });
|
|
284
|
+
// });
|
|
285
|
+
// });
|
|
286
|
+
|
|
287
|
+
// describe('#getMeetingPreferences', () => {
|
|
288
|
+
// it('Fetch login users information ', async () => {
|
|
289
|
+
// const userPreferences = {userPreferences: 'userPreferences'};
|
|
290
|
+
|
|
291
|
+
// webex.request = sinon.stub().returns(Promise.resolve({body: userPreferences}));
|
|
292
|
+
|
|
293
|
+
// const res = await services.getMeetingPreferences();
|
|
294
|
+
|
|
295
|
+
// assert.calledWith(webex.request, {
|
|
296
|
+
// method: 'GET',
|
|
297
|
+
// service: 'hydra',
|
|
298
|
+
// resource: 'meetingPreferences',
|
|
299
|
+
// });
|
|
300
|
+
// assert.isDefined(res);
|
|
301
|
+
// assert.equal(res, userPreferences);
|
|
302
|
+
// });
|
|
303
|
+
|
|
304
|
+
// it('Resolve getMeetingPreferences if the api request fails ', async () => {
|
|
305
|
+
// webex.request = sinon.stub().returns(Promise.reject());
|
|
306
|
+
|
|
307
|
+
// const res = await services.getMeetingPreferences();
|
|
308
|
+
|
|
309
|
+
// assert.calledWith(webex.request, {
|
|
310
|
+
// method: 'GET',
|
|
311
|
+
// service: 'hydra',
|
|
312
|
+
// resource: 'meetingPreferences',
|
|
313
|
+
// });
|
|
314
|
+
// assert.isUndefined(res);
|
|
315
|
+
// });
|
|
316
|
+
// });
|
|
270
317
|
|
|
271
318
|
describe('#updateCatalog', () => {
|
|
272
319
|
it('updates the catalog', async () => {
|
|
@@ -287,107 +334,118 @@ describe('webex-core', () => {
|
|
|
287
334
|
});
|
|
288
335
|
});
|
|
289
336
|
|
|
290
|
-
describe('#_fetchNewServiceHostmap()', () => {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
337
|
+
// describe('#_fetchNewServiceHostmap()', () => {
|
|
338
|
+
// beforeEach(() => {
|
|
339
|
+
// sinon.spy(webex.internal.newMetrics.callDiagnosticLatencies, 'measureLatency');
|
|
340
|
+
// });
|
|
341
|
+
|
|
342
|
+
// afterEach(() => {
|
|
343
|
+
// sinon.restore();
|
|
344
|
+
// });
|
|
345
|
+
|
|
346
|
+
// it('checks service request resolves', async () => {
|
|
347
|
+
// const mapResponse = 'map response';
|
|
348
|
+
|
|
349
|
+
// sinon.stub(services, '_formatReceivedHostmap').resolves(mapResponse);
|
|
350
|
+
// sinon.stub(services, 'request').resolves({});
|
|
351
|
+
|
|
352
|
+
// const mapResult = await services._fetchNewServiceHostmap({from: 'limited'});
|
|
353
|
+
|
|
354
|
+
// assert.deepEqual(mapResult, mapResponse);
|
|
355
|
+
|
|
356
|
+
// assert.calledOnceWithExactly(services.request, {
|
|
357
|
+
// method: 'GET',
|
|
358
|
+
// service: 'u2c',
|
|
359
|
+
// resource: '/limited/catalog',
|
|
360
|
+
// qs: {format: 'hostmap'},
|
|
361
|
+
// });
|
|
362
|
+
// assert.calledOnceWithExactly(
|
|
363
|
+
// webex.internal.newMetrics.callDiagnosticLatencies.measureLatency,
|
|
364
|
+
// sinon.match.func,
|
|
365
|
+
// 'internal.get.u2c.time'
|
|
366
|
+
// );
|
|
367
|
+
// });
|
|
368
|
+
|
|
369
|
+
// it('checks service request rejects', async () => {
|
|
370
|
+
// const error = new Error('some error');
|
|
371
|
+
|
|
372
|
+
// sinon.spy(services, '_formatReceivedHostmap');
|
|
373
|
+
// sinon.stub(services, 'request').rejects(error);
|
|
374
|
+
|
|
375
|
+
// const promise = services._fetchNewServiceHostmap({from: 'limited'});
|
|
376
|
+
// const rejectedValue = await assert.isRejected(promise);
|
|
377
|
+
|
|
378
|
+
// assert.deepEqual(rejectedValue, error);
|
|
379
|
+
|
|
380
|
+
// assert.notCalled(services._formatReceivedHostmap);
|
|
381
|
+
|
|
382
|
+
// assert.calledOnceWithExactly(services.request, {
|
|
383
|
+
// method: 'GET',
|
|
384
|
+
// service: 'u2c',
|
|
385
|
+
// resource: '/limited/catalog',
|
|
386
|
+
// qs: {format: 'hostmap'},
|
|
387
|
+
// });
|
|
388
|
+
// assert.calledOnceWithExactly(
|
|
389
|
+
// webex.internal.newMetrics.callDiagnosticLatencies.measureLatency,
|
|
390
|
+
// sinon.match.func,
|
|
391
|
+
// 'internal.get.u2c.time'
|
|
392
|
+
// );
|
|
393
|
+
// });
|
|
394
|
+
// });
|
|
395
|
+
|
|
396
|
+
// describe('replaceHostFromHostmap', () => {
|
|
397
|
+
// it('returns the same uri if the hostmap is not set', () => {
|
|
398
|
+
// services._hostCatalog = null;
|
|
399
|
+
|
|
400
|
+
// const uri = 'http://example.com';
|
|
401
|
+
|
|
402
|
+
// assert.equal(services.replaceHostFromHostmap(uri), uri);
|
|
403
|
+
// });
|
|
404
|
+
|
|
405
|
+
// it('returns the same uri if the hostmap does not contain the host', () => {
|
|
406
|
+
// services._hostCatalog = {
|
|
407
|
+
// 'not-example.com': [
|
|
408
|
+
// {
|
|
409
|
+
// host: 'example-1.com',
|
|
410
|
+
// ttl: -1,
|
|
411
|
+
// priority: 5,
|
|
412
|
+
// id: '0:0:0:example',
|
|
413
|
+
// },
|
|
414
|
+
// ],
|
|
415
|
+
// };
|
|
416
|
+
|
|
417
|
+
// const uri = 'http://example.com';
|
|
418
|
+
|
|
419
|
+
// assert.equal(services.replaceHostFromHostmap(uri), uri);
|
|
420
|
+
// });
|
|
421
|
+
|
|
422
|
+
// it('returns the original uri if the hostmap has no hosts for the host', () => {
|
|
423
|
+
// services._hostCatalog = {
|
|
424
|
+
// 'example.com': [],
|
|
425
|
+
// };
|
|
426
|
+
|
|
427
|
+
// const uri = 'http://example.com';
|
|
428
|
+
|
|
429
|
+
// assert.equal(services.replaceHostFromHostmap(uri), uri);
|
|
430
|
+
// });
|
|
431
|
+
|
|
432
|
+
// it('returns the replaces the host in the uri with the host from the hostmap', () => {
|
|
433
|
+
// services._hostCatalog = {
|
|
434
|
+
// 'example.com': [
|
|
435
|
+
// {
|
|
436
|
+
// host: 'example-1.com',
|
|
437
|
+
// ttl: -1,
|
|
438
|
+
// priority: 5,
|
|
439
|
+
// id: '0:0:0:example',
|
|
440
|
+
// },
|
|
441
|
+
// ],
|
|
442
|
+
// };
|
|
443
|
+
|
|
444
|
+
// const uri = 'http://example.com/somepath';
|
|
445
|
+
|
|
446
|
+
// assert.equal(services.replaceHostFromHostmap(uri), 'http://example-1.com/somepath');
|
|
447
|
+
// });
|
|
448
|
+
// });
|
|
391
449
|
|
|
392
450
|
describe('#_formatReceivedHostmap()', () => {
|
|
393
451
|
let serviceHostmap;
|
|
@@ -457,60 +515,48 @@ describe('webex-core', () => {
|
|
|
457
515
|
});
|
|
458
516
|
});
|
|
459
517
|
|
|
460
|
-
describe('#updateCredentialsConfig()', () => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
it('should retain the authorize url property when authorization string is provided', () => {
|
|
505
|
-
const authUrl = 'http://example-auth-url.com/resource';
|
|
506
|
-
|
|
507
|
-
webex.config.credentials.authorizationString = authUrl;
|
|
508
|
-
webex.config.credentials.authorizeUrl = authUrl;
|
|
509
|
-
|
|
510
|
-
services.updateCredentialsConfig();
|
|
511
|
-
|
|
512
|
-
assert.equal(webex.config.credentials.authorizeUrl, authUrl);
|
|
513
|
-
});
|
|
514
|
-
});
|
|
518
|
+
// describe('#updateCredentialsConfig()', () => {
|
|
519
|
+
// // updateCredentialsConfig must remove `/` if exist. so expected serviceList must be.
|
|
520
|
+
// const expectedServiceList = {
|
|
521
|
+
// idbroker: 'https://idbroker.webex.com',
|
|
522
|
+
// identity: 'https://identity.webex.com',
|
|
523
|
+
// };
|
|
524
|
+
|
|
525
|
+
// beforeEach(async () => {
|
|
526
|
+
// const servicesList = {
|
|
527
|
+
// idbroker: 'https://idbroker.webex.com',
|
|
528
|
+
// identity: 'https://identity.webex.com/',
|
|
529
|
+
// };
|
|
530
|
+
|
|
531
|
+
// catalog.list = sinon.stub().returns(servicesList);
|
|
532
|
+
// await services.updateCredentialsConfig();
|
|
533
|
+
// });
|
|
534
|
+
|
|
535
|
+
// it('sets the idbroker url properly when trailing slash is not present', () => {
|
|
536
|
+
// assert.equal(webex.config.credentials.idbroker.url, expectedServiceList.idbroker);
|
|
537
|
+
// });
|
|
538
|
+
|
|
539
|
+
// it('sets the identity url properly when a trailing slash is present', () => {
|
|
540
|
+
// assert.equal(webex.config.credentials.identity.url, expectedServiceList.identity);
|
|
541
|
+
// });
|
|
542
|
+
|
|
543
|
+
// it('sets the authorize url properly when authorization string is not provided', () => {
|
|
544
|
+
// assert.equal(
|
|
545
|
+
// webex.config.credentials.authorizeUrl,
|
|
546
|
+
// `${expectedServiceList.idbroker}/idb/oauth2/v1/authorize`
|
|
547
|
+
// );
|
|
548
|
+
// });
|
|
549
|
+
|
|
550
|
+
// it('should retain the authorize url property when authorization string is provided', () => {
|
|
551
|
+
// const authUrl = 'http://example-auth-url.com/resource';
|
|
552
|
+
|
|
553
|
+
// webex.config.credentials.authorizationString = authUrl;
|
|
554
|
+
// webex.config.credentials.authorizeUrl = authUrl;
|
|
555
|
+
|
|
556
|
+
// services.updateCredentialsConfig();
|
|
557
|
+
|
|
558
|
+
// assert.equal(webex.config.credentials.authorizeUrl, authUrl);
|
|
559
|
+
// });
|
|
560
|
+
// });
|
|
515
561
|
});
|
|
516
562
|
});
|