Merge lp:~jelmer/launchpad/394798-auto-buildd-secret into lp:launchpad

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 11171
Proposed branch: lp:~jelmer/launchpad/394798-auto-buildd-secret
Merge into: lp:launchpad
Diff against target: 153 lines (+34/-29)
3 files modified
lib/lp/soyuz/browser/archive.py (+16/-7)
lib/lp/soyuz/browser/tests/test_archive_admin_view.py (+15/-7)
lib/lp/soyuz/stories/ppa/xx-ppa-workflow.txt (+3/-15)
To merge this branch: bzr merge lp:~jelmer/launchpad/394798-auto-buildd-secret
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Review via email: mp+28759@code.launchpad.net

Commit message

Generate buildd_secret when none is specified and an archive is being make secret.

Description of the change

This trivial branch makes us generate buildd secrets for private PPA's on the fly, rather than requiring the administrator that makes the PPA private to come up with a random string.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/browser/archive.py'
2--- lib/lp/soyuz/browser/archive.py 2010-07-15 14:20:49 +0000
3+++ lib/lp/soyuz/browser/archive.py 2010-07-20 10:28:18 +0000
4@@ -46,6 +46,7 @@
5
6 from canonical.cachedproperty import cachedproperty
7 from canonical.launchpad import _
8+from canonical.launchpad.components.tokens import create_token
9 from canonical.launchpad.helpers import english_list
10 from canonical.lazr.utils import smartquote
11 from lp.buildmaster.interfaces.buildbase import BuildStatus
12@@ -1877,11 +1878,24 @@
13
14 custom_widget('enabled_restricted_families', LabeledMultiCheckBoxWidget)
15
16+ def updateContextFromData(self, data):
17+ """Update context from form data.
18+
19+ If the user did not specify a buildd secret but marked the
20+ archive as private, generate a secret for them.
21+ """
22+ if data['private'] and data['buildd_secret'] is None:
23+ # buildd secrets are only used by builders, autogenerate one.
24+ self.context.buildd_secret = create_token(16)
25+ del(data['buildd_secret'])
26+ super(ArchiveAdminView, self).updateContextFromData(data)
27+
28 def validate_save(self, action, data):
29 """Validate the save action on ArchiveAdminView.
30
31- buildd_secret can only be set, and must be set, when
32- this is a private archive.
33+ buildd_secret can only, and must, be set for private archives.
34+ If the archive is private and the buildd secret is not set it will be
35+ generated.
36 """
37 form.getWidgetsData(self.widgets, 'field', data)
38
39@@ -1893,11 +1907,6 @@
40 'This archive already has published sources. It is '
41 'not possible to switch the privacy.')
42
43- if data.get('buildd_secret') is None and data['private']:
44- self.setFieldError(
45- 'buildd_secret',
46- 'Required for private archives.')
47-
48 if self.owner_is_private_team and not data['private']:
49 self.setFieldError(
50 'private',
51
52=== modified file 'lib/lp/soyuz/browser/tests/test_archive_admin_view.py'
53--- lib/lp/soyuz/browser/tests/test_archive_admin_view.py 2010-02-16 15:53:05 +0000
54+++ lib/lp/soyuz/browser/tests/test_archive_admin_view.py 2010-07-20 10:28:18 +0000
55@@ -23,19 +23,19 @@
56 # object.
57 login('admin@canonical.com')
58
59- def initialize_admin_view(self, private=True):
60+ def initialize_admin_view(self, private=True, buildd_secret=''):
61 """Initialize the admin view to set the privacy.."""
62 method = 'POST'
63 form = {
64 'field.enabled': 'on',
65 'field.actions.save': 'Save',
66 }
67+
68+ form['field.buildd_secret'] = buildd_secret
69 if private is True:
70 form['field.private'] = 'on'
71- form['field.buildd_secret'] = 'test'
72 else:
73 form['field.private'] = 'off'
74- form['field.buildd_secret'] = ''
75
76 view = ArchiveAdminView(self.ppa, LaunchpadTestRequest(
77 method=method, form=form))
78@@ -56,7 +56,7 @@
79 def test_set_private_without_packages(self):
80 # If a ppa does not have packages published, it is possible to
81 # update the private attribute.
82- view = self.initialize_admin_view(private=True)
83+ view = self.initialize_admin_view(private=True, buildd_secret="test")
84 self.assertEqual(0, len(view.errors))
85 self.assertTrue(view.context.private)
86
87@@ -66,14 +66,22 @@
88 self.make_ppa_private(self.ppa)
89 self.assertTrue(self.ppa.private)
90
91- view = self.initialize_admin_view(private=False)
92+ view = self.initialize_admin_view(private=False, buildd_secret='')
93 self.assertEqual(0, len(view.errors))
94 self.assertFalse(view.context.private)
95
96+ def test_set_private_without_buildd_secret(self):
97+ """If a PPA is marked private but no buildd secret is specified,
98+ one will be generated."""
99+ view = self.initialize_admin_view(private=True, buildd_secret='')
100+ self.assertEqual(0, len(view.errors))
101+ self.assertTrue(view.context.private)
102+ self.assertTrue(len(view.context.buildd_secret) > 4)
103+
104 def test_set_private_with_packages(self):
105 # A PPA that does have packages cannot be privatised.
106 self.publish_to_ppa(self.ppa)
107- view = self.initialize_admin_view(private=True)
108+ view = self.initialize_admin_view(private=True, buildd_secret="test")
109 self.assertEqual(1, len(view.errors))
110 self.assertEqual(
111 'This archive already has published sources. '
112@@ -87,7 +95,7 @@
113 self.assertTrue(self.ppa.private)
114 self.publish_to_ppa(self.ppa)
115
116- view = self.initialize_admin_view(private=False)
117+ view = self.initialize_admin_view(private=False, buildd_secret='')
118 self.assertEqual(1, len(view.errors))
119 self.assertEqual(
120 'This archive already has published sources. '
121
122=== modified file 'lib/lp/soyuz/stories/ppa/xx-ppa-workflow.txt'
123--- lib/lp/soyuz/stories/ppa/xx-ppa-workflow.txt 2010-06-16 21:49:38 +0000
124+++ lib/lp/soyuz/stories/ppa/xx-ppa-workflow.txt 2010-07-20 10:28:18 +0000
125@@ -402,25 +402,13 @@
126 'deb not_a_url' is not a complete and valid sources.list entry
127
128
129-When the archive is private, the buildd secret must also be set, or an
130-error is issued:
131-
132- >>> admin_browser.getControl(
133- ... name="field.external_dependencies").value = ""
134- >>> admin_browser.getControl(name="field.private").value = True
135- >>> admin_browser.getControl(name="field.buildd_secret").value = ""
136- >>> admin_browser.getControl("Save").click()
137-
138- >>> for error in get_feedback_messages(admin_browser.contents):
139- ... print error
140- There is 1 error.
141- Required for private archives.
142-
143-Conversely, setting the buildd secret for non-private archives also generates
144+Setting the buildd secret for non-private archives also generates
145 an error. Because the "commercial" flag is also currently set, removing
146 privacy will also trigger a validation error because the commercial flag can
147 only be set on private archives:
148
149+ >>> admin_browser.getControl(
150+ ... name="field.external_dependencies").value = ""
151 >>> admin_browser.getControl(name="field.private").value = False
152 >>> admin_browser.getControl(name="field.buildd_secret").value = "secret"
153 >>> admin_browser.getControl("Save").click()