From 7e1c5bc6d5b206b0d9a70f5dabab3d861453b2cc 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..7b36b89dde7 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", + "mid\\dle", + "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.NilError(t, err, v) + } + +}