Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to do a couple more things

  1. homeCluster should not override priority decisions (this is a problem with the current implementation)
  2. the array probably needs to be pre-sorted by priority

As it is right now, -1 urls would be removed, but we could still have a logic error based on the following
A. If homeCluster is set to true for an "invalid" FQDN
B. if the order of the array is incorrect

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think we need Colin's input on this re: homeCluster since he added this part

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we decide we don't have to do these? i thought we could merge this as is?

? current
: previous,
{}
).host
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down
Loading