diff options
author | John Cai <jcai@gitlab.com> | 2020-03-10 20:08:58 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2020-03-12 18:54:07 +0300 |
commit | e0736906034ff09d14069b07afa50c46bc2ec54b (patch) | |
tree | f87a9fae00b50719fe569331950b96fbb21e48cc | |
parent | ca611acce3b696423c6693fa7f5833703a08975f (diff) |
Test that GL_* values get passed to custom hooks
-rw-r--r-- | cmd/gitaly-hooks/hooks_test.go | 69 | ||||
-rw-r--r-- | internal/service/operations/branches_test.go | 8 | ||||
-rw-r--r-- | internal/service/operations/cherry_pick_test.go | 4 | ||||
-rw-r--r-- | internal/service/operations/commit_files_test.go | 2 | ||||
-rw-r--r-- | internal/service/operations/merge_test.go | 8 | ||||
-rw-r--r-- | internal/service/operations/rebase_test.go | 6 | ||||
-rw-r--r-- | internal/service/operations/revert_test.go | 4 | ||||
-rw-r--r-- | internal/service/operations/tags_test.go | 8 | ||||
-rw-r--r-- | internal/service/operations/testhelper_test.go | 34 | ||||
-rw-r--r-- | internal/service/operations/update_branches_test.go | 4 | ||||
-rw-r--r-- | internal/testhelper/testhelper.go | 30 | ||||
-rw-r--r-- | internal/testhelper/testserver.go | 22 |
12 files changed, 127 insertions, 72 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index fa84aa22d..0d8a162d2 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -36,6 +36,8 @@ func TestHooksPrePostReceive(t *testing.T) { secretToken := "secret token" glID := "key-1234" + glUsername := "iamgitlab" + glProtocol := "ssh" glRepository := "some_repo" tempGitlabShellDir, cleanup := testhelper.CreateTemporaryGitlabShellDir(t) @@ -71,6 +73,9 @@ func TestHooksPrePostReceive(t *testing.T) { for _, hook := range []string{"pre-receive", "post-receive"} { t.Run(hook, func(t *testing.T) { + customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hook) + defer cleanup() + var stderr, stdout bytes.Buffer stdin := bytes.NewBuffer([]byte(changes)) hookPath, err := filepath.Abs(fmt.Sprintf("../../ruby/git-hooks/%s", hook)) @@ -81,9 +86,13 @@ func TestHooksPrePostReceive(t *testing.T) { cmd.Stdin = stdin cmd.Env = testhelper.EnvForHooks( t, - glRepository, tempGitlabShellDir, - glID, + testhelper.GlHookValues{ + GLID: glID, + GLUsername: glUsername, + GLRepo: glRepository, + GLProtocol: glProtocol, + }, gitPushOptions..., ) cmd.Dir = testRepoPath @@ -91,12 +100,22 @@ func TestHooksPrePostReceive(t *testing.T) { require.NoError(t, cmd.Run()) require.Empty(t, stderr.String()) require.Empty(t, stdout.String()) + + output := string(testhelper.MustReadFile(t, customHookOutputPath)) + require.Contains(t, output, "GL_USERNAME="+glUsername) + require.Contains(t, output, "GL_ID="+glID) + require.Contains(t, output, "GL_REPOSITORY="+glRepository) + if hook != "pre-receive" { + require.Contains(t, output, "GL_PROTOCOL="+glProtocol) + } }) } } func TestHooksUpdate(t *testing.T) { glID := "key-1234" + glUsername := "iamgitlab" + glProtocol := "ssh" glRepository := "some_repo" tempGitlabShellDir, cleanup := testhelper.CreateTemporaryGitlabShellDir(t) @@ -110,6 +129,9 @@ func TestHooksUpdate(t *testing.T) { testhelper.WriteShellSecretFile(t, tempGitlabShellDir, "the wrong token") + customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, "update") + defer cleanup() + gitlabShellDir := config.Config.GitlabShell.Dir defer func() { config.Config.GitlabShell.Dir = gitlabShellDir @@ -127,7 +149,12 @@ func TestHooksUpdate(t *testing.T) { updateHookPath, err := filepath.Abs("../../ruby/git-hooks/update") require.NoError(t, err) cmd := exec.Command(updateHookPath, refval, oldval, newval) - cmd.Env = testhelper.EnvForHooks(t, glRepository, tempGitlabShellDir, glID) + cmd.Env = testhelper.EnvForHooks(t, tempGitlabShellDir, testhelper.GlHookValues{ + GLID: glID, + GLUsername: glUsername, + GLRepo: glRepository, + GLProtocol: glProtocol, + }) cmd.Stdout = &stdout cmd.Stderr = &stderr cmd.Dir = testRepoPath @@ -145,11 +172,19 @@ func TestHooksUpdate(t *testing.T) { require.NoError(t, json.NewDecoder(f).Decode(&inputs)) require.Equal(t, []string{refval, oldval, newval}, inputs) require.NoError(t, f.Close()) + + output := string(testhelper.MustReadFile(t, customHookOutputPath)) + require.Contains(t, output, "GL_USERNAME="+glUsername) + require.Contains(t, output, "GL_ID="+glID) + require.Contains(t, output, "GL_REPOSITORY="+glRepository) + require.Contains(t, output, "GL_PROTOCOL="+glProtocol) } func TestHooksPostReceiveFailed(t *testing.T) { secretToken := "secret token" glID := "key-1234" + glUsername := "iamgitlab" + glProtocol := "ssh" glRepository := "some_repo" changes := "oldhead newhead" @@ -186,12 +221,20 @@ func TestHooksPostReceiveFailed(t *testing.T) { config.Config.GitlabShell.Dir = tempGitlabShellDir + customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive") + defer cleanup() + var stdout, stderr bytes.Buffer postReceiveHookPath, err := filepath.Abs("../../ruby/git-hooks/post-receive") require.NoError(t, err) cmd := exec.Command(postReceiveHookPath) - cmd.Env = testhelper.EnvForHooks(t, glRepository, tempGitlabShellDir, glID) + cmd.Env = testhelper.EnvForHooks(t, tempGitlabShellDir, testhelper.GlHookValues{ + GLID: glID, + GLUsername: glUsername, + GLRepo: glRepository, + GLProtocol: glProtocol, + }) cmd.Stdout = &stdout cmd.Stderr = &stderr cmd.Stdin = bytes.NewBuffer([]byte(changes)) @@ -204,11 +247,16 @@ func TestHooksPostReceiveFailed(t *testing.T) { require.Equal(t, 1, code, "exit status") require.Empty(t, stdout.String()) require.Empty(t, stderr.String()) + + output := string(testhelper.MustReadFile(t, customHookOutputPath)) + require.Empty(t, output, "custom hook should not have run") } func TestHooksNotAllowed(t *testing.T) { secretToken := "secret token" glID := "key-1234" + glUsername := "iamgitlab" + glProtocol := "ssh" glRepository := "some_repo" changes := "oldhead newhead" @@ -238,6 +286,9 @@ func TestHooksNotAllowed(t *testing.T) { config.Config.GitlabShell.Dir = gitlabShellDir }() + customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive") + defer cleanup() + config.Config.GitlabShell.Dir = tempGitlabShellDir var stderr, stdout bytes.Buffer @@ -248,12 +299,20 @@ func TestHooksNotAllowed(t *testing.T) { cmd.Stderr = &stderr cmd.Stdout = &stdout cmd.Stdin = strings.NewReader(changes) - cmd.Env = testhelper.EnvForHooks(t, glRepository, tempGitlabShellDir, glID) + cmd.Env = testhelper.EnvForHooks(t, tempGitlabShellDir, testhelper.GlHookValues{ + GLID: glID, + GLUsername: glUsername, + GLRepo: glRepository, + GLProtocol: glProtocol, + }) cmd.Dir = testRepoPath require.Error(t, cmd.Run()) require.Equal(t, "GitLab: 401 Unauthorized\n", stderr.String()) require.Equal(t, "", stdout.String()) + + output := string(testhelper.MustReadFile(t, customHookOutputPath)) + require.Empty(t, output, "custom hook should not have run") } func TestCheckOK(t *testing.T) { diff --git a/internal/service/operations/branches_test.go b/internal/service/operations/branches_test.go index 5d6081bf0..c377d4a09 100644 --- a/internal/service/operations/branches_test.go +++ b/internal/service/operations/branches_test.go @@ -102,7 +102,7 @@ func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) { t.Run(hookName, func(t *testing.T) { defer exec.Command("git", "-C", testRepoPath, "branch", "-D", branchName).Run() - hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName) + hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() ctx, cancel := testhelper.Context() @@ -142,7 +142,7 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) { hookContent := []byte("#!/bin/sh\nprintenv | paste -sd ' ' -\nexit 1") for _, hookName := range gitlabPreHooks { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() @@ -298,7 +298,7 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) { t.Run(hookName, func(t *testing.T) { testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) - hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName) + hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() ctx, cancel := testhelper.Context() @@ -405,7 +405,7 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) { for _, hookName := range gitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() diff --git a/internal/service/operations/cherry_pick_test.go b/internal/service/operations/cherry_pick_test.go index fb3a18cf8..509a28327 100644 --- a/internal/service/operations/cherry_pick_test.go +++ b/internal/service/operations/cherry_pick_test.go @@ -165,7 +165,7 @@ func TestSuccessfulGitHooksForUserCherryPickRequest(t *testing.T) { var hookOutputFiles []string for _, hookName := range operations.GitlabHooks { - hookOutputTempPath, cleanup := operations.WriteEnvToCustomHook(t, testRepoPath, hookName) + hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() hookOutputFiles = append(hookOutputFiles, hookOutputTempPath) } @@ -309,7 +309,7 @@ func TestFailedUserCherryPickRequestDueToPreReceiveError(t *testing.T) { for _, hookName := range operations.GitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() diff --git a/internal/service/operations/commit_files_test.go b/internal/service/operations/commit_files_test.go index ad073dfa4..915312b0a 100644 --- a/internal/service/operations/commit_files_test.go +++ b/internal/service/operations/commit_files_test.go @@ -434,7 +434,7 @@ func TestFailedUserCommitFilesRequestDueToHooks(t *testing.T) { for _, hookName := range operations.GitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() md := testhelper.GitalyServersMetadata(t, serverSocketPath) diff --git a/internal/service/operations/merge_test.go b/internal/service/operations/merge_test.go index 2074a5abf..51d9e0709 100644 --- a/internal/service/operations/merge_test.go +++ b/internal/service/operations/merge_test.go @@ -50,7 +50,7 @@ func TestSuccessfulMerge(t *testing.T) { hookTempfiles := make([]string, len(hooks)) for i, h := range hooks { var cleanup func() - hookTempfiles[i], cleanup = WriteEnvToCustomHook(t, testRepoPath, h) + hookTempfiles[i], cleanup = testhelper.WriteEnvToCustomHook(t, testRepoPath, h) defer cleanup() } @@ -241,7 +241,7 @@ func TestFailedMergeDueToHooks(t *testing.T) { for _, hookName := range gitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() @@ -450,7 +450,7 @@ func TestFailedUserFFBranchDueToHooks(t *testing.T) { for _, hookName := range gitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() @@ -703,7 +703,7 @@ func TestUserMergeToRefIgnoreHooksRequest(t *testing.T) { for _, hookName := range gitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() diff --git a/internal/service/operations/rebase_test.go b/internal/service/operations/rebase_test.go index 7d1a75677..228284530 100644 --- a/internal/service/operations/rebase_test.go +++ b/internal/service/operations/rebase_test.go @@ -57,8 +57,8 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) { rebaseStream, err := client.UserRebaseConfirmable(ctx) require.NoError(t, err) - preReceiveHookOutputPath, removePreReceive := operations.WriteEnvToCustomHook(t, testRepoPath, "pre-receive") - postReceiveHookOutputPath, removePostReceive := operations.WriteEnvToCustomHook(t, testRepoPath, "post-receive") + preReceiveHookOutputPath, removePreReceive := testhelper.WriteEnvToCustomHook(t, testRepoPath, "pre-receive") + postReceiveHookOutputPath, removePostReceive := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive") defer removePreReceive() defer removePostReceive() @@ -317,7 +317,7 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) { for i, hookName := range operations.GitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err, "set up hooks override") defer remove() diff --git a/internal/service/operations/revert_test.go b/internal/service/operations/revert_test.go index 716e8f1b3..f4494e161 100644 --- a/internal/service/operations/revert_test.go +++ b/internal/service/operations/revert_test.go @@ -163,7 +163,7 @@ func TestSuccessfulGitHooksForUserRevertRequest(t *testing.T) { var hookOutputFiles []string for _, hookName := range operations.GitlabHooks { - hookOutputTempPath, cleanup := operations.WriteEnvToCustomHook(t, testRepoPath, hookName) + hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() hookOutputFiles = append(hookOutputFiles, hookOutputTempPath) } @@ -307,7 +307,7 @@ func TestFailedUserRevertRequestDueToPreReceiveError(t *testing.T) { for _, hookName := range operations.GitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() diff --git a/internal/service/operations/tags_test.go b/internal/service/operations/tags_test.go index 4273d7ccf..ec47dad02 100644 --- a/internal/service/operations/tags_test.go +++ b/internal/service/operations/tags_test.go @@ -86,7 +86,7 @@ func TestSuccessfulGitHooksForUserDeleteTagRequest(t *testing.T) { t.Run(hookName, func(t *testing.T) { testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", tagNameInput) - hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName) + hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() ctx, cancel := testhelper.Context() @@ -219,7 +219,7 @@ func TestSuccessfulGitHooksForUserCreateTagRequest(t *testing.T) { t.Run(hookName, func(t *testing.T) { defer exec.Command("git", "-C", testRepoPath, "tag", "-d", tagName).Run() - hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName) + hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() ctx, cancel := testhelper.Context() @@ -327,7 +327,7 @@ func TestFailedUserDeleteTagDueToHooks(t *testing.T) { for _, hookName := range gitlabPreHooks { t.Run(hookName, func(t *testing.T) { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() @@ -374,7 +374,7 @@ func TestFailedUserCreateTagDueToHooks(t *testing.T) { hookContent := []byte("#!/bin/sh\necho GL_ID=$GL_ID\nexit 1") for _, hookName := range gitlabPreHooks { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() diff --git a/internal/service/operations/testhelper_test.go b/internal/service/operations/testhelper_test.go index 38e461f52..56d48ab56 100644 --- a/internal/service/operations/testhelper_test.go +++ b/internal/service/operations/testhelper_test.go @@ -1,15 +1,12 @@ package operations import ( - "fmt" - "io/ioutil" "net" "os" "path/filepath" "testing" log "github.com/sirupsen/logrus" - "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -98,37 +95,6 @@ func newOperationClient(t *testing.T, serverSocketPath string) (gitalypb.Operati var NewOperationClient = newOperationClient -// The callee is responsible for clean up of the specific hook, testMain removes -// the hook dir -func WriteEnvToCustomHook(t *testing.T, repoPath, hookName string) (string, func()) { - hookOutputTemp, err := ioutil.TempFile("", "") - require.NoError(t, err) - require.NoError(t, hookOutputTemp.Close()) - - hookContent := fmt.Sprintf("#!/bin/sh\n/usr/bin/env > %s\n", hookOutputTemp.Name()) - - cleanupCustomHook, err := WriteCustomHook(repoPath, hookName, []byte(hookContent)) - require.NoError(t, err) - - return hookOutputTemp.Name(), func() { - cleanupCustomHook() - os.Remove(hookOutputTemp.Name()) - } -} - -// write a hook in the repo/path.git/custom_hooks directory -func WriteCustomHook(repoPath, name string, content []byte) (func(), error) { - fullPath := filepath.Join(repoPath, "custom_hooks", name) - fullpathDir := filepath.Dir(fullPath) - if err := os.MkdirAll(fullpathDir, 0755); err != nil { - return func() {}, err - } - - return func() { - os.RemoveAll(fullpathDir) - }, ioutil.WriteFile(fullPath, content, 0755) -} - func SetupAndStartGitlabServer(t *testing.T, glID, glRepository string, gitPushOptions ...string) func() { return testhelper.SetupAndStartGitlabServer(t, &testhelper.GitlabTestServerOptions{ SecretToken: "secretToken", diff --git a/internal/service/operations/update_branches_test.go b/internal/service/operations/update_branches_test.go index d332b9a1a..44f9427de 100644 --- a/internal/service/operations/update_branches_test.go +++ b/internal/service/operations/update_branches_test.go @@ -69,7 +69,7 @@ func TestSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T) { cleanupSrv := SetupAndStartGitlabServer(t, user.GlId, testRepo.GlRepository) defer cleanupSrv() - hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName) + hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() ctx, cancel := testhelper.Context() @@ -118,7 +118,7 @@ func TestFailedUserUpdateBranchDueToHooks(t *testing.T) { hookContent := []byte("#!/bin/sh\nprintenv | paste -sd ' ' -\nexit 1") for _, hookName := range gitlabPreHooks { - remove, err := WriteCustomHook(testRepoPath, hookName, hookContent) + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) require.NoError(t, err) defer remove() diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index 5d7d0647a..4b61d3ed2 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -598,3 +598,33 @@ func GrpcErrorHasMessage(grpcError error, msg string) bool { } return status.Message() == msg } + +// dump the env vars that the custom hooks receives to a file +func WriteEnvToCustomHook(t *testing.T, repoPath, hookName string) (string, func()) { + hookOutputTemp, err := ioutil.TempFile("", "") + require.NoError(t, err) + require.NoError(t, hookOutputTemp.Close()) + + hookContent := fmt.Sprintf("#!/bin/sh\n/usr/bin/env > %s\n", hookOutputTemp.Name()) + + cleanupCustomHook, err := WriteCustomHook(repoPath, hookName, []byte(hookContent)) + require.NoError(t, err) + + return hookOutputTemp.Name(), func() { + cleanupCustomHook() + os.Remove(hookOutputTemp.Name()) + } +} + +// write a hook in the repo/path.git/custom_hooks directory +func WriteCustomHook(repoPath, name string, content []byte) (func(), error) { + fullPath := filepath.Join(repoPath, "custom_hooks", name) + fullpathDir := filepath.Dir(fullPath) + if err := os.MkdirAll(fullpathDir, 0755); err != nil { + return func() {}, err + } + + return func() { + os.RemoveAll(fullpathDir) + }, ioutil.WriteFile(fullPath, content, 0755) +} diff --git a/internal/testhelper/testserver.go b/internal/testhelper/testserver.go index 6fa2f865f..9d14e2342 100644 --- a/internal/testhelper/testserver.go +++ b/internal/testhelper/testserver.go @@ -361,27 +361,27 @@ func WriteTemporaryGitalyConfigFile(t *testing.T, tempDir string) (string, func( } } +type GlHookValues struct { + GLID, GLUsername, GLRepo, GLProtocol string +} + // EnvForHooks generates a set of environment variables for gitaly hooks -func EnvForHooks(t *testing.T, glRepo, gitlabShellDir, glID string, gitPushOptions ...string) []string { +func EnvForHooks(t *testing.T, gitlabShellDir string, glHookValues GlHookValues, gitPushOptions ...string) []string { rubyDir, err := filepath.Abs("../../ruby") require.NoError(t, err) - return append(append(oldEnv(t, glRepo, gitlabShellDir, glID), []string{ + return append(append([]string{ fmt.Sprintf("GITALY_BIN_DIR=%s", config.Config.BinDir), fmt.Sprintf("GITALY_RUBY_DIR=%s", rubyDir), - }...), hooks.GitPushOptions(gitPushOptions)...) -} - -func oldEnv(t *testing.T, glRepo, gitlabShellDir, glID string) []string { - return append([]string{ - fmt.Sprintf("GL_ID=%s", glID), - fmt.Sprintf("GL_REPOSITORY=%s", glRepo), - "GL_PROTOCOL=ssh", + fmt.Sprintf("GL_ID=%s", glHookValues.GLID), + fmt.Sprintf("GL_REPOSITORY=%s", glHookValues.GLRepo), + fmt.Sprintf("GL_PROTOCOL=%s", glHookValues.GLProtocol), + fmt.Sprintf("GL_USERNAME=%s", glHookValues.GLUsername), fmt.Sprintf("GITALY_GITLAB_SHELL_DIR=%s", gitlabShellDir), fmt.Sprintf("GITALY_LOG_DIR=%s", gitlabShellDir), "GITALY_LOG_LEVEL=info", "GITALY_LOG_FORMAT=json", - }, os.Environ()...) + }, os.Environ()...), hooks.GitPushOptions(gitPushOptions)...) } // WriteShellSecretFile writes a .gitlab_shell_secret file in the specified directory |