From 1eaf1211a259a38cdf3e7dad2e00e140409bef9a Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 3 Jan 2022 14:27:09 +0100 Subject: tests/cli: Check for leftover socket file This fails at the moment: $ go test ./tests/cli/ --- FAIL: TestMountPasswordEmpty (0.01s) cli_test.go:430: socket file "/tmp/gocryptfs-test-parent-1026/3413782690/TestMountPasswordEmpty.753166857.sock" left behind https://github.com/rfjakob/gocryptfs/issues/634 --- tests/cli/cli_test.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index c433e92..915759d 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -398,15 +398,37 @@ func TestShadows(t *testing.T) { } // TestMountPasswordIncorrect makes sure the correct exit code is used when the password -// was incorrect while mounting +// was incorrect while mounting. +// Also checks that we don't leave a socket file behind. func TestMountPasswordIncorrect(t *testing.T) { cDir := test_helpers.InitFS(t) // Create filesystem with password "test" + ctlSock := cDir + ".sock" pDir := cDir + ".mnt" - err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo WRONG", "-wpanic=false") + err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo WRONG", "-wpanic=false", "-ctlsock", ctlSock) exitCode := test_helpers.ExtractCmdExitCode(err) if exitCode != exitcodes.PasswordIncorrect { t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode) } + if _, err := os.Stat(ctlSock); err == nil { + t.Errorf("socket file %q left behind", ctlSock) + } +} + +// TestMountPasswordEmpty makes sure the correct exit code is used when the password +// was empty while mounting. +// Also checks that we don't leave a socket file behind (https://github.com/rfjakob/gocryptfs/issues/634). +func TestMountPasswordEmpty(t *testing.T) { + cDir := test_helpers.InitFS(t) // Create filesystem with password "test" + ctlSock := cDir + ".sock" + pDir := cDir + ".mnt" + err := test_helpers.Mount(cDir, pDir, false, "-extpass", "true", "-wpanic=false", "-ctlsock", ctlSock) + exitCode := test_helpers.ExtractCmdExitCode(err) + if exitCode != exitcodes.ReadPassword { + t.Errorf("want=%d, got=%d", exitcodes.ReadPassword, exitCode) + } + if _, err := os.Stat(ctlSock); err == nil { + t.Errorf("socket file %q left behind", ctlSock) + } } // TestPasswdPasswordIncorrect makes sure the correct exit code is used when the password -- cgit v1.2.3