diff --git a/packages/@webex/webex-core/src/lib/services/service-url.js b/packages/@webex/webex-core/src/lib/services/service-url.js index 786fe37050d..2a95653d143 100644 --- a/packages/@webex/webex-core/src/lib/services/service-url.js +++ b/packages/@webex/webex-core/src/lib/services/service-url.js @@ -75,7 +75,9 @@ const ServiceUrl = AmpState.extend({ return this._generateHostUrl( filteredHosts.reduce( (previous, current) => - previous.priority > current.priority || !previous.homeCluster ? current : previous, + current.priority > 0 && (previous.priority > current.priority || !previous.homeCluster) + ? current + : previous, {} ).host ); diff --git a/packages/@webex/webex-core/test/integration/spec/services/services.js b/packages/@webex/webex-core/test/integration/spec/services/services.js index 2dc520aa6e5..d9c1e05ace9 100644 --- a/packages/@webex/webex-core/test/integration/spec/services/services.js +++ b/packages/@webex/webex-core/test/integration/spec/services/services.js @@ -320,6 +320,41 @@ describe('webex-core', () => { assert.isUndefined(serviceObject); }); + + it('handles case where there is a priority of -1 for a service url', () => { + const negativePriorityTemplate = { + defaultUrl: 'https://www.negative-priority.com/api/v1', + hosts: [ + { + host: 'www.negative-priority.com', + ttl: -1, + priority: 1, + id: 'exampleClusterId2', + homeCluster: true, + }, + { + host: 'www.negative-p3.com', + ttl: -1, + priority: -1, + id: 'exampleClusterId', + homeCluster: true, + }, + ], + name: 'negative-priority', + }; + const negativePriorityUrl = new ServiceUrl(negativePriorityTemplate); + catalog._loadServiceUrls('preauth', [negativePriorityUrl]); + + const serviceObject = services.getServiceFromUrl( + 'https://www.negative-priority.com/api/v1/somepath' + ); + + assert.equal(serviceObject.name, negativePriorityTemplate.name); + assert.equal(serviceObject.defaultUrl, negativePriorityTemplate.defaultUrl); + assert.equal(serviceObject.priorityUrl, 'https://www.negative-priority.com/api/v1'); + + catalog._unloadServiceUrls('preauth', [negativePriorityUrl]); + }); }); describe('#hasService()', () => {