diff options
author | Jakob Unterwurzacher | 2021-10-21 09:37:04 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-10-21 14:55:30 +0200 |
commit | dc32710045f6f46913ae336b6fb77bf90b6bdb85 (patch) | |
tree | 890dde8bdef6facc61ee9cd3c4d0246225fee6ad /internal/nametransform/longnames_test.go | |
parent | a652be805e1562948aff4dc232bd1c516ff01d00 (diff) |
nametransform: add longNameMax parameter
Determines when to start hashing long names instead
of hardcoded 255. Will be used to alleviate "name too long"
issues some users see on cloud storage.
https://github.com/rfjakob/gocryptfs/issues/499
Diffstat (limited to 'internal/nametransform/longnames_test.go')
-rw-r--r-- | internal/nametransform/longnames_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/nametransform/longnames_test.go b/internal/nametransform/longnames_test.go index 4210492..7a4e915 100644 --- a/internal/nametransform/longnames_test.go +++ b/internal/nametransform/longnames_test.go @@ -1,7 +1,11 @@ package nametransform import ( + "strings" "testing" + + "github.com/rfjakob/gocryptfs/v2/internal/contentenc" + "github.com/rfjakob/gocryptfs/v2/internal/cryptocore" ) func TestIsLongName(t *testing.T) { @@ -28,3 +32,40 @@ func TestRemoveLongNameSuffix(t *testing.T) { t.Error(".name suffix not removed") } } + +func newLognamesTestInstance(longNameMax uint8) *NameTransform { + key := make([]byte, cryptocore.KeyLen) + cCore := cryptocore.New(key, cryptocore.BackendGoGCM, contentenc.DefaultIVBits, true) + return New(cCore.EMECipher, true, longNameMax, true, nil, false) +} + +func TestLongNameMax(t *testing.T) { + iv := make([]byte, 16) + for max := 0; max <= NameMax; max++ { + n := newLognamesTestInstance(uint8(max)) + if max == 0 { + // effective value is 255 + max = NameMax + } + for l := 0; l <= NameMax+10; l++ { + name := strings.Repeat("x", l) + out, err := n.EncryptAndHashName(name, iv) + if l == 0 || l > NameMax { + if err == nil { + t.Errorf("should have rejected a name of length %d, but did not", l) + } + continue + } + cName, _ := n.EncryptName(name, iv) + rawLen := len(cName) + want := LongNameNone + if rawLen > max { + want = LongNameContent + } + have := NameType(out) + if have != want { + t.Errorf("l=%d max=%d: wanted %v, got %v\nname=%q\nout=%q", l, max, want, have, name, out) + } + } + } +} |