From 8fcd39a3b08f956edc0939c87b089b4dbb60afd6 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 1 Apr 2018 14:25:10 +0200 Subject: main: add "-fsck" flag The fsck operation is not yet implemented, this commits just adds the flag and improves cli flag handling. --- tests/cli/cli_test.go | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index 9eebc5f..2cdaf37 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -18,6 +18,18 @@ import ( var testPw = []byte("test") +// Extract the exit code from an error value that was returned from +// exec.Run() +func extractExitCode(err error) int { + if err == nil { + return 0 + } + // OMG this is convoluted + err2 := err.(*exec.ExitError) + code := err2.Sys().(syscall.WaitStatus).ExitStatus() + return code +} + func TestMain(m *testing.M) { test_helpers.ResetTmpDir(false) r := m.Run() @@ -332,8 +344,7 @@ func TestMountPasswordIncorrect(t *testing.T) { cDir := test_helpers.InitFS(t) // Create filesystem with password "test" pDir := cDir + ".mnt" err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo WRONG", "-wpanic=false") - // vvvvvvvvvvvvvv OMG vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv - exitCode := err.(*exec.ExitError).Sys().(syscall.WaitStatus).ExitStatus() + exitCode := extractExitCode(err) if exitCode != exitcodes.PasswordIncorrect { t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode) } @@ -362,7 +373,7 @@ func TestPasswdPasswordIncorrect(t *testing.T) { t.Fatal(err) } err = cmd.Wait() - exitCode := err.(*exec.ExitError).Sys().(syscall.WaitStatus).ExitStatus() + exitCode := extractExitCode(err) if exitCode != exitcodes.PasswordIncorrect { t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode) } @@ -417,3 +428,27 @@ func TestMountBackground(t *testing.T) { t.Fatal("timeout") } } + +// Test that "gocryptfs -init -info CIPHERDIR" returns an error to the +// user. Only one operation flag is allowed. +func TestMultipleOperationFlags(t *testing.T) { + // Test all combinations + opFlags := []string{"-init", "-info", "-passwd", "-fsck"} + for _, flag1 := range opFlags { + var flag2 string + for _, flag2 = range opFlags { + if flag1 == flag2 { + continue + } + args := []string{flag1, flag2, "/tmp"} + //t.Logf("testing %v", args) + cmd := exec.Command(test_helpers.GocryptfsBinary, args...) + err := cmd.Run() + exitCode := extractExitCode(err) + if exitCode != exitcodes.Usage { + t.Fatalf("this should have failed with code %d, but returned %d", + exitcodes.Usage, exitCode) + } + } + } +} -- cgit v1.2.3