mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-05 19:30:58 +00:00
[v12.0/forgejo] fix: use credentials helpers for git clones (#9068)
**Backport**: https://codeberg.org/forgejo/forgejo/pulls/9067 When performing a `git clone` that requires credentials, they are temporarily stored in files and used with [Git credential](https://git-scm.com/docs/gitcredentials/2.50.0#_requesting_credentials). They were previously included in the URL that were readable by a user with shell access to the host running the Forgejo instance when, for instance, they ask for the list of process (`ps`). Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9068
This commit is contained in:
parent
1bc42842ba
commit
b98109ee69
8 changed files with 291 additions and 15 deletions
|
@ -105,6 +105,8 @@ func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
|||
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
// Set user:password
|
||||
doGitSetRemoteURL(dstLocalPath, "origin", u)(t)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,6 +119,8 @@ func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
|||
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
// Set user:password
|
||||
doGitSetRemoteURL(dstLocalPath, "origin", u)(t)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,6 +166,14 @@ func doGitAddRemote(dstPath, remoteName string, u *url.URL) func(*testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func doGitSetRemoteURL(dstPath, remoteName string, u *url.URL) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Helper()
|
||||
_, _, err := git.NewCommand(git.DefaultContext, "remote", "set-url").AddDynamicArguments(remoteName, u.String()).RunStdString(&git.RunOpts{Dir: dstPath})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func doGitPushTestRepository(dstPath string, args ...string) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Helper()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue