Skip to content

Commit 1bb88da

Browse files
zeripathlunny
authored andcommitted
Fix local runs of ssh-requiring integration tests (#7857)
1 parent 94f0151 commit 1bb88da

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

integrations/git_helper_for_declarative_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@ import (
2424
)
2525

2626
func withKeyFile(t *testing.T, keyname string, callback func(string)) {
27-
keyFile := filepath.Join(setting.AppDataPath, keyname)
28-
err := ssh.GenKeyPair(keyFile)
27+
28+
tmpDir, err := ioutil.TempDir("", "key-file")
29+
assert.NoError(t, err)
30+
defer os.RemoveAll(tmpDir)
31+
32+
err = os.Chmod(tmpDir, 0700)
33+
assert.NoError(t, err)
34+
35+
keyFile := filepath.Join(tmpDir, keyname)
36+
err = ssh.GenKeyPair(keyFile)
2937
assert.NoError(t, err)
3038

3139
//Setup ssh wrapper
3240
os.Setenv("GIT_SSH_COMMAND",
33-
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "+
34-
filepath.Join(setting.AppWorkPath, keyFile))
41+
"ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"IdentitiesOnly=yes\" -i \""+keyFile+"\"")
3542
os.Setenv("GIT_SSH_VARIANT", "ssh")
3643

3744
callback(keyFile)
38-
39-
defer os.RemoveAll(keyFile)
40-
defer os.RemoveAll(keyFile + ".pub")
4145
}
4246

4347
func createSSHUrl(gitPath string, u *url.URL) *url.URL {

0 commit comments

Comments
 (0)