Merge ~twom/launchpad:gdbpr-add-gpg-key-info into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: cfcd47acd2831c20e7d70bf73ef13ae549f9e7ac
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:gdbpr-add-gpg-key-info
Merge into: launchpad:master
Diff against target: 78 lines (+43/-0)
2 files modified
lib/lp/registry/model/person.py (+19/-0)
lib/lp/registry/tests/test_personset.py (+24/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+406092@code.launchpad.net

Commit message

Add PGP/GPG key info to GDPR endpoint

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
2index c669daf..70a7933 100644
3--- a/lib/lp/registry/model/person.py
4+++ b/lib/lp/registry/model/person.py
5@@ -4127,6 +4127,9 @@ class PersonSet:
6 if not account.sshkeys.is_empty():
7 return_data["sshkeys"] = canonical_url(
8 account, view_name="+sshkeys")
9+ gpg_keys_urls = self._checkForGPGKeys(account)
10+ if gpg_keys_urls:
11+ return_data["openpgp-keys"] = gpg_keys_urls
12 # This is only an 'account' in terms of the end user view,
13 # it does not refer to an `IAccount`.
14 if len(return_data.keys()) > 1:
15@@ -4228,6 +4231,22 @@ class PersonSet:
16 req.prepare_url(answers_url, query_arguments)
17 return req.url
18
19+ def _checkForGPGKeys(self, account):
20+ """Check if we have GPG keys for the given Person."""
21+ # We return the keyserver url, not an LP url
22+ urls = []
23+ keyserver_url = "https://keyserver.ubuntu.com/pks/lookup"
24+ keys = account.gpg_keys + account.inactive_gpg_keys
25+ for key in keys:
26+ req = PreparedRequest()
27+ query_arguments = {
28+ "fingerprint": "on",
29+ "op": "index",
30+ "search": "0x{}".format(key.fingerprint)}
31+ req.prepare_url(keyserver_url, query_arguments)
32+ urls.append(req.url)
33+ return urls
34+
35 def getUserOverview(self, person):
36 """See `IPersonSet`."""
37 overview = {}
38diff --git a/lib/lp/registry/tests/test_personset.py b/lib/lp/registry/tests/test_personset.py
39index cee7182..9bf188f 100644
40--- a/lib/lp/registry/tests/test_personset.py
41+++ b/lib/lp/registry/tests/test_personset.py
42@@ -13,6 +13,7 @@ from testtools.matchers import (
43 GreaterThan,
44 LessThan,
45 MatchesDict,
46+ MatchesListwise,
47 )
48 import transaction
49 from zope.component import getUtility
50@@ -1367,6 +1368,29 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
51 "sshkeys": canonical_url(person, view_name="+sshkeys")
52 }, result)
53
54+ def test_account_data_gpg_keys(self):
55+ person = self.factory.makePerson(email="test@example.com")
56+ with admin_logged_in():
57+ self.factory.makeGPGKey(person)
58+ result = self.person_set.getUserData(u"test@example.com")
59+ self.assertThat(result, ContainsDict({
60+ "status": Equals("account with data"),
61+ "person": Equals(canonical_url(person)),
62+ "openpgp-keys": MatchesListwise([
63+ Contains("https://keyserver.ubuntu.com")])}))
64+
65+ def test_account_data_gpg_keys_inactive(self):
66+ person = self.factory.makePerson(email="test@example.com")
67+ with admin_logged_in():
68+ key = self.factory.makeGPGKey(person)
69+ key.active = False
70+ result = self.person_set.getUserData(u"test@example.com")
71+ self.assertThat(result, ContainsDict({
72+ "status": Equals("account with data"),
73+ "person": Equals(canonical_url(person)),
74+ "openpgp-keys": MatchesListwise([
75+ Contains("https://keyserver.ubuntu.com")])}))
76+
77 def test_getUserOverview(self):
78 ppa = self.factory.makeArchive(owner=self.user)
79

Subscribers

People subscribed via source and target branches

to status/vote changes: