mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-08-28 23:45:48 +02:00
* 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>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package storage
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestBuildLocalPath(t *testing.T) {
|
|
kases := []struct {
|
|
localDir string
|
|
path string
|
|
expected string
|
|
}{
|
|
{
|
|
"a",
|
|
"0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"a",
|
|
"../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"a",
|
|
"0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"b",
|
|
"a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"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) {
|
|
l := LocalStorage{dir: k.localDir}
|
|
|
|
assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
|
|
})
|
|
}
|
|
}
|