aboutsummaryrefslogtreecommitdiffstats
path: root/modules/storage/local_test.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-03-22 21:02:26 +0000
committerGitHub <noreply@github.com>2022-03-22 17:02:26 -0400
commit3f71ab9a12f12a021c3f7b9d8cf89c4fe45bf3e4 (patch)
tree734c7830b58d66516c2f9229134ca08ea19c81d5 /modules/storage/local_test.go
parentd2c165811a1bad081b2e99ca580e3bdbb18171f0 (diff)
downloadgitea-3f71ab9a12f12a021c3f7b9d8cf89c4fe45bf3e4.tar.gz
gitea-3f71ab9a12f12a021c3f7b9d8cf89c4fe45bf3e4.zip
Clean paths when looking in Storage (#19124)
* Clean paths when looking in Storage Ensure paths are clean for minio aswell as local storage. Use url.Path not RequestURI/EscapedPath in storageHandler. Signed-off-by: Andrew Thornton <art27@cantab.net> * Apply suggestions from code review Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/storage/local_test.go')
-rw-r--r--modules/storage/local_test.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go
index 8714f37f0d..0749036cb7 100644
--- a/modules/storage/local_test.go
+++ b/modules/storage/local_test.go
@@ -10,36 +10,44 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestLocalPathIsValid(t *testing.T) {
+func TestBuildLocalPath(t *testing.T) {
kases := []struct {
- path string
- valid bool
+ localDir string
+ path string
+ expected string
}{
{
+ "a",
+ "0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- true,
},
{
- "../a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- false,
+ "a",
+ "../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
{
- "a\\0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- true,
+ "a",
+ "0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
{
- "b/../a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- false,
+ "b",
+ "a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
{
- "..\\a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- false,
+ "b",
+ "a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
}
for _, k := range kases {
t.Run(k.path, func(t *testing.T) {
- assert.EqualValues(t, k.valid, isLocalPathValid(k.path))
+ l := LocalStorage{dir: k.localDir}
+
+ assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
})
}
}