69d88505fd
Our git version is v2+ for some time now, but go.mod still declared v1. Hopefully making both match makes https://pkg.go.dev/github.com/rfjakob/gocryptfs/v2 work. All the import paths have been fixed like this: find . -name \*.go | xargs sed -i s%github.com/rfjakob/gocryptfs/%github.com/rfjakob/gocryptfs/v2/%
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package fusefrontend
|
|
|
|
// This file is named "xattr_unit_test.go" because there is also a
|
|
// "xattr_integration_test.go" in the test/xattr package.
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanwen/go-fuse/v2/fs"
|
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/contentenc"
|
|
"github.com/rfjakob/gocryptfs/v2/internal/cryptocore"
|
|
"github.com/rfjakob/gocryptfs/v2/internal/nametransform"
|
|
)
|
|
|
|
func newTestFS(args Args) *RootNode {
|
|
// Init crypto backend
|
|
key := make([]byte, cryptocore.KeyLen)
|
|
cCore := cryptocore.New(key, cryptocore.BackendGoGCM, contentenc.DefaultIVBits, true, false)
|
|
cEnc := contentenc.New(cCore, contentenc.DefaultBS, false)
|
|
n := nametransform.New(cCore.EMECipher, true, true, nil, false)
|
|
rn := NewRootNode(args, cEnc, n)
|
|
oneSec := time.Second
|
|
options := &fs.Options{
|
|
EntryTimeout: &oneSec,
|
|
AttrTimeout: &oneSec,
|
|
}
|
|
fs.NewNodeFS(rn, options)
|
|
return rn
|
|
}
|
|
|
|
func TestEncryptDecryptXattrName(t *testing.T) {
|
|
fs := newTestFS(Args{})
|
|
attr1 := "user.foo123456789"
|
|
cAttr, err := fs.encryptXattrName(attr1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Logf("cAttr=%v", cAttr)
|
|
attr2, err := fs.decryptXattrName(cAttr)
|
|
if attr1 != attr2 || err != nil {
|
|
t.Fatalf("Decrypt mismatch: %v != %v", attr1, attr2)
|
|
}
|
|
}
|