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:
authorToon Claes <toon@gitlab.com>2022-02-03 14:13:56 +0300
committerToon Claes <toon@gitlab.com>2022-04-04 14:37:39 +0300
commit024b77a89f03912039434abb416121feea740543 (patch)
treead03e93e5307983616e9fab7ae9c4b7696a4c2b4
parentcc452e83e51c9c8d8e34a04b5673d6533d1a3b04 (diff)
ssh: Add test with custom pre-receive hook
Add test to check if the error message from a failing custom pre-receive hook is presented to the user.
-rw-r--r--internal/gitaly/service/ssh/receive_pack_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go
index 6d5fb606f..6cdbaa349 100644
--- a/internal/gitaly/service/ssh/receive_pack_test.go
+++ b/internal/gitaly/service/ssh/receive_pack_test.go
@@ -241,6 +241,60 @@ func TestReceivePackPushHookFailure(t *testing.T) {
require.Contains(t, err.Error(), "(pre-receive hook declined)")
}
+func TestReceivePackPushHookFailureWithCustomHook(t *testing.T) {
+ t.Parallel()
+
+ cfg := testcfg.Build(t)
+ gitCmdFactory := gittest.NewCommandFactory(t, cfg)
+
+ testcfg.BuildGitalySSH(t, cfg)
+ testcfg.BuildGitalyHooks(t, cfg)
+
+ cfg.SocketPath = runSSHServer(t, cfg, testserver.WithGitCommandFactory(gitCmdFactory))
+ ctx := testhelper.Context(t)
+
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
+
+ cloneDetails, cleanup := setupSSHClone(t, cfg, repo, repoPath)
+ defer cleanup()
+
+ hookContent := []byte("#!/bin/sh\necho 'this is wrong' >&2;exit 1")
+ gittest.WriteCustomHook(t, cloneDetails.RemoteRepoPath, "pre-receive", hookContent)
+
+ cmd := sshPushCommand(ctx, t, cfg, cloneDetails, cfg.SocketPath,
+ pushParams{
+ storageName: cfg.Storages[0].Name,
+ glID: "1",
+ glRepository: repo.GlRepository,
+ })
+
+ stdout, err := cmd.StdoutPipe()
+ require.NoError(t, err)
+ stderr, err := cmd.StderrPipe()
+ require.NoError(t, err)
+
+ require.NoError(t, cmd.Start())
+
+ c, err := io.Copy(io.Discard, stdout)
+ require.NoError(t, err)
+ require.Equal(t, c, int64(0))
+
+ slurpErr, err := io.ReadAll(stderr)
+ require.NoError(t, err)
+
+ require.Error(t, cmd.Wait())
+
+ require.Contains(t, string(slurpErr), "remote: this is wrong")
+ require.Contains(t, string(slurpErr), "(pre-receive hook declined)")
+
+ if testhelper.IsPraefectEnabled() {
+ // This is a bug tracked in https://gitlab.com/gitlab-org/gitaly/-/issues/3636
+ require.Contains(t, string(slurpErr), "final transactional vote: transaction was stopped")
+ }
+}
+
func TestObjectPoolRefAdvertisementHidingSSH(t *testing.T) {
t.Parallel()