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

@ -0,0 +1,25 @@
Feature: User deletion with IMAP data removal
Background:
Given there exists an account with username "[user:user]" and password "password"
And the account "[user:user]" has the following custom mailboxes:
| name | type |
| one | folder |
And the address "[user:user]@[domain]" of account "[user:user]" has the following messages in "Folders/one":
| from | to | subject | unread |
| a@example.com | a@example.com | one | true |
| b@example.com | b@example.com | two | false |
| c@example.com | c@example.com | three | true |
| c@example.com | c@example.com | four | false |
Then it succeeds
When bridge starts
And the user logs in with username "[user:user]" and password "password"
And user "[user:user]" finishes syncing
Then it succeeds
Scenario: User is deleted from Bridge and IMAP data is removed
When user "[user:user]" connects and authenticates IMAP client "1"
Then IMAP client "1" sees the following mailbox info for "Folders/one":
| name | total | unread |
| Folders/one | 4 | 2 |
And user "[user:user]" is deleted alongside IMAP data for client "1"
Then it succeeds

View File

@ -116,6 +116,7 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) {
ctx.Step(`^user "([^"]*)" has telemetry set to (\d+)$`, s.userHasTelemetrySetTo)
ctx.Step(`^the bridge password of user "([^"]*)" is changed to "([^"]*)"`, s.bridgePasswordOfUserIsChangedTo)
ctx.Step(`^the bridge password of user "([^"]*)" is equal to "([^"]*)"`, s.bridgePasswordOfUserIsEqualTo)
ctx.Step(`^user "([^"]*)" is deleted alongside IMAP data for client "([^"]*)"$`, s.userIsDeletedAndImapDataRemoved)
// ==== ACCOUNT SETTINGS ====
ctx.Step(`^the account "([^"]*)" has public key attachment "([^"]*)"`, s.accountHasPublicKeyAttachment)

View File

@ -22,6 +22,8 @@ import (
"errors"
"fmt"
"net/mail"
"os"
"path/filepath"
"strings"
"time"
@ -388,6 +390,70 @@ func (s *scenario) userIsDeleted(username string) error {
return s.t.bridge.DeleteUser(context.Background(), s.t.getUserByName(username).getUserID())
}
func (s *scenario) userIsDeletedAndImapDataRemoved(username string) error {
gluonCacheDir := s.t.bridge.GetGluonCacheDir()
userID := s.t.getUserByName(username).userID
userMap := s.t.bridge.GetUsers()
userObj, ok := userMap[userID]
if !ok {
return fmt.Errorf("could not find user object")
}
gluonIDMap := userObj.GetGluonIDs()
gluonIDs := make([]string, 0, len(gluonIDMap))
for _, id := range gluonIDMap {
gluonIDs = append(gluonIDs, id)
}
var relevantPaths []string
if err := filepath.Walk(gluonCacheDir, func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
for _, gluonID := range gluonIDs {
if strings.Contains(path, gluonID) {
relevantPaths = append(relevantPaths, path)
}
}
return nil
}); err != nil {
return err
}
if len(relevantPaths) == 0 {
return fmt.Errorf("found no user related gluon paths")
}
if err := s.t.bridge.DeleteUser(context.Background(), userID); err != nil {
return fmt.Errorf("could not delete user: %w", err)
}
foundDeferredDelete := false
var remainingPaths []string
if err := filepath.Walk(gluonCacheDir, func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
for _, gluonID := range gluonIDs {
if strings.Contains(path, gluonID) {
remainingPaths = append(remainingPaths, path)
}
}
if strings.Contains(path, "deferred_delete") {
foundDeferredDelete = true
}
return nil
}); err != nil {
return err
}
if len(remainingPaths) == 0 && foundDeferredDelete {
return nil
}
return fmt.Errorf("user gluon data is still present or could not find deferred deletion directory")
}
func (s *scenario) theAuthOfUserIsRevoked(username string) error {
return s.t.withClient(context.Background(), username, func(ctx context.Context, client *proton.Client) error {
return client.AuthRevokeAll(ctx)