Gitiles: Fix issue where the auth prefix was misplaced
Bug: #19428 Signed-off-by: Gustaf Lundh <gustaf.lundh@axis.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/integration': patch
|
||||
---
|
||||
|
||||
Gitiles: Fixed auth prefix issue
|
||||
@@ -39,6 +39,14 @@ describe('gerrit core', () => {
|
||||
host: 'gerrit.com',
|
||||
gitilesBaseUrl: 'https://gerrit.com/gitiles',
|
||||
};
|
||||
const configWithPath: GerritIntegrationConfig = {
|
||||
host: 'gerrit.com',
|
||||
gitilesBaseUrl: 'https://gerrit.com/path/gitiles',
|
||||
};
|
||||
const configWithPathSlash: GerritIntegrationConfig = {
|
||||
host: 'gerrit.com',
|
||||
gitilesBaseUrl: 'https://gerrit.com/path1/path2/gitiles/',
|
||||
};
|
||||
it('can create an archive url for a branch', () => {
|
||||
expect(buildGerritGitilesArchiveUrl(config, 'repo', 'dev', '')).toEqual(
|
||||
'https://gerrit.com/gitiles/repo/+archive/refs/heads/dev.tar.gz',
|
||||
@@ -67,6 +75,30 @@ describe('gerrit core', () => {
|
||||
'https://gerrit.com/a/gitiles/repo/+archive/refs/heads/dev/docs.tar.gz',
|
||||
);
|
||||
});
|
||||
it('can create an authenticated url when auth is enabled and an url-path is used', () => {
|
||||
const authConfig = {
|
||||
...configWithPath,
|
||||
username: 'username',
|
||||
password: 'password',
|
||||
};
|
||||
expect(
|
||||
buildGerritGitilesArchiveUrl(authConfig, 'repo', 'dev', 'docs'),
|
||||
).toEqual(
|
||||
'https://gerrit.com/path/a/gitiles/repo/+archive/refs/heads/dev/docs.tar.gz',
|
||||
);
|
||||
});
|
||||
it('can create an authenticated url when auth is enabled and an url-path + slash is used', () => {
|
||||
const authConfig = {
|
||||
...configWithPathSlash,
|
||||
username: 'username',
|
||||
password: 'password',
|
||||
};
|
||||
expect(
|
||||
buildGerritGitilesArchiveUrl(authConfig, 'repo', 'dev', 'docs'),
|
||||
).toEqual(
|
||||
'https://gerrit.com/path1/path2/a/gitiles/repo/+archive/refs/heads/dev/docs.tar.gz',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildGerritGitilesUrl', () => {
|
||||
|
||||
@@ -157,9 +157,13 @@ export function getGitilesAuthenticationUrl(
|
||||
config: GerritIntegrationConfig,
|
||||
): string {
|
||||
const parsedUrl = new URL(config.gitilesBaseUrl!);
|
||||
return `${parsedUrl.protocol}//${parsedUrl.host}${getAuthenticationPrefix(
|
||||
config,
|
||||
)}${parsedUrl.pathname.substring(1)}`;
|
||||
parsedUrl.pathname = parsedUrl.pathname.replace(/\/?$/, '');
|
||||
parsedUrl.pathname = parsedUrl.pathname.replace(
|
||||
/\/([^\/]*)$/,
|
||||
`${getAuthenticationPrefix(config)}$1`,
|
||||
);
|
||||
|
||||
return parsedUrl.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user