mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 23:11:31 +00:00
5ad36a2387
* ci(linter): add renovate/no-host-rules-mock rule Flags vi.mock()/vi.doMock() calls whose module specifier contains "host-rules" in spec files. Tests should configure real rules via hostRules.add() instead of mocking the host-rules module. Enabled at "warn" severity instead of "error": the repo currently has 35 pre-existing violations across 34 spec files, which exceeds the agreed fix threshold of 12 files. No violation fixes are included; migrating each spec to real hostRules.add()/clear() setup is a semantic test rewrite that should be done incrementally, after which the rule can be promoted to "error". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ci(linter): enforce renovate/no-host-rules-mock at error Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(datasource): use real host-rules instead of mocking Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(manager): use real host-rules instead of mocking Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(platform): use real host-rules instead of mocking Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(util,workers): use real host-rules instead of mocking Also narrow renovate/no-host-rules-mock to the host-rules module itself so that mocking e.g. host-rules-from-env is not flagged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ci(linter): mention '~test/host-rules.ts' util in no-host-rules-mock message Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
221 lines
6.8 KiB
TypeScript
221 lines
6.8 KiB
TypeScript
import { hostRules } from '~test/host-rules.ts';
|
|
import { getHttpUrl, getRemoteUrlWithToken, parseGitUrl } from './url.ts';
|
|
|
|
describe('util/git/url', () => {
|
|
describe('parseGitUrl', () => {
|
|
it('supports ports', () => {
|
|
expect(parseGitUrl('https://gitlab.com:8443/')).toEqual({
|
|
filepath: '',
|
|
filepathtype: '',
|
|
full_name: '',
|
|
git_suffix: false,
|
|
hash: '',
|
|
host: 'gitlab.com:8443',
|
|
href: 'https://gitlab.com:8443',
|
|
name: '',
|
|
organization: '',
|
|
owner: '',
|
|
parse_failed: false,
|
|
password: '',
|
|
pathname: '/',
|
|
port: '8443',
|
|
protocol: 'https',
|
|
protocols: ['https'],
|
|
query: {},
|
|
ref: '',
|
|
resource: 'gitlab.com',
|
|
search: '',
|
|
source: 'gitlab.com',
|
|
toString: expect.toBeFunction(),
|
|
token: '',
|
|
user: '',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('getHttpUrl()', () => {
|
|
it('returns https url for git url', () => {
|
|
expect(getHttpUrl('git://foo.bar/')).toBe('https://foo.bar/');
|
|
});
|
|
|
|
it('returns https url for https url', () => {
|
|
expect(getHttpUrl('https://foo.bar/')).toBe('https://foo.bar/');
|
|
});
|
|
|
|
it('returns http url for http url', () => {
|
|
expect(getHttpUrl('http://foo.bar/')).toBe('http://foo.bar/');
|
|
});
|
|
|
|
it('returns http url for ssh url with port', () => {
|
|
expect(
|
|
getHttpUrl(
|
|
'ssh://git@gitlab.example.com:22222/typo3-extensions/poll-pro.git',
|
|
),
|
|
).toBe('https://gitlab.example.com/typo3-extensions/poll-pro.git');
|
|
});
|
|
|
|
it('returns gitlab url with token', () => {
|
|
expect(getHttpUrl('http://gitlab.com/', 'token')).toBe(
|
|
'http://gitlab-ci-token:token@gitlab.com/',
|
|
);
|
|
expect(getHttpUrl('http://gitlab.com/', 'gitlab-ci-token:token')).toBe(
|
|
'http://gitlab-ci-token:token@gitlab.com/',
|
|
);
|
|
expect(
|
|
getHttpUrl('http://gitlab.com:8443/', 'gitlab-ci-token:token'),
|
|
).toBe('http://gitlab-ci-token:token@gitlab.com:8443/');
|
|
expect(getHttpUrl('git@gitlab.com:some/repo', 'token')).toBe(
|
|
'https://gitlab-ci-token:token@gitlab.com/some/repo',
|
|
);
|
|
});
|
|
|
|
it('returns github url with token', () => {
|
|
expect(getHttpUrl('http://github.com/', 'token')).toBe(
|
|
'http://x-access-token:token@github.com/',
|
|
);
|
|
expect(getHttpUrl('http://github.com/', 'x-access-token:token')).toBe(
|
|
'http://x-access-token:token@github.com/',
|
|
);
|
|
expect(
|
|
getHttpUrl('http://github.com:8443/', 'x-access-token:token'),
|
|
).toBe('http://x-access-token:token@github.com:8443/');
|
|
expect(getHttpUrl('git@github.com:some/repo', 'token')).toBe(
|
|
'https://x-access-token:token@github.com/some/repo',
|
|
);
|
|
});
|
|
|
|
it('returns bitbucket-server url', () => {
|
|
expect(getHttpUrl('http://git.mycompany.com/scm/proj/repo.git')).toBe(
|
|
'http://git.mycompany.com/scm/proj/repo.git',
|
|
);
|
|
hostRules.add({
|
|
matchHost: 'git.mycompany.com',
|
|
hostType: 'bitbucket-server',
|
|
});
|
|
expect(getHttpUrl('ssh://git@git.mycompany.com:7999/proj/repo.git')).toBe(
|
|
'https://git.mycompany.com/scm/proj/repo.git',
|
|
);
|
|
});
|
|
|
|
it('removes username/password from URL', () => {
|
|
expect(getHttpUrl('https://user:password@foo.bar/someOrg/someRepo')).toBe(
|
|
'https://foo.bar/someOrg/someRepo',
|
|
);
|
|
});
|
|
|
|
it('replaces username/password with given token', () => {
|
|
expect(
|
|
getHttpUrl(
|
|
'https://user:password@foo.bar/someOrg/someRepo',
|
|
'another-user:a-secret-pwd',
|
|
),
|
|
).toBe('https://another-user:a-secret-pwd@foo.bar/someOrg/someRepo');
|
|
});
|
|
});
|
|
|
|
describe('getRemoteUrlWithToken()', () => {
|
|
it('returns original url if no host rule is found', () => {
|
|
expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
|
|
'https://foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('transforms an ssh git url to https for the purpose of finding hostRules', () => {
|
|
// this rule can only match after the ssh url is transformed to https
|
|
hostRules.add({
|
|
matchHost: 'https://foo.bar/some/repo',
|
|
token: 'token',
|
|
});
|
|
expect(getRemoteUrlWithToken('git@foo.bar:some/repo')).toBe(
|
|
'https://token@foo.bar/some/repo',
|
|
);
|
|
});
|
|
|
|
it('does not transform urls that are not parseable as git urls', () => {
|
|
expect(getRemoteUrlWithToken('abcdefg')).toBe('abcdefg');
|
|
});
|
|
|
|
it('returns http url with token', () => {
|
|
hostRules.add({ token: 'token' });
|
|
expect(getRemoteUrlWithToken('http://foo.bar/')).toBe(
|
|
'http://token@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns https url with token', () => {
|
|
hostRules.add({ token: 'token' });
|
|
expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
|
|
'https://token@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns https url with token for non-http protocols', () => {
|
|
hostRules.add({ token: 'token' });
|
|
expect(getRemoteUrlWithToken('ssh://foo.bar/')).toBe(
|
|
'https://token@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns https url with encoded token', () => {
|
|
hostRules.add({ token: 't#ken' });
|
|
expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
|
|
'https://t%23ken@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns http url with username and password', () => {
|
|
hostRules.add({
|
|
username: 'user',
|
|
password: 'pass',
|
|
});
|
|
expect(getRemoteUrlWithToken('http://foo.bar/')).toBe(
|
|
'http://user:pass@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns https url with username and password', () => {
|
|
hostRules.add({
|
|
username: 'user',
|
|
password: 'pass',
|
|
});
|
|
expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
|
|
'https://user:pass@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns https url with username and password for non-http protocols', () => {
|
|
hostRules.add({
|
|
username: 'user',
|
|
password: 'pass',
|
|
});
|
|
expect(getRemoteUrlWithToken('ssh://foo.bar/')).toBe(
|
|
'https://user:pass@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns https url with encoded username and password', () => {
|
|
hostRules.add({
|
|
username: 'u$er',
|
|
password: 'p@ss',
|
|
});
|
|
expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
|
|
'https://u%24er:p%40ss@foo.bar/',
|
|
);
|
|
});
|
|
|
|
it('returns https url with encoded gitlab token', () => {
|
|
hostRules.add({ token: 'token' });
|
|
expect(getRemoteUrlWithToken('ssh://gitlab.com/some/repo.git')).toBe(
|
|
'https://gitlab-ci-token:token@gitlab.com/some/repo.git',
|
|
);
|
|
});
|
|
|
|
it('returns https url for ssh url with encoded github token', () => {
|
|
hostRules.add({ token: 'token' });
|
|
expect(getRemoteUrlWithToken('ssh://github.com/some/repo.git')).toBe(
|
|
'https://x-access-token:token@github.com/some/repo.git',
|
|
);
|
|
});
|
|
});
|
|
});
|