Skip to content

Commit

Permalink
validatePathComponent tests
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Dec 4, 2024
1 parent c0b8f63 commit 7e1c5bc
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 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,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",
"A<A",
"A>A",
"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)
}

}

0 comments on commit 7e1c5bc

Please sign in to comment.