Skip to content

Commit

Permalink
validatePathComponent tests
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
  • Loading branch information
apostasie committed Dec 4, 2024
1 parent c0b8f63 commit 3d944cb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions pkg/store/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package store

import (
"fmt"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -218,3 +220,60 @@ 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",
"∞",
}

if runtime.GOOS == "windows" {
invalid = append(invalid, []string{
"\\start",
"mid\\dle",
"end\\",
"\\",
"\\.",
"com².whatever",
"lpT2",
"Prn.",
"nUl",
"AUX",
"A<A",
"A>A",
"A:A",
"A\"A",
"A|A",
"A?A",
"A*A",
"end.dot.",
"end.space ",
}...)
}

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

}
2 changes: 1 addition & 1 deletion pkg/store/filestore_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func validatePlatformSpecific(pathComponent string) error {
}

if pathComponent[len(pathComponent)-1:] == "." || pathComponent[len(pathComponent)-1:] == " " {
return fmt.Errorf("identifier %q cannot end with a space of dot", pathComponent)
return fmt.Errorf("identifier %q cannot end with a space or dot", pathComponent)
}

return nil
Expand Down

0 comments on commit 3d944cb

Please sign in to comment.