diff --git a/internal/users/users.go b/internal/users/users.go index d397cd79..2a34c6ae 100644 --- a/internal/users/users.go +++ b/internal/users/users.go @@ -34,6 +34,9 @@ import ( var ( log = logrus.WithField("pkg", "users") //nolint[gochecknoglobals] isApplicationOutdated = false //nolint[gochecknoglobals] + + // ErrWrongMailboxPassword is returned when login password is OK but not the mailbox one. + ErrWrongMailboxPassword = errors.New("wrong mailbox password") ) // Users is a struct handling users. @@ -332,27 +335,27 @@ func getAPIUser(client pmapi.Client, mbPassphrase string) (user *pmapi.User, has salt, err := client.AuthSalt() if err != nil { log.WithError(err).Error("Could not get salt") - return + return nil, "", err } hashedPassphrase, err = pmapi.HashMailboxPassword(mbPassphrase, salt) if err != nil { log.WithError(err).Error("Could not hash mailbox password") - return + return nil, "", err } // We unlock the user's PGP key here to detect if the user's mailbox password is wrong. if err = client.Unlock([]byte(hashedPassphrase)); err != nil { log.WithError(err).Error("Wrong mailbox password") - return + return nil, "", ErrWrongMailboxPassword } if user, err = client.CurrentUser(); err != nil { log.WithError(err).Error("Could not load user data") - return + return nil, "", err } - return + return user, hashedPassphrase, nil } // GetUsers returns all added users into keychain (even logged out users). diff --git a/internal/users/users_login_test.go b/internal/users/users_login_test.go index 2025aef8..fc884811 100644 --- a/internal/users/users_login_test.go +++ b/internal/users/users_login_test.go @@ -18,7 +18,6 @@ package users import ( - "errors" "testing" "github.com/ProtonMail/proton-bridge/internal/events" @@ -26,6 +25,7 @@ import ( "github.com/ProtonMail/proton-bridge/internal/users/credentials" "github.com/ProtonMail/proton-bridge/pkg/pmapi" gomock "github.com/golang/mock/gomock" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -33,19 +33,18 @@ func TestUsersFinishLoginBadMailboxPassword(t *testing.T) { m := initMocks(t) defer m.ctrl.Finish() - err := errors.New("bad password") gomock.InOrder( // Init users with no user from keychain. m.credentialsStore.EXPECT().List().Return([]string{}, nil), // Set up mocks for FinishLogin. m.pmapiClient.EXPECT().AuthSalt().Return("", nil), - m.pmapiClient.EXPECT().Unlock([]byte(testCredentials.MailboxPassword)).Return(err), + m.pmapiClient.EXPECT().Unlock([]byte(testCredentials.MailboxPassword)).Return(errors.New("no keys could be unlocked")), m.pmapiClient.EXPECT().DeleteAuth(), m.pmapiClient.EXPECT().Logout(), ) - checkUsersFinishLogin(t, m, testAuth, testCredentials.MailboxPassword, "", err) + checkUsersFinishLogin(t, m, testAuth, testCredentials.MailboxPassword, "", ErrWrongMailboxPassword) } func refreshWithToken(token string) *pmapi.Auth { diff --git a/unreleased.md b/unreleased.md index 1e4983f3..fdb8f66e 100644 --- a/unreleased.md +++ b/unreleased.md @@ -10,6 +10,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) ### Changed * GODT-885 Do not explicitly unlabel folders during move to match behaviour of other clients. +* GODT-616 Better user message about wrong mailbox password. ### Fixed * GODT-1011 Stable integration test deleting many messages using UID EXPUNGE.