Merge ~cjwatson/launchpad:close-account-oauth-tokens into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 5bc869c6c7b711d11adcf8ba975edce6485cd591
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:close-account-oauth-tokens
Merge into: launchpad:master
Diff against target: 79 lines (+44/-4)
2 files modified
lib/lp/registry/scripts/closeaccount.py (+5/-3)
lib/lp/registry/scripts/tests/test_closeaccount.py (+39/-1)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Kristian Glass (community) Approve
Review via email: mp+379618@code.launchpad.net

Commit message

Handle OAuth tokens in close-account

Description of the change

Just like login tokens, OAuth request and access tokens are no longer interesting if the user can no longer log in, so just remove them.

To post a comment you must log in.
Revision history for this message
Kristian Glass (doismellburning) :
review: Approve
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/scripts/closeaccount.py b/lib/lp/registry/scripts/closeaccount.py
2index 711f8b6..faf5056 100644
3--- a/lib/lp/registry/scripts/closeaccount.py
4+++ b/lib/lp/registry/scripts/closeaccount.py
5@@ -1,4 +1,4 @@
6-# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
7+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 """Remove personal details of a user from the database, leaving a stub."""
11@@ -262,9 +262,11 @@ def close_account(username, log):
12 # concerned with being removed from our systems.
13 ('EmailAddress', 'person'),
14
15- # Login tokens are no longer interesting if the user can no longer
16- # log in.
17+ # Login and OAuth tokens are no longer interesting if the user can
18+ # no longer log in.
19 ('LoginToken', 'requester'),
20+ ('OAuthAccessToken', 'person'),
21+ ('OAuthRequestToken', 'person'),
22
23 # Trash their codes of conduct and GPG keys
24 ('SignedCodeOfConduct', 'owner'),
25diff --git a/lib/lp/registry/scripts/tests/test_closeaccount.py b/lib/lp/registry/scripts/tests/test_closeaccount.py
26index 49102f1..883fad0 100644
27--- a/lib/lp/registry/scripts/tests/test_closeaccount.py
28+++ b/lib/lp/registry/scripts/tests/test_closeaccount.py
29@@ -1,4 +1,4 @@
30-# Copyright 2018-2019 Canonical Ltd. This software is licensed under the
31+# Copyright 2018-2020 Canonical Ltd. This software is licensed under the
32 # GNU Affero General Public License version 3 (see the file LICENSE).
33
34 """Test the close-account script."""
35@@ -544,6 +544,44 @@ class TestCloseAccount(TestCaseWithFactory):
36 self.assertRaises(
37 KeyError, login_token_set.__getitem__, plaintext_token)
38
39+ def test_handles_oauth_request_token(self):
40+ person = self.factory.makePerson()
41+ other_person = self.factory.makePerson()
42+ request_token = self.factory.makeOAuthRequestToken(reviewed_by=person)
43+ other_request_token = self.factory.makeOAuthRequestToken(
44+ reviewed_by=other_person)
45+ self.assertContentEqual([request_token], person.oauth_request_tokens)
46+ self.assertContentEqual(
47+ [other_request_token], other_person.oauth_request_tokens)
48+ person_id = person.id
49+ account_id = person.account.id
50+ script = self.makeScript([six.ensure_str(person.name)])
51+ with dbuser('launchpad'):
52+ self.runScript(script)
53+ self.assertRemoved(account_id, person_id)
54+ self.assertContentEqual([], person.oauth_request_tokens)
55+ self.assertContentEqual(
56+ [other_request_token], other_person.oauth_request_tokens)
57+
58+ def test_handles_oauth_access_token(self):
59+ person = self.factory.makePerson()
60+ other_person = self.factory.makePerson()
61+ access_token, _ = self.factory.makeOAuthAccessToken(owner=person)
62+ other_access_token, _ = self.factory.makeOAuthAccessToken(
63+ owner=other_person)
64+ self.assertContentEqual([access_token], person.oauth_access_tokens)
65+ self.assertContentEqual(
66+ [other_access_token], other_person.oauth_access_tokens)
67+ person_id = person.id
68+ account_id = person.account.id
69+ script = self.makeScript([six.ensure_str(person.name)])
70+ with dbuser('launchpad'):
71+ self.runScript(script)
72+ self.assertRemoved(account_id, person_id)
73+ self.assertContentEqual([], person.oauth_access_tokens)
74+ self.assertContentEqual(
75+ [other_access_token], other_person.oauth_access_tokens)
76+
77 def test_fails_on_undeleted_ppa(self):
78 person = self.factory.makePerson()
79 ppa = self.factory.makeArchive(owner=person)

Subscribers

People subscribed via source and target branches

to status/vote changes: