2018-03-18 17:43:38 +01:00
|
|
|
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"
|
2020-07-11 20:15:47 +02:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hanwen/go-fuse/v2/fs"
|
2018-03-18 17:43:38 +01:00
|
|
|
|
2021-08-23 15:05:15 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/contentenc"
|
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/cryptocore"
|
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/nametransform"
|
2018-03-18 17:43:38 +01:00
|
|
|
)
|
|
|
|
|
2020-07-11 20:15:47 +02:00
|
|
|
func newTestFS(args Args) *RootNode {
|
2018-03-18 17:43:38 +01:00
|
|
|
// Init crypto backend
|
|
|
|
key := make([]byte, cryptocore.KeyLen)
|
2021-09-10 12:14:19 +02:00
|
|
|
cCore := cryptocore.New(key, cryptocore.BackendGoGCM, contentenc.DefaultIVBits, true)
|
|
|
|
cEnc := contentenc.New(cCore, contentenc.DefaultBS)
|
2021-10-21 09:37:04 +02:00
|
|
|
n := nametransform.New(cCore.EMECipher, true, 0, true, nil, false)
|
2020-07-11 20:15:47 +02:00
|
|
|
rn := NewRootNode(args, cEnc, n)
|
|
|
|
oneSec := time.Second
|
|
|
|
options := &fs.Options{
|
|
|
|
EntryTimeout: &oneSec,
|
|
|
|
AttrTimeout: &oneSec,
|
|
|
|
}
|
|
|
|
fs.NewNodeFS(rn, options)
|
|
|
|
return rn
|
2018-03-18 17:43:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEncryptDecryptXattrName(t *testing.T) {
|
2020-07-14 19:55:20 +02:00
|
|
|
fs := newTestFS(Args{})
|
|
|
|
attr1 := "user.foo123456789"
|
2021-06-02 14:21:30 +02:00
|
|
|
cAttr, err := fs.encryptXattrName(attr1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-07-14 19:55:20 +02:00
|
|
|
t.Logf("cAttr=%v", cAttr)
|
|
|
|
attr2, err := fs.decryptXattrName(cAttr)
|
|
|
|
if attr1 != attr2 || err != nil {
|
|
|
|
t.Fatalf("Decrypt mismatch: %v != %v", attr1, attr2)
|
|
|
|
}
|
2018-03-18 17:43:38 +01:00
|
|
|
}
|