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>2022-10-31 18:22:35 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2022-11-08 12:33:03 +0300
commit52f1d86984251bb14537c39362302325d398df79 (patch)
tree1400edb6cc6fe7a230f20e1405e8d0035c6a8769
parent0e5faf42aa06ec3c5a3474d483dba75b921cf79f (diff)
praefect: Use 'service.ValidateRepository()' to validate input
Replace simple non-nil check with call of the ValidateRepository() function that also validates RelativePath and StorageName fields. Part of https://gitlab.com/gitlab-org/gitaly/-/issues/3717
-rw-r--r--internal/praefect/rename_repository.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/praefect/rename_repository.go b/internal/praefect/rename_repository.go
index d6d4cde35..1e6f88879 100644
--- a/internal/praefect/rename_repository.go
+++ b/internal/praefect/rename_repository.go
@@ -4,7 +4,7 @@ import (
"errors"
"fmt"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/commonerr"
@@ -16,12 +16,13 @@ import (
func validateRenameRepositoryRequest(req *gitalypb.RenameRepositoryRequest, virtualStorages map[string]struct{}) error {
// These checks are not strictly necessary but they exist to keep retain compatibility with
// Gitaly's tested behavior.
- if req.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
} else if req.GetRelativePath() == "" {
return helper.ErrInvalidArgumentf("destination relative path is empty")
- } else if _, ok := virtualStorages[req.GetRepository().GetStorageName()]; !ok {
- return helper.ErrInvalidArgumentf("GetStorageByName: no such storage: %q", req.GetRepository().GetStorageName())
+ } else if _, ok := virtualStorages[repository.GetStorageName()]; !ok {
+ return helper.ErrInvalidArgumentf("GetStorageByName: no such storage: %q", repository.GetStorageName())
} else if _, err := storage.ValidateRelativePath("/fake-root", req.GetRelativePath()); err != nil {
// Gitaly uses ValidateRelativePath to verify there are no traversals, so we use the same function
// here. Praefect is not susceptible to path traversals as it generates its own disk paths but we