Merge ~twom/turnip:code-import-support-for-checkRefPermissions into turnip:master

Proposed by Tom Wardill
Status: Merged
Approved by: Colin Watson
Approved revision: 0de65c59a1c616586f2a19bba43cd349b359852c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/turnip:code-import-support-for-checkRefPermissions
Merge into: turnip:master
Diff against target: 99 lines (+37/-13)
2 files modified
turnip/pack/git.py (+15/-13)
turnip/pack/tests/test_functional.py (+22/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+357744@code.launchpad.net

Commit message

Check for more auth methods in checkRefPermissions

Description of the change

Allow http auth.

To post a comment you must log in.
e1990a9... by Tom Wardill

Correct method naming style

0de65c5... by Tom Wardill

Remove typo

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/turnip/pack/git.py b/turnip/pack/git.py
2index d45e1db..79c6194 100644
3--- a/turnip/pack/git.py
4+++ b/turnip/pack/git.py
5@@ -214,6 +214,19 @@ class PackServerProtocol(PackProxyProtocol):
6 self.sendPacket(ERROR_PREFIX + message + b'\n')
7 self.transport.loseConnection()
8
9+ def createAuthParams(self, params):
10+ auth_params = {}
11+ for key, value in params.items():
12+ if key.startswith(b'turnip-authenticated-'):
13+ decoded_key = key[len(b'turnip-authenticated-'):].decode(
14+ 'utf-8')
15+ auth_params[decoded_key] = value
16+ if 'uid' in auth_params:
17+ auth_params['uid'] = int(auth_params['uid'])
18+ if params.get(b'turnip-can-authenticate') == b'yes':
19+ auth_params['can-authenticate'] = True
20+ return auth_params
21+
22
23 class GitProcessProtocol(protocol.ProcessProtocol):
24
25@@ -421,9 +434,7 @@ class PackBackendProtocol(PackServerProtocol):
26 if params.pop(b'turnip-advertise-refs', None):
27 args.append(b'--advertise-refs')
28 args.append(self.path)
29- uid = params.get('turnip-authenticated-uid')
30- uid = int(uid) if uid else None
31- auth_params = {'uid': uid}
32+ auth_params = self.createAuthParams(params)
33 self.spawnGit(subcmd,
34 args,
35 write_operation=write_operation,
36@@ -549,16 +560,7 @@ class PackVirtServerProtocol(PackProxyServerProtocol):
37 permission = b'read' if command == b'git-upload-pack' else b'write'
38 proxy = xmlrpc.Proxy(self.factory.virtinfo_endpoint, allowNone=True)
39 try:
40- auth_params = {}
41- for key, value in params.items():
42- if key.startswith(b'turnip-authenticated-'):
43- decoded_key = key[len(b'turnip-authenticated-'):].decode(
44- 'utf-8')
45- auth_params[decoded_key] = value
46- if 'uid' in auth_params:
47- auth_params['uid'] = int(auth_params['uid'])
48- if params.get(b'turnip-can-authenticate') == b'yes':
49- auth_params['can-authenticate'] = True
50+ auth_params = self.createAuthParams(params)
51 self.log.info("Translating request.")
52 translated = yield proxy.callRemote(
53 b'translatePath', pathname, permission, auth_params)
54diff --git a/turnip/pack/tests/test_functional.py b/turnip/pack/tests/test_functional.py
55index 6f0a838..6de8489 100644
56--- a/turnip/pack/tests/test_functional.py
57+++ b/turnip/pack/tests/test_functional.py
58@@ -106,6 +106,7 @@ class FakeVirtInfoService(xmlrpc.XMLRPC):
59 self.translations = []
60 self.authentications = []
61 self.push_notifications = []
62+ self.ref_permissions_checks = []
63 self.ref_permissions = {}
64
65 def xmlrpc_translatePath(self, pathname, permission, auth_params):
66@@ -130,6 +131,7 @@ class FakeVirtInfoService(xmlrpc.XMLRPC):
67 self.push_notifications.append(path)
68
69 def xmlrpc_checkRefPermissions(self, path, ref_paths, auth_params):
70+ self.ref_permissions_checks.append((path, ref_paths, auth_params))
71 return self.ref_permissions
72
73
74@@ -677,6 +679,26 @@ class TestSmartHTTPFrontendWithAuthFunctional(TestSmartHTTPFrontendFunctional):
75 {b'can-authenticate': True, b'user': b'test-user'})],
76 self.virtinfo.translations)
77
78+ @defer.inlineCallbacks
79+ def test_authenticated_push(self):
80+ test_root = self.useFixture(TempDir()).path
81+ clone = os.path.join(test_root, 'clone')
82+ yield self.assertCommandSuccess((b'git', b'clone', self.url, clone))
83+ yield self.assertCommandSuccess(
84+ (b'git', b'config', b'user.name', b'Test User'), path=clone)
85+ yield self.assertCommandSuccess(
86+ (b'git', b'config', b'user.email', b'test@example.com'),
87+ path=clone)
88+ yield self.assertCommandSuccess(
89+ (b'git', b'commit', b'--allow-empty', b'-m', b'Committed test'),
90+ path=clone)
91+ yield self.assertCommandSuccess(
92+ (b'git', b'push', b'origin', b'master'), path=clone)
93+ self.assertEqual(
94+ [(self.internal_name, [b'refs/heads/master'],
95+ {b'can-authenticate': True, b'user': b'test-user'})],
96+ self.virtinfo.ref_permissions_checks)
97+
98
99 class TestSmartSSHServiceFunctional(FrontendFunctionalTestMixin, TestCase):
100

Subscribers

People subscribed via source and target branches