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 (
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).

View File

@ -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 {

View File

@ -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.