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.
This commit is contained in:
parent
d5adde1eeb
commit
18f354d84b
2
main.go
2
main.go
@ -76,7 +76,7 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf
|
|||||||
func changePassword(args *argContainer) {
|
func changePassword(args *argContainer) {
|
||||||
masterkey, confFile, err := loadConfig(args)
|
masterkey, confFile, err := loadConfig(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(exitcodes.LoadConf)
|
exitcodes.Exit(err)
|
||||||
}
|
}
|
||||||
tlog.Info.Println("Please enter your new password.")
|
tlog.Info.Println("Please enter your new password.")
|
||||||
newPw := readpassword.Twice(args.extpass)
|
newPw := readpassword.Twice(args.extpass)
|
||||||
|
@ -318,10 +318,10 @@ func TestInitTrailingGarbage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPasswordIncorrect makes sure the correct exit code is used when the password
|
// TestMountPasswordIncorrect makes sure the correct exit code is used when the password
|
||||||
// was incorrect
|
// was incorrect while mounting
|
||||||
func TestPasswordIncorrect(t *testing.T) {
|
func TestMountPasswordIncorrect(t *testing.T) {
|
||||||
cDir := test_helpers.InitFS(t)
|
cDir := test_helpers.InitFS(t) // Create filesystem with password "test"
|
||||||
pDir := cDir + ".mnt"
|
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")
|
||||||
// vvvvvvvvvvvvvv OMG vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
// vvvvvvvvvvvvvv OMG vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||||
@ -330,3 +330,32 @@ func TestPasswordIncorrect(t *testing.T) {
|
|||||||
t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user