2016-09-25 15:05:09 +02:00
|
|
|
package reverse_test
|
|
|
|
|
|
|
|
import (
|
2016-10-08 20:57:38 +02:00
|
|
|
"io/ioutil"
|
2016-09-25 15:05:09 +02:00
|
|
|
"os"
|
2017-02-16 21:20:29 +01:00
|
|
|
"syscall"
|
2016-09-25 15:05:09 +02:00
|
|
|
"testing"
|
2016-09-25 15:32:46 +02:00
|
|
|
|
2017-03-07 10:09:09 +01:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
2016-09-25 15:32:46 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
2016-09-25 15:05:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLongnameStat(t *testing.T) {
|
2016-09-25 15:32:46 +02:00
|
|
|
fd, err := os.Create(dirA + "/" + x240)
|
2016-09-25 15:05:09 +02:00
|
|
|
if err != nil {
|
2016-09-25 15:32:46 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
path := dirC + "/" + x240
|
|
|
|
if !test_helpers.VerifyExistence(path) {
|
|
|
|
t.Fail()
|
2016-09-25 15:05:09 +02:00
|
|
|
}
|
2016-09-25 15:32:46 +02:00
|
|
|
test_helpers.VerifySize(t, path, 0)
|
|
|
|
_, err = fd.Write(make([]byte, 10))
|
2016-09-25 15:05:09 +02:00
|
|
|
if err != nil {
|
2016-09-25 15:32:46 +02:00
|
|
|
t.Fatal(err)
|
2016-09-25 15:05:09 +02:00
|
|
|
}
|
2016-09-25 15:32:46 +02:00
|
|
|
fd.Close()
|
|
|
|
/*
|
|
|
|
time.Sleep(1000 * time.Millisecond)
|
|
|
|
test_helpers.VerifySize(t, path, 10)
|
|
|
|
*/
|
2016-09-25 15:05:09 +02:00
|
|
|
}
|
2016-09-25 18:01:24 +02:00
|
|
|
|
|
|
|
func TestSymlinks(t *testing.T) {
|
|
|
|
target := "/"
|
|
|
|
os.Symlink(target, dirA+"/symlink")
|
|
|
|
cSymlink := dirC + "/symlink"
|
|
|
|
_, err := os.Lstat(cSymlink)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Lstat: %v", err)
|
|
|
|
}
|
|
|
|
_, err = os.Stat(cSymlink)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Stat: %v", err)
|
|
|
|
}
|
|
|
|
actualTarget, err := os.Readlink(cSymlink)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if target != actualTarget {
|
|
|
|
t.Errorf("wrong symlink target: want=%q have=%q", target, actualTarget)
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 20:57:38 +02:00
|
|
|
|
2017-03-07 10:09:09 +01:00
|
|
|
// Symbolic link dentry sizes should be set to the length of the string
|
|
|
|
// that contains the target path.
|
|
|
|
func TestSymlinkDentrySize(t *testing.T) {
|
2017-03-07 20:53:58 +01:00
|
|
|
if plaintextnames {
|
|
|
|
t.Skip("this only tests encrypted names")
|
|
|
|
}
|
2017-03-07 10:09:09 +01:00
|
|
|
symlink := "a_symlink"
|
|
|
|
|
|
|
|
mnt, err := ioutil.TempDir(test_helpers.TmpDir, "reverse_mnt_")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sock := mnt + ".sock"
|
|
|
|
test_helpers.MountOrFatal(t, "ctlsock_reverse_test_fs", mnt, "-reverse", "-extpass", "echo test", "-ctlsock="+sock)
|
|
|
|
defer test_helpers.UnmountPanic(mnt)
|
|
|
|
|
|
|
|
req := ctlsock.RequestStruct{EncryptPath: symlink}
|
|
|
|
symlinkResponse := test_helpers.QueryCtlSock(t, sock, req)
|
|
|
|
if symlinkResponse.ErrNo != 0 {
|
|
|
|
t.Errorf("Encrypt: %q ErrNo=%d ErrText=%s", symlink, symlinkResponse.ErrNo, symlinkResponse.ErrText)
|
|
|
|
}
|
|
|
|
|
|
|
|
fi, err := os.Lstat(mnt + "/" + symlinkResponse.Result)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Lstat: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
target, err := os.Readlink(mnt + "/" + symlinkResponse.Result)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Readlink: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if fi.Size() != int64(len(target)) {
|
|
|
|
t.Errorf("Lstat reports that symbolic link %q's dentry size is %d, but this does not "+
|
|
|
|
"match the length of the string returned by readlink, which is %d.",
|
|
|
|
symlink, fi.Size(), len(target))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 20:57:38 +02:00
|
|
|
// .gocryptfs.reverse.conf in the plaintext dir should be visible as
|
|
|
|
// gocryptfs.conf
|
|
|
|
func TestConfigMapping(t *testing.T) {
|
|
|
|
c := dirB + "/gocryptfs.conf"
|
2016-10-08 22:25:08 +02:00
|
|
|
if !test_helpers.VerifyExistence(c) {
|
|
|
|
t.Errorf("%s missing", c)
|
|
|
|
}
|
2016-10-08 20:57:38 +02:00
|
|
|
data, err := ioutil.ReadFile(c)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(data) == 0 {
|
|
|
|
t.Errorf("empty file")
|
|
|
|
}
|
|
|
|
}
|
2017-02-16 21:20:29 +01:00
|
|
|
|
|
|
|
// Check that the access() syscall works on virtual files
|
|
|
|
func TestAccessVirtual(t *testing.T) {
|
|
|
|
if plaintextnames {
|
2017-03-07 20:53:58 +01:00
|
|
|
t.Skip("test makes no sense for plaintextnames")
|
2017-02-16 21:20:29 +01:00
|
|
|
}
|
|
|
|
var R_OK uint32 = 4
|
|
|
|
var W_OK uint32 = 2
|
|
|
|
var X_OK uint32 = 1
|
|
|
|
fn := dirB + "/gocryptfs.diriv"
|
|
|
|
err := syscall.Access(fn, R_OK)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%q should be readable, but got error: %v", fn, err)
|
|
|
|
}
|
|
|
|
err = syscall.Access(fn, W_OK)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("should NOT be writeable")
|
|
|
|
}
|
|
|
|
err = syscall.Access(fn, X_OK)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("should NOT be executable")
|
|
|
|
}
|
|
|
|
}
|