← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~andrey-fedoseev/launchpad:packaging-security into launchpad:master

 

Andrey Fedoseev has proposed merging ~andrey-fedoseev/launchpad:packaging-security into launchpad:master.

Commit message:
Fix the failing tests caused by the recent changes in `Packaging` security

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~andrey-fedoseev/launchpad/+git/launchpad/+merge/430124
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~andrey-fedoseev/launchpad:packaging-security into launchpad:master.
diff --git a/lib/lp/answers/browser/tests/test_questiontarget.py b/lib/lp/answers/browser/tests/test_questiontarget.py
index 5a289c0..b9a8bd2 100644
--- a/lib/lp/answers/browser/tests/test_questiontarget.py
+++ b/lib/lp/answers/browser/tests/test_questiontarget.py
@@ -180,9 +180,10 @@ class TestSearchQuestionsViewUnknown(TestCaseWithFactory):
         self.factory.makeSourcePackagePublishingHistory(
             sourcepackagename=sourcepackagename, distroseries=hoary
         )
-        product.development_focus.setPackaging(
-            hoary, sourcepackagename, product.owner
-        )
+        with person_logged_in(product.development_focus.owner):
+            product.development_focus.setPackaging(
+                hoary, sourcepackagename, product.owner
+            )
 
     def setUp(self):
         super().setUp()
diff --git a/lib/lp/code/model/tests/test_branchtarget.py b/lib/lp/code/model/tests/test_branchtarget.py
index 19c3fb4..1b74d7a 100644
--- a/lib/lp/code/model/tests/test_branchtarget.py
+++ b/lib/lp/code/model/tests/test_branchtarget.py
@@ -180,9 +180,10 @@ class TestPackageBranchTarget(TestCaseWithFactory, BaseBranchTargetTests):
         # Products that are linked to the packages are mergeable.
         branch = self.factory.makeProductBranch()
         # Link it up.
-        self.original.setPackaging(
-            branch.product.development_focus, branch.owner
-        )
+        with person_logged_in(self.original.owner):
+            self.original.setPackaging(
+                branch.product.development_focus, branch.owner
+            )
         self.assertTrue(self.target.areBranchesMergeable(branch.target))
 
     def test_default_merge_target(self):
diff --git a/lib/lp/soyuz/stories/distribution/xx-distribution-packages.rst b/lib/lp/soyuz/stories/distribution/xx-distribution-packages.rst
index 3b380bb..bc7a550 100644
--- a/lib/lp/soyuz/stories/distribution/xx-distribution-packages.rst
+++ b/lib/lp/soyuz/stories/distribution/xx-distribution-packages.rst
@@ -172,6 +172,7 @@ It will thus not be listed in the "...other untrusted versions of..." portlet.
 A /$DISTRO/+source/$PACKAGE page shows an overview of a source package in
 a distribution.  There are several sections of information.
 
+    >>> user_browser = setupBrowser(auth="Basic limi@xxxxxxxxx:test")
     >>> user_browser.open("http://launchpad.test/ubuntu/+source/iceweasel/";)
 
 The page has an appropriate title and main heading.
@@ -331,6 +332,7 @@ menu, and a "Subscribers" portlet.
     View full change log
     Subscribe to bug mail
     Edit bug mail
+    Configure bug tracker
 
     >>> print(
     ...     extract_text(find_tag_by_id(user_browser.contents, "involvement"))
@@ -361,9 +363,9 @@ distroseries.  The distroseries are presented in order, most recent first.
 
     >>> browser.open("http://launchpad.test/ubuntutest/+source/netapplet/";)
     >>> print(extract_text(find_tag_by_id(browser.contents, "packages_list")))
-    Mock Hoary (active development)                   Set upstream link
+    Mock Hoary (active development)
       1.0.1a  release  (main)  ...
-    Breezy Badger Autotest  (active development)      Set upstream link
+    Breezy Badger Autotest  (active development)
       1.3.1   release  (main)  ...
 
 (See more about packaging in:
diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
index 9965749..3ebd99c 100644
--- a/lib/lp/testing/factory.py
+++ b/lib/lp/testing/factory.py
@@ -1389,6 +1389,7 @@ class LaunchpadObjectFactory(ObjectFactory):
         sourcepackage=None,
         distroseries=None,
         sourcepackagename=None,
+        owner=None,
         **kwargs
     ):
         """Make a package branch on an arbitrary package.
@@ -1407,9 +1408,13 @@ class LaunchpadObjectFactory(ObjectFactory):
         ), "Don't pass in both sourcepackage and sourcepackagename"
         if sourcepackage is None:
             sourcepackage = self.makeSourcePackage(
-                sourcepackagename=sourcepackagename, distroseries=distroseries
+                sourcepackagename=sourcepackagename,
+                distroseries=distroseries,
+                owner=owner,
             )
-        return self.makeBranch(sourcepackage=sourcepackage, **kwargs)
+        return self.makeBranch(
+            sourcepackage=sourcepackage, owner=owner, **kwargs
+        )
 
     def makePersonalBranch(self, owner=None, **kwargs):
         """Make a personal branch on an arbitrary person.
@@ -3374,10 +3379,11 @@ class LaunchpadObjectFactory(ObjectFactory):
         name=None,
         displayname=None,
         registrant=None,
+        owner=None,
     ):
         """Make a new `DistroSeries`."""
         if distribution is None:
-            distribution = self.makeDistribution()
+            distribution = self.makeDistribution(owner=owner)
         if name is None:
             name = self.getUniqueString(prefix="distroseries")
         if displayname is None:
@@ -4538,7 +4544,11 @@ class LaunchpadObjectFactory(ObjectFactory):
         return getUtility(ISourcePackageNameSet).getOrCreateByName(name)
 
     def makeSourcePackage(
-        self, sourcepackagename=None, distroseries=None, publish=False
+        self,
+        sourcepackagename=None,
+        distroseries=None,
+        publish=False,
+        owner=None,
     ):
         """Make an `ISourcePackage`.
 
@@ -4551,7 +4561,7 @@ class LaunchpadObjectFactory(ObjectFactory):
                 sourcepackagename
             )
         if distroseries is None:
-            distroseries = self.makeDistroSeries()
+            distroseries = self.makeDistroSeries(owner=owner)
         if publish:
             self.makeSourcePackagePublishingHistory(
                 distroseries=distroseries, sourcepackagename=sourcepackagename
diff --git a/lib/lp/translations/browser/tests/test_sharing_details.py b/lib/lp/translations/browser/tests/test_sharing_details.py
index fecbe12..4828730 100644
--- a/lib/lp/translations/browser/tests/test_sharing_details.py
+++ b/lib/lp/translations/browser/tests/test_sharing_details.py
@@ -5,6 +5,7 @@ import re
 
 from lazr.restful.interfaces import IJSONRequestCache
 from soupmatchers import HTMLContains, Tag
+from testscenarios import WithScenarios
 
 from lp.app.enums import ServiceUsage
 from lp.services.webapp import canonical_url
@@ -103,8 +104,7 @@ class TestSourcePackageTranslationSharingDetailsView(
         self.shared_template_ubuntu_side = self.factory.makePOTemplate(
             sourcepackage=self.sourcepackage, name="shared-template"
         )
-        self.privileged_user = self.factory.makePerson(karma=200)
-        product = self.factory.makeProduct(owner=self.privileged_user)
+        product = self.factory.makeProduct()
         self.productseries = self.factory.makeProductSeries(product=product)
         self.shared_template_upstream_side = self.factory.makePOTemplate(
             productseries=self.productseries, name="shared-template"
@@ -126,7 +126,7 @@ class TestSourcePackageTranslationSharingDetailsView(
         done only if explicitly specified.
         """
         # Suppress merge job creation.
-        with EventRecorder():
+        with EventRecorder(), person_logged_in(self.sourcepackage.owner):
             self.sourcepackage.setPackaging(
                 self.productseries, self.productseries.owner
             )
@@ -585,6 +585,73 @@ class TestSourcePackageTranslationSharingDetailsView(
                 expected, view.translation_sync_link_configured.escapedtext
             )
 
+
+class TestSourcePackageTranslationSharingDetailsViewPackagingLinks(
+    WithScenarios, TestCaseWithFactory
+):
+
+    layer = DatabaseFunctionalLayer
+    scenarios = [
+        (
+            "has packaging, any user",
+            {
+                "has_packaging": True,
+                "user_type": "any_user",
+                "set_link_visible": False,
+                "change_link_visible": False,
+                "remove_link_visible": False,
+            },
+        ),
+        (
+            "has packaging, package owner",
+            {
+                "has_packaging": True,
+                "user_type": "package_owner",
+                "set_link_visible": True,
+                "change_link_visible": True,
+                "remove_link_visible": True,
+            },
+        ),
+        (
+            "no packaging, any user",
+            {
+                "has_packaging": False,
+                "user_type": "any_user",
+                "set_link_visible": False,
+                "change_link_visible": False,
+                "remove_link_visible": False,
+            },
+        ),
+        (
+            "no packaging, package owner",
+            {
+                "has_packaging": False,
+                "user_type": "package_owner",
+                "set_link_visible": True,
+                "change_link_visible": True,
+                "remove_link_visible": False,
+            },
+        ),
+    ]
+
+    def setUp(self, *args, **kwargs):
+        super().setUp(*args, **kwargs)
+        self.productseries = self.factory.makeProductSeries()
+        self.sourcepackage = self.factory.makeSourcePackage()
+        if self.has_packaging:
+            with person_logged_in(self.sourcepackage.owner):
+                self.sourcepackage.setPackaging(
+                    self.productseries, self.productseries.owner
+                )
+        if self.user_type == "any_user":
+            self.user = self.factory.makePerson()
+        elif self.user_type == "package_owner":
+            self.user = self.sourcepackage.owner
+        else:
+            raise AssertionError(
+                "Unknown user type: {}".format(self.user_type)
+            )
+
     def _getExpectedPackagingLink(self, id, url, icon, text, visible):
         url = "%s/%s" % (canonical_url(self.sourcepackage), url)
         return (
@@ -598,220 +665,48 @@ class TestSourcePackageTranslationSharingDetailsView(
             "text": text,
         }
 
-    def test_set_packaging_link__anonymous(self):
-        # The "set packaging" link is hidden for anonymous users.
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
-            id="set-packaging",
-            url="+edit-packaging",
-            icon="add",
-            text="Set upstream link",
-            visible=False,
-        )
-        self.assertEqual(expected, self.view.set_packaging_link.escapedtext)
-
-    def test_set_packaging_link__no_packaging_any_user(self):
-        # If packaging is not configured, any user sees the "set packaging"
-        # link.
-        expected = self._getExpectedPackagingLink(
-            id="set-packaging",
-            url="+edit-packaging",
-            icon="add",
-            text="Set upstream link",
-            visible=True,
-        )
-        with person_logged_in(self.factory.makePerson()):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
-            )
-            view.initialize()
-            self.assertEqual(
-                expected, self.view.set_packaging_link.escapedtext
-            )
-
-    def test_set_packaging_link__with_packaging_probationary_user(self):
-        # If packaging is configured, probationary users do no see
-        # the "set packaging" link.
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
-            id="set-packaging",
-            url="+edit-packaging",
-            icon="add",
-            text="Set upstream link",
-            visible=False,
-        )
-        with person_logged_in(self.factory.makePerson()):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
-            )
-            view.initialize()
-            self.assertEqual(
-                expected, self.view.set_packaging_link.escapedtext
-            )
+    def test_packaging_links(self):
 
-    def test_set_packaging_link__with_packaging_privileged_user(self):
-        # If packaging is configured, privileged users see the
-        # "set packaging" link. (See Packaging.userCanDelete() for more
-        # details about which people are "privileged".)
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
+        expected_set_upstream = self._getExpectedPackagingLink(
             id="set-packaging",
             url="+edit-packaging",
             icon="add",
             text="Set upstream link",
-            visible=True,
-        )
-        with person_logged_in(self.privileged_user):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
-            )
-            view.initialize()
-            self.assertEqual(
-                expected, self.view.set_packaging_link.escapedtext
-            )
-
-    def test_change_packaging_link__anonymous(self):
-        # The "change packaging" link is hidden for anonymous users.
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
-            id="change-packaging",
-            url="+edit-packaging",
-            icon="edit",
-            text="Change upstream link",
-            visible=False,
-        )
-        self.assertEqual(expected, self.view.change_packaging_link.escapedtext)
-
-    def test_change_packaging_link__no_packaging_any_user(self):
-        # If packaging is not configured, any user sees the "change packaging"
-        # link.
-        expected = self._getExpectedPackagingLink(
-            id="change-packaging",
-            url="+edit-packaging",
-            icon="edit",
-            text="Change upstream link",
-            visible=True,
-        )
-        with person_logged_in(self.factory.makePerson()):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
-            )
-            view.initialize()
-            self.assertEqual(
-                expected, self.view.change_packaging_link.escapedtext
-            )
-
-    def test_change_packaging_link__with_packaging_probationary_user(self):
-        # If packaging is configured, probationary users do no see
-        # the "change packaging" link.
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
-            id="change-packaging",
-            url="+edit-packaging",
-            icon="edit",
-            text="Change upstream link",
-            visible=False,
+            visible=self.set_link_visible,
         )
-        with person_logged_in(self.factory.makePerson()):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
-            )
-            view.initialize()
-            self.assertEqual(
-                expected, self.view.change_packaging_link.escapedtext
-            )
 
-    def test_change_packaging_link__with_packaging_privileged_user(self):
-        # If packaging is configured, privileged users see the
-        # "change packaging" link. (See Packaging.userCanDelete() for more
-        # details about which people are "privileged".)
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
+        expected_change_upstream = self._getExpectedPackagingLink(
             id="change-packaging",
             url="+edit-packaging",
             icon="edit",
             text="Change upstream link",
-            visible=True,
+            visible=self.change_link_visible,
         )
-        with person_logged_in(self.privileged_user):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
-            )
-            view.initialize()
-            self.assertEqual(
-                expected, self.view.change_packaging_link.escapedtext
-            )
 
-    def test_remove_packaging_link__anonymous(self):
-        # The "remove packaging" link is hidden for anonymous users.
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
+        expected_remove_upstream = self._getExpectedPackagingLink(
             id="remove-packaging",
             url="+remove-packaging",
             icon="remove",
             text="Remove upstream link",
-            visible=False,
+            visible=self.remove_link_visible,
         )
-        self.assertEqual(expected, self.view.remove_packaging_link.escapedtext)
 
-    def test_remove_packaging_link__no_packaging_any_user(self):
-        # If packaging is not configured, any user sees the "remove packaging"
-        # link.
-        expected = self._getExpectedPackagingLink(
-            id="remove-packaging",
-            url="+remove-packaging",
-            icon="remove",
-            text="Remove upstream link",
-            visible=True,
-        )
-        with person_logged_in(self.factory.makePerson()):
+        with person_logged_in(self.user):
             view = SourcePackageTranslationSharingDetailsView(
                 self.sourcepackage, LaunchpadTestRequest()
             )
             view.initialize()
-            self.assertEqual(
-                expected, self.view.remove_packaging_link.escapedtext
-            )
 
-    def test_remove_packaging_link__with_packaging_probationary_user(self):
-        # If packaging is configured, probationary users do no see
-        # the "remove packaging" link.
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
-            id="remove-packaging",
-            url="+remove-packaging",
-            icon="remove",
-            text="Remove upstream link",
-            visible=False,
-        )
-        with person_logged_in(self.factory.makePerson()):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
-            )
-            view.initialize()
             self.assertEqual(
-                expected, self.view.remove_packaging_link.escapedtext
+                expected_set_upstream, view.set_packaging_link.escapedtext
             )
-
-    def test_remove_packaging_link__with_packaging_privileged_user(self):
-        # If packaging is configured, privileged users see the
-        # "remove packaging" link. (See Packaging.userCanDelete() for more
-        # details about which people are "privileged".)
-        self.configureSharing()
-        expected = self._getExpectedPackagingLink(
-            id="remove-packaging",
-            url="+remove-packaging",
-            icon="remove",
-            text="Remove upstream link",
-            visible=True,
-        )
-        with person_logged_in(self.privileged_user):
-            view = SourcePackageTranslationSharingDetailsView(
-                self.sourcepackage, LaunchpadTestRequest()
+            self.assertEqual(
+                expected_change_upstream,
+                view.change_packaging_link.escapedtext,
             )
-            view.initialize()
             self.assertEqual(
-                expected, self.view.remove_packaging_link.escapedtext
+                expected_remove_upstream,
+                view.remove_packaging_link.escapedtext,
             )