From 82dac42e85f01b1ea3383470350aa837a19f0ac3 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 4 Dec 2024 19:47:43 +0100 Subject: gocryptfs -passwd: fix the tests I just broke Turns out at least the tests depended on the old behavoir. Fixes d5bd98eb3f4cbfb8dd9d0b2eb64dbff69c3c88b1 --- tests/cli/cli_test.go | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'tests/cli/cli_test.go') diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index b2f9f40..fb09338 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -117,25 +117,37 @@ func TestInitMasterkey(t *testing.T) { // the -extpass method, then from "test" to "newpasswd" using the // stdin method. func testPasswd(t *testing.T, dir string, extraArgs ...string) { - // Change password using "-extpass" + // Change password #1: old passwd via "-extpass", new one via stdin args := []string{"-q", "-passwd", "-extpass", "echo test"} args = append(args, extraArgs...) args = append(args, dir) cmd := exec.Command(test_helpers.GocryptfsBinary, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - err := cmd.Run() + p, err := cmd.StdinPipe() + if err != nil { + t.Fatal(err) + } + err = cmd.Start() if err != nil { t.Error(err) } - // Change password using stdin + // New password through stdin + p.Write([]byte("test\n")) + p.Close() + err = cmd.Wait() + if err != nil { + t.Error(err) + } + + // Change password #2: using stdin args = []string{"-q", "-passwd"} args = append(args, extraArgs...) args = append(args, dir) cmd = exec.Command(test_helpers.GocryptfsBinary, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - p, err := cmd.StdinPipe() + p, err = cmd.StdinPipe() if err != nil { t.Fatal(err) } @@ -336,10 +348,22 @@ func TestInitConfig(t *testing.T) { "-config", config, dir) cmd2.Stdout = os.Stdout cmd2.Stderr = os.Stderr - err = cmd2.Run() + p, err := cmd2.StdinPipe() + if err != nil { + t.Fatal(err) + } + err = cmd2.Start() if err != nil { t.Error(err) } + // New password + p.Write([]byte("passwd\n")) + p.Close() + err = cmd2.Wait() + if err != nil { + t.Error(err) + } + } // Test -ro -- cgit v1.2.3