summaryrefslogtreecommitdiff
path: root/tests/test_helpers/helpers.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/test_helpers/helpers.go
parentd3764b775395faa31afb1db34c5c2814a0e9af09 (diff)
ctlsock: implement EncryptPath for reverse mode, add tests
Diffstat (limited to 'tests/test_helpers/helpers.go')
-rw-r--r--tests/test_helpers/helpers.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index aec1f7c..1bbfdf3 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -3,15 +3,19 @@ package test_helpers
import (
"crypto/md5"
"encoding/hex"
+ "encoding/json"
"fmt"
"io/ioutil"
+ "net"
"os"
"os/exec"
"path/filepath"
"runtime"
"syscall"
"testing"
+ "time"
+ "github.com/rfjakob/gocryptfs/internal/ctlsock"
"github.com/rfjakob/gocryptfs/internal/nametransform"
)
@@ -323,3 +327,30 @@ func Du(t *testing.T, fd int) (nBytes int64) {
// st.Blocks = number of 512-byte blocks
return st.Blocks * 512
}
+
+// QueryCtlSock sends a request to the control socket at "socketPath" and
+// returns the response.
+func QueryCtlSock(t *testing.T, socketPath string, req ctlsock.RequestStruct) (response ctlsock.ResponseStruct) {
+ conn, err := net.DialTimeout("unix", socketPath, 1*time.Second)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer conn.Close()
+ conn.SetDeadline(time.Now().Add(time.Second))
+ msg, err := json.Marshal(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, 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]
+ json.Unmarshal(buf, &response)
+ return response
+}