Merge lp:~wgrant/launchpad/bug-932518 into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 14806
Proposed branch: lp:~wgrant/launchpad/bug-932518
Merge into: lp:launchpad
Diff against target: 187 lines (+4/-118)
5 files modified
lib/lp/app/browser/tales.py (+1/-2)
lib/lp/registry/stories/product/xx-product-files.txt (+0/-82)
lib/lp/services/librarian/browser.py (+1/-8)
lib/lp/services/librarian/doc/librarian.txt (+1/-24)
lib/lp/services/librarian/tests/test_libraryfilealiasview.py (+1/-2)
To merge this branch: bzr merge lp:~wgrant/launchpad/bug-932518
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+93127@code.launchpad.net

Commit message

[r=stevenk][bug=932518] Return ProductReleaseFile downloads to HTTPS.

Description of the change

This branch moves ProductReleaseFile downloads back to HTTPS, reverting the fix for bug #174186. The world is a bit more HTTPS-friendly 4 years later.

The PRF TALES formatter no longer forces links to HTTP, and the librarian redirector no longer respects the X-SCHEME header set by our Apache config.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) wrote :

Excellent, more bugs squashed.

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/app/browser/tales.py'
2--- lib/lp/app/browser/tales.py 2012-02-01 15:26:32 +0000
3+++ lib/lp/app/browser/tales.py 2012-02-15 04:18:18 +0000
4@@ -1581,8 +1581,7 @@
5 url = urlappend(canonical_url(self._release), '+download')
6 # Quote the filename to eliminate non-ascii characters which
7 # are invalid in the url.
8- url = urlappend(url, urllib.quote(lfa.filename.encode('utf-8')))
9- return str(URI(url).replace(scheme='http'))
10+ return urlappend(url, urllib.quote(lfa.filename.encode('utf-8')))
11
12
13 class BranchFormatterAPI(ObjectFormatterAPI):
14
15=== modified file 'lib/lp/registry/stories/product/xx-product-files.txt'
16--- lib/lp/registry/stories/product/xx-product-files.txt 2012-01-15 11:06:57 +0000
17+++ lib/lp/registry/stories/product/xx-product-files.txt 2012-02-15 04:18:18 +0000
18@@ -480,85 +480,3 @@
19 >>> firefox_owner.getControl('Delete Files').click()
20 >>> get_feedback_messages(firefox_owner.contents)
21 [u'1 file has been deleted.']
22-
23-
24-Scheme redirection
25-==================
26-
27-Files may be downloaded over http or https with the URL for the
28-librarian file constructed based upon the scheme of the original
29-request. The Apache configuration for Launchpad production servers
30-sets a header called 'X-SCHEME' to indicate the original scheme
31-(http or https).
32-
33-If the configuration 'use_https' is False then http will be used
34-regardless of the value of X-SCHEME. In order to exercise the
35-use of X-SCHEME we must set 'use_https' to True and remember
36-to reset it when we're done.
37-
38- >>> from lp.services.config import config
39- >>> use_https_true_data = """
40- ... [librarian]
41- ... use_https: True
42- ... """
43- >>> config.push('use_https_true_data', use_https_true_data)
44-
45-If the original scheme is https the redirect URL should be https too.
46-
47- >>> from textwrap import dedent
48- >>> firefox_owner.open('http://launchpad.dev/firefox/+download')
49- >>> link = firefox_owner.getLink('foo.txt')
50- >>> url_path = urlparse(link.url)[2]
51- >>> redirect_resp = http(dedent("""\
52- ... GET %s HTTP/1.1
53- ... X-SCHEME: https
54- ... """ % url_path))
55- >>> location = redirect_resp.getOutput().split("\n")[3]
56- >>> redirect_url = location.split()[1]
57- >>> print redirect_url
58- https://.../foo.txt
59-
60-However if the original scheme is http then the redirect URL should be
61-over http.
62-
63- >>> redirect_resp = http(dedent("""\
64- ... GET %s HTTP/1.1
65- ... X-SCHEME: http
66- ... """ % url_path))
67- >>> location = redirect_resp.getOutput().split("\n")[3]
68- >>> redirect_url = location.split()[1]
69- >>> print redirect_url
70- http://.../foo.txt
71-
72-When 'use_https' is False the result will always be http.
73-
74- >>> config_data = config.pop('use_https_true_data')
75- >>> use_https_false_data = """
76- ... [vhosts]
77- ... use_https: False
78- ... """
79- >>> config.push('use_https_false_data', use_https_false_data)
80- >>> firefox_owner.open('http://launchpad.dev/firefox/+download')
81- >>> link = firefox_owner.getLink('foo.txt')
82- >>> url_path = urlparse(link.url)[2]
83- >>> redirect_resp = http(dedent("""\
84- ... GET %s HTTP/1.1
85- ... X-SCHEME: https
86- ... """ % url_path))
87- >>> location = redirect_resp.getOutput().split("\n")[3]
88- >>> redirect_url = location.split()[1]
89- >>> print redirect_url
90- http://.../foo.txt
91-
92- >>> redirect_resp = http(dedent("""\
93- ... GET %s HTTP/1.1
94- ... X-SCHEME: http
95- ... """ % url_path))
96- >>> location = redirect_resp.getOutput().split("\n")[3]
97- >>> redirect_url = location.split()[1]
98- >>> print redirect_url
99- http://.../foo.txt
100-
101-Return 'use_https' to its original value to not mess up future tests.
102-
103- >>> config_data = config.pop('use_https_false_data')
104
105=== modified file 'lib/lp/services/librarian/browser.py'
106--- lib/lp/services/librarian/browser.py 2011-12-30 01:10:37 +0000
107+++ lib/lp/services/librarian/browser.py 2012-02-15 04:18:18 +0000
108@@ -49,14 +49,7 @@
109 # If the LFA is deleted, throw a 410.
110 if self.context.deleted:
111 raise GoneError("File deleted.")
112- # Redirect based on the scheme of the request, as set by
113- # Apache in the 'X-SCHEME' environment variable, which is
114- # mapped to 'HTTP_X_SCHEME. Note that only some requests
115- # for librarian files are allowed to come in via http as
116- # most are forced to https via Apache redirection.
117- self.request.response.redirect(
118- self.context.getURL(
119- secure=self.request.get('HTTP_X_SCHEME') != 'http'))
120+ self.request.response.redirect(self.context.getURL())
121
122
123 class LibraryFileAliasMD5View(LaunchpadView):
124
125=== modified file 'lib/lp/services/librarian/doc/librarian.txt'
126--- lib/lp/services/librarian/doc/librarian.txt 2011-12-30 06:14:56 +0000
127+++ lib/lp/services/librarian/doc/librarian.txt 2012-02-15 04:18:18 +0000
128@@ -130,29 +130,6 @@
129 ... ) is not None
130 True
131
132-However, we can force the use of HTTP by setting the 'HTTP_X_SCHEME'
133-header in the request to 'http', even when 'use_https' is True.
134-
135- >>> from zope.component import getMultiAdapter
136- >>> from lp.services.webapp.servers import LaunchpadTestRequest
137- >>> from urlparse import urlparse
138- >>> request = LaunchpadTestRequest(
139- ... environ={'REQUEST_METHOD': 'GET', 'HTTP_X_SCHEME': 'http'})
140- >>> view = getMultiAdapter((alias,request), name='+index')
141- >>> view.initialize()
142- >>> print urlparse(request.response.getHeader('Location'))[0]
143- http
144-
145-When the incoming scheme is 'https' then the redirect scheme is
146-unaffected.
147-
148- >>> request = LaunchpadTestRequest(
149- ... environ={'REQUEST_METHOD': 'GET', 'HTTP_X_SCHEME': 'https'})
150- >>> view = getMultiAdapter((alias,request), name='+index')
151- >>> view.initialize()
152- >>> print urlparse(request.response.getHeader('Location'))[0]
153- https
154-
155 Reset 'use_https' to its original state.
156
157 >>> test_config_data = config.pop('test')
158@@ -371,6 +348,7 @@
159 temporary measure until we're sure no restricted files leak into the
160 traversal hierarchy.
161
162+ >>> from zope.component import getMultiAdapter
163 >>> view = getMultiAdapter((file_alias, request), name='+index')
164 >>> view.initialize()
165 Traceback (most recent call last):
166@@ -568,7 +546,6 @@
167 A librarian file has a default view that should redirect to the download
168 URL.
169
170- >>> from zope.component import getMultiAdapter
171 >>> from lp.services.webapp.servers import LaunchpadTestRequest
172 >>> req = LaunchpadTestRequest()
173 >>> alias = lfas.create(
174
175=== modified file 'lib/lp/services/librarian/tests/test_libraryfilealiasview.py'
176--- lib/lp/services/librarian/tests/test_libraryfilealiasview.py 2012-01-01 02:58:52 +0000
177+++ lib/lp/services/librarian/tests/test_libraryfilealiasview.py 2012-02-15 04:18:18 +0000
178@@ -23,8 +23,7 @@
179 lfa = self.factory.makeLibraryFileAlias()
180 removeSecurityProxy(lfa).content = None
181 self.assertTrue(lfa.deleted)
182- request = LaunchpadTestRequest(
183- environ={'REQUEST_METHOD': 'GET', 'HTTP_X_SCHEME' : 'http' })
184+ request = LaunchpadTestRequest()
185 view = getMultiAdapter((lfa, request), name='+index')
186 self.assertRaisesWithContent(
187 GoneError, "'File deleted.'", view.initialize)