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) + } + +}