Merge lp:~cjwatson/launchpad/archive-sourcefiles-private into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18649
Proposed branch: lp:~cjwatson/launchpad/archive-sourcefiles-private
Merge into: lp:launchpad
Diff against target: 177 lines (+54/-19)
3 files modified
lib/lp/soyuz/browser/archive.py (+21/-2)
lib/lp/soyuz/browser/publishing.py (+2/-2)
lib/lp/soyuz/stories/ppa/xx-ppa-files.txt (+31/-15)
To merge this branch: bzr merge lp:~cjwatson/launchpad/archive-sourcefiles-private
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+345442@code.launchpad.net

Commit message

Fix Archive:+sourcefiles for private archives.

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/soyuz/browser/archive.py'
2--- lib/lp/soyuz/browser/archive.py 2018-05-04 21:59:32 +0000
3+++ lib/lp/soyuz/browser/archive.py 2018-05-11 18:13:12 +0000
4@@ -58,6 +58,7 @@
5 SimpleTerm,
6 SimpleVocabulary,
7 )
8+from zope.security.interfaces import Unauthorized
9 from zope.security.proxy import removeSecurityProxy
10
11 from lp import _
12@@ -99,7 +100,10 @@
13 from lp.services.database.bulk import load_related
14 from lp.services.helpers import english_list
15 from lp.services.job.model.job import Job
16-from lp.services.librarian.browser import FileNavigationMixin
17+from lp.services.librarian.browser import (
18+ DeletedProxiedLibraryFileAlias,
19+ FileNavigationMixin,
20+ )
21 from lp.services.propertycache import cachedproperty
22 from lp.services.webapp import (
23 canonical_url,
24@@ -120,6 +124,7 @@
25 IStructuredString,
26 )
27 from lp.services.webapp.menu import NavigationMenu
28+from lp.services.webapp.publisher import RedirectionView
29 from lp.services.worlddata.interfaces.country import ICountrySet
30 from lp.soyuz.adapters.archivedependencies import (
31 default_component_dependency_name,
32@@ -478,9 +483,23 @@
33 version = self.request.stepstogo.consume()
34 filename = self.request.stepstogo.consume()
35
36- return self.context.getSourceFileByName(
37+ if not check_permission('launchpad.View', self.context):
38+ raise Unauthorized()
39+
40+ library_file = self.context.getSourceFileByName(
41 sourcepackagename, version, filename)
42
43+ # Deleted library files result in a NotFound-like error.
44+ if library_file.deleted:
45+ raise DeletedProxiedLibraryFileAlias(filename, self.context)
46+
47+ # There can be no further path segments.
48+ if len(self.request.stepstogo) > 0:
49+ return None
50+
51+ return RedirectionView(
52+ library_file.getURL(include_token=True), self.request)
53+
54
55 class ArchiveMenuMixin:
56
57
58=== modified file 'lib/lp/soyuz/browser/publishing.py'
59--- lib/lp/soyuz/browser/publishing.py 2018-05-04 21:59:32 +0000
60+++ lib/lp/soyuz/browser/publishing.py 2018-05-11 18:13:12 +0000
61@@ -17,6 +17,7 @@
62 from lazr.delegates import delegate_to
63 from zope.interface import implementer
64
65+from lp.archiveuploader.utils import re_isadeb
66 from lp.services.librarian.browser import (
67 FileNavigationMixin,
68 ProxiedLibraryFileAlias,
69@@ -287,8 +288,7 @@
70 custom_dict = {}
71 custom_dict["filename"] = library_file.filename
72 custom_dict["filesize"] = library_file.content.filesize
73- if (library_file.filename.endswith('.deb') or
74- library_file.filename.endswith('.udeb')):
75+ if re_isadeb.match(library_file.filename):
76 custom_dict['class'] = 'binary'
77 custom_dict["url"] = ProxiedLibraryFileAlias(
78 library_file, self.context.archive).http_url
79
80=== modified file 'lib/lp/soyuz/stories/ppa/xx-ppa-files.txt'
81--- lib/lp/soyuz/stories/ppa/xx-ppa-files.txt 2018-05-04 21:59:32 +0000
82+++ lib/lp/soyuz/stories/ppa/xx-ppa-files.txt 2018-05-11 18:13:12 +0000
83@@ -236,17 +236,14 @@
84 Retrieve file information for using the direct HTTP browsing API.
85
86 >>> login('foo.bar@canonical.com')
87- >>> file_content = dsc_file.read()
88- >>> file_size = str(dsc_file.content.filesize)
89- >>> file_mimetype = dsc_file.mimetype
90- >>> file_lp_url = str(
91- ... 'http://launchpad.dev/~no-priv/+archive/ubuntu/p3a/+files/%s' %
92- ... dsc_file.filename)
93+ >>> dsc_file_lp_url = (
94+ ... 'http://launchpad.dev/~no-priv/+archive/ubuntu/p3a/+sourcefiles/'
95+ ... 'test-pkg/1.0/%s' % dsc_file.filename)
96 >>> logout()
97
98 Sample Person can't access the file.
99
100- >>> browser.open(file_lp_url)
101+ >>> browser.open(dsc_file_lp_url)
102 Traceback (most recent call last):
103 ...
104 Unauthorized
105@@ -256,12 +253,32 @@
106 >>> print http(r"""
107 ... GET %s HTTP/1.1
108 ... Authorization: Basic no-priv@canonical.com:test
109- ... """ % (file_lp_url.replace('http://launchpad.dev', '')))
110+ ... """ % (dsc_file_lp_url.replace('http://launchpad.dev', '')))
111 HTTP/1.1 303 See Other
112 ...
113 Location: https://...restricted.../test-pkg_1.0.dsc?token=...
114 ...
115
116+Binary files are served via '+files' rather than '+sourcefiles'.
117+
118+ >>> login('foo.bar@canonical.com')
119+ >>> deb_file_lp_url = (
120+ ... 'http://launchpad.dev/~no-priv/+archive/ubuntu/p3a/+files/%s' %
121+ ... deb_file.filename)
122+ >>> logout()
123+ >>> browser.open(deb_file_lp_url)
124+ Traceback (most recent call last):
125+ ...
126+ Unauthorized
127+ >>> print http(r"""
128+ ... GET %s HTTP/1.1
129+ ... Authorization: Basic no-priv@canonical.com:test
130+ ... """ % (deb_file_lp_url.replace('http://launchpad.dev', '')))
131+ HTTP/1.1 303 See Other
132+ ...
133+ Location: https://...restricted.../test-bin_1.0_all.deb?token=...
134+ ...
135+
136 If the associated PPA and the `LibraryFileAlias` are public, the +files/
137 proxy redirects to the public http url. We'll copy the test sources and
138 binaries across to no-priv's public ppa.
139@@ -286,8 +303,8 @@
140 False
141 >>> file_librarian_url = dsc_file.http_url
142 >>> file_lp_url = str(
143- ... 'http://launchpad.dev/~no-priv/+archive/ubuntu/ppa/+files/%s' %
144- ... dsc_file.filename)
145+ ... 'http://launchpad.dev/~no-priv/+archive/ubuntu/ppa/+sourcefiles/'
146+ ... 'test-pkg/1.0/%s' % dsc_file.filename)
147
148 >>> transaction.commit()
149 >>> logout()
150@@ -318,9 +335,8 @@
151 sure that '+files' isn't understood as the PPA name, but instead
152 redirect to the files for the default named PPA.
153
154- >>> file_lp_url_without_ppa_name = file_lp_url.replace('/ubuntu/ppa', '')
155- >>> print file_lp_url_without_ppa_name
156- http://launchpad.dev/~no-priv/+archive/+files/test-pkg_1.0.dsc
157+ >>> file_lp_url_without_ppa_name = (
158+ ... 'http://launchpad.dev/~no-priv/+archive/+files/test-pkg_1.0.dsc')
159
160 >>> print http(r"""
161 ... GET %s HTTP/1.1
162@@ -390,7 +406,7 @@
163 LP proxy URL a proper NotFound error is raised.
164
165 >>> print file_lp_url
166- http://launchpad.dev/~no-priv/+archive/ubuntu/ppa/+files/test-pkg_1.0.dsc
167+ http://launchpad.dev/~no-priv/+archive/ubuntu/ppa/+sourcefiles/test-pkg/1.0/test-pkg_1.0.dsc
168
169 >>> not_found_file = http(r"""
170 ... GET %s HTTP/1.1
171@@ -410,6 +426,6 @@
172 Lost something?
173 ...
174 NotFound:
175- Object: <Archive at ...>, name: u'test-pkg_1.0.dsc'...
176+ Object: <Archive at ...>, name: u'test-pkg'...
177 ...
178