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
|
|
|
|
|
|
|
"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
|
|
|
|
|
|
|
// .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 {
|
|
|
|
t.Skip()
|
|
|
|
}
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|