aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend/xattr_unit_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-03-18 17:43:38 +0100
committerJakob Unterwurzacher2018-03-25 21:06:10 +0200
commit1ed3d51df1750d5472b1349222c352171f1e8d64 (patch)
treeb5f02aa633e8ebf1a71c4d1778a2e29310541d33 /internal/fusefrontend/xattr_unit_test.go
parentf20974c4dad913a07ce5808005fe07084f87c95f (diff)
fusefrontend: add xattr support
At the moment, only for reverse mode. https://github.com/rfjakob/gocryptfs/issues/217
Diffstat (limited to 'internal/fusefrontend/xattr_unit_test.go')
-rw-r--r--internal/fusefrontend/xattr_unit_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/fusefrontend/xattr_unit_test.go b/internal/fusefrontend/xattr_unit_test.go
new file mode 100644
index 0000000..ea5d3bb
--- /dev/null
+++ b/internal/fusefrontend/xattr_unit_test.go
@@ -0,0 +1,41 @@
+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 (
+ "syscall"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/internal/contentenc"
+ "github.com/rfjakob/gocryptfs/internal/cryptocore"
+ "github.com/rfjakob/gocryptfs/internal/nametransform"
+)
+
+func newTestFS() *FS {
+ // 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)
+ args := Args{}
+ return NewFS(args, cEnc, nameTransform)
+}
+
+func TestEncryptDecryptXattrName(t *testing.T) {
+ fs := newTestFS()
+ _, err := fs.encryptXattrName("xxxx")
+ if err != syscall.EPERM {
+ t.Fatalf("Names that don't start with 'user.' should fail")
+ }
+ 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 {
+ t.Fatalf("Decrypt mismatch: %v != %v", attr1, attr2)
+ }
+}