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
1=== modified file 'lib/lp/bugs/doc/bug-heat.txt'
2--- lib/lp/bugs/doc/bug-heat.txt 2010-06-22 16:08:05 +0000
3+++ lib/lp/bugs/doc/bug-heat.txt 2010-07-26 08:41:50 +0000
4@@ -311,15 +311,18 @@
5 A DistributionSourcePackage also has a cached value for bug_count and
6 total_bug_heat.
7
8- >>> print dsp.bug_count
9+ >>> from lp.testing.factory import (
10+ ... remove_security_proxy_and_shout_at_engineer)
11+ >>> naked_dsp = remove_security_proxy_and_shout_at_engineer(dsp)
12+ >>> print naked_dsp.bug_count
13 1
14- >>> print dsp.total_bug_heat
15+ >>> print naked_dsp.total_bug_heat
16 123
17 >>> dsp_task2 = factory.makeBugTask(target=dsp)
18 >>> dsp_task2.bug.setHeat(7)
19- >>> print dsp.bug_count
20+ >>> print naked_dsp.bug_count
21 2
22- >>> print dsp.total_bug_heat
23+ >>> print naked_dsp.total_bug_heat
24 130
25
26 Transitioning from one target to another, calculates the value for the new
27
28=== modified file 'lib/lp/bugs/tests/test_bugheat.py'
29--- lib/lp/bugs/tests/test_bugheat.py 2010-07-18 00:55:24 +0000
30+++ lib/lp/bugs/tests/test_bugheat.py 2010-07-26 08:41:50 +0000
31@@ -12,7 +12,8 @@
32 from canonical.testing import LaunchpadZopelessLayer
33
34 from lp.testing import TestCaseWithFactory
35-from lp.testing.factory import LaunchpadObjectFactory
36+from lp.testing.factory import (
37+ LaunchpadObjectFactory, remove_security_proxy_and_shout_at_engineer)
38
39
40 class MaxHeatByTargetBase:
41@@ -75,10 +76,14 @@
42 self.assertEqual(None, self.target.max_bug_heat)
43
44 def test_null_total_bug_heat(self):
45- self.assertEqual(None, self.target.total_bug_heat)
46+ naked_target = remove_security_proxy_and_shout_at_engineer(
47+ self.target)
48+ self.assertEqual(None, naked_target.total_bug_heat)
49
50 def test_null_bug_count(self):
51- self.assertEqual(None, self.target.bug_count)
52+ naked_target = remove_security_proxy_and_shout_at_engineer(
53+ self.target)
54+ self.assertEqual(None, naked_target.bug_count)
55
56
57 class DistributionSourcePackageZeroRecalculateBugHeatCacheTest(
58@@ -96,10 +101,14 @@
59 self.assertEqual(0, self.target.max_bug_heat)
60
61 def test_zero_total_bug_heat(self):
62- self.assertEqual(0, self.target.total_bug_heat)
63+ naked_target = remove_security_proxy_and_shout_at_engineer(
64+ self.target)
65+ self.assertEqual(0, naked_target.total_bug_heat)
66
67 def test_zero_bug_count(self):
68- self.assertEqual(0, self.target.bug_count)
69+ naked_target = remove_security_proxy_and_shout_at_engineer(
70+ self.target)
71+ self.assertEqual(0, naked_target.bug_count)
72
73
74 class DistributionSourcePackageMultipleBugsRecalculateBugHeatCacheTest(
75@@ -131,14 +140,18 @@
76 self.assertEqual(self.max_heat, self.target.max_bug_heat)
77
78 def test_total_bug_heat(self):
79- self.assertEqual(self.total_heat, self.target.total_bug_heat)
80+ naked_target = remove_security_proxy_and_shout_at_engineer(
81+ self.target)
82+ self.assertEqual(self.total_heat, naked_target.total_bug_heat)
83 self.failUnless(
84- self.target.total_bug_heat > self.target.max_bug_heat,
85+ naked_target.total_bug_heat > naked_target.max_bug_heat,
86 "Total bug heat should be more than the max bug heat, "
87 "since we know that multiple bugs have nonzero heat.")
88
89 def test_bug_count(self):
90- self.assertEqual(2, self.target.bug_count)
91+ naked_target = remove_security_proxy_and_shout_at_engineer(
92+ self.target)
93+ self.assertEqual(2, naked_target.bug_count)
94
95
96 class SourcePackageMaxHeatByTargetTest(
97
98=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposal.py'
99--- lib/lp/code/browser/tests/test_branchmergeproposal.py 2010-03-11 20:54:36 +0000
100+++ lib/lp/code/browser/tests/test_branchmergeproposal.py 2010-07-26 08:41:50 +0000
101@@ -28,6 +28,7 @@
102 from lp.code.tests.helpers import add_revision_to_branch
103 from lp.testing import (
104 login_person, TestCaseWithFactory, time_counter)
105+from lp.testing.factory import remove_security_proxy_and_shout_at_engineer
106 from lp.testing.views import create_initialized_view
107 from lp.code.model.diff import PreviewDiff, StaticDiff
108 from canonical.launchpad.database.message import MessageSet
109@@ -78,7 +79,8 @@
110 """It should be possible to review an unmergeable proposal."""
111 request = self.factory.makeCodeReviewVoteReference()
112 bmp = request.branch_merge_proposal
113- bmp.rejectBranch(bmp.target_branch.owner, 'foo')
114+ naked_bmp = remove_security_proxy_and_shout_at_engineer(bmp)
115+ naked_bmp.rejectBranch(bmp.target_branch.owner, 'foo')
116 d = DecoratedCodeReviewVoteReference(request, request.reviewer, None)
117 self.assertTrue(d.user_can_review)
118 self.assertTrue(d.can_change_review)
119@@ -752,7 +754,6 @@
120
121 layer = LaunchpadFunctionalLayer
122
123-
124 def _makeCommentFromEmailWithAttachment(self, attachment_body):
125 # Make an email message with an attachment, and create a code
126 # review comment from it.
127
128=== modified file 'lib/lp/testing/factory.py'
129--- lib/lp/testing/factory.py 2010-07-26 06:21:45 +0000
130+++ lib/lp/testing/factory.py 2010-07-26 08:41:50 +0000
131@@ -1026,7 +1026,7 @@
132 else:
133 raise AssertionError('Unknown status: %s' % set_state)
134
135- return proposal
136+ return ProxyFactory(proposal)
137
138 def makeBranchSubscription(self, branch=None, person=None,
139 subscribed_by=None):
140@@ -1586,7 +1586,7 @@
141 def makeCodeReviewVoteReference(self):
142 bmp = removeSecurityProxy(self.makeBranchMergeProposal())
143 candidate = self.makePerson()
144- return bmp.nominateReviewer(candidate, bmp.registrant)
145+ return ProxyFactory(bmp.nominateReviewer(candidate, bmp.registrant))
146
147 def makeMessage(self, subject=None, content=None, parent=None,
148 owner=None):
149@@ -2466,7 +2466,7 @@
150 section_name=section_name,
151 priority=priority)
152
153- return BinaryPackagePublishingHistory(
154+ return ProxyFactory(BinaryPackagePublishingHistory(
155 distroarchseries=distroarchseries,
156 binarypackagerelease=bpr,
157 component=bpr.component,
158@@ -2476,7 +2476,7 @@
159 scheduleddeletiondate=scheduleddeletiondate,
160 pocket=pocket,
161 priority=priority,
162- archive=archive)
163+ archive=archive))
164
165 def makeBinaryPackageName(self, name=None):
166 if name is None:
167@@ -2565,7 +2565,8 @@
168 if distribution is None:
169 distribution = self.makeDistribution()
170
171- return DistributionSourcePackage(distribution, sourcepackagename)
172+ return ProxyFactory(
173+ DistributionSourcePackage(distribution, sourcepackagename))
174
175 def makeEmailMessage(self, body=None, sender=None, to=None,
176 attachments=None, encode_attachments=False):