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
This commit is contained in:
Jakob Unterwurzacher 2022-01-03 14:27:09 +01:00
parent 5749e70c7c
commit 1eaf1211a2

View File

@ -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