Merge lp:~cjwatson/launchpad/snap-edit-better-reauth into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18157
Proposed branch: lp:~cjwatson/launchpad/snap-edit-better-reauth
Merge into: lp:launchpad
Diff against target: 90 lines (+46/-2)
2 files modified
lib/lp/snappy/browser/snap.py (+2/-0)
lib/lp/snappy/browser/tests/test_snap.py (+44/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-edit-better-reauth
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+300303@code.launchpad.net

Commit message

Reauthorize store uploads in Snap:+edit if store_upload is newly-enabled.

Description of the change

Reauthorize store uploads in Snap:+edit if store_upload is newly-enabled.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/snappy/browser/snap.py'
2--- lib/lp/snappy/browser/snap.py 2016-07-16 07:46:23 +0000
3+++ lib/lp/snappy/browser/snap.py 2016-07-18 10:01:08 +0000
4@@ -567,6 +567,8 @@
5 if (not store_upload or
6 store_distro_series is None or store_name is None):
7 return False
8+ if not self.context.store_upload:
9+ return True
10 if store_distro_series.snappy_series != self.context.store_series:
11 return True
12 if store_name != self.context.store_name:
13
14=== modified file 'lib/lp/snappy/browser/tests/test_snap.py'
15--- lib/lp/snappy/browser/tests/test_snap.py 2016-07-16 07:46:23 +0000
16+++ lib/lp/snappy/browser/tests/test_snap.py 2016-07-18 10:01:08 +0000
17@@ -63,6 +63,7 @@
18 SNAP_TESTING_FLAGS,
19 SnapPrivateFeatureDisabled,
20 )
21+from lp.snappy.interfaces.snappyseries import ISnappyDistroSeriesSet
22 from lp.snappy.interfaces.snapstoreclient import ISnapStoreClient
23 from lp.testing import (
24 admin_logged_in,
25@@ -439,7 +440,7 @@
26
27 def test_create_new_snap_display_processors(self):
28 branch = self.factory.makeAnyBranch()
29- distroseries = self.setUpDistroSeries()
30+ self.setUpDistroSeries()
31 browser = self.getViewBrowser(
32 branch, view_name="+new-snap", user=self.person)
33 processors = browser.getControl(name="field.processors")
34@@ -466,7 +467,7 @@
35
36 def test_create_new_snap_processors(self):
37 branch = self.factory.makeAnyBranch()
38- distroseries = self.setUpDistroSeries()
39+ self.setUpDistroSeries()
40 browser = self.getViewBrowser(
41 branch, view_name="+new-snap", user=self.person)
42 processors = browser.getControl(name="field.processors")
43@@ -859,6 +860,47 @@
44 login_person(self.person)
45 self.assertSnapProcessors(snap, ["386", "armhf"])
46
47+ def assertNeedStoreReauth(self, expected, initial_kwargs, data):
48+ initial_kwargs.setdefault("store_upload", True)
49+ initial_kwargs.setdefault("store_series", self.snappyseries)
50+ initial_kwargs.setdefault("store_name", u"one")
51+ snap = self.factory.makeSnap(
52+ registrant=self.person, owner=self.person,
53+ distroseries=self.distroseries, **initial_kwargs)
54+ view = create_initialized_view(snap, "+edit", principal=self.person)
55+ data.setdefault("store_upload", snap.store_upload)
56+ data.setdefault("store_distro_series", snap.store_distro_series)
57+ data.setdefault("store_name", snap.store_name)
58+ self.assertEqual(expected, view._needStoreReauth(data))
59+
60+ def test__needStoreReauth_no_change(self):
61+ # If the user didn't change any store settings, no reauthorization
62+ # is needed.
63+ self.assertNeedStoreReauth(False, {}, {})
64+
65+ def test__needStoreReauth_different_series(self):
66+ # Changing the store series requires reauthorization.
67+ with admin_logged_in():
68+ new_snappyseries = self.factory.makeSnappySeries(
69+ usable_distro_series=[self.distroseries])
70+ sds = getUtility(ISnappyDistroSeriesSet).getByBothSeries(
71+ new_snappyseries, self.distroseries)
72+ self.assertNeedStoreReauth(True, {}, {"store_distro_series": sds})
73+
74+ def test__needStoreReauth_different_name(self):
75+ # Changing the store name requires reauthorization.
76+ self.assertNeedStoreReauth(True, {}, {"store_name": u"two"})
77+
78+ def test__needStoreReauth_enable_upload(self):
79+ # Enabling store upload requires reauthorization. (This can happen
80+ # on its own if both store_series and store_name were set to begin
81+ # with, which is especially plausible for Git-based snap packages,
82+ # or if this option is disabled and then re-enabled. In the latter
83+ # case, we can't tell if store_series or store_name were also
84+ # changed in between, so reauthorizing is the conservative course.)
85+ self.assertNeedStoreReauth(
86+ True, {"store_upload": False}, {"store_upload": True})
87+
88 def test_edit_store_upload(self):
89 # Changing store upload settings on a snap sets all the appropriate
90 # fields and redirects to SSO for reauthorization.