From 4c58d421e026385cd45cd1527ee6dc048fa1796f Mon Sep 17 00:00:00 2001 From: jsoter Date: Tue, 29 Jul 2025 11:20:39 -0400 Subject: [PATCH 1/3] fix: updated u2c logic to filter out urls with negative priority --- .../src/lib/services/service-url.js | 2 +- .../integration/spec/services/services.js | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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..684265ea9e6 100644 --- a/packages/@webex/webex-core/src/lib/services/service-url.js +++ b/packages/@webex/webex-core/src/lib/services/service-url.js @@ -60,7 +60,7 @@ const ServiceUrl = AmpState.extend({ ? this.hosts.filter((host) => host.id === clusterId) : this.hosts.filter((host) => host.homeCluster); - const aliveHosts = filteredHosts.filter((host) => !host.failed); + const aliveHosts = filteredHosts.filter((host) => !host.failed && host.priority > 1); filteredHosts = aliveHosts.length === 0 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..a561ab7e3ad 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,39 @@ 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.example.com/api/v1', + hosts: [ + { + host: 'www.example.com', + ttl: -1, + priority: 1, + id: 'exampleClusterId', + }, + { + host: 'www.example-p3.com', + ttl: -1, + priority: -1, + id: 'exampleClusterId', + }, + ], + name: 'exampleValid', + }; + negativePriorityUrl = new ServiceUrl(negativePriorityTemplate); + catalog._loadServiceUrls('preauth', [negativePriorityUrl]); + + const serviceObject = services.getServiceFromUrl('https://www.example.com/api/v1/somepath'); + + assert.equal(serviceObject, { + name: negativePriorityTemplate.name, + priorityUrl: 'www.example.com', + defaultUrl: negativePriorityTemplate.defaultUrl, + }); + + catalog._unloadServiceUrls('preauth', [negativePriorityUrl]); + }); }); describe('#hasService()', () => { From f3d43b184acf5b23d5eaabf215814c915cf63ad6 Mon Sep 17 00:00:00 2001 From: jsoter Date: Tue, 29 Jul 2025 11:36:54 -0400 Subject: [PATCH 2/3] fix: edge case --- packages/@webex/webex-core/src/lib/services/service-url.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 684265ea9e6..2a95653d143 100644 --- a/packages/@webex/webex-core/src/lib/services/service-url.js +++ b/packages/@webex/webex-core/src/lib/services/service-url.js @@ -60,7 +60,7 @@ const ServiceUrl = AmpState.extend({ ? this.hosts.filter((host) => host.id === clusterId) : this.hosts.filter((host) => host.homeCluster); - const aliveHosts = filteredHosts.filter((host) => !host.failed && host.priority > 1); + const aliveHosts = filteredHosts.filter((host) => !host.failed); filteredHosts = aliveHosts.length === 0 @@ -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 ); From 9450eee522e138ac39ef07ebed07e7410a09aceb Mon Sep 17 00:00:00 2001 From: jsoter Date: Tue, 29 Jul 2025 15:18:39 -0700 Subject: [PATCH 3/3] fix: updated test --- .../integration/spec/services/services.js | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) 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 a561ab7e3ad..d9c1e05ace9 100644 --- a/packages/@webex/webex-core/test/integration/spec/services/services.js +++ b/packages/@webex/webex-core/test/integration/spec/services/services.js @@ -323,33 +323,35 @@ describe('webex-core', () => { it('handles case where there is a priority of -1 for a service url', () => { const negativePriorityTemplate = { - defaultUrl: 'https://www.example.com/api/v1', + defaultUrl: 'https://www.negative-priority.com/api/v1', hosts: [ { - host: 'www.example.com', + host: 'www.negative-priority.com', ttl: -1, priority: 1, - id: 'exampleClusterId', + id: 'exampleClusterId2', + homeCluster: true, }, { - host: 'www.example-p3.com', + host: 'www.negative-p3.com', ttl: -1, priority: -1, id: 'exampleClusterId', + homeCluster: true, }, ], - name: 'exampleValid', + name: 'negative-priority', }; - negativePriorityUrl = new ServiceUrl(negativePriorityTemplate); + const negativePriorityUrl = new ServiceUrl(negativePriorityTemplate); catalog._loadServiceUrls('preauth', [negativePriorityUrl]); - const serviceObject = services.getServiceFromUrl('https://www.example.com/api/v1/somepath'); + const serviceObject = services.getServiceFromUrl( + 'https://www.negative-priority.com/api/v1/somepath' + ); - assert.equal(serviceObject, { - name: negativePriorityTemplate.name, - priorityUrl: 'www.example.com', - defaultUrl: negativePriorityTemplate.defaultUrl, - }); + 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]); });