diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-15 17:55:09 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-20 20:02:06 +0300 |
commit | 1381a25128c4fbecded1fc24e79487ebb329a4f0 (patch) | |
tree | 4e59e0c382a85ecee9b7310de3148295bcc42a77 /internal/gitaly/hook/prereceive_test.go | |
parent | 69e9c5ebbf5100b56a7f85b4a49603f8f5bf33bd (diff) |
hook: Convert environment tests to be stricter
The tests which check whether environment variables are set up as
expected for custom hooks currently filter down the list of environment
variables to a specific subset. While this works, this is much too
lenient: we do not verify that unrelated environment variables get
filtered out in the hooks' environment, and furthermore we don't check
the value of other environment variables which aren't currently included
in this allowed-list.
Convert the test to instead use a deny-list of filtered variables such
that we only exclude a certain set of environment variables which we
know to be inconsistent across environments.
Diffstat (limited to 'internal/gitaly/hook/prereceive_test.go')
-rw-r--r-- | internal/gitaly/hook/prereceive_test.go | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/internal/gitaly/hook/prereceive_test.go b/internal/gitaly/hook/prereceive_test.go index caeda1659..095cd54c3 100644 --- a/internal/gitaly/hook/prereceive_test.go +++ b/internal/gitaly/hook/prereceive_test.go @@ -79,33 +79,22 @@ func TestPrereceive_customHooks(t *testing.T) { expectedStderr string }{ { - desc: "hook receives environment variables", - env: []string{payload}, - hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' | sort\n", - stdin: "change\n", - expectedStdout: strings.Join([]string{ - "GL_ID=1234", - fmt.Sprintf("GL_PROJECT_PATH=%s", repo.GetGlProjectPath()), - "GL_PROTOCOL=web", - fmt.Sprintf("GL_REPOSITORY=%s", repo.GetGlRepository()), - "GL_USERNAME=user", - }, "\n") + "\n", + desc: "hook receives environment variables", + env: []string{payload}, + hook: "#!/bin/sh\nenv | grep -v -e '^SHLVL=' -e '^_=' | sort\n", + stdin: "change\n", + expectedStdout: strings.Join(getExpectedEnv(t, cfg, repo), "\n") + "\n", }, { desc: "hook receives push options", env: []string{payload}, pushOptions: []string{"mr.create", "mr.merge_when_pipeline_succeeds"}, - hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' -e '^GIT_PUSH_' | sort\n", + hook: "#!/bin/sh\nenv | grep '^GIT_PUSH_' | sort\n", stdin: "change\n", expectedStdout: strings.Join([]string{ "GIT_PUSH_OPTION_0=mr.create", "GIT_PUSH_OPTION_1=mr.merge_when_pipeline_succeeds", "GIT_PUSH_OPTION_COUNT=2", - "GL_ID=1234", - fmt.Sprintf("GL_PROJECT_PATH=%s", repo.GetGlProjectPath()), - "GL_PROTOCOL=web", - fmt.Sprintf("GL_REPOSITORY=%s", repo.GetGlRepository()), - "GL_USERNAME=user", }, "\n") + "\n", }, { |