fix(BRIDGE-261): delete gluon data during user deletion; integration tests; FF kill switch; Sentry report if error;

This commit is contained in:
Atanas Janeshliev
2024-11-11 15:49:23 +01:00
parent 2e98d64f94
commit af01c63298
8 changed files with 137 additions and 8 deletions

View File

@ -733,3 +733,8 @@ func (bridge *Bridge) ReportMessageWithContext(message string, messageCtx report
}).Info("Error occurred when sending Report to Sentry")
}
}
// GetUsers is only used for testing purposes.
func (bridge *Bridge) GetUsers() map[string]*user.User {
return bridge.users
}

View File

@ -33,6 +33,7 @@ import (
"github.com/ProtonMail/proton-bridge/v3/internal/safe"
"github.com/ProtonMail/proton-bridge/v3/internal/services/imapservice"
"github.com/ProtonMail/proton-bridge/v3/internal/try"
"github.com/ProtonMail/proton-bridge/v3/internal/unleash"
"github.com/ProtonMail/proton-bridge/v3/internal/user"
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
"github.com/go-resty/resty/v2"
@ -607,7 +608,7 @@ func (bridge *Bridge) newVaultUser(
return bridge.vault.GetOrAddUser(apiUser.ID, apiUser.Name, apiUser.Email, authUID, authRef, saltedKeyPass)
}
// logout logs out the given user, optionally logging them out from the API too.
// logoutUser logs out the given user, optionally logging them out from the API and deleting user related gluon data.
func (bridge *Bridge) logoutUser(ctx context.Context, user *user.User, withAPI, withData bool) {
defer delete(bridge.users, user.ID())
@ -617,7 +618,7 @@ func (bridge *Bridge) logoutUser(ctx context.Context, user *user.User, withAPI,
"withData": withData,
}).Debug("Logging out user")
if err := user.Logout(ctx, withAPI); err != nil {
if err := user.Logout(ctx, withAPI, withData, bridge.unleashService.GetFlagValue(unleash.UserRemovalGluonDataCleanupDisabled)); err != nil {
logUser.WithError(err).Error("Failed to logout user")
}

View File

@ -233,6 +233,12 @@ func (s *Service) OnLogout(ctx context.Context) error {
return err
}
func (s *Service) OnDelete(ctx context.Context) error {
_, err := s.cpc.Send(ctx, &onDeleteReq{})
return err
}
func (s *Service) ShowAllMail(ctx context.Context, v bool) error {
_, err := s.cpc.Send(ctx, &showAllMailReq{v: v})
@ -362,6 +368,11 @@ func (s *Service) run(ctx context.Context) { //nolint gocyclo
err := s.removeConnectorsFromServer(ctx, s.connectors, false)
req.Reply(ctx, nil, err)
case *onDeleteReq:
s.log.Debug("Delete Request")
err := s.removeConnectorsFromServer(ctx, s.connectors, true)
req.Reply(ctx, nil, err)
case *showAllMailReq:
s.log.Debug("Show all mail request")
req.Reply(ctx, nil, nil)
@ -644,6 +655,8 @@ type onLogoutReq struct{}
type showAllMailReq struct{ v bool }
type onDeleteReq struct{}
type setAddressModeReq struct {
mode usertypes.AddressMode
}

View File

@ -37,8 +37,9 @@ var pollJitter = 2 * time.Minute //nolint:gochecknoglobals
const filename = "unleash_flags"
const (
EventLoopNotificationDisabled = "InboxBridgeEventLoopNotificationDisabled"
IMAPAuthenticateCommandDisabled = "InboxBridgeImapAuthenticateCommandDisabled"
EventLoopNotificationDisabled = "InboxBridgeEventLoopNotificationDisabled"
IMAPAuthenticateCommandDisabled = "InboxBridgeImapAuthenticateCommandDisabled"
UserRemovalGluonDataCleanupDisabled = "InboxBridgeUserRemovalGluonDataCleanupDisabled"
)
type requestFeaturesFn func(ctx context.Context) (proton.FeatureFlagResult, error)

View File

@ -592,8 +592,13 @@ func (user *User) CheckAuth(email string, password []byte) (string, error) {
}
// Logout logs the user out from the API.
func (user *User) Logout(ctx context.Context, withAPI bool) error {
user.log.WithField("withAPI", withAPI).Info("Logging out user")
func (user *User) Logout(ctx context.Context, withAPI, withData, withDataDisabledKillSwitch bool) error {
user.log.WithFields(
logrus.Fields{
"withAPI": withAPI,
"withData": withData,
"withDataDisabledKillSwitch": withDataDisabledKillSwitch,
}).Info("Logging out user")
user.log.Debug("Canceling ongoing tasks")
@ -601,8 +606,20 @@ func (user *User) Logout(ctx context.Context, withAPI bool) error {
return fmt.Errorf("failed to remove user from smtp server: %w", err)
}
if err := user.imapService.OnLogout(ctx); err != nil {
return fmt.Errorf("failed to remove user from imap server: %w", err)
if withData && !withDataDisabledKillSwitch {
if err := user.imapService.OnDelete(ctx); err != nil {
if rerr := user.reporter.ReportMessageWithContext("Failed to delete user IMAP data", map[string]any{
"error": err.Error(),
}); rerr != nil {
logrus.WithError(rerr).Info("Failed to report user IMAP deletion issue to Sentry")
}
return fmt.Errorf("failed to delete user from imap server: %w", err)
}
} else {
if err := user.imapService.OnLogout(ctx); err != nil {
return fmt.Errorf("failed to remove user from imap server: %w", err)
}
}
user.tasks.CancelAndWait()