feat(scaffolder): add git proxy protection

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2024-11-28 17:40:12 +01:00
parent c20f3d8e77
commit 1a23421cec
5 changed files with 17 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-node': patch
---
Make sure that isomorphic git push commands are not proxied.
@@ -98,18 +98,11 @@ describe('initRepoAndPush', () => {
});
});
it('adds the appropriate remote', () => {
expect(mockedGit.addRemote).toHaveBeenCalledWith({
dir: '/test/repo/dir/',
url: 'git@github.com:test/repo.git',
remote: 'origin',
});
});
it('pushes to the remote', () => {
expect(mockedGit.push).toHaveBeenCalledWith({
dir: '/test/repo/dir/',
remote: 'origin',
url: 'git@github.com:test/repo.git',
});
});
});
@@ -65,15 +65,11 @@ export async function initRepoAndPush(input: {
author: authorInfo,
committer: authorInfo,
});
await git.addRemote({
dir,
url: remoteUrl,
remote: 'origin',
});
await git.push({
dir,
remote: 'origin',
url: remoteUrl,
});
return { commitHash };
@@ -452,6 +452,8 @@ describe('Git', () => {
'user-agent': 'git/@isomorphic-git',
},
onAuth: expect.any(Function),
corsProxy: '',
url: undefined,
});
});
@@ -480,6 +482,8 @@ describe('Git', () => {
'user-agent': 'git/@isomorphic-git',
},
onAuth: expect.any(Function),
corsProxy: '',
url: undefined,
});
});
@@ -506,6 +510,8 @@ describe('Git', () => {
'user-agent': 'git/@isomorphic-git',
},
onAuth: expect.any(Function),
corsProxy: '',
url: undefined,
});
});
+4 -1
View File
@@ -262,9 +262,10 @@ export class Git {
dir: string;
remote: string;
remoteRef?: string;
url?: string;
force?: boolean;
}) {
const { dir, remote, remoteRef, force } = options;
const { dir, remote, url, remoteRef, force } = options;
this.config.logger?.info(
`Pushing directory to remote {dir=${dir},remote=${remote}}`,
);
@@ -278,7 +279,9 @@ export class Git {
force,
headers: this.headers,
remote,
url,
onAuth: this.onAuth,
corsProxy: '',
});
} catch (ex) {
this.config.logger?.error(