Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-02-12 09:57:47 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-02-12 13:38:08 +0300
commiteb49052f9e7edac32c4ad3f36a6a7e49f955bf87 (patch)
tree52fd40f90f7483e22880fc7d57b6cc32e2cd8f77 /cmd/gitaly-hooks
parentf759f16177f4d54419cade648336c9c7beda325d (diff)
gitaly: Set up requested hooks bitmap
With the infrastructure being in place to support executing requested hooks only, this commit converts all callsites of `NewHooksPayload()` to also pass the bitmap of hooks they want to execute. This finally fixes an issue where we could've accidentally executed an unwanted hook only because we set up `core.hooksPath` for a git command.
Diffstat (limited to 'cmd/gitaly-hooks')
-rw-r--r--cmd/gitaly-hooks/hooks_test.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go
index 96240ee28..b64e23cf0 100644
--- a/cmd/gitaly-hooks/hooks_test.go
+++ b/cmd/gitaly-hooks/hooks_test.go
@@ -43,7 +43,7 @@ func envForHooks(t testing.TB, gitlabShellDir string, repo *gitalypb.Repository,
UserID: glHookValues.GLID,
Username: glHookValues.GLUsername,
Protocol: glHookValues.GLProtocol,
- }).Env()
+ }, git.AllHooks).Env()
require.NoError(t, err)
env := append(os.Environ(), []string{
@@ -469,6 +469,7 @@ func TestHooksPostReceiveFailed(t *testing.T) {
Username: glUsername,
Protocol: glProtocol,
},
+ git.PostReceiveHook,
).Env()
require.NoError(t, err)
@@ -726,3 +727,38 @@ func TestGitalyHooksPackObjects(t *testing.T) {
})
}
}
+
+func TestRequestedHooks(t *testing.T) {
+ for hook, hookName := range map[git.Hook]string{
+ git.ReferenceTransactionHook: "reference-transaction",
+ git.UpdateHook: "update",
+ git.PreReceiveHook: "pre-receive",
+ git.PostReceiveHook: "post-receive",
+ git.PackObjectsHook: "git",
+ } {
+ t.Run(hookName, func(t *testing.T) {
+ t.Run("unrequested hook is ignored", func(t *testing.T) {
+ payload, err := git.NewHooksPayload(config.Config, &gitalypb.Repository{}, nil, nil, nil, git.AllHooks&^hook).Env()
+ require.NoError(t, err)
+
+ cmd := exec.Command(filepath.Join(config.Config.BinDir, "gitaly-hooks"), hookName)
+ cmd.Env = []string{payload}
+ require.NoError(t, cmd.Run())
+ })
+
+ t.Run("requested hook runs", func(t *testing.T) {
+ payload, err := git.NewHooksPayload(config.Config, &gitalypb.Repository{}, nil, nil, nil, hook).Env()
+ require.NoError(t, err)
+
+ cmd := exec.Command(filepath.Join(config.Config.BinDir, "gitaly-hooks"), hookName)
+ cmd.Env = []string{payload}
+
+ // We simply check that there is an error here as an indicator that
+ // the hook logic ran. We don't care for the actual error because we
+ // know that in the previous testcase without the hook being
+ // requested, there was no error.
+ require.Error(t, cmd.Run(), "hook should have run and failed due to incomplete setup")
+ })
+ })
+ }
+}