aboutsummaryrefslogtreecommitdiff
path: root/tests/defaults/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-11-10 23:32:51 +0100
committerJakob Unterwurzacher2016-11-10 23:32:51 +0100
commitc03fc46a5150715bf6aee20ce4b89d9704141220 (patch)
treeaa7cb2a5cf9a068f4867702d4846e04cf6da3e02 /tests/defaults/main_test.go
parentd3764b775395faa31afb1db34c5c2814a0e9af09 (diff)
ctlsock: implement EncryptPath for reverse mode, add tests
Diffstat (limited to 'tests/defaults/main_test.go')
-rw-r--r--tests/defaults/main_test.go33
1 files changed, 9 insertions, 24 deletions
diff --git a/tests/defaults/main_test.go b/tests/defaults/main_test.go
index 8733c8b..95835a4 100644
--- a/tests/defaults/main_test.go
+++ b/tests/defaults/main_test.go
@@ -2,14 +2,10 @@
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"
@@ -48,27 +44,16 @@ func TestCtlSock(t *testing.T) {
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)
+ req := ctlsock.RequestStruct{
+ EncryptPath: "foobar",
}
- 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)
+ response := test_helpers.QueryCtlSock(t, sock, req)
if response.Result == "" || response.ErrNo != 0 {
- fmt.Printf("%s\n", string(buf))
- t.Errorf("got an error reply")
+ t.Errorf("got an error reply: %+v", response)
+ }
+ req.EncryptPath = "not-existing-dir/xyz"
+ response = test_helpers.QueryCtlSock(t, sock, req)
+ if response.ErrNo != int32(syscall.ENOENT) || response.Result != "" {
+ t.Errorf("incorrect error handling: %+v", response)
}
}