aboutsummaryrefslogtreecommitdiff
path: root/internal/nametransform/names_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-06-02 14:21:30 +0200
committerJakob Unterwurzacher2021-06-02 14:29:48 +0200
commit04858ddd222bbf7156f33f99cfb293a9b1e15ec8 (patch)
tree732cbf83c9d842a911d515abbad7c153c4159354 /internal/nametransform/names_test.go
parent242cdf966f262b2e20785eb0ff49ac55a8bd4636 (diff)
nametransform: check name validity on encryption
xfstests generic/523 discovered that we allowed to set xattrs with "/" in the name, but did not allow to read them later. With this change we do not allow to set them in the first place.
Diffstat (limited to 'internal/nametransform/names_test.go')
-rw-r--r--internal/nametransform/names_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/nametransform/names_test.go b/internal/nametransform/names_test.go
index 9d77c2d..b4e98d4 100644
--- a/internal/nametransform/names_test.go
+++ b/internal/nametransform/names_test.go
@@ -2,6 +2,7 @@ package nametransform
import (
"bytes"
+ "strings"
"testing"
)
@@ -51,3 +52,26 @@ func TestUnpad16Garbage(t *testing.T) {
}
}
}
+
+func TestIsValidName(t *testing.T) {
+ cases := []struct {
+ in string
+ want bool
+ }{
+ {"", false},
+ {".", false},
+ {"..", false},
+ {"...", true},
+ {"asdasd/asdasd", false},
+ {"asdasd\000asdasd", false},
+ {"hello", true},
+ {strings.Repeat("x", 255), true},
+ {strings.Repeat("x", 256), false},
+ }
+ for _, c := range cases {
+ have := IsValidName(c.in)
+ if (have == nil) != c.want {
+ t.Errorf("IsValidName(%q): want %v have %v", c.in, c.want, have)
+ }
+ }
+}