aboutsummaryrefslogtreecommitdiff
path: root/tests/cli
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-05-14 13:14:00 +0200
committerJakob Unterwurzacher2017-05-14 13:14:00 +0200
commit18f354d84b4ae58c620474a544b9929662b108d8 (patch)
treeea3c91bab468662bd99bf00edb650c885a75b98a /tests/cli
parentd5adde1eeb13ba377f7c05b9f21893c01f61ec16 (diff)
main: password change: exit with code 12 on wrong password
We used to return code 8, now we return code 12 as documented in the man page. Also adds a test.
Diffstat (limited to 'tests/cli')
-rw-r--r--tests/cli/cli_test.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go
index 905a890..f5eaf9e 100644
--- a/tests/cli/cli_test.go
+++ b/tests/cli/cli_test.go
@@ -318,10 +318,10 @@ func TestInitTrailingGarbage(t *testing.T) {
}
}
-// TestPasswordIncorrect makes sure the correct exit code is used when the password
-// was incorrect
-func TestPasswordIncorrect(t *testing.T) {
- cDir := test_helpers.InitFS(t)
+// TestMountPasswordIncorrect makes sure the correct exit code is used when the password
+// was incorrect while mounting
+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
@@ -330,3 +330,32 @@ func TestPasswordIncorrect(t *testing.T) {
t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)
}
}
+
+// TestPasswdPasswordIncorrect makes sure the correct exit code is used when the password
+// was incorrect while changing the password
+func TestPasswdPasswordIncorrect(t *testing.T) {
+ cDir := test_helpers.InitFS(t) // Create filesystem with password "test"
+ // Change password
+ cmd := exec.Command(test_helpers.GocryptfsBinary, "-passwd", cDir)
+ childStdin, err := cmd.StdinPipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = cmd.Start()
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, err = childStdin.Write([]byte("WRONGPASSWORD\nNewPassword"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = childStdin.Close()
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = cmd.Wait()
+ exitCode := err.(*exec.ExitError).Sys().(syscall.WaitStatus).ExitStatus()
+ if exitCode != exitcodes.PasswordIncorrect {
+ t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)
+ }
+}