mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
fix(BRIDGE-261): delete gluon data during user deletion; integration tests; FF kill switch; Sentry report if error;
This commit is contained in:
25
tests/features/user/delete_imap.feature
Normal file
25
tests/features/user/delete_imap.feature
Normal 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
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user