diff options
author | zeripath | 2019-08-14 12:02:04 +0100 |
---|---|---|
committer | Lunny Xiao | 2019-08-14 19:02:04 +0800 |
commit | 1bb88dad2003b807125f2f51e3b7e86df5b94e2e (patch) | |
tree | 01aacc9e98375e61cc857d65a633002eefd5aa88 | |
parent | 94f0151789997b56d8b5ffcce1e48916026184a0 (diff) |
Fix local runs of ssh-requiring integration tests (#7857)
-rw-r--r-- | integrations/git_helper_for_declarative_test.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/integrations/git_helper_for_declarative_test.go b/integrations/git_helper_for_declarative_test.go index 235f4b4a9..9190d4bb4 100644 --- a/integrations/git_helper_for_declarative_test.go +++ b/integrations/git_helper_for_declarative_test.go @@ -24,20 +24,24 @@ import ( ) func withKeyFile(t *testing.T, keyname string, callback func(string)) { - keyFile := filepath.Join(setting.AppDataPath, keyname) - err := ssh.GenKeyPair(keyFile) + + tmpDir, err := ioutil.TempDir("", "key-file") + assert.NoError(t, err) + defer os.RemoveAll(tmpDir) + + err = os.Chmod(tmpDir, 0700) + assert.NoError(t, err) + + keyFile := filepath.Join(tmpDir, keyname) + err = ssh.GenKeyPair(keyFile) assert.NoError(t, err) //Setup ssh wrapper os.Setenv("GIT_SSH_COMMAND", - "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "+ - filepath.Join(setting.AppWorkPath, keyFile)) + "ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"IdentitiesOnly=yes\" -i \""+keyFile+"\"") os.Setenv("GIT_SSH_VARIANT", "ssh") callback(keyFile) - - defer os.RemoveAll(keyFile) - defer os.RemoveAll(keyFile + ".pub") } func createSSHUrl(gitPath string, u *url.URL) *url.URL { |