Merge lp:~adeuring/launchpad/security-guarded-test-object-factory-3 into lp:launchpad

Proposed by Abel Deuring
Status: Rejected
Rejected by: Abel Deuring
Proposed branch: lp:~adeuring/launchpad/security-guarded-test-object-factory-3
Merge into: lp:launchpad
Diff against target: 176 lines (+37/-19)
4 files modified
lib/lp/bugs/doc/bug-heat.txt (+7/-4)
lib/lp/bugs/tests/test_bugheat.py (+21/-8)
lib/lp/code/browser/tests/test_branchmergeproposal.py (+3/-2)
lib/lp/testing/factory.py (+6/-5)
To merge this branch: bzr merge lp:~adeuring/launchpad/security-guarded-test-object-factory-3
Reviewer Review Type Date Requested Status
Henning Eggers (community) code Abstain
Aaron Bentley Pending
Review via email: mp+30917@code.launchpad.net

Description of the change

this branch is another sequel to ensure that objects returned by methods of LPObjectFactory are wrapped in security proxies. It changes the methods makeBranchMergeProposal(), makeCodeReviewVoteReference(), makeBinaryPackagePublishingHistory(), makeDistributionSourcePackage() and affected tests.

See also the branches lp:~adeuring/launchpad/security-guarded-test-object-factory-1 and ~adeuring/launchpad/security-guarded-test-object-factory-2 and bug 607236

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

erm, tests: All those that I changed.

No newly introduced lint.

Revision history for this message
Aaron Bentley (abentley) wrote :

This is a team-wide change. Was there a preimplementation call for this?

I certainly don't remember being consulted, and I don't think shouting at anyone is an improvement. We all already know that removeSecurityProxy is a warning sign, but it has legitimate uses.

Revision history for this message
Henning Eggers (henninge) wrote :

With the ongoing discussion in mind, I refrain from approving this change.

review: Abstain (code)
Revision history for this message
Abel Deuring (adeuring) wrote :

Let's wait for the result of the related discussion on the mailing list

Unmerged revisions

11164. By Abel Deuring

trunk merged

11163. By Abel Deuring

fixed test failures in bug-heat.txt

11162. By Abel Deuring

fixed test failures in test_bugheat.py

11161. By Abel Deuring

trunk merged

11160. By Abel Deuring

parent branch merged

11159. By Abel Deuring

add securoty proxies to the result returned by LaunchpadObjectFactory.makeBranchMergeProposal() and LaunchpadObjectFactory.makeDistributionSourcePackage()

11158. By Abel Deuring

fixed a failing test in test_braachmergeproposal.py

11157. By Abel Deuring

let LaunchpadObjectFactory.makeCodeReviewVoteReference() and LaunchpadObjectFactory.makeBinaryPackagePublishingHistory() return security proxied objects

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/bugs/doc/bug-heat.txt'
--- lib/lp/bugs/doc/bug-heat.txt 2010-06-22 16:08:05 +0000
+++ lib/lp/bugs/doc/bug-heat.txt 2010-07-26 08:41:50 +0000
@@ -311,15 +311,18 @@
311A DistributionSourcePackage also has a cached value for bug_count and311A DistributionSourcePackage also has a cached value for bug_count and
312total_bug_heat.312total_bug_heat.
313313
314 >>> print dsp.bug_count314 >>> from lp.testing.factory import (
315 ... remove_security_proxy_and_shout_at_engineer)
316 >>> naked_dsp = remove_security_proxy_and_shout_at_engineer(dsp)
317 >>> print naked_dsp.bug_count
315 1318 1
316 >>> print dsp.total_bug_heat319 >>> print naked_dsp.total_bug_heat
317 123320 123
318 >>> dsp_task2 = factory.makeBugTask(target=dsp)321 >>> dsp_task2 = factory.makeBugTask(target=dsp)
319 >>> dsp_task2.bug.setHeat(7)322 >>> dsp_task2.bug.setHeat(7)
320 >>> print dsp.bug_count323 >>> print naked_dsp.bug_count
321 2324 2
322 >>> print dsp.total_bug_heat325 >>> print naked_dsp.total_bug_heat
323 130326 130
324327
325Transitioning from one target to another, calculates the value for the new328Transitioning from one target to another, calculates the value for the new
326329
=== modified file 'lib/lp/bugs/tests/test_bugheat.py'
--- lib/lp/bugs/tests/test_bugheat.py 2010-07-18 00:55:24 +0000
+++ lib/lp/bugs/tests/test_bugheat.py 2010-07-26 08:41:50 +0000
@@ -12,7 +12,8 @@
12from canonical.testing import LaunchpadZopelessLayer12from canonical.testing import LaunchpadZopelessLayer
1313
14from lp.testing import TestCaseWithFactory14from lp.testing import TestCaseWithFactory
15from lp.testing.factory import LaunchpadObjectFactory15from lp.testing.factory import (
16 LaunchpadObjectFactory, remove_security_proxy_and_shout_at_engineer)
1617
1718
18class MaxHeatByTargetBase:19class MaxHeatByTargetBase:
@@ -75,10 +76,14 @@
75 self.assertEqual(None, self.target.max_bug_heat)76 self.assertEqual(None, self.target.max_bug_heat)
7677
77 def test_null_total_bug_heat(self):78 def test_null_total_bug_heat(self):
78 self.assertEqual(None, self.target.total_bug_heat)79 naked_target = remove_security_proxy_and_shout_at_engineer(
80 self.target)
81 self.assertEqual(None, naked_target.total_bug_heat)
7982
80 def test_null_bug_count(self):83 def test_null_bug_count(self):
81 self.assertEqual(None, self.target.bug_count)84 naked_target = remove_security_proxy_and_shout_at_engineer(
85 self.target)
86 self.assertEqual(None, naked_target.bug_count)
8287
8388
84class DistributionSourcePackageZeroRecalculateBugHeatCacheTest(89class DistributionSourcePackageZeroRecalculateBugHeatCacheTest(
@@ -96,10 +101,14 @@
96 self.assertEqual(0, self.target.max_bug_heat)101 self.assertEqual(0, self.target.max_bug_heat)
97102
98 def test_zero_total_bug_heat(self):103 def test_zero_total_bug_heat(self):
99 self.assertEqual(0, self.target.total_bug_heat)104 naked_target = remove_security_proxy_and_shout_at_engineer(
105 self.target)
106 self.assertEqual(0, naked_target.total_bug_heat)
100107
101 def test_zero_bug_count(self):108 def test_zero_bug_count(self):
102 self.assertEqual(0, self.target.bug_count)109 naked_target = remove_security_proxy_and_shout_at_engineer(
110 self.target)
111 self.assertEqual(0, naked_target.bug_count)
103112
104113
105class DistributionSourcePackageMultipleBugsRecalculateBugHeatCacheTest(114class DistributionSourcePackageMultipleBugsRecalculateBugHeatCacheTest(
@@ -131,14 +140,18 @@
131 self.assertEqual(self.max_heat, self.target.max_bug_heat)140 self.assertEqual(self.max_heat, self.target.max_bug_heat)
132141
133 def test_total_bug_heat(self):142 def test_total_bug_heat(self):
134 self.assertEqual(self.total_heat, self.target.total_bug_heat)143 naked_target = remove_security_proxy_and_shout_at_engineer(
144 self.target)
145 self.assertEqual(self.total_heat, naked_target.total_bug_heat)
135 self.failUnless(146 self.failUnless(
136 self.target.total_bug_heat > self.target.max_bug_heat,147 naked_target.total_bug_heat > naked_target.max_bug_heat,
137 "Total bug heat should be more than the max bug heat, "148 "Total bug heat should be more than the max bug heat, "
138 "since we know that multiple bugs have nonzero heat.")149 "since we know that multiple bugs have nonzero heat.")
139150
140 def test_bug_count(self):151 def test_bug_count(self):
141 self.assertEqual(2, self.target.bug_count)152 naked_target = remove_security_proxy_and_shout_at_engineer(
153 self.target)
154 self.assertEqual(2, naked_target.bug_count)
142155
143156
144class SourcePackageMaxHeatByTargetTest(157class SourcePackageMaxHeatByTargetTest(
145158
=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposal.py'
--- lib/lp/code/browser/tests/test_branchmergeproposal.py 2010-03-11 20:54:36 +0000
+++ lib/lp/code/browser/tests/test_branchmergeproposal.py 2010-07-26 08:41:50 +0000
@@ -28,6 +28,7 @@
28from lp.code.tests.helpers import add_revision_to_branch28from lp.code.tests.helpers import add_revision_to_branch
29from lp.testing import (29from lp.testing import (
30 login_person, TestCaseWithFactory, time_counter)30 login_person, TestCaseWithFactory, time_counter)
31from lp.testing.factory import remove_security_proxy_and_shout_at_engineer
31from lp.testing.views import create_initialized_view32from lp.testing.views import create_initialized_view
32from lp.code.model.diff import PreviewDiff, StaticDiff33from lp.code.model.diff import PreviewDiff, StaticDiff
33from canonical.launchpad.database.message import MessageSet34from canonical.launchpad.database.message import MessageSet
@@ -78,7 +79,8 @@
78 """It should be possible to review an unmergeable proposal."""79 """It should be possible to review an unmergeable proposal."""
79 request = self.factory.makeCodeReviewVoteReference()80 request = self.factory.makeCodeReviewVoteReference()
80 bmp = request.branch_merge_proposal81 bmp = request.branch_merge_proposal
81 bmp.rejectBranch(bmp.target_branch.owner, 'foo')82 naked_bmp = remove_security_proxy_and_shout_at_engineer(bmp)
83 naked_bmp.rejectBranch(bmp.target_branch.owner, 'foo')
82 d = DecoratedCodeReviewVoteReference(request, request.reviewer, None)84 d = DecoratedCodeReviewVoteReference(request, request.reviewer, None)
83 self.assertTrue(d.user_can_review)85 self.assertTrue(d.user_can_review)
84 self.assertTrue(d.can_change_review)86 self.assertTrue(d.can_change_review)
@@ -752,7 +754,6 @@
752754
753 layer = LaunchpadFunctionalLayer755 layer = LaunchpadFunctionalLayer
754756
755
756 def _makeCommentFromEmailWithAttachment(self, attachment_body):757 def _makeCommentFromEmailWithAttachment(self, attachment_body):
757 # Make an email message with an attachment, and create a code758 # Make an email message with an attachment, and create a code
758 # review comment from it.759 # review comment from it.
759760
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2010-07-26 06:21:45 +0000
+++ lib/lp/testing/factory.py 2010-07-26 08:41:50 +0000
@@ -1026,7 +1026,7 @@
1026 else:1026 else:
1027 raise AssertionError('Unknown status: %s' % set_state)1027 raise AssertionError('Unknown status: %s' % set_state)
10281028
1029 return proposal1029 return ProxyFactory(proposal)
10301030
1031 def makeBranchSubscription(self, branch=None, person=None,1031 def makeBranchSubscription(self, branch=None, person=None,
1032 subscribed_by=None):1032 subscribed_by=None):
@@ -1586,7 +1586,7 @@
1586 def makeCodeReviewVoteReference(self):1586 def makeCodeReviewVoteReference(self):
1587 bmp = removeSecurityProxy(self.makeBranchMergeProposal())1587 bmp = removeSecurityProxy(self.makeBranchMergeProposal())
1588 candidate = self.makePerson()1588 candidate = self.makePerson()
1589 return bmp.nominateReviewer(candidate, bmp.registrant)1589 return ProxyFactory(bmp.nominateReviewer(candidate, bmp.registrant))
15901590
1591 def makeMessage(self, subject=None, content=None, parent=None,1591 def makeMessage(self, subject=None, content=None, parent=None,
1592 owner=None):1592 owner=None):
@@ -2466,7 +2466,7 @@
2466 section_name=section_name,2466 section_name=section_name,
2467 priority=priority)2467 priority=priority)
24682468
2469 return BinaryPackagePublishingHistory(2469 return ProxyFactory(BinaryPackagePublishingHistory(
2470 distroarchseries=distroarchseries,2470 distroarchseries=distroarchseries,
2471 binarypackagerelease=bpr,2471 binarypackagerelease=bpr,
2472 component=bpr.component,2472 component=bpr.component,
@@ -2476,7 +2476,7 @@
2476 scheduleddeletiondate=scheduleddeletiondate,2476 scheduleddeletiondate=scheduleddeletiondate,
2477 pocket=pocket,2477 pocket=pocket,
2478 priority=priority,2478 priority=priority,
2479 archive=archive)2479 archive=archive))
24802480
2481 def makeBinaryPackageName(self, name=None):2481 def makeBinaryPackageName(self, name=None):
2482 if name is None:2482 if name is None:
@@ -2565,7 +2565,8 @@
2565 if distribution is None:2565 if distribution is None:
2566 distribution = self.makeDistribution()2566 distribution = self.makeDistribution()
25672567
2568 return DistributionSourcePackage(distribution, sourcepackagename)2568 return ProxyFactory(
2569 DistributionSourcePackage(distribution, sourcepackagename))
25692570
2570 def makeEmailMessage(self, body=None, sender=None, to=None,2571 def makeEmailMessage(self, body=None, sender=None, to=None,
2571 attachments=None, encode_attachments=False):2572 attachments=None, encode_attachments=False):