Take custom ports into account when matching integrations to URLs

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-08-23 19:09:42 +02:00
parent 5aebf54a12
commit f0ba514f0b
3 changed files with 35 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/integration': patch
---
Take custom ports into account when matching integrations to URLs. It used to be the case that an integration with e.g. `host: 'scm.mycompany.net:8080'` would not be matched by the `byUrl` method, while hosts without a custom port did match.
+29 -1
View File
@@ -14,7 +14,35 @@
* limitations under the License.
*/
import { defaultScmResolveUrl, isValidHost } from './helpers';
import { BitbucketIntegration } from './bitbucket';
import {
basicIntegrations,
defaultScmResolveUrl,
isValidHost,
} from './helpers';
describe('basicIntegrations', () => {
describe('byUrl', () => {
it('handles hosts without a port', () => {
const integration = new BitbucketIntegration({ host: 'host.com' });
const integrations = basicIntegrations<BitbucketIntegration>(
[integration],
i => i.config.host,
);
expect(integrations.byUrl('https://host.com/a')).toBe(integration);
expect(integrations.byUrl('https://host.com:8080/a')).toBeUndefined();
});
it('handles hosts with a port', () => {
const integration = new BitbucketIntegration({ host: 'host.com:8080' });
const integrations = basicIntegrations<BitbucketIntegration>(
[integration],
i => i.config.host,
);
expect(integrations.byUrl('https://host.com:8080/a')).toBe(integration);
expect(integrations.byUrl('https://host.com/a')).toBeUndefined();
});
});
});
describe('isValidHost', () => {
it.each([
+1 -1
View File
@@ -46,7 +46,7 @@ export function basicIntegrations<T extends ScmIntegration>(
byUrl(url: string | URL): T | undefined {
try {
const parsed = typeof url === 'string' ? new URL(url) : url;
return integrations.find(i => getHost(i) === parsed.hostname);
return integrations.find(i => getHost(i) === parsed.host);
} catch {
return undefined;
}