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 Bajao <ebajao@gitlab.com>2019-06-05 01:43:13 +0300
committerPaul Okstad <pokstad@gitlab.com>2019-06-05 01:43:13 +0300
commit11a757ce00e09b26746f4ea3d8e84c2e889fd578 (patch)
tree4d8badd144e6dee4309673908c41da4dc78ab798 /internal/helper/repo_test.go
parentb27493b8a6f19a0b4ab6325d38781a4f03088904 (diff)
Update vendored gitaly-proto
The gitaly-proto version being used has been rebased and updated. Need to update it here as well.
Diffstat (limited to 'internal/helper/repo_test.go')
-rw-r--r--internal/helper/repo_test.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/internal/helper/repo_test.go b/internal/helper/repo_test.go
index ca2c43cc2..58a200423 100644
--- a/internal/helper/repo_test.go
+++ b/internal/helper/repo_test.go
@@ -160,3 +160,77 @@ func TestGetRepoPathWithCorruptedRepo(t *testing.T) {
assertInvalidRepoWithoutFile(t, testRepo, testRepoPath, file)
}
}
+
+func TestGetObjectDirectoryPath(t *testing.T) {
+ testRepo := testhelper.TestRepository()
+ repoPath, err := GetRepoPath(testRepo)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ testCases := []struct {
+ desc string
+ repo *gitalypb.Repository
+ path string
+ err codes.Code
+ }{
+ {
+ desc: "storages configured",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "objects/"},
+ path: path.Join(repoPath, "objects/"),
+ },
+ {
+ desc: "no GitObjectDirectoryPath",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath},
+ err: codes.InvalidArgument,
+ },
+ {
+ desc: "with directory traversal",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "../bazqux.git"},
+ err: codes.InvalidArgument,
+ },
+ {
+ desc: "valid path but doesn't exist",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "foo../bazqux.git"},
+ err: codes.NotFound,
+ },
+ {
+ desc: "with sneaky directory traversal",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "/../bazqux.git"},
+ err: codes.InvalidArgument,
+ },
+ {
+ desc: "with one level traversal at the end",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "objects/.."},
+ err: codes.InvalidArgument,
+ },
+ {
+ desc: "with one level dashed traversal at the end",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "objects/../"},
+ err: codes.InvalidArgument,
+ },
+ {
+ desc: "with deep traversal at the end",
+ repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "bazqux.git/../.."},
+ err: codes.InvalidArgument,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.desc, func(t *testing.T) {
+ path, err := GetObjectDirectoryPath(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)
+ })
+ }
+}