Merge lp:~cjwatson/launchpad/git-xmlrpc-auth-params-cleanup into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18234
Proposed branch: lp:~cjwatson/launchpad/git-xmlrpc-auth-params-cleanup
Merge into: lp:launchpad
Diff against target: 176 lines (+15/-52)
2 files modified
lib/lp/code/xmlrpc/git.py (+2/-13)
lib/lp/code/xmlrpc/tests/test_git.py (+13/-39)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-xmlrpc-auth-params-cleanup
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+308494@code.launchpad.net

Commit message

Remove old-style authentication parameters handling from GitAPI.translatePath.

Description of the change

The corresponding turnip changes are on production now, so we can drop the compatibility code.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/xmlrpc/git.py'
2--- lib/lp/code/xmlrpc/git.py 2016-10-12 12:41:25 +0000
3+++ lib/lp/code/xmlrpc/git.py 2016-10-14 11:51:45 +0000
4@@ -295,20 +295,9 @@
5 else:
6 raise
7
8- def translatePath(self, path, permission, requester_id,
9- can_authenticate=None):
10+ def translatePath(self, path, permission, auth_params):
11 """See `IGitAPI`."""
12- if can_authenticate is None:
13- # XXX cjwatson 2016-10-06: Ugly compatibility hack. This method
14- # should be "translatePath(self, path, permission, *auth_args)"
15- # instead, but it may be called using mapply which doesn't
16- # support the *auth_args syntax. This can go away once turnip
17- # uses the new-style interface.
18- auth_params = requester_id
19- requester_id = auth_params.get("uid")
20- else:
21- auth_params = {
22- "uid": requester_id, "can-authenticate": can_authenticate}
23+ requester_id = auth_params.get("uid")
24 if requester_id is None:
25 requester_id = LAUNCHPAD_ANONYMOUS
26 if isinstance(path, str):
27
28=== modified file 'lib/lp/code/xmlrpc/tests/test_git.py'
29--- lib/lp/code/xmlrpc/tests/test_git.py 2016-10-12 12:30:13 +0000
30+++ lib/lp/code/xmlrpc/tests/test_git.py 2016-10-14 11:51:45 +0000
31@@ -6,10 +6,6 @@
32 __metaclass__ = type
33
34 from pymacaroons import Macaroon
35-from testscenarios import (
36- load_tests_apply_scenarios,
37- WithScenarios,
38- )
39 from zope.component import getUtility
40 from zope.security.proxy import removeSecurityProxy
41
42@@ -47,34 +43,21 @@
43 from lp.xmlrpc import faults
44
45
46-class TestGitAPIMixin(WithScenarios):
47+class TestGitAPIMixin:
48 """Helper methods for `IGitAPI` tests, and security-relevant tests."""
49
50- scenarios = [
51- ("auth_params_flat", {"auth_params_dict": False}),
52- ("auth_params_dict", {"auth_params_dict": True}),
53- ]
54-
55 def setUp(self):
56 super(TestGitAPIMixin, self).setUp()
57 self.git_api = GitAPI(None, None)
58 self.hosting_fixture = self.useFixture(GitHostingFixture())
59 self.repository_set = getUtility(IGitRepositorySet)
60
61- def _translatePath(self, path, permission, auth_params):
62- if self.auth_params_dict:
63- return self.git_api.translatePath(path, permission, auth_params)
64- else:
65- return self.git_api.translatePath(
66- path, permission, auth_params.get("uid"),
67- auth_params.get("can-authenticate", False))
68-
69 def assertGitRepositoryNotFound(self, requester, path, permission="read",
70 can_authenticate=False):
71 """Assert that the given path cannot be translated."""
72 if requester is not None:
73 requester = requester.id
74- fault = self._translatePath(
75+ fault = self.git_api.translatePath(
76 path, permission,
77 {"uid": requester, "can-authenticate": can_authenticate})
78 self.assertEqual(
79@@ -90,7 +73,7 @@
80 auth_params = {"uid": requester, "can-authenticate": can_authenticate}
81 if macaroon_raw is not None:
82 auth_params["macaroon"] = macaroon_raw
83- fault = self._translatePath(path, permission, auth_params)
84+ fault = self.git_api.translatePath(path, permission, auth_params)
85 self.assertEqual(faults.PermissionDenied(message), fault)
86
87 def assertUnauthorized(self, requester, path,
88@@ -99,7 +82,7 @@
89 """Assert that looking at the given path returns Unauthorized."""
90 if requester is not None:
91 requester = requester.id
92- fault = self._translatePath(
93+ fault = self.git_api.translatePath(
94 path, permission,
95 {"uid": requester, "can-authenticate": can_authenticate})
96 self.assertEqual(faults.Unauthorized(message), fault)
97@@ -109,7 +92,7 @@
98 """Assert that looking at the given path returns NotFound."""
99 if requester is not None:
100 requester = requester.id
101- fault = self._translatePath(
102+ fault = self.git_api.translatePath(
103 path, permission,
104 {"uid": requester, "can-authenticate": can_authenticate})
105 self.assertEqual(faults.NotFound(message), fault)
106@@ -121,7 +104,7 @@
107 InvalidSourcePackageName."""
108 if requester is not None:
109 requester = requester.id
110- fault = self._translatePath(
111+ fault = self.git_api.translatePath(
112 path, permission,
113 {"uid": requester, "can-authenticate": can_authenticate})
114 self.assertEqual(faults.InvalidSourcePackageName(name), fault)
115@@ -131,7 +114,7 @@
116 """Assert that looking at the given path returns InvalidBranchName."""
117 if requester is not None:
118 requester = requester.id
119- fault = self._translatePath(
120+ fault = self.git_api.translatePath(
121 path, permission,
122 {"uid": requester, "can-authenticate": can_authenticate})
123 self.assertEqual(faults.InvalidBranchName(Exception(message)), fault)
124@@ -141,7 +124,7 @@
125 """Assert that looking at the given path OOPSes."""
126 if requester is not None:
127 requester = requester.id
128- fault = self._translatePath(
129+ fault = self.git_api.translatePath(
130 path, permission,
131 {"uid": requester, "can-authenticate": can_authenticate})
132 self.assertIsInstance(fault, faults.OopsOccurred)
133@@ -159,7 +142,7 @@
134 auth_params = {"uid": requester, "can-authenticate": can_authenticate}
135 if macaroon_raw is not None:
136 auth_params["macaroon"] = macaroon_raw
137- translation = self._translatePath(path, permission, auth_params)
138+ translation = self.git_api.translatePath(path, permission, auth_params)
139 login(ANONYMOUS)
140 self.assertEqual(
141 {"path": repository.getInternalPath(), "writable": writable,
142@@ -172,7 +155,7 @@
143 requester_id = requester
144 else:
145 requester_id = requester.id
146- translation = self._translatePath(
147+ translation = self.git_api.translatePath(
148 path, "write",
149 {"uid": requester_id, "can-authenticate": can_authenticate})
150 login(ANONYMOUS)
151@@ -666,15 +649,9 @@
152 None, path, permission="write", macaroon_raw=macaroons[0])
153 with celebrity_logged_in("vcs_imports"):
154 getUtility(ICodeImportJobWorkflow).startJob(jobs[0], machine)
155- # This only works with new-style passing of authentication parameters.
156- if self.auth_params_dict:
157- self.assertTranslates(
158- None, path, code_imports[0].git_repository, True,
159- permission="write", macaroon_raw=macaroons[0].serialize())
160- else:
161- self.assertPermissionDenied(
162- None, path, permission="write",
163- macaroon_raw=macaroons[0].serialize())
164+ self.assertTranslates(
165+ None, path, code_imports[0].git_repository, True,
166+ permission="write", macaroon_raw=macaroons[0].serialize())
167 self.assertPermissionDenied(
168 None, path, permission="write",
169 macaroon_raw=macaroons[1].serialize())
170@@ -747,6 +724,3 @@
171 """
172
173 layer = AppServerLayer
174-
175-
176-load_tests = load_tests_apply_scenarios