Merge lp:~abentley/launchpad/build-security into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~abentley/launchpad/build-security
Merge into: lp:launchpad
Diff against target: 139 lines (+64/-9)
3 files modified
lib/canonical/launchpad/security.py (+32/-6)
lib/lp/code/tests/test_sourcepackagerecipebuild.py (+29/-1)
lib/lp/testing/factory.py (+3/-2)
To merge this branch: bzr merge lp:~abentley/launchpad/build-security
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+23741@code.launchpad.net

Commit message

Provide launchpad.View for SourcePackageRecipeBuild.

Description of the change

= Summary =
Fix bug 552976, "SourcePackageRecipeBuild security needs work"

== Proposed fix ==
Define launchpad.View such that it is only provided when the user has
launchpad.View on the recipe and the archive.

== Pre-implementation notes ==
None

== Implementation details ==
Extracted DerivedAuthorization from ViewSourcePackageRecipe, and reused it
for ViewSourcePackageRecipeBuild.

== Tests ==
bin/test -t test_view_private test_sourcepackagerecipebuild

== Demo and Q/A ==
None

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/code/tests/test_sourcepackagerecipebuild.py
  lib/canonical/launchpad/security.py
  lib/lp/testing/factory.py

== Pylint notices ==

lib/lp/code/tests/test_sourcepackagerecipebuild.py
    13: [F0401] Unable to import 'transaction'
    14: [F0401] Unable to import 'zope.component'
    16: [F0401] Unable to import 'canonical.testing.layers'
    18: [F0401] Unable to import 'canonical.launchpad.webapp.authorization'
    19: [F0401] Unable to import 'lp.buildmaster.interfaces.buildbase'
    20: [F0401] Unable to import 'lp.buildmaster.interfaces.buildqueue'
    21: [F0401] Unable to import 'lp.code.interfaces.sourcepackagerecipebuild'
    24: [F0401] Unable to import 'lp.testing'

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Yay

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/launchpad/security.py'
--- lib/canonical/launchpad/security.py 2010-04-23 17:31:49 +0000
+++ lib/canonical/launchpad/security.py 2010-04-26 22:01:31 +0000
@@ -29,6 +29,8 @@
29from lp.code.interfaces.branchsubscription import (29from lp.code.interfaces.branchsubscription import (
30 IBranchSubscription)30 IBranchSubscription)
31from lp.code.interfaces.sourcepackagerecipe import ISourcePackageRecipe31from lp.code.interfaces.sourcepackagerecipe import ISourcePackageRecipe
32from lp.code.interfaces.sourcepackagerecipebuild import (
33 ISourcePackageRecipeBuild)
32from lp.bugs.interfaces.bug import IBug34from lp.bugs.interfaces.bug import IBug
33from lp.bugs.interfaces.bugattachment import IBugAttachment35from lp.bugs.interfaces.bugattachment import IBugAttachment
34from lp.bugs.interfaces.bugbranch import IBugBranch36from lp.bugs.interfaces.bugbranch import IBugBranch
@@ -2172,14 +2174,19 @@
2172 return user.in_admin2174 return user.in_admin
21732175
21742176
2175class ViewSourcePackageRecipe(AuthorizationBase):2177class DerivedAuthorization(AuthorizationBase):
21762178 """An Authorization that is based on permissions for other objects.
2177 permission = "launchpad.View"2179
2178 usedfor = ISourcePackageRecipe2180 Implementations must define permission, usedfor and iter_objects.
2181 iter_objects should iterate through the objects to check permission on.
2182
2183 Failure on the permission check for any object causes an overall failure.
2184 """
21792185
2180 def iter_adapters(self):2186 def iter_adapters(self):
2181 for branch in self.obj.getReferencedBranches():2187 return (
2182 yield getAdapter(branch, IAuthorization, self.permission)2188 getAdapter(obj, IAuthorization, self.permission)
2189 for obj in self.iter_objects())
21832190
2184 def checkAuthenticated(self, user):2191 def checkAuthenticated(self, user):
2185 for adapter in self.iter_adapters():2192 for adapter in self.iter_adapters():
@@ -2194,6 +2201,25 @@
2194 return True2201 return True
21952202
21962203
2204class ViewSourcePackageRecipe(DerivedAuthorization):
2205
2206 permission = "launchpad.View"
2207 usedfor = ISourcePackageRecipe
2208
2209 def iter_objects(self):
2210 return self.obj.getReferencedBranches()
2211
2212
2213class ViewSourcePackageRecipeBuild(DerivedAuthorization):
2214
2215 permission = "launchpad.View"
2216 usedfor = ISourcePackageRecipeBuild
2217
2218 def iter_objects(self):
2219 yield self.obj.recipe
2220 yield self.obj.archive
2221
2222
2197class ViewSourcePackagePublishingHistory(ViewArchive):2223class ViewSourcePackagePublishingHistory(ViewArchive):
2198 """Restrict viewing of source publications."""2224 """Restrict viewing of source publications."""
2199 permission = "launchpad.View"2225 permission = "launchpad.View"
22002226
=== modified file 'lib/lp/code/tests/test_sourcepackagerecipebuild.py'
--- lib/lp/code/tests/test_sourcepackagerecipebuild.py 2010-03-25 15:29:31 +0000
+++ lib/lp/code/tests/test_sourcepackagerecipebuild.py 2010-04-26 22:01:31 +0000
@@ -3,6 +3,8 @@
33
4"""Tests for source package builds."""4"""Tests for source package builds."""
55
6from __future__ import with_statement
7
6__metaclass__ = type8__metaclass__ = type
79
8import datetime10import datetime
@@ -13,12 +15,13 @@
1315
14from canonical.testing.layers import DatabaseFunctionalLayer16from canonical.testing.layers import DatabaseFunctionalLayer
1517
18from canonical.launchpad.webapp.authorization import check_permission
16from lp.buildmaster.interfaces.buildbase import IBuildBase19from lp.buildmaster.interfaces.buildbase import IBuildBase
17from lp.buildmaster.interfaces.buildqueue import IBuildQueue20from lp.buildmaster.interfaces.buildqueue import IBuildQueue
18from lp.code.interfaces.sourcepackagerecipebuild import (21from lp.code.interfaces.sourcepackagerecipebuild import (
19 ISourcePackageRecipeBuildJob, ISourcePackageRecipeBuild,22 ISourcePackageRecipeBuildJob, ISourcePackageRecipeBuild,
20 ISourcePackageRecipeBuildSource)23 ISourcePackageRecipeBuildSource)
21from lp.testing import TestCaseWithFactory24from lp.testing import ANONYMOUS, login, person_logged_in, TestCaseWithFactory
2225
2326
24class TestSourcePackageRecipeBuild(TestCaseWithFactory):27class TestSourcePackageRecipeBuild(TestCaseWithFactory):
@@ -86,6 +89,31 @@
86 spb = self.makeSourcePackageRecipeBuild()89 spb = self.makeSourcePackageRecipeBuild()
87 self.assertEqual(False, spb.is_private)90 self.assertEqual(False, spb.is_private)
8891
92 def test_view_private_branch(self):
93 """Recipebuilds with private branches are restricted."""
94 owner = self.factory.makePerson()
95 branch = self.factory.makeAnyBranch(owner=owner, private=True)
96 with person_logged_in(owner):
97 recipe = self.factory.makeSourcePackageRecipe(branches=[branch])
98 build = self.factory.makeSourcePackageRecipeBuild(recipe=recipe)
99 self.assertTrue(check_permission('launchpad.View', build))
100 with person_logged_in(self.factory.makePerson()):
101 self.assertFalse(check_permission('launchpad.View', build))
102 login(ANONYMOUS)
103 self.assertFalse(check_permission('launchpad.View', build))
104
105 def test_view_private_archive(self):
106 """Recipebuilds with private branches are restricted."""
107 owner = self.factory.makePerson()
108 archive = self.factory.makeArchive(owner=owner, private=True)
109 build = self.factory.makeSourcePackageRecipeBuild(archive=archive)
110 with person_logged_in(owner):
111 self.assertTrue(check_permission('launchpad.View', build))
112 with person_logged_in(self.factory.makePerson()):
113 self.assertFalse(check_permission('launchpad.View', build))
114 login(ANONYMOUS)
115 self.assertFalse(check_permission('launchpad.View', build))
116
89 def test_estimateDuration(self):117 def test_estimateDuration(self):
90 # The duration estimate is currently hard-coded as two minutes.118 # The duration estimate is currently hard-coded as two minutes.
91 spb = self.makeSourcePackageRecipeBuild()119 spb = self.makeSourcePackageRecipeBuild()
92120
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2010-04-25 03:40:36 +0000
+++ lib/lp/testing/factory.py 2010-04-26 22:01:31 +0000
@@ -1671,8 +1671,9 @@
1671 description=description)1671 description=description)
16721672
1673 if private:1673 if private:
1674 archive.private = True1674 naked_archive = removeSecurityProxy(archive)
1675 archive.buildd_secret = "sekrit"1675 naked_archive.private = True
1676 naked_archive.buildd_secret = "sekrit"
16761677
1677 return archive1678 return archive
16781679