From 300bafaaf8f577d2abc3beff8dd5a08b65e1f91a Mon Sep 17 00:00:00 2001 From: apostasie Date: Tue, 3 Dec 2024 14:18:40 -0800 Subject: [PATCH] validatePathComponent tests Signed-off-by: apostasie --- pkg/store/filestore_test.go | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/pkg/store/filestore_test.go b/pkg/store/filestore_test.go index 2496b96cbb1..b696aaa9f3c 100644 --- a/pkg/store/filestore_test.go +++ b/pkg/store/filestore_test.go @@ -17,6 +17,8 @@ package store import ( + "fmt" + "runtime" "testing" "time" @@ -218,3 +220,59 @@ func TestFileStoreConcurrent(t *testing.T) { }) assert.NilError(t, lErr, "locking should not error") } + +func TestFileStoreFilesystemRestrictions(t *testing.T) { + invalid := []string{ + "/", + "/start", + "mid/dle", + "end/", + ".", + "..", + "", + fmt.Sprintf("A%0255s", "A"), + } + + valid := []string{ + fmt.Sprintf("A%0254s", "A"), + "test", + "test-hyphen", + ".start.dot", + "mid.dot", + "end.dot.", + "∞", + } + + if runtime.GOOS == "windows" { + invalid = append(invalid, []string{ + "\\start", + "mi\\ddle", + "end\\", + "\\", + "\\.", + "com²whatever", + "lpT2", + "Prn.", + "nUl", + "AUX", + "AA", + "A:A", + "A\"A", + "A|A", + "A?A", + "A*A", + }...) + } + + for _, v := range invalid { + err := validatePathComponent(v) + assert.ErrorIs(t, err, ErrInvalidArgument, v) + } + + for _, v := range valid { + err := validatePathComponent(v) + assert.ErrorIs(t, err, nil, v) + } + +}