Better user message about wrong mailbox password

This commit is contained in:
Michal Horejsek
2021-02-01 14:27:31 +01:00
committed by Jakub Cuth
parent 46bc8b08dc
commit 72c01046e3
3 changed files with 12 additions and 9 deletions

View File

@ -34,6 +34,9 @@ import (
var ( var (
log = logrus.WithField("pkg", "users") //nolint[gochecknoglobals] log = logrus.WithField("pkg", "users") //nolint[gochecknoglobals]
isApplicationOutdated = false //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. // 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() salt, err := client.AuthSalt()
if err != nil { if err != nil {
log.WithError(err).Error("Could not get salt") log.WithError(err).Error("Could not get salt")
return return nil, "", err
} }
hashedPassphrase, err = pmapi.HashMailboxPassword(mbPassphrase, salt) hashedPassphrase, err = pmapi.HashMailboxPassword(mbPassphrase, salt)
if err != nil { if err != nil {
log.WithError(err).Error("Could not hash mailbox password") 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. // 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 { if err = client.Unlock([]byte(hashedPassphrase)); err != nil {
log.WithError(err).Error("Wrong mailbox password") log.WithError(err).Error("Wrong mailbox password")
return return nil, "", ErrWrongMailboxPassword
} }
if user, err = client.CurrentUser(); err != nil { if user, err = client.CurrentUser(); err != nil {
log.WithError(err).Error("Could not load user data") 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). // GetUsers returns all added users into keychain (even logged out users).

View File

@ -18,7 +18,6 @@
package users package users
import ( import (
"errors"
"testing" "testing"
"github.com/ProtonMail/proton-bridge/internal/events" "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/internal/users/credentials"
"github.com/ProtonMail/proton-bridge/pkg/pmapi" "github.com/ProtonMail/proton-bridge/pkg/pmapi"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -33,19 +33,18 @@ func TestUsersFinishLoginBadMailboxPassword(t *testing.T) {
m := initMocks(t) m := initMocks(t)
defer m.ctrl.Finish() defer m.ctrl.Finish()
err := errors.New("bad password")
gomock.InOrder( gomock.InOrder(
// Init users with no user from keychain. // Init users with no user from keychain.
m.credentialsStore.EXPECT().List().Return([]string{}, nil), m.credentialsStore.EXPECT().List().Return([]string{}, nil),
// Set up mocks for FinishLogin. // Set up mocks for FinishLogin.
m.pmapiClient.EXPECT().AuthSalt().Return("", nil), 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().DeleteAuth(),
m.pmapiClient.EXPECT().Logout(), m.pmapiClient.EXPECT().Logout(),
) )
checkUsersFinishLogin(t, m, testAuth, testCredentials.MailboxPassword, "", err) checkUsersFinishLogin(t, m, testAuth, testCredentials.MailboxPassword, "", ErrWrongMailboxPassword)
} }
func refreshWithToken(token string) *pmapi.Auth { func refreshWithToken(token string) *pmapi.Auth {

View File

@ -10,6 +10,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
### Changed ### Changed
* GODT-885 Do not explicitly unlabel folders during move to match behaviour of other clients. * 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 ### Fixed
* GODT-1011 Stable integration test deleting many messages using UID EXPUNGE. * GODT-1011 Stable integration test deleting many messages using UID EXPUNGE.