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:
authorPavlo Strokov <pstrokov@gitlab.com>2020-11-22 00:44:54 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2020-12-03 15:19:43 +0300
commit190c7ada7051a1e23796c0ad8138556824dc3fb3 (patch)
tree8791f99cd972f62959d39ad27a637686f3c1d396
parent2721def3fcccaee50fff5fb2ca48c5b562623738 (diff)
Inject locator into Hook manager to resolve repository path
To remove dependencies on the global config.Config var the Locator dependency injected into hook manager. To reduce amount of parameters to pass into GitlabAPI.Allowed method a new AllowedParams struct defined and used instead. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r--cmd/gitaly-hooks/hooks.go5
-rw-r--r--cmd/gitaly-hooks/hooks_test.go2
-rw-r--r--cmd/gitaly-ssh/auth_test.go2
-rw-r--r--cmd/gitaly/main.go2
-rw-r--r--internal/gitaly/hook/access.go43
-rw-r--r--internal/gitaly/hook/access_test.go30
-rw-r--r--internal/gitaly/hook/custom.go3
-rw-r--r--internal/gitaly/hook/custom_test.go6
-rw-r--r--internal/gitaly/hook/manager.go5
-rw-r--r--internal/gitaly/hook/postreceive_test.go7
-rw-r--r--internal/gitaly/hook/prereceive.go22
-rw-r--r--internal/gitaly/hook/prereceive_test.go37
-rw-r--r--internal/gitaly/hook/update_test.go2
-rw-r--r--internal/gitaly/service/cleanup/testhelper_test.go2
-rw-r--r--internal/gitaly/service/hook/pre_receive_test.go8
-rw-r--r--internal/gitaly/service/hook/testhelper_test.go2
-rw-r--r--internal/gitaly/service/objectpool/testhelper_test.go2
-rw-r--r--internal/gitaly/service/operations/branches_test.go2
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go2
-rw-r--r--internal/gitaly/service/operations/update_with_hooks_test.go2
-rw-r--r--internal/gitaly/service/ref/testhelper_test.go5
-rw-r--r--internal/gitaly/service/repository/clone_from_pool_internal_test.go4
-rw-r--r--internal/gitaly/service/repository/clone_from_pool_test.go3
-rw-r--r--internal/gitaly/service/repository/fetch_test.go34
-rw-r--r--internal/gitaly/service/repository/fork_test.go10
-rw-r--r--internal/gitaly/service/repository/replicate_test.go10
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go2
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack_test.go15
-rw-r--r--internal/gitaly/service/smarthttp/testhelper_test.go5
-rw-r--r--internal/gitaly/service/ssh/testhelper_test.go5
-rw-r--r--internal/praefect/replicator_test.go2
31 files changed, 170 insertions, 111 deletions
diff --git a/cmd/gitaly-hooks/hooks.go b/cmd/gitaly-hooks/hooks.go
index 669b33e26..8d7504138 100644
--- a/cmd/gitaly-hooks/hooks.go
+++ b/cmd/gitaly-hooks/hooks.go
@@ -331,12 +331,11 @@ func check(configPath string) (*hook.CheckInfo, error) {
if err != nil {
return nil, err
}
- config.Config = cfg
- gitlabAPI, err := hook.NewGitlabAPI(config.Config.Gitlab, config.Config.TLS)
+ gitlabAPI, err := hook.NewGitlabAPI(cfg.Gitlab, cfg.TLS)
if err != nil {
return nil, err
}
- return hook.NewManager(gitlabAPI, config.Config).Check(context.TODO())
+ return hook.NewManager(config.NewLocator(cfg), gitlabAPI, cfg).Check(context.TODO())
}
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go
index 2c81211bc..ba6e0256e 100644
--- a/cmd/gitaly-hooks/hooks_test.go
+++ b/cmd/gitaly-hooks/hooks_test.go
@@ -604,7 +604,7 @@ func runHookServiceServer(t *testing.T, token string) (string, func()) {
func runHookServiceServerWithAPI(t *testing.T, token string, gitlabAPI gitalyhook.GitlabAPI) (string, func()) {
server := testhelper.NewServerWithAuth(t, nil, nil, token)
- gitalypb.RegisterHookServiceServer(server.GrpcServer(), hook.NewServer(config.Config, gitalyhook.NewManager(gitlabAPI, config.Config)))
+ gitalypb.RegisterHookServiceServer(server.GrpcServer(), hook.NewServer(config.Config, gitalyhook.NewManager(config.NewLocator(config.Config), gitlabAPI, config.Config)))
reflection.Register(server.GrpcServer())
require.NoError(t, server.Start())
diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go
index 7b8f92764..c5b8a7c0e 100644
--- a/cmd/gitaly-ssh/auth_test.go
+++ b/cmd/gitaly-ssh/auth_test.go
@@ -126,7 +126,7 @@ func TestConnectivity(t *testing.T) {
func runServer(t *testing.T, newServer func(rubyServer *rubyserver.Server, hookManager hook.Manager, cfg config.Cfg, conns *client.Pool) *grpc.Server, cfg config.Cfg, connectionType string, addr string) (int, func()) {
conns := client.NewPool()
- srv := newServer(nil, hook.NewManager(hook.GitlabAPIStub, cfg), cfg, conns)
+ srv := newServer(nil, hook.NewManager(config.NewLocator(cfg), hook.GitlabAPIStub, cfg), cfg, conns)
listener, err := net.Listen(connectionType, addr)
require.NoError(t, err)
diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go
index b58db95db..d04dd8456 100644
--- a/cmd/gitaly/main.go
+++ b/cmd/gitaly/main.go
@@ -125,7 +125,7 @@ func run(b *bootstrap.Bootstrap) error {
}
}
- hookManager := hook.NewManager(gitlabAPI, config.Config)
+ hookManager := hook.NewManager(config.NewLocator(config.Config), gitlabAPI, config.Config)
prometheus.MustRegister(hookManager)
conns := client.NewPool()
diff --git a/internal/gitaly/hook/access.go b/internal/gitaly/hook/access.go
index 4cb326998..adb957028 100644
--- a/internal/gitaly/hook/access.go
+++ b/internal/gitaly/hook/access.go
@@ -13,9 +13,7 @@ import (
"strings"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
- "gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/version"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-shell/client"
)
@@ -53,10 +51,28 @@ func marshallGitObjectDirs(gitObjectDirRel string, gitAltObjectDirsRel []string)
return string(envString), nil
}
+// AllowedParams compose set of parameters required to call 'GitlabAPI.Allowed' method.
+type AllowedParams struct {
+ // RepoPath is an absolute path to the repository.
+ RepoPath string
+ // GitObjectDirectory is a path to git object directory.
+ GitObjectDirectory string
+ // GitAlternateObjectDirectories are the paths to alternate object directories.
+ GitAlternateObjectDirectories []string
+ // GLRepository is a name of the repository.
+ GLRepository string
+ // GLID is an identifier of the repository.
+ GLID string
+ // GLProtocol is a protocol used for operation.
+ GLProtocol string
+ // Changes is a set of changes to be applied.
+ Changes string
+}
+
// GitlabAPI is an interface for accessing the gitlab internal API
type GitlabAPI interface {
// Allowed queries the gitlab internal api /allowed endpoint to determine if a ref change for a given repository and user is allowed
- Allowed(ctx context.Context, repo *gitalypb.Repository, glRepository, glID, glProtocol, changes string) (bool, string, error)
+ Allowed(ctx context.Context, params AllowedParams) (bool, string, error)
// Check verifies that GitLab can be reached, and authenticated to
Check(ctx context.Context) (*CheckInfo, error)
// PreReceive queries the gitlab internal api /pre_receive to increase the reference counter
@@ -125,27 +141,22 @@ func NewGitlabAPI(gitlabCfg config.Gitlab, tlsCfg config.TLS) (GitlabAPI, error)
}
// Allowed checks if a ref change for a given repository is allowed through the gitlab internal api /allowed endpoint
-func (a *gitlabAPI) Allowed(ctx context.Context, repo *gitalypb.Repository, glRepository, glID, glProtocol, changes string) (bool, string, error) {
- repoPath, err := helper.GetRepoPath(repo)
- if err != nil {
- return false, "", fmt.Errorf("getting the repository path: %w", err)
- }
-
- gitObjDirVars, err := marshallGitObjectDirs(repo.GetGitObjectDirectory(), repo.GetGitAlternateObjectDirectories())
+func (a *gitlabAPI) Allowed(ctx context.Context, params AllowedParams) (bool, string, error) {
+ gitObjDirVars, err := marshallGitObjectDirs(params.GitObjectDirectory, params.GitAlternateObjectDirectories)
if err != nil {
return false, "", fmt.Errorf("when getting git object directories json encoded string: %w", err)
}
req := AllowedRequest{
Action: "git-receive-pack",
- GLRepository: glRepository,
- Changes: changes,
- Protocol: glProtocol,
- Project: strings.Replace(repoPath, "'", "", -1),
+ GLRepository: params.GLRepository,
+ Changes: params.Changes,
+ Protocol: params.GLProtocol,
+ Project: strings.Replace(params.RepoPath, "'", "", -1),
Env: gitObjDirVars,
}
- if err := req.parseAndSetGLID(glID); err != nil {
+ if err := req.parseAndSetGLID(params.GLID); err != nil {
return false, "", fmt.Errorf("setting gl_id: %w", err)
}
@@ -295,7 +306,7 @@ func (a *AllowedRequest) parseAndSetGLID(glID string) error {
// mockAPI is a noop gitlab API client
type mockAPI struct{}
-func (m *mockAPI) Allowed(ctx context.Context, repo *gitalypb.Repository, glRepository, glID, glProtocol, changes string) (bool, string, error) {
+func (m *mockAPI) Allowed(ctx context.Context, params AllowedParams) (bool, string, error) {
return true, "", nil
}
diff --git a/internal/gitaly/hook/access_test.go b/internal/gitaly/hook/access_test.go
index de970a015..bd3f27132 100644
--- a/internal/gitaly/hook/access_test.go
+++ b/internal/gitaly/hook/access_test.go
@@ -114,7 +114,15 @@ func TestAccess_verifyParams(t *testing.T) {
}
for _, tc := range testCases {
- allowed, _, err := c.Allowed(context.Background(), tc.repo, tc.glRepository, tc.glID, tc.protocol, tc.changes)
+ allowed, _, err := c.Allowed(context.Background(), AllowedParams{
+ RepoPath: tc.repo.RelativePath,
+ GitObjectDirectory: tc.repo.GitObjectDirectory,
+ GitAlternateObjectDirectories: tc.repo.GitAlternateObjectDirectories,
+ GLRepository: tc.glRepository,
+ GLID: tc.glID,
+ GLProtocol: tc.protocol,
+ Changes: tc.changes,
+ })
require.NoError(t, err)
require.Equal(t, tc.allowed, allowed)
}
@@ -209,7 +217,15 @@ func TestAccess_escapedAndRelativeURLs(t *testing.T) {
},
}, config.TLS{})
require.NoError(t, err)
- allowed, _, err := c.Allowed(context.Background(), testRepo, glRepository, glID, protocol, changes)
+ allowed, _, err := c.Allowed(context.Background(), AllowedParams{
+ RepoPath: testRepo.RelativePath,
+ GitObjectDirectory: testRepo.GitObjectDirectory,
+ GitAlternateObjectDirectories: testRepo.GitAlternateObjectDirectories,
+ GLID: glID,
+ GLRepository: glRepository,
+ GLProtocol: protocol,
+ Changes: changes,
+ })
require.NoError(t, err)
require.True(t, allowed)
})
@@ -342,7 +358,15 @@ func TestAccess_allowedResponseHandling(t *testing.T) {
}, config.TLS{})
require.NoError(t, err)
- allowed, message, err := c.Allowed(context.Background(), testRepo, "repo-1", "key-123", "http", "a\nb\nc\nd")
+ allowed, message, err := c.Allowed(context.Background(), AllowedParams{
+ RepoPath: testRepo.RelativePath,
+ GitObjectDirectory: testRepo.GitObjectDirectory,
+ GitAlternateObjectDirectories: testRepo.GitAlternateObjectDirectories,
+ GLRepository: "repo-1",
+ GLID: "key-123",
+ GLProtocol: "http",
+ Changes: "a\nb\nc\nd",
+ })
require.Equal(t, tc.allowed, allowed)
if err != nil {
require.Contains(t, err.Error(), tc.errMsg)
diff --git a/internal/gitaly/hook/custom.go b/internal/gitaly/hook/custom.go
index 428a6fcba..1ed289ea3 100644
--- a/internal/gitaly/hook/custom.go
+++ b/internal/gitaly/hook/custom.go
@@ -12,7 +12,6 @@ import (
"strings"
"gitlab.com/gitlab-org/gitaly/internal/command"
- "gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"golang.org/x/sys/unix"
)
@@ -26,7 +25,7 @@ type customHooksExecutor func(ctx context.Context, args, env []string, stdin io.
// 2. <repository>.git/custom_hooks/<hook_name>.d/* - per project hooks
// 3. <repository>.git/hooks/<hook_name>.d/* - global hooks
func (m *GitLabHookManager) newCustomHooksExecutor(repo *gitalypb.Repository, hookName string) (customHooksExecutor, error) {
- repoPath, err := helper.GetRepoPath(repo)
+ repoPath, err := m.locator.GetRepoPath(repo)
if err != nil {
return nil, err
}
diff --git a/internal/gitaly/hook/custom_test.go b/internal/gitaly/hook/custom_test.go
index c9bac564d..482a78a23 100644
--- a/internal/gitaly/hook/custom_test.go
+++ b/internal/gitaly/hook/custom_test.go
@@ -150,6 +150,7 @@ func TestCustomHookPartialFailure(t *testing.T) {
defer cleanup()
mgr := GitLabHookManager{
+ locator: config.NewLocator(config.Config),
hooksConfig: config.Hooks{
CustomHooksDir: globalCustomHooksDir,
},
@@ -204,6 +205,7 @@ func TestCustomHooksMultipleHooks(t *testing.T) {
}
mgr := GitLabHookManager{
+ locator: config.NewLocator(config.Config),
hooksConfig: config.Hooks{
CustomHooksDir: globalCustomHooksDir,
},
@@ -275,6 +277,7 @@ func TestCustomHooksWithSymlinks(t *testing.T) {
expectedExecutedScripts := []string{updateHookPath, updateTildePath}
mgr := GitLabHookManager{
+ locator: config.NewLocator(config.Config),
hooksConfig: config.Hooks{
CustomHooksDir: globalCustomHooksDir,
},
@@ -307,6 +310,7 @@ func TestMultilineStdin(t *testing.T) {
writeCustomHook(t, "pre-receive-script", projectHooksPath, printStdinScript)
mgr := GitLabHookManager{
+ locator: config.NewLocator(config.Config),
hooksConfig: config.Hooks{
CustomHooksDir: globalCustomHooksDir,
},
@@ -345,6 +349,7 @@ func TestMultipleScriptsStdin(t *testing.T) {
}
mgr := GitLabHookManager{
+ locator: config.NewLocator(config.Config),
hooksConfig: config.Hooks{
CustomHooksDir: globalCustomHooksDir,
},
@@ -376,6 +381,7 @@ func callAndVerifyHooks(t *testing.T, repo *gitalypb.Repository, hookName, globa
defer cleanup()
mgr := GitLabHookManager{
+ locator: config.NewLocator(config.Config),
hooksConfig: config.Hooks{
CustomHooksDir: globalHooksDir,
},
diff --git a/internal/gitaly/hook/manager.go b/internal/gitaly/hook/manager.go
index 092816468..e838d63f3 100644
--- a/internal/gitaly/hook/manager.go
+++ b/internal/gitaly/hook/manager.go
@@ -7,6 +7,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly/client"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
@@ -48,6 +49,7 @@ type Manager interface {
// GitLabHookManager is a hook manager containing Git hook business logic. It
// uses the GitLab API to authenticate and track ongoing hook calls.
type GitLabHookManager struct {
+ locator storage.Locator
gitlabAPI GitlabAPI
hooksConfig config.Hooks
conns *client.Pool
@@ -55,8 +57,9 @@ type GitLabHookManager struct {
}
// NewManager returns a new hook manager
-func NewManager(gitlabAPI GitlabAPI, cfg config.Cfg) *GitLabHookManager {
+func NewManager(locator storage.Locator, gitlabAPI GitlabAPI, cfg config.Cfg) *GitLabHookManager {
return &GitLabHookManager{
+ locator: locator,
gitlabAPI: gitlabAPI,
hooksConfig: cfg.Hooks,
conns: client.NewPool(),
diff --git a/internal/gitaly/hook/postreceive_test.go b/internal/gitaly/hook/postreceive_test.go
index 7466af265..60775c830 100644
--- a/internal/gitaly/hook/postreceive_test.go
+++ b/internal/gitaly/hook/postreceive_test.go
@@ -13,7 +13,6 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/praefect/metadata"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func TestPrintAlert(t *testing.T) {
@@ -71,7 +70,7 @@ func TestPostReceive_customHook(t *testing.T) {
repo, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- hookManager := NewManager(GitlabAPIStub, config.Config)
+ hookManager := NewManager(config.NewLocator(config.Config), GitlabAPIStub, config.Config)
standardEnv := []string{
fmt.Sprintf("GITALY_SOCKET=%s", config.Config.GitalyInternalSocketPath()),
@@ -222,7 +221,7 @@ type postreceiveAPIMock struct {
postreceive func(context.Context, string, string, string, ...string) (bool, []PostReceiveMessage, error)
}
-func (m *postreceiveAPIMock) Allowed(ctx context.Context, repo *gitalypb.Repository, glRepository, glID, glProtocol, changes string) (bool, string, error) {
+func (m *postreceiveAPIMock) Allowed(ctx context.Context, params AllowedParams) (bool, string, error) {
return true, "", nil
}
@@ -340,7 +339,7 @@ func TestPostReceive_gitlab(t *testing.T) {
},
}
- hookManager := NewManager(&gitlabAPI, config.Config)
+ hookManager := NewManager(config.NewLocator(config.Config), &gitlabAPI, config.Config)
cleanup, err := testhelper.WriteCustomHook(testRepoPath, "post-receive", []byte("#!/bin/sh\necho hook called\n"))
require.NoError(t, err)
diff --git a/internal/gitaly/hook/prereceive.go b/internal/gitaly/hook/prereceive.go
index 06478b443..5750e345e 100644
--- a/internal/gitaly/hook/prereceive.go
+++ b/internal/gitaly/hook/prereceive.go
@@ -64,12 +64,12 @@ func (m *GitLabHookManager) PreReceiveHook(ctx context.Context, repo *gitalypb.R
}
func (m *GitLabHookManager) preReceiveHook(ctx context.Context, repo *gitalypb.Repository, env []string, changes []byte, stdout, stderr io.Writer) error {
- if gitObjDir, gitAltObjDirs := getEnvVar("GIT_OBJECT_DIRECTORY", env), getEnvVar("GIT_ALTERNATE_OBJECT_DIRECTORIES", env); gitObjDir != "" && gitAltObjDirs != "" {
- repoPath, err := helper.GetRepoPath(repo)
- if err != nil {
- return helper.ErrInternalf("getting repo path: %v", err)
- }
+ repoPath, err := m.locator.GetRepoPath(repo)
+ if err != nil {
+ return helper.ErrInternalf("getting repo path: %v", err)
+ }
+ if gitObjDir, gitAltObjDirs := getEnvVar("GIT_OBJECT_DIRECTORY", env), getEnvVar("GIT_ALTERNATE_OBJECT_DIRECTORIES", env); gitObjDir != "" && gitAltObjDirs != "" {
gitObjectDirRel, gitAltObjectDirRel, err := getRelativeObjectDirs(repoPath, gitObjDir, gitAltObjDirs)
if err != nil {
return helper.ErrInternalf("getting relative git object directories: %v", err)
@@ -94,7 +94,17 @@ func (m *GitLabHookManager) preReceiveHook(ctx context.Context, repo *gitalypb.R
return helper.ErrInternalf("GL_PROTOCOL not set")
}
- allowed, message, err := m.gitlabAPI.Allowed(ctx, repo, glRepo, glID, glProtocol, string(changes))
+ params := AllowedParams{
+ RepoPath: repoPath,
+ GitObjectDirectory: repo.GitObjectDirectory,
+ GitAlternateObjectDirectories: repo.GitAlternateObjectDirectories,
+ GLRepository: glRepo,
+ GLID: glID,
+ GLProtocol: glProtocol,
+ Changes: string(changes),
+ }
+
+ allowed, message, err := m.gitlabAPI.Allowed(ctx, params)
if err != nil {
return fmt.Errorf("GitLab: %v", err)
}
diff --git a/internal/gitaly/hook/prereceive_test.go b/internal/gitaly/hook/prereceive_test.go
index 393280afd..483a2f0f6 100644
--- a/internal/gitaly/hook/prereceive_test.go
+++ b/internal/gitaly/hook/prereceive_test.go
@@ -13,14 +13,13 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/praefect/metadata"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func TestPrereceive_customHooks(t *testing.T) {
repo, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- hookManager := NewManager(GitlabAPIStub, config.Config)
+ hookManager := NewManager(config.NewLocator(config.Config), GitlabAPIStub, config.Config)
standardEnv := []string{
fmt.Sprintf("GITALY_SOCKET=%s", config.Config.GitalyInternalSocketPath()),
@@ -158,12 +157,12 @@ func TestPrereceive_customHooks(t *testing.T) {
}
type prereceiveAPIMock struct {
- allowed func(context.Context, *gitalypb.Repository, string, string, string, string) (bool, string, error)
+ allowed func(context.Context, AllowedParams) (bool, string, error)
prereceive func(context.Context, string) (bool, error)
}
-func (m *prereceiveAPIMock) Allowed(ctx context.Context, repo *gitalypb.Repository, glRepository, glID, glProtocol, changes string) (bool, string, error) {
- return m.allowed(ctx, repo, glRepository, glID, glProtocol, changes)
+func (m *prereceiveAPIMock) Allowed(ctx context.Context, params AllowedParams) (bool, string, error) {
+ return m.allowed(ctx, params)
}
func (m *prereceiveAPIMock) PreReceive(ctx context.Context, glRepository string) (bool, error) {
@@ -197,7 +196,7 @@ func TestPrereceive_gitlab(t *testing.T) {
desc string
env []string
changes string
- allowed func(*testing.T, context.Context, *gitalypb.Repository, string, string, string, string) (bool, string, error)
+ allowed func(*testing.T, context.Context, AllowedParams) (bool, string, error)
prereceive func(*testing.T, context.Context, string) (bool, error)
expectHookCall bool
expectedErr error
@@ -206,12 +205,12 @@ func TestPrereceive_gitlab(t *testing.T) {
desc: "allowed change",
env: standardEnv,
changes: "changes\n",
- allowed: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, glRepo, glID, glProtocol, changes string) (bool, string, error) {
- require.Equal(t, testRepo, repo)
- require.Equal(t, testRepo.GlRepository, glRepo)
- require.Equal(t, "1234", glID)
- require.Equal(t, "web", glProtocol)
- require.Equal(t, "changes\n", changes)
+ allowed: func(t *testing.T, ctx context.Context, params AllowedParams) (bool, string, error) {
+ require.Equal(t, testRepoPath, params.RepoPath)
+ require.Equal(t, testRepo.GlRepository, params.GLRepository)
+ require.Equal(t, "1234", params.GLID)
+ require.Equal(t, "web", params.GLProtocol)
+ require.Equal(t, "changes\n", params.Changes)
return true, "", nil
},
prereceive: func(t *testing.T, ctx context.Context, glRepo string) (bool, error) {
@@ -224,7 +223,7 @@ func TestPrereceive_gitlab(t *testing.T) {
desc: "disallowed change",
env: standardEnv,
changes: "changes\n",
- allowed: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, glRepo, glID, glProtocol, changes string) (bool, string, error) {
+ allowed: func(t *testing.T, ctx context.Context, params AllowedParams) (bool, string, error) {
return false, "you shall not pass", nil
},
expectHookCall: false,
@@ -234,7 +233,7 @@ func TestPrereceive_gitlab(t *testing.T) {
desc: "allowed returns error",
env: standardEnv,
changes: "changes\n",
- allowed: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, glRepo, glID, glProtocol, changes string) (bool, string, error) {
+ allowed: func(t *testing.T, ctx context.Context, params AllowedParams) (bool, string, error) {
return false, "", errors.New("oops")
},
expectHookCall: false,
@@ -244,7 +243,7 @@ func TestPrereceive_gitlab(t *testing.T) {
desc: "prereceive rejects",
env: standardEnv,
changes: "changes\n",
- allowed: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, glRepo, glID, glProtocol, changes string) (bool, string, error) {
+ allowed: func(t *testing.T, ctx context.Context, params AllowedParams) (bool, string, error) {
return true, "", nil
},
prereceive: func(t *testing.T, ctx context.Context, glRepo string) (bool, error) {
@@ -257,7 +256,7 @@ func TestPrereceive_gitlab(t *testing.T) {
desc: "prereceive errors",
env: standardEnv,
changes: "changes\n",
- allowed: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, glRepo, glID, glProtocol, changes string) (bool, string, error) {
+ allowed: func(t *testing.T, ctx context.Context, params AllowedParams) (bool, string, error) {
return true, "", nil
},
prereceive: func(t *testing.T, ctx context.Context, glRepo string) (bool, error) {
@@ -274,15 +273,15 @@ func TestPrereceive_gitlab(t *testing.T) {
defer cleanup()
gitlabAPI := prereceiveAPIMock{
- allowed: func(ctx context.Context, repo *gitalypb.Repository, glRepo, glID, glProtocol, changes string) (bool, string, error) {
- return tc.allowed(t, ctx, repo, glRepo, glID, glProtocol, changes)
+ allowed: func(ctx context.Context, params AllowedParams) (bool, string, error) {
+ return tc.allowed(t, ctx, params)
},
prereceive: func(ctx context.Context, glRepo string) (bool, error) {
return tc.prereceive(t, ctx, glRepo)
},
}
- hookManager := NewManager(&gitlabAPI, config.Config)
+ hookManager := NewManager(config.NewLocator(config.Config), &gitlabAPI, config.Config)
cleanup, err := testhelper.WriteCustomHook(testRepoPath, "pre-receive", []byte("#!/bin/sh\necho called\n"))
require.NoError(t, err)
diff --git a/internal/gitaly/hook/update_test.go b/internal/gitaly/hook/update_test.go
index 8ab5609e3..f9efffc9d 100644
--- a/internal/gitaly/hook/update_test.go
+++ b/internal/gitaly/hook/update_test.go
@@ -16,7 +16,7 @@ func TestUpdate_customHooks(t *testing.T) {
repo, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- hookManager := NewManager(GitlabAPIStub, config.Config)
+ hookManager := NewManager(config.NewLocator(config.Config), GitlabAPIStub, config.Config)
standardEnv := []string{
fmt.Sprintf("GITALY_SOCKET=%s", config.Config.GitalyInternalSocketPath()),
diff --git a/internal/gitaly/service/cleanup/testhelper_test.go b/internal/gitaly/service/cleanup/testhelper_test.go
index f87642580..a0807ca3d 100644
--- a/internal/gitaly/service/cleanup/testhelper_test.go
+++ b/internal/gitaly/service/cleanup/testhelper_test.go
@@ -30,7 +30,7 @@ func runCleanupServiceServer(t *testing.T, cfg config.Cfg) (string, func()) {
srv := testhelper.NewServer(t, nil, nil, testhelper.WithInternalSocket(cfg))
gitalypb.RegisterCleanupServiceServer(srv.GrpcServer(), NewServer())
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(cfg, hook.NewManager(hook.GitlabAPIStub, cfg)))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(cfg, hook.NewManager(config.NewLocator(cfg), hook.GitlabAPIStub, cfg)))
reflection.Register(srv.GrpcServer())
require.NoError(t, srv.Start())
diff --git a/internal/gitaly/service/hook/pre_receive_test.go b/internal/gitaly/service/hook/pre_receive_test.go
index 3f568b3ef..8ddf82dab 100644
--- a/internal/gitaly/service/hook/pre_receive_test.go
+++ b/internal/gitaly/service/hook/pre_receive_test.go
@@ -135,7 +135,7 @@ func TestPreReceiveHook_GitlabAPIAccess(t *testing.T) {
gitlabAPI, err := gitalyhook.NewGitlabAPI(gitlabConfig, config.Config.TLS)
require.NoError(t, err)
- serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Cfg{})
+ serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Config)
defer stop()
client, conn := newHooksClient(t, serverSocketPath)
@@ -238,7 +238,7 @@ func TestPreReceive_APIErrors(t *testing.T) {
gitlabAPI, err := gitalyhook.NewGitlabAPI(gitlabConfig, config.Config.TLS)
require.NoError(t, err)
- serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Cfg{})
+ serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Config)
defer stop()
client, conn := newHooksClient(t, serverSocketPath)
@@ -301,7 +301,7 @@ exit %d
gitlabAPI, err := gitalyhook.NewGitlabAPI(gitlabConfig, config.Config.TLS)
require.NoError(t, err)
- serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Cfg{})
+ serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Config)
defer stop()
client, conn := newHooksClient(t, serverSocketPath)
@@ -421,7 +421,7 @@ func TestPreReceiveHook_Primary(t *testing.T) {
}, config.Config.TLS)
require.NoError(t, err)
- serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Cfg{})
+ serverSocketPath, stop := runHooksServerWithAPI(t, gitlabAPI, config.Config)
defer stop()
client, conn := newHooksClient(t, serverSocketPath)
diff --git a/internal/gitaly/service/hook/testhelper_test.go b/internal/gitaly/service/hook/testhelper_test.go
index 97f5fa8c9..7cc59858e 100644
--- a/internal/gitaly/service/hook/testhelper_test.go
+++ b/internal/gitaly/service/hook/testhelper_test.go
@@ -45,7 +45,7 @@ func runHooksServer(t *testing.T, cfg config.Cfg) (string, func()) {
func runHooksServerWithAPI(t *testing.T, gitlabAPI gitalyhook.GitlabAPI, cfg config.Cfg) (string, func()) {
srv := testhelper.NewServer(t, nil, nil)
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), NewServer(cfg, gitalyhook.NewManager(gitlabAPI, cfg)))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), NewServer(cfg, gitalyhook.NewManager(config.NewLocator(cfg), gitlabAPI, cfg)))
reflection.Register(srv.GrpcServer())
require.NoError(t, srv.Start())
diff --git a/internal/gitaly/service/objectpool/testhelper_test.go b/internal/gitaly/service/objectpool/testhelper_test.go
index 7296cf82f..40fc2d14a 100644
--- a/internal/gitaly/service/objectpool/testhelper_test.go
+++ b/internal/gitaly/service/objectpool/testhelper_test.go
@@ -39,7 +39,7 @@ func runObjectPoolServer(t *testing.T, cfg config.Cfg, locator storage.Locator)
require.NoError(t, err)
gitalypb.RegisterObjectPoolServiceServer(server, NewServer(locator))
- gitalypb.RegisterHookServiceServer(server, hookservice.NewServer(cfg, hook.NewManager(hook.GitlabAPIStub, cfg)))
+ gitalypb.RegisterHookServiceServer(server, hookservice.NewServer(cfg, hook.NewManager(locator, hook.GitlabAPIStub, cfg)))
go server.Serve(listener)
go server.Serve(internalListener)
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index 755c83b27..a0dcead6a 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -143,8 +143,8 @@ func testUserCreateBranchWithTransaction(t *testing.T, withRefTxHook bool) {
transactionServer := &testTransactionServer{}
srv := testhelper.NewServerWithAuth(t, nil, nil, config.Config.Auth.Token)
- hookManager := gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config)
locator := config.NewLocator(config.Config)
+ hookManager := gitalyhook.NewManager(locator, gitalyhook.GitlabAPIStub, config.Config)
conns := client.NewPool()
defer conns.Close()
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index 151c7ace4..2161cdaf1 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -85,8 +85,8 @@ func runOperationServiceServerWithRubyServer(t *testing.T, ruby *rubyserver.Serv
conns := client.NewPool()
- hookManager := gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config)
locator := config.NewLocator(config.Config)
+ hookManager := gitalyhook.NewManager(locator, gitalyhook.GitlabAPIStub, config.Config)
server := NewServer(config.Config, ruby, hookManager, locator, conns)
gitalypb.RegisterOperationServiceServer(srv.GrpcServer(), server)
diff --git a/internal/gitaly/service/operations/update_with_hooks_test.go b/internal/gitaly/service/operations/update_with_hooks_test.go
index bbac6b89a..90382244d 100644
--- a/internal/gitaly/service/operations/update_with_hooks_test.go
+++ b/internal/gitaly/service/operations/update_with_hooks_test.go
@@ -113,7 +113,7 @@ func TestUpdateReferenceWithHooks(t *testing.T) {
// We need to set up a separate "real" hook service here, as it will be used in
// git-update-ref(1) spawned by `updateRefWithHooks()`
- gitalypb.RegisterHookServiceServer(server.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(hook.GitlabAPIStub, config.Config)))
+ gitalypb.RegisterHookServiceServer(server.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(config.NewLocator(config.Config), hook.GitlabAPIStub, config.Config)))
require.NoError(t, server.Start())
user := &gitalypb.User{
diff --git a/internal/gitaly/service/ref/testhelper_test.go b/internal/gitaly/service/ref/testhelper_test.go
index cad73508d..4b74da2fa 100644
--- a/internal/gitaly/service/ref/testhelper_test.go
+++ b/internal/gitaly/service/ref/testhelper_test.go
@@ -45,8 +45,9 @@ func testMain(m *testing.M) int {
func runRefServiceServer(t *testing.T) (func(), string) {
srv := testhelper.NewServer(t, nil, nil, testhelper.WithInternalSocket(config.Config))
- gitalypb.RegisterRefServiceServer(srv.GrpcServer(), NewServer(config.NewLocator(config.Config)))
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(hook.GitlabAPIStub, config.Config)))
+ locator := config.NewLocator(config.Config)
+ gitalypb.RegisterRefServiceServer(srv.GrpcServer(), NewServer(locator))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(locator, hook.GitlabAPIStub, config.Config)))
require.NoError(t, srv.Start())
diff --git a/internal/gitaly/service/repository/clone_from_pool_internal_test.go b/internal/gitaly/service/repository/clone_from_pool_internal_test.go
index ba3736add..f3f14d58b 100644
--- a/internal/gitaly/service/repository/clone_from_pool_internal_test.go
+++ b/internal/gitaly/service/repository/clone_from_pool_internal_test.go
@@ -39,7 +39,7 @@ func getForkDestination(t *testing.T) (*gitalypb.Repository, string, func()) {
}
func TestCloneFromPoolInternal(t *testing.T) {
- serverSocketPath, clean := runFullServer(t)
+ serverSocketPath, clean := runFullServer(t, config.NewLocator(config.Config))
defer clean()
ctxOuter, cancel := testhelper.Context()
@@ -94,7 +94,7 @@ func TestCloneFromPoolInternal_bad_token(t *testing.T) {
defer func(old string) { config.Config.Auth.Token = old }(config.Config.Auth.Token)
config.Config.Auth.Token = "invalid"
- serverSocketPath, clean := runFullServer(t)
+ serverSocketPath, clean := runFullServer(t, config.NewLocator(config.Config))
defer clean()
ctxOuter, cancel := testhelper.Context()
diff --git a/internal/gitaly/service/repository/clone_from_pool_test.go b/internal/gitaly/service/repository/clone_from_pool_test.go
index e46ab3803..503e69fb5 100644
--- a/internal/gitaly/service/repository/clone_from_pool_test.go
+++ b/internal/gitaly/service/repository/clone_from_pool_test.go
@@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/repository"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -14,7 +15,7 @@ import (
)
func TestCloneFromPoolHTTP(t *testing.T) {
- serverSocketPath, clean := runFullServer(t)
+ serverSocketPath, clean := runFullServer(t, config.NewLocator(config.Config))
defer clean()
ctxOuter, cancel := testhelper.Context()
diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go
index c25a9c21b..296172074 100644
--- a/internal/gitaly/service/repository/fetch_test.go
+++ b/internal/gitaly/service/repository/fetch_test.go
@@ -23,11 +23,11 @@ import (
)
func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
- serverSocketPath, clean := runFullServer(t)
- defer clean()
-
locator := config.NewLocator(config.Config)
+ serverSocketPath, clean := runFullServer(t, locator)
+ defer clean()
+
client, conn := repository.NewRepositoryClient(t, serverSocketPath)
defer conn.Close()
@@ -83,11 +83,11 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
}
func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) {
- serverSocketPath, clean := runFullServer(t)
- defer clean()
-
locator := config.NewLocator(config.Config)
+ serverSocketPath, clean := runFullServer(t, locator)
+ defer clean()
+
client, conn := repository.NewRepositoryClient(t, serverSocketPath)
defer conn.Close()
@@ -140,11 +140,11 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) {
}
func TestFetchSourceBranchBranchNotFound(t *testing.T) {
- serverSocketPath, clean := runFullServer(t)
- defer clean()
-
locator := config.NewLocator(config.Config)
+ serverSocketPath, clean := runFullServer(t, locator)
+ defer clean()
+
client, conn := repository.NewRepositoryClient(t, serverSocketPath)
defer conn.Close()
@@ -216,11 +216,11 @@ func TestFetchSourceBranchBranchNotFound(t *testing.T) {
}
func TestFetchSourceBranchWrongRef(t *testing.T) {
- serverSocketPath, clean := runFullServer(t)
- defer clean()
-
locator := config.NewLocator(config.Config)
+ serverSocketPath, clean := runFullServer(t, locator)
+ defer clean()
+
client, conn := repository.NewRepositoryClient(t, serverSocketPath)
defer conn.Close()
@@ -352,7 +352,7 @@ func TestFetchFullServerRequiresAuthentication(t *testing.T) {
// we want to be sure that authentication is handled correctly. If the
// tests in this file were using a server without authentication we could
// not be confident that authentication is done right.
- serverSocketPath, clean := runFullServer(t)
+ serverSocketPath, clean := runFullServer(t, config.NewLocator(config.Config))
defer clean()
connOpts := []grpc.DialOption{
@@ -386,9 +386,9 @@ func newTestRepo(t *testing.T, locator storage.Locator, relativePath string) (*g
return repo, repoPath, func() { require.NoError(t, os.RemoveAll(repoPath)) }
}
-func runFullServer(t *testing.T) (string, func()) {
+func runFullServer(t *testing.T, locator storage.Locator) (string, func()) {
conns := client.NewPool()
- hookManager := hook.NewManager(hook.GitlabAPIStub, config.Config)
+ hookManager := hook.NewManager(locator, hook.GitlabAPIStub, config.Config)
server := serverPkg.NewInsecure(repository.RubyServer, hookManager, config.Config, conns)
@@ -410,9 +410,9 @@ func runFullServer(t *testing.T) (string, func()) {
}
}
-func runFullSecureServer(t *testing.T) (*grpc.Server, string, testhelper.Cleanup) {
+func runFullSecureServer(t *testing.T, locator storage.Locator) (*grpc.Server, string, testhelper.Cleanup) {
conns := client.NewPool()
- hookManager := hook.NewManager(hook.GitlabAPIStub, config.Config)
+ hookManager := hook.NewManager(locator, hook.GitlabAPIStub, config.Config)
server := serverPkg.NewSecure(repository.RubyServer, hookManager, config.Config, conns)
listener, addr := testhelper.GetLocalhostListener(t)
diff --git a/internal/gitaly/service/repository/fork_test.go b/internal/gitaly/service/repository/fork_test.go
index 9614e93d9..d18c5693a 100644
--- a/internal/gitaly/service/repository/fork_test.go
+++ b/internal/gitaly/service/repository/fork_test.go
@@ -40,14 +40,14 @@ func TestSuccessfulCreateForkRequest(t *testing.T) {
defer sslCleanup()
var serverCleanup testhelper.Cleanup
- _, serverSocketPath, serverCleanup = runFullSecureServer(t)
+ _, serverSocketPath, serverCleanup = runFullSecureServer(t, locator)
defer serverCleanup()
client, conn = repository.NewSecureRepoClient(t, serverSocketPath, testPool)
defer conn.Close()
} else {
var clean func()
- serverSocketPath, clean = runFullServer(t)
+ serverSocketPath, clean = runFullServer(t, locator)
defer clean()
client, conn = repository.NewRepositoryClient(t, serverSocketPath)
@@ -94,11 +94,11 @@ func TestSuccessfulCreateForkRequest(t *testing.T) {
}
func TestFailedCreateForkRequestDueToExistingTarget(t *testing.T) {
- serverSocketPath, clean := runFullServer(t)
- defer clean()
-
locator := config.NewLocator(config.Config)
+ serverSocketPath, clean := runFullServer(t, locator)
+ defer clean()
+
client, conn := repository.NewRepositoryClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go
index b62f3ba53..a7b403de8 100644
--- a/internal/gitaly/service/repository/replicate_test.go
+++ b/internal/gitaly/service/repository/replicate_test.go
@@ -44,7 +44,9 @@ func TestReplicateRepository(t *testing.T) {
},
}
- serverSocketPath, clean := runFullServer(t)
+ locator := config.NewLocator(config.Config)
+
+ serverSocketPath, clean := runFullServer(t, locator)
defer clean()
testRepo, testRepoPath, cleanupRepo := testhelper.NewTestRepo(t)
@@ -79,7 +81,6 @@ func TestReplicateRepository(t *testing.T) {
})
require.NoError(t, err)
- locator := config.NewLocator(config.Config)
targetRepoPath, err := locator.GetRepoPath(&targetRepo)
require.NoError(t, err)
@@ -257,8 +258,9 @@ func TestReplicateRepository_BadRepository(t *testing.T) {
invalidRepos = append(invalidRepos, targetRepo)
}
+ locator := config.NewLocator(config.Config)
for _, invalidRepo := range invalidRepos {
- invalidRepoPath, err := config.NewLocator(config.Config).GetPath(invalidRepo)
+ invalidRepoPath, err := locator.GetPath(invalidRepo)
require.NoError(t, err)
// delete git data so make the repo invalid
@@ -267,7 +269,7 @@ func TestReplicateRepository_BadRepository(t *testing.T) {
}
}
- serverSocketPath, clean := runFullServer(t)
+ serverSocketPath, clean := runFullServer(t, locator)
defer clean()
config.Config.SocketPath = serverSocketPath
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 31a71a9cf..3fa641313 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -109,7 +109,7 @@ func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, locator storage.Locat
srv := testhelper.NewServerWithAuth(t, streamInt, unaryInt, cfg.Auth.Token, opts...)
gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), NewServer(cfg, RubyServer, locator))
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(hook.GitlabAPIStub, cfg)))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(locator, hook.GitlabAPIStub, cfg)))
require.NoError(t, srv.Start())
diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go
index 85475491f..529a9cb3b 100644
--- a/internal/gitaly/service/smarthttp/receive_pack_test.go
+++ b/internal/gitaly/service/smarthttp/receive_pack_test.go
@@ -444,8 +444,9 @@ func runSmartHTTPHookServiceServer(t *testing.T) (*grpc.Server, string) {
t.Fatal(err)
}
- gitalypb.RegisterSmartHTTPServiceServer(server, NewServer(config.NewLocator(config.Config)))
- gitalypb.RegisterHookServiceServer(server, hook.NewServer(config.Config, gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config)))
+ locator := config.NewLocator(config.Config)
+ gitalypb.RegisterSmartHTTPServiceServer(server, NewServer(locator))
+ gitalypb.RegisterHookServiceServer(server, hook.NewServer(config.Config, gitalyhook.NewManager(locator, gitalyhook.GitlabAPIStub, config.Config)))
reflection.Register(server)
go server.Serve(listener)
@@ -505,9 +506,10 @@ func TestPostReceiveWithTransactionsViaPraefect(t *testing.T) {
testhelper.WriteShellSecretFile(t, gitlabShellDir, secretToken)
+ locator := config.NewLocator(config.Config)
gitalyServer := testhelper.NewServerWithAuth(t, nil, nil, config.Config.Auth.Token)
- gitalypb.RegisterSmartHTTPServiceServer(gitalyServer.GrpcServer(), NewServer(config.NewLocator(config.Config)))
- gitalypb.RegisterHookServiceServer(gitalyServer.GrpcServer(), hook.NewServer(config.Config, gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config)))
+ gitalypb.RegisterSmartHTTPServiceServer(gitalyServer.GrpcServer(), NewServer(locator))
+ gitalypb.RegisterHookServiceServer(gitalyServer.GrpcServer(), hook.NewServer(config.Config, gitalyhook.NewManager(locator, gitalyhook.GitlabAPIStub, config.Config)))
reflection.Register(gitalyServer.GrpcServer())
require.NoError(t, gitalyServer.Start())
defer gitalyServer.Stop()
@@ -552,9 +554,10 @@ func (t *testTransactionServer) VoteTransaction(ctx context.Context, in *gitalyp
func TestPostReceiveWithReferenceTransactionHook(t *testing.T) {
refTransactionServer := &testTransactionServer{}
+ locator := config.NewLocator(config.Config)
gitalyServer := testhelper.NewTestGrpcServer(t, nil, nil)
- gitalypb.RegisterSmartHTTPServiceServer(gitalyServer, NewServer(config.NewLocator(config.Config)))
- gitalypb.RegisterHookServiceServer(gitalyServer, hook.NewServer(config.Config, gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config)))
+ gitalypb.RegisterSmartHTTPServiceServer(gitalyServer, NewServer(locator))
+ gitalypb.RegisterHookServiceServer(gitalyServer, hook.NewServer(config.Config, gitalyhook.NewManager(locator, gitalyhook.GitlabAPIStub, config.Config)))
gitalypb.RegisterRefTransactionServer(gitalyServer, refTransactionServer)
reflection.Register(gitalyServer)
diff --git a/internal/gitaly/service/smarthttp/testhelper_test.go b/internal/gitaly/service/smarthttp/testhelper_test.go
index 6c2a9dbee..9aadd9104 100644
--- a/internal/gitaly/service/smarthttp/testhelper_test.go
+++ b/internal/gitaly/service/smarthttp/testhelper_test.go
@@ -58,8 +58,9 @@ func runSmartHTTPServer(t *testing.T, serverOpts ...ServerOpt) (string, func())
},
testhelper.WithInternalSocket(config.Config))
- gitalypb.RegisterSmartHTTPServiceServer(srv.GrpcServer(), NewServer(config.NewLocator(config.Config), serverOpts...))
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(hook.GitlabAPIStub, config.Config)))
+ locator := config.NewLocator(config.Config)
+ gitalypb.RegisterSmartHTTPServiceServer(srv.GrpcServer(), NewServer(locator, serverOpts...))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(locator, hook.GitlabAPIStub, config.Config)))
require.NoError(t, srv.Start())
diff --git a/internal/gitaly/service/ssh/testhelper_test.go b/internal/gitaly/service/ssh/testhelper_test.go
index cba341786..cc3299a2f 100644
--- a/internal/gitaly/service/ssh/testhelper_test.go
+++ b/internal/gitaly/service/ssh/testhelper_test.go
@@ -42,8 +42,9 @@ func testMain(m *testing.M) int {
func runSSHServer(t *testing.T, serverOpts ...ServerOpt) (string, func()) {
srv := testhelper.NewServer(t, nil, nil, testhelper.WithInternalSocket(config.Config))
- gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), NewServer(config.NewLocator(config.Config), serverOpts...))
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(hook.GitlabAPIStub, config.Config)))
+ locator := config.NewLocator(config.Config)
+ gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), NewServer(locator, serverOpts...))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(locator, hook.GitlabAPIStub, config.Config)))
require.NoError(t, srv.Start())
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index c7c2f2ccc..5a7feccba 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -974,7 +974,7 @@ func TestBackoff(t *testing.T) {
func runFullGitalyServer(t *testing.T) (string, func()) {
conns := client.NewPool()
- server := serverPkg.NewInsecure(RubyServer, hook.NewManager(hook.GitlabAPIStub, gitaly_config.Config), gitaly_config.Config, conns)
+ server := serverPkg.NewInsecure(RubyServer, hook.NewManager(gitaly_config.NewLocator(gitaly_config.Config), hook.GitlabAPIStub, gitaly_config.Config), gitaly_config.Config, conns)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()