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"
|
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/internal/contentenc"
|
|
|
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
|
|
|
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
|
|
|
)
|
|
|
|
|
2018-10-14 20:11:49 +02:00
|
|
|
func newTestFS(args Args) *FS {
|
2018-03-18 17:43:38 +01:00
|
|
|
// 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)
|
|
|
|
nameTransform := nametransform.New(cCore.EMECipher, true, true)
|
|
|
|
return NewFS(args, cEnc, nameTransform)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEncryptDecryptXattrName(t *testing.T) {
|
2018-10-14 20:11:49 +02:00
|
|
|
fs := newTestFS(Args{})
|
2018-03-18 17:43:38 +01:00
|
|
|
attr1 := "user.foo123456789"
|
2018-04-17 20:33:04 +02:00
|
|
|
cAttr := fs.encryptXattrName(attr1)
|
2018-03-18 17:43:38 +01:00
|
|
|
t.Logf("cAttr=%v", cAttr)
|
|
|
|
attr2, err := fs.decryptXattrName(cAttr)
|
2018-04-17 20:33:04 +02:00
|
|
|
if attr1 != attr2 || err != nil {
|
2018-03-18 17:43:38 +01:00
|
|
|
t.Fatalf("Decrypt mismatch: %v != %v", attr1, attr2)
|
|
|
|
}
|
|
|
|
}
|