Files
Michael Kriese 6cc889803a fix(platform/github): use x-access-token for personal access tokens in clone URLs (#47073)
* fix(platform/github): use `x-access-token` for personal access tokens in clone URLs

Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
Co-Authored-By: Claude Sonnet 5.5 <michael.kriese+claude-code@mend.io>

* fix(platform/github): drop unreachable password fallback in clone URLs

Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
Co-Authored-By: Claude Sonnet 5.5 <michael.kriese+claude-code@mend.io>

---------

Co-authored-by: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
2026-10-15 11:53:08 +00:00

92 lines
2.5 KiB
TypeScript

import { CONFIG_GIT_URL_UNAVAILABLE } from '../../../constants/error-messages.ts';
import { parseUrl } from '../../../util/url.ts';
import { getRepoUrl } from './utils.ts';
describe('modules/platform/github/utils', () => {
describe('getRepoUrl()', () => {
it('returns sshUrl when gitUrl is ssh', () => {
expect(
getRepoUrl(
'some/repo',
'ssh',
'git@github.com:some/repo.git',
parseUrl('https://api.github.com')!,
'token',
),
).toBe('git@github.com:some/repo.git');
});
it('throws when gitUrl is ssh but sshUrl is missing', () => {
expect(() =>
getRepoUrl(
'some/repo',
'ssh',
null,
parseUrl('https://api.github.com')!,
'token',
),
).toThrow(CONFIG_GIT_URL_UNAVAILABLE);
});
it('builds an endpoint URL with embedded credentials by default', () => {
expect(
getRepoUrl(
'some/repo',
undefined,
'git@github.com:some/repo.git',
parseUrl('https://api.github.com')!,
'x-access-token:abc123',
),
).toBe('https://x-access-token:abc123@github.com/some/repo.git');
});
it('builds an endpoint URL when gitUrl is endpoint', () => {
expect(
getRepoUrl(
'some/repo',
'endpoint',
'git@github.com:some/repo.git',
parseUrl('https://api.github.com')!,
'token',
),
).toBe('https://x-access-token:token@github.com/some/repo.git');
});
it('sets username and password when provided as a username:password combination', () => {
expect(
getRepoUrl(
'some/repo',
undefined,
null,
parseUrl('https://api.github.com')!,
'user:pass',
),
).toBe('https://user:pass@github.com/some/repo.git');
});
it('omits credentials when authToken is null', () => {
expect(
getRepoUrl(
'some/repo',
undefined,
null,
parseUrl('https://api.github.com')!,
null,
),
).toBe('https://github.com/some/repo.git');
});
it('preserves a GHES endpoint host', () => {
expect(
getRepoUrl(
'some/repo',
undefined,
null,
parseUrl('https://ghe.example.com/api/v3')!,
'token',
),
).toBe('https://x-access-token:token@ghe.example.com/some/repo.git');
});
});
});