Take custom ports into account when matching integrations to URLs
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -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.
|
||||
@@ -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([
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user