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-12-15 20:24:04 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2020-12-16 15:26:18 +0300
commit1f73d6fd3796378e16c25dddd6a12536d7f4cf14 (patch)
tree3201b82e48b908c6ae3cd646f0432ebd7b06e9d6 /internal/helper/repo_test.go
parentef065f1e55b31be704077e519999eb7e01a27832 (diff)
Removal of helper.GetRepoPath
helper.GetRepoPath is not used anymore in the production code so we remove it and all outdated dependencies of it. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
Diffstat (limited to 'internal/helper/repo_test.go')
-rw-r--r--internal/helper/repo_test.go156
1 files changed, 0 insertions, 156 deletions
diff --git a/internal/helper/repo_test.go b/internal/helper/repo_test.go
index ba8648ee3..8f4b3d8b6 100644
--- a/internal/helper/repo_test.go
+++ b/internal/helper/repo_test.go
@@ -2,14 +2,11 @@ package helper
import (
"os"
- "path/filepath"
"testing"
"github.com/stretchr/testify/assert"
- "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
- "google.golang.org/grpc/codes"
)
func TestMain(m *testing.M) {
@@ -73,156 +70,3 @@ func TestRepoPathEqual(t *testing.T) {
})
}
}
-
-func TestGetRepoPath(t *testing.T) {
- defer func(oldStorages []config.Storage) {
- config.Config.Storages = oldStorages
- }(config.Config.Storages)
-
- testRepo, _, cleanup := testhelper.NewTestRepo(t)
- defer cleanup()
-
- repoPath, err := GetRepoPath(testRepo)
- if err != nil {
- t.Fatal(err)
- }
-
- exampleStorages := []config.Storage{
- {Name: "default", Path: testhelper.GitlabTestStoragePath()},
- {Name: "other", Path: "/home/git/repositories2"},
- {Name: "third", Path: "/home/git/repositories3"},
- }
-
- testCases := []struct {
- desc string
- storages []config.Storage
- repo *gitalypb.Repository
- path string
- err codes.Code
- }{
- {
- desc: "storages configured",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: testRepo.GetRelativePath()},
- path: repoPath,
- },
- {
- desc: "no storage config, storage name provided",
- repo: &gitalypb.Repository{StorageName: "does not exist", RelativePath: testRepo.GetRelativePath()},
- err: codes.InvalidArgument,
- },
- {
- desc: "no storage config, nil repo",
- err: codes.InvalidArgument,
- },
- {
- desc: "storage config provided, empty repo",
- storages: exampleStorages,
- repo: &gitalypb.Repository{},
- err: codes.InvalidArgument,
- },
- {
- desc: "no storage config, empty repo",
- repo: &gitalypb.Repository{},
- err: codes.InvalidArgument,
- },
- {
- desc: "non existing repo",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "made/up/path.git"},
- err: codes.NotFound,
- },
- {
- desc: "non existing storage",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: "does not exists", RelativePath: testRepo.GetRelativePath()},
- err: codes.InvalidArgument,
- },
- {
- desc: "storage defined but storage dir does not exist",
- storages: []config.Storage{{Name: testRepo.GetStorageName(), Path: "/does/not/exist"}},
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "foobar.git"},
- err: codes.Internal,
- },
- {
- desc: "relative path with directory traversal",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "../bazqux.git"},
- err: codes.InvalidArgument,
- },
- {
- desc: "valid path with ..",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "foo../bazqux.git"},
- err: codes.NotFound, // Because the directory doesn't exist
- },
- {
- desc: "relative path with sneaky directory traversal",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "/../bazqux.git"},
- err: codes.InvalidArgument,
- },
- {
- desc: "relative path with traversal outside storage",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: testRepo.GetRelativePath() + "/../../../../.."},
- err: codes.InvalidArgument,
- },
- {
- desc: "relative path with traversal outside storage with trailing slash",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: testRepo.GetRelativePath() + "/../../../../../"},
- err: codes.InvalidArgument,
- },
- {
- desc: "relative path with deep traversal at the end",
- storages: exampleStorages,
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "bazqux.git/../.."},
- err: codes.InvalidArgument,
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- config.Config.Storages = tc.storages
- path, err := GetRepoPath(tc.repo)
-
- if tc.err != codes.OK {
- testhelper.RequireGrpcError(t, err, tc.err)
- return
- }
-
- if err != nil {
- assert.NoError(t, err)
- return
- }
-
- assert.Equal(t, tc.path, path)
- })
- }
-}
-
-func assertInvalidRepoWithoutFile(t *testing.T, repo *gitalypb.Repository, repoPath, file string) {
- oldRoute := filepath.Join(repoPath, file)
- renamedRoute := filepath.Join(repoPath, file+"moved")
- os.Rename(oldRoute, renamedRoute)
- defer func() {
- os.Rename(renamedRoute, oldRoute)
- }()
-
- _, err := GetRepoPath(repo)
-
- testhelper.RequireGrpcError(t, err, codes.NotFound)
-}
-
-func TestGetRepoPathWithCorruptedRepo(t *testing.T) {
- testRepo, _, cleanup := testhelper.NewTestRepo(t)
- defer cleanup()
-
- testRepoStoragePath := testhelper.GitlabTestStoragePath()
- testRepoPath := filepath.Join(testRepoStoragePath, testRepo.RelativePath)
-
- for _, file := range []string{"objects", "refs", "HEAD"} {
- assertInvalidRepoWithoutFile(t, testRepo, testRepoPath, file)
- }
-}