@webex/webex-core 3.3.1 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -0
- package/dist/index.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/services/index.js +7 -0
- package/dist/lib/services/index.js.map +1 -1
- package/dist/lib/services/interceptors/hostmap.js +64 -0
- package/dist/lib/services/interceptors/hostmap.js.map +1 -0
- package/dist/lib/services/service-catalog.js +21 -6
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/services.js +75 -48
- package/dist/lib/services/services.js.map +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +5 -3
- package/dist/webex-core.js.map +1 -1
- package/package.json +13 -13
- package/src/index.js +1 -0
- package/src/lib/services/index.js +1 -0
- package/src/lib/services/interceptors/hostmap.js +36 -0
- package/src/lib/services/service-catalog.js +12 -4
- package/src/lib/services/services.js +86 -46
- package/src/webex-core.js +2 -0
- package/test/integration/spec/services/services.js +9 -5
- package/test/unit/spec/services/interceptors/hostmap.js +79 -0
- package/test/unit/spec/services/service-catalog.js +51 -1
- package/test/unit/spec/services/services.js +245 -10
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2024 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint-disable camelcase */
|
|
6
|
+
|
|
7
|
+
import sinon from 'sinon';
|
|
8
|
+
import {assert} from '@webex/test-helper-chai';
|
|
9
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
10
|
+
import {HostMapInterceptor, config, Credentials} from '@webex/webex-core';
|
|
11
|
+
import {cloneDeep} from 'lodash';
|
|
12
|
+
|
|
13
|
+
describe('webex-core', () => {
|
|
14
|
+
describe('Interceptors', () => {
|
|
15
|
+
describe('HostMapInterceptor', () => {
|
|
16
|
+
let interceptor, webex;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
webex = new MockWebex({
|
|
20
|
+
children: {
|
|
21
|
+
credentials: Credentials,
|
|
22
|
+
},
|
|
23
|
+
config: cloneDeep(config),
|
|
24
|
+
request: sinon.spy(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
webex.internal.services = {
|
|
28
|
+
replaceHostFromHostmap: sinon.stub().returns('http://replaceduri.com'),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interceptor = Reflect.apply(HostMapInterceptor.create, webex, []);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('#onRequest', () => {
|
|
35
|
+
it('calls replaceHostFromHostmap if options.uri is defined', () => {
|
|
36
|
+
const options = {
|
|
37
|
+
uri: 'http://example.com',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
interceptor.onRequest(options);
|
|
41
|
+
|
|
42
|
+
sinon.assert.calledWith(
|
|
43
|
+
webex.internal.services.replaceHostFromHostmap,
|
|
44
|
+
'http://example.com'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
assert.equal(options.uri, 'http://replaceduri.com');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('does not call replaceHostFromHostmap if options.uri is not defined', () => {
|
|
51
|
+
const options = {};
|
|
52
|
+
|
|
53
|
+
interceptor.onRequest(options);
|
|
54
|
+
|
|
55
|
+
sinon.assert.notCalled(webex.internal.services.replaceHostFromHostmap);
|
|
56
|
+
|
|
57
|
+
assert.isUndefined(options.uri);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('does not modify options.uri if replaceHostFromHostmap throws an error', () => {
|
|
61
|
+
const options = {
|
|
62
|
+
uri: 'http://example.com',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
webex.internal.services.replaceHostFromHostmap.throws(new Error('replaceHostFromHostmap error'));
|
|
66
|
+
|
|
67
|
+
interceptor.onRequest(options);
|
|
68
|
+
|
|
69
|
+
sinon.assert.calledWith(
|
|
70
|
+
webex.internal.services.replaceHostFromHostmap,
|
|
71
|
+
'http://example.com'
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
assert.equal(options.uri, 'http://example.com');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -13,7 +13,7 @@ describe('webex-core', () => {
|
|
|
13
13
|
let services;
|
|
14
14
|
let catalog;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
beforeEach(() => {
|
|
17
17
|
webex = new MockWebex();
|
|
18
18
|
services = new Services(undefined, {parent: webex});
|
|
19
19
|
catalog = services._getCatalog();
|
|
@@ -201,6 +201,56 @@ describe('webex-core', () => {
|
|
|
201
201
|
assert.match(['example-a', 'example-b', 'example-c', 'example-e', 'example-f'], list);
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
|
+
|
|
205
|
+
describe('findServiceUrlFromUrl()', () => {
|
|
206
|
+
const otherService = {
|
|
207
|
+
defaultUrl: 'https://example.com/differentresource',
|
|
208
|
+
hosts: [{host: 'example1.com'}, {host: 'example2.com'}],
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
it.each([
|
|
212
|
+
'discovery',
|
|
213
|
+
'preauth',
|
|
214
|
+
'signin',
|
|
215
|
+
'postauth',
|
|
216
|
+
'override'
|
|
217
|
+
])('matches a default url correctly', (serviceGroup) => {
|
|
218
|
+
const url = 'https://example.com/resource/id';
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
const exampleService = {
|
|
222
|
+
defaultUrl: 'https://example.com/resource',
|
|
223
|
+
hosts: [{host: 'example1.com'}, {host: 'example2.com'}],
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
catalog.serviceGroups[serviceGroup].push(otherService, exampleService);
|
|
227
|
+
|
|
228
|
+
const service = catalog.findServiceUrlFromUrl(url);
|
|
229
|
+
|
|
230
|
+
assert.equal(service, exampleService);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it.each([
|
|
234
|
+
'discovery',
|
|
235
|
+
'preauth',
|
|
236
|
+
'signin',
|
|
237
|
+
'postauth',
|
|
238
|
+
'override'
|
|
239
|
+
])('matches an alternate host url', (serviceGroup) => {
|
|
240
|
+
const url = 'https://example2.com/resource/id';
|
|
241
|
+
|
|
242
|
+
const exampleService = {
|
|
243
|
+
defaultUrl: 'https://example.com/resource',
|
|
244
|
+
hosts: [{host: 'example1.com'}, {host: 'example2.com'}],
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
catalog.serviceGroups[serviceGroup].push(otherService, exampleService);
|
|
248
|
+
|
|
249
|
+
const service = catalog.findServiceUrlFromUrl(url);
|
|
250
|
+
|
|
251
|
+
assert.equal(service, exampleService);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
204
254
|
});
|
|
205
255
|
});
|
|
206
256
|
/* eslint-enable no-underscore-dangle */
|
|
@@ -290,6 +290,61 @@ describe('webex-core', () => {
|
|
|
290
290
|
});
|
|
291
291
|
});
|
|
292
292
|
|
|
293
|
+
describe('replaceHostFromHostmap', () => {
|
|
294
|
+
it('returns the same uri if the hostmap is not set', () => {
|
|
295
|
+
services._hostCatalog = null;
|
|
296
|
+
|
|
297
|
+
const uri = 'http://example.com';
|
|
298
|
+
|
|
299
|
+
assert.equal(services.replaceHostFromHostmap(uri), uri);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('returns the same uri if the hostmap does not contain the host', () => {
|
|
303
|
+
services._hostCatalog = {
|
|
304
|
+
'not-example.com': [
|
|
305
|
+
{
|
|
306
|
+
host: 'example-1.com',
|
|
307
|
+
ttl: -1,
|
|
308
|
+
priority: 5,
|
|
309
|
+
id: '0:0:0:example',
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const uri = 'http://example.com';
|
|
315
|
+
|
|
316
|
+
assert.equal(services.replaceHostFromHostmap(uri), uri);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('returns the original uri if the hostmap has no hosts for the host', () => {
|
|
320
|
+
|
|
321
|
+
services._hostCatalog = {
|
|
322
|
+
'example.com': [],
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const uri = 'http://example.com';
|
|
326
|
+
|
|
327
|
+
assert.equal(services.replaceHostFromHostmap(uri), uri);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('returns the replaces the host in the uri with the host from the hostmap', () => {
|
|
331
|
+
services._hostCatalog = {
|
|
332
|
+
'example.com': [
|
|
333
|
+
{
|
|
334
|
+
host: 'example-1.com',
|
|
335
|
+
ttl: -1,
|
|
336
|
+
priority: 5,
|
|
337
|
+
id: '0:0:0:example',
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const uri = 'http://example.com/somepath';
|
|
343
|
+
|
|
344
|
+
assert.equal(services.replaceHostFromHostmap(uri), 'http://example-1.com/somepath');
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
293
348
|
describe('#_formatReceivedHostmap()', () => {
|
|
294
349
|
let serviceHostmap;
|
|
295
350
|
let formattedHM;
|
|
@@ -301,6 +356,9 @@ describe('webex-core', () => {
|
|
|
301
356
|
'example-b': 'https://example-b.com/api/v1',
|
|
302
357
|
'example-c': 'https://example-c.com/api/v1',
|
|
303
358
|
'example-d': 'https://example-d.com/api/v1',
|
|
359
|
+
'example-e': 'https://example-e.com/api/v1',
|
|
360
|
+
'example-f': 'https://example-f.com/api/v1',
|
|
361
|
+
'example-g': 'https://example-g.com/api/v1',
|
|
304
362
|
},
|
|
305
363
|
hostCatalog: {
|
|
306
364
|
'example-a.com': [
|
|
@@ -383,6 +441,48 @@ describe('webex-core', () => {
|
|
|
383
441
|
id: '0:0:0:example-d-x',
|
|
384
442
|
},
|
|
385
443
|
],
|
|
444
|
+
'example-e.com': [
|
|
445
|
+
{
|
|
446
|
+
host: 'example-e-1.com',
|
|
447
|
+
ttl: -1,
|
|
448
|
+
priority: 5,
|
|
449
|
+
id: '0:0:0:different-e',
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
host: 'example-e-2.com',
|
|
453
|
+
ttl: -1,
|
|
454
|
+
priority: 3,
|
|
455
|
+
id: '0:0:0:different-e',
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
host: 'example-e-3.com',
|
|
459
|
+
ttl: -1,
|
|
460
|
+
priority: 1,
|
|
461
|
+
id: '0:0:0:different-e',
|
|
462
|
+
},
|
|
463
|
+
],
|
|
464
|
+
'example-e-1.com': [
|
|
465
|
+
{
|
|
466
|
+
host: 'example-e-4.com',
|
|
467
|
+
ttl: -1,
|
|
468
|
+
priority: 5,
|
|
469
|
+
id: '0:0:0:different-e',
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
host: 'example-e-5.com',
|
|
473
|
+
ttl: -1,
|
|
474
|
+
priority: 3,
|
|
475
|
+
id: '0:0:0:different-e',
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
host: 'example-e-3.com',
|
|
479
|
+
ttl: -1,
|
|
480
|
+
priority: 1,
|
|
481
|
+
id: '0:0:0:different-e-x',
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
'example-f.com': [
|
|
485
|
+
],
|
|
386
486
|
},
|
|
387
487
|
format: 'hostmap',
|
|
388
488
|
};
|
|
@@ -440,16 +540,6 @@ describe('webex-core', () => {
|
|
|
440
540
|
});
|
|
441
541
|
});
|
|
442
542
|
|
|
443
|
-
it('creates a formmated host map containing all received host map host entries', () => {
|
|
444
|
-
formattedHM = services._formatReceivedHostmap(serviceHostmap);
|
|
445
|
-
|
|
446
|
-
formattedHM.forEach((service) => {
|
|
447
|
-
const foundHosts = serviceHostmap.hostCatalog[service.defaultHost];
|
|
448
|
-
|
|
449
|
-
assert.isDefined(foundHosts);
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
|
|
453
543
|
it('creates an array with matching names', () => {
|
|
454
544
|
formattedHM = services._formatReceivedHostmap(serviceHostmap);
|
|
455
545
|
|
|
@@ -459,6 +549,151 @@ describe('webex-core', () => {
|
|
|
459
549
|
);
|
|
460
550
|
});
|
|
461
551
|
|
|
552
|
+
it('creates the expected formatted host map', () => {
|
|
553
|
+
formattedHM = services._formatReceivedHostmap(serviceHostmap);
|
|
554
|
+
|
|
555
|
+
assert.deepEqual(formattedHM, [
|
|
556
|
+
{
|
|
557
|
+
defaultHost: 'example-a.com',
|
|
558
|
+
defaultUrl: 'https://example-a.com/api/v1',
|
|
559
|
+
hosts: [
|
|
560
|
+
{
|
|
561
|
+
homeCluster: true,
|
|
562
|
+
host: 'example-a-1.com',
|
|
563
|
+
id: '0:0:0:example-a',
|
|
564
|
+
priority: 5,
|
|
565
|
+
ttl: -1,
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
homeCluster: true,
|
|
569
|
+
host: 'example-a-2.com',
|
|
570
|
+
id: '0:0:0:example-a',
|
|
571
|
+
priority: 3,
|
|
572
|
+
ttl: -1,
|
|
573
|
+
},
|
|
574
|
+
],
|
|
575
|
+
name: 'example-a',
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
defaultHost: 'example-b.com',
|
|
579
|
+
defaultUrl: 'https://example-b.com/api/v1',
|
|
580
|
+
hosts: [
|
|
581
|
+
{
|
|
582
|
+
homeCluster: true,
|
|
583
|
+
host: 'example-b-1.com',
|
|
584
|
+
id: '0:0:0:example-b',
|
|
585
|
+
priority: 5,
|
|
586
|
+
ttl: -1,
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
homeCluster: true,
|
|
590
|
+
host: 'example-b-2.com',
|
|
591
|
+
id: '0:0:0:example-b',
|
|
592
|
+
priority: 3,
|
|
593
|
+
ttl: -1,
|
|
594
|
+
},
|
|
595
|
+
],
|
|
596
|
+
name: 'example-b',
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
defaultHost: 'example-c.com',
|
|
600
|
+
defaultUrl: 'https://example-c.com/api/v1',
|
|
601
|
+
hosts: [
|
|
602
|
+
{
|
|
603
|
+
homeCluster: true,
|
|
604
|
+
host: 'example-c-1.com',
|
|
605
|
+
id: '0:0:0:example-c',
|
|
606
|
+
priority: 5,
|
|
607
|
+
ttl: -1,
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
homeCluster: true,
|
|
611
|
+
host: 'example-c-2.com',
|
|
612
|
+
id: '0:0:0:example-c',
|
|
613
|
+
priority: 3,
|
|
614
|
+
ttl: -1,
|
|
615
|
+
},
|
|
616
|
+
],
|
|
617
|
+
name: 'example-c',
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
defaultHost: 'example-d.com',
|
|
621
|
+
defaultUrl: 'https://example-d.com/api/v1',
|
|
622
|
+
hosts: [
|
|
623
|
+
{
|
|
624
|
+
homeCluster: true,
|
|
625
|
+
host: 'example-c-1.com',
|
|
626
|
+
id: '0:0:0:example-d',
|
|
627
|
+
priority: 5,
|
|
628
|
+
ttl: -1,
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
homeCluster: true,
|
|
632
|
+
host: 'example-c-2.com',
|
|
633
|
+
id: '0:0:0:example-d',
|
|
634
|
+
priority: 3,
|
|
635
|
+
ttl: -1,
|
|
636
|
+
},
|
|
637
|
+
],
|
|
638
|
+
name: 'example-d',
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
defaultHost: 'example-e.com',
|
|
642
|
+
defaultUrl: 'https://example-e.com/api/v1',
|
|
643
|
+
hosts: [
|
|
644
|
+
{
|
|
645
|
+
homeCluster: true,
|
|
646
|
+
host: 'example-e-1.com',
|
|
647
|
+
id: '0:0:0:different-e',
|
|
648
|
+
priority: 5,
|
|
649
|
+
ttl: -1,
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
homeCluster: true,
|
|
653
|
+
host: 'example-e-2.com',
|
|
654
|
+
id: '0:0:0:different-e',
|
|
655
|
+
priority: 3,
|
|
656
|
+
ttl: -1,
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
homeCluster: true,
|
|
660
|
+
host: 'example-e-3.com',
|
|
661
|
+
id: '0:0:0:different-e',
|
|
662
|
+
priority: 1,
|
|
663
|
+
ttl: -1,
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
homeCluster: false,
|
|
667
|
+
host: 'example-e-4.com',
|
|
668
|
+
id: '0:0:0:different-e',
|
|
669
|
+
priority: 5,
|
|
670
|
+
ttl: -1,
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
homeCluster: false,
|
|
674
|
+
host: 'example-e-5.com',
|
|
675
|
+
id: '0:0:0:different-e',
|
|
676
|
+
priority: 3,
|
|
677
|
+
ttl: -1,
|
|
678
|
+
},
|
|
679
|
+
],
|
|
680
|
+
name: 'example-e',
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
defaultHost: 'example-f.com',
|
|
684
|
+
defaultUrl: 'https://example-f.com/api/v1',
|
|
685
|
+
hosts: [],
|
|
686
|
+
name: 'example-f',
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
defaultHost: 'example-g.com',
|
|
690
|
+
defaultUrl: 'https://example-g.com/api/v1',
|
|
691
|
+
hosts: [],
|
|
692
|
+
name: 'example-g',
|
|
693
|
+
}
|
|
694
|
+
]);
|
|
695
|
+
});
|
|
696
|
+
|
|
462
697
|
it('has hostCatalog updated', () => {
|
|
463
698
|
services._formatReceivedHostmap(serviceHostmap);
|
|
464
699
|
|