aboutsummaryrefslogtreecommitdiff
path: root/tests/cli
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-07-23 20:28:41 +0200
committerJakob Unterwurzacher2017-07-24 00:05:29 +0200
commit318c41827cf23476b9705081f63b7f93fecba09a (patch)
tree6573d7855dedd2870a32dc0d24cdd600bcf4666e /tests/cli
parent0b6e3ce635ed7a9ec592f0cb72bc1afe7b9ed23e (diff)
tests: check if we close stderr and stdout correctly on mount
Currently fails, as reported at https://github.com/rfjakob/gocryptfs/issues/130 .
Diffstat (limited to 'tests/cli')
-rw-r--r--tests/cli/cli_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go
index f5eaf9e..97de8da 100644
--- a/tests/cli/cli_test.go
+++ b/tests/cli/cli_test.go
@@ -8,6 +8,7 @@ import (
"os/exec"
"syscall"
"testing"
+ "time"
"github.com/rfjakob/gocryptfs/internal/configfile"
"github.com/rfjakob/gocryptfs/internal/exitcodes"
@@ -359,3 +360,53 @@ func TestPasswdPasswordIncorrect(t *testing.T) {
t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)
}
}
+
+// Check that we correctly background on mount and close stderr and stdout.
+// Something like
+// gocryptfs a b | cat
+// must not hang ( https://github.com/rfjakob/gocryptfs/issues/130 ).
+func TestMountBackground(t *testing.T) {
+ dir := test_helpers.InitFS(t)
+ mnt := dir + ".mnt"
+ err := os.Mkdir(mnt, 0700)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // Manually create a pipe pair and connect the child's stdout and stderr
+ // to it. We cannot use StdoutPipe because that will close the pipe
+ // when the child forks away.
+ pr, pw, err := os.Pipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ args := []string{"-extpass", "echo test", dir, mnt}
+ cmd := exec.Command(test_helpers.GocryptfsBinary, args...)
+ cmd.Stdout = pw
+ cmd.Stderr = pw
+ err = cmd.Run()
+ if err != nil {
+ t.Error(err)
+ }
+ pw.Close()
+ defer test_helpers.UnmountPanic(mnt)
+ // Read until we get EOF.
+ c1 := make(chan struct{}, 1)
+ go func() {
+ buf := make([]byte, 1000)
+ for {
+ _, err = pr.Read(buf)
+ // We should get io.EOF when the child closes stdout
+ // and stderr.
+ if err != nil {
+ c1 <- struct{}{}
+ return
+ }
+ }
+ }()
+ select {
+ case <-c1:
+ return
+ case <-time.After(time.Second * 5):
+ t.Fatal("timeout")
+ }
+}