summaryrefslogtreecommitdiff
path: root/tests/defaults
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-11-10 00:27:08 +0100
committerJakob Unterwurzacher2016-11-10 00:27:08 +0100
commit75ebb28a625bc16d145f5acd9e0cc1d305716afe (patch)
tree6e4c654c67b93933a2575857883777b3f05fc5d3 /tests/defaults
parentdf28fc5a11f5e52897f45cc299ab62a2a2cbaf4c (diff)
ctlsock: add initial limited implementation
At the moment, in forward mode you can only encrypt paths and in reverse mode you can only decrypt paths.
Diffstat (limited to 'tests/defaults')
-rw-r--r--tests/defaults/main_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/defaults/main_test.go b/tests/defaults/main_test.go
index 849aa69..8733c8b 100644
--- a/tests/defaults/main_test.go
+++ b/tests/defaults/main_test.go
@@ -2,10 +2,16 @@
package defaults
import (
+ "encoding/json"
+ "fmt"
+ "net"
"os"
"os/exec"
+ "syscall"
"testing"
+ "time"
+ "github.com/rfjakob/gocryptfs/internal/ctlsock"
"github.com/rfjakob/gocryptfs/tests/test_helpers"
)
@@ -35,3 +41,34 @@ func Test1980Tar(t *testing.T) {
t.Errorf("Wrong mtime: %d", m)
}
}
+
+func TestCtlSock(t *testing.T) {
+ cDir := test_helpers.InitFS(t)
+ pDir := cDir + ".mnt"
+ sock := cDir + ".sock"
+ test_helpers.MountOrFatal(t, cDir, pDir, "-ctlsock="+sock, "-extpass", "echo test")
+ defer test_helpers.UnmountPanic(pDir)
+ conn, err := net.DialTimeout("unix", sock, 1*time.Second)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer conn.Close()
+ conn.SetDeadline(time.Now().Add(time.Second))
+ msg := []byte(`{"EncryptPath": "foobar"}`)
+ _, err = conn.Write(msg)
+ if err != nil {
+ t.Fatal(err)
+ }
+ buf := make([]byte, 2*syscall.PathMax)
+ n, err := conn.Read(buf)
+ if err != nil {
+ t.Fatal(err)
+ }
+ buf = buf[:n]
+ var response ctlsock.ResponseStruct
+ json.Unmarshal(buf, &response)
+ if response.Result == "" || response.ErrNo != 0 {
+ fmt.Printf("%s\n", string(buf))
+ t.Errorf("got an error reply")
+ }
+}