Skip to content

Commit

Permalink
v2api: fix TestOpenBackingDir
Browse files Browse the repository at this point in the history
  • Loading branch information
rfjakob committed Jul 11, 2020
1 parent 7de3330 commit b0342fa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
32 changes: 18 additions & 14 deletions internal/fusefrontend/openbackingdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"golang.org/x/sys/unix"

"github.com/hanwen/go-fuse/v2/fuse"

"github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/tests/test_helpers"
)
Expand All @@ -17,14 +19,15 @@ func TestOpenBackingDir(t *testing.T) {
Cipherdir: cipherdir,
}
fs := newTestFS(args)
out := &fuse.EntryOut{}

code := fs.Mkdir("dir1", 0700, nil)
if !code.Ok() {
t.Fatal(code)
_, errno := fs.Mkdir(nil, "dir1", 0700, out)
if errno != 0 {
t.Fatal(errno)
}
code = fs.Mkdir("dir1/dir2", 0700, nil)
if !code.Ok() {
t.Fatal(code)
_, errno = fs.Mkdir(nil, "dir1/dir2", 0700, out)
if errno != 0 {
t.Fatal(errno)
}

dirfd, cName, err := fs.openBackingDir("")
Expand All @@ -37,7 +40,7 @@ func TestOpenBackingDir(t *testing.T) {
syscall.Close(dirfd)

// Again, but populate the cache for "" by looking up a non-existing file
fs.GetAttr("xyz1234", nil)
fs.Getattr(nil, "xyz1234", &fuse.AttrOut{})
dirfd, cName, err = fs.openBackingDir("")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -84,7 +87,7 @@ func TestOpenBackingDir(t *testing.T) {

n255 := strings.Repeat("n", 255)
path := "dir1/" + n255
fs.Mkdir(path, 0700, nil)
fs.Mkdir(nil, path, 0700, out)
dirfd, cName, err = fs.openBackingDir(path)
if err != nil {
t.Fatal(err)
Expand All @@ -109,14 +112,15 @@ func TestOpenBackingDirPlaintextNames(t *testing.T) {
PlaintextNames: true,
}
fs := newTestFS(args)
out := &fuse.EntryOut{}

code := fs.Mkdir("dir1", 0700, nil)
if !code.Ok() {
t.Fatal(code)
_, errno := fs.Mkdir(nil, "dir1", 0700, out)
if errno != 0 {
t.Fatal(errno)
}
code = fs.Mkdir("dir1/dir2", 0700, nil)
if !code.Ok() {
t.Fatal(code)
_, errno = fs.Mkdir(nil, "dir1/dir2", 0700, out)
if errno != 0 {
t.Fatal(errno)
}

dirfd, cName, err := fs.openBackingDir("")
Expand Down
35 changes: 24 additions & 11 deletions internal/fusefrontend/xattr_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,41 @@ package fusefrontend

import (
"testing"
"time"

"github.com/hanwen/go-fuse/v2/fs"

"github.com/rfjakob/gocryptfs/internal/contentenc"
"github.com/rfjakob/gocryptfs/internal/cryptocore"
"github.com/rfjakob/gocryptfs/internal/nametransform"
)

func newTestFS(args Args) *FS {
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)
nameTransform := nametransform.New(cCore.EMECipher, true, true)
return NewFS(args, cEnc, nameTransform)
n := nametransform.New(cCore.EMECipher, true, true)
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 := fs.encryptXattrName(attr1)
t.Logf("cAttr=%v", cAttr)
attr2, err := fs.decryptXattrName(cAttr)
if attr1 != attr2 || err != nil {
t.Fatalf("Decrypt mismatch: %v != %v", attr1, attr2)
}
t.Fatal("not yet implemented")
/*
fs := newTestFS(Args{})
attr1 := "user.foo123456789"
cAttr := fs.encryptXattrName(attr1)
t.Logf("cAttr=%v", cAttr)
attr2, err := fs.decryptXattrName(cAttr)
if attr1 != attr2 || err != nil {
t.Fatalf("Decrypt mismatch: %v != %v", attr1, attr2)
}
*/
}

0 comments on commit b0342fa

Please sign in to comment.