Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add a background database update to purge account data for deactivated users. #11655

Merged
merged 22 commits into from
Feb 2, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
68b663d
Remove account data upon user deactivation
reivilibre Dec 21, 2021
13fec0d
Document that account data is removed upon user deactivation
reivilibre Dec 21, 2021
c1fed49
Newsfile
reivilibre Dec 21, 2021
4da869e
Remove account data upon user deactivation
reivilibre Dec 21, 2021
b132bba
Test the removal of account data upon deactivation
reivilibre Dec 29, 2021
1589d6a
Pull out the account data transaction so it can be reused in other tr…
reivilibre Dec 29, 2021
5344446
Add a background job to retroactively purge account data for deactiva…
reivilibre Dec 29, 2021
da884c0
Add a schema delta to trigger the clean-up job
reivilibre Dec 29, 2021
288b0e8
Newsfile
reivilibre Dec 29, 2021
2690bd6
Add tests for the background update job
reivilibre Jan 17, 2022
9413a46
Fix port_db script not being able to run the background job
reivilibre Jan 17, 2022
3b48c9d
Merge branch 'develop' into rei/add_job
reivilibre Jan 24, 2022
2337b28
Reformat after merge
reivilibre Jan 24, 2022
2ee3d8f
Simplify test after merge
reivilibre Jan 24, 2022
d362e31
Fix order of args after merge
reivilibre Jan 24, 2022
3ecc6bc
Move schema delta to correct version
reivilibre Jan 24, 2022
9a4ec65
Fix database port script's Method Resolution Order
reivilibre Jan 24, 2022
0543946
Fix abstract method error in synapse_port_db
reivilibre Jan 28, 2022
d18e2dd
job → update
reivilibre Jan 28, 2022
99353f3
Remove obsolete manual cache invalidations in tests
reivilibre Feb 2, 2022
2587e51
Merge branch 'develop' into rei/add_job
reivilibre Feb 2, 2022
2f79559
Fix up background update delta number
reivilibre Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for the background update job
  • Loading branch information
reivilibre committed Jan 17, 2022
commit 2690bd684f89e58bcbd97854be46887ecc201cb0
121 changes: 121 additions & 0 deletions tests/handlers/test_deactivate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,124 @@ def test_account_data_deleted_upon_deactivation(self) -> None:
)
),
)

def _rerun_retroactive_account_data_deletion_job(self) -> None:
# Reset the 'all done' flag
self._store.db_pool.updates._all_done = False

self.get_success(
self._store.db_pool.simple_insert(
"background_updates",
{
"update_name": "delete_account_data_for_deactivated_users",
"progress_json": "{}",
},
)
)

self.wait_for_background_updates()

def test_account_data_deleted_retroactively_by_background_job_if_deactivated(
self,
) -> None:
"""
Tests that a user, who deactivated their account before account data was
deleted automatically upon deactivation, has their account data retroactively
scrubbed by the background job.
"""

# Request the deactivation of our account
req = self.get_success(
self.make_request(
"POST",
"account/deactivate",
{
"auth": {
"type": "m.login.password",
"user": self.user,
"password": "pass",
},
"erase": True,
},
access_token=self.token,
)
)
self.assertEqual(req.code, 200, req)

# Add some account data
# (we do this after the deactivation so that the act of deactivating doesn't
# clear it out. This emulates a user that was deactivated before this was cleared
# upon deactivation.)
self.get_success(
self._store.add_account_data_for_user(
self.user,
AccountDataTypes.DIRECT,
{"@someone:remote": ["!somewhere:remote"]},
)
)

# Check that the account data is there.
self.assertIsNotNone(
self.get_success(
self._store.get_global_account_data_by_type_for_user(
AccountDataTypes.DIRECT,
self.user,
)
),
)

# Re-run the retroactive deletion job
self._rerun_retroactive_account_data_deletion_job()

# Check that the account data was cleared.
self._store.get_global_account_data_by_type_for_user.invalidate_all()
Copy link
Contributor

@squahtx squahtx Feb 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having the caches be cleared automatically looks like a footgun. I think this has already been discussed in the previous PR, so I won't block on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agh good spot — this line shouldn't be needed anymore, but I forgot about that. The curse of having too much stuff going on, but at least the reviewers are competent :-).

self.assertIsNone(
self.get_success(
self._store.get_global_account_data_by_type_for_user(
AccountDataTypes.DIRECT,
self.user,
)
),
)

def test_account_data_preserved_by_background_job_if_not_deactivated(self) -> None:
"""
Tests that the background job does not scrub account data for users that have
not been deactivated.
"""

# Add some account data
# (we do this after the deactivation so that the act of deactivating doesn't
# clear it out. This emulates a user that was deactivated before this was cleared
# upon deactivation.)
self.get_success(
self._store.add_account_data_for_user(
self.user,
AccountDataTypes.DIRECT,
{"@someone:remote": ["!somewhere:remote"]},
)
)

# Check that the account data is there.
self.assertIsNotNone(
self.get_success(
self._store.get_global_account_data_by_type_for_user(
AccountDataTypes.DIRECT,
self.user,
)
),
)

# Re-run the retroactive deletion job
self._rerun_retroactive_account_data_deletion_job()

# Check that the account data was NOT cleared.
self._store.get_global_account_data_by_type_for_user.invalidate_all()
self.assertIsNotNone(
self.get_success(
self._store.get_global_account_data_by_type_for_user(
AccountDataTypes.DIRECT,
self.user,
)
),
)