launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27643
[Merge] ~lgp171188/launchpad:serve-language-packs-files-over-https into launchpad:master
Guruprasad has proposed merging ~lgp171188/launchpad:serve-language-packs-files-over-https into launchpad:master.
Commit message:
Serve the distroseries language pack files over HTTPS
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lgp171188/launchpad/+git/launchpad/+merge/411091
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~lgp171188/launchpad:serve-language-packs-files-over-https into launchpad:master.
diff --git a/lib/lp/translations/browser/tests/test_distroseries_views.py b/lib/lp/translations/browser/tests/test_distroseries_views.py
index 5a61f92..fc74811 100644
--- a/lib/lp/translations/browser/tests/test_distroseries_views.py
+++ b/lib/lp/translations/browser/tests/test_distroseries_views.py
@@ -3,11 +3,18 @@
"""Tests for the translations views on a distroseries."""
+from six.moves.urllib.parse import urlsplit
+
+from lp.services.beautifulsoup import BeautifulSoup
+from lp.services.config import config
+from lp.services.propertycache import cachedproperty
+from lp.services.webapp import canonical_url
from lp.testing import (
person_logged_in,
TestCaseWithFactory,
)
from lp.testing.layers import LaunchpadFunctionalLayer
+from lp.testing.pages import extract_link_from_tag
from lp.testing.views import create_initialized_view
from lp.translations.enums import LanguagePackType
@@ -17,6 +24,28 @@ class TestLanguagePacksView(TestCaseWithFactory):
layer = LaunchpadFunctionalLayer
+ @cachedproperty
+ def librarian_base_domain(self):
+ return urlsplit(config.librarian.download_url).netloc
+
+ def set_up_language_packs_for_distroseries(self, distroseries):
+ with person_logged_in(distroseries.distribution.owner):
+ distroseries.language_pack_base = self.factory.makeLanguagePack(
+ distroseries)
+ delta_pack = self.factory.makeLanguagePack(
+ distroseries, LanguagePackType.DELTA)
+ distroseries.language_pack_delta = delta_pack
+ distroseries.language_pack_proposed = delta_pack
+
+ def assert_languagepack_download_links_start_with(self, page_content,
+ scheme):
+ soup = BeautifulSoup(page_content)
+ for anchor_tag in soup.find_all('a', class_='download'):
+ href = extract_link_from_tag(anchor_tag)
+ if self.librarian_base_domain in href:
+ self.assertStartsWith(href, scheme)
+
+
def test_unused_language_packs_many_language_packs(self):
distroseries = self.factory.makeUbuntuDistroSeries()
# This is one more than the default for shortlist.
@@ -54,3 +83,31 @@ class TestLanguagePacksView(TestCaseWithFactory):
view = create_initialized_view(
distroseries, '+language-packs', rootsite='translations')
self.assertEqual(0, len(view.unused_language_packs))
+
+ def test_languagepack_urls_use_http_when_librarian_uses_http(self):
+ distroseries = self.factory.makeUbuntuDistroSeries()
+ self.set_up_language_packs_for_distroseries(distroseries)
+
+ url = canonical_url(distroseries, view_name='+language-packs',
+ rootsite='translations')
+ browser = self.getUserBrowser(user=self.factory.makePerson())
+ browser.open(url)
+
+ # In the test environment, librarian defaults to http
+ self.assert_languagepack_download_links_start_with(browser.contents,
+ 'http://')
+
+ def test_languagepack_urls_use_https_when_librarian_uses_https(self):
+ self.pushConfig("librarian", use_https=True)
+
+ distroseries = self.factory.makeUbuntuDistroSeries()
+ self.set_up_language_packs_for_distroseries(distroseries)
+
+ url = canonical_url(distroseries, view_name='+language-packs',
+ rootsite='translations')
+
+ browser = self.getUserBrowser(user=self.factory.makePerson())
+ browser.open(url)
+
+ self.assert_languagepack_download_links_start_with(browser.contents,
+ 'https://')
diff --git a/lib/lp/translations/templates/distroseries-language-packs.pt b/lib/lp/translations/templates/distroseries-language-packs.pt
index bec4ed6..31dd71b 100644
--- a/lib/lp/translations/templates/distroseries-language-packs.pt
+++ b/lib/lp/translations/templates/distroseries-language-packs.pt
@@ -38,7 +38,7 @@
Base pack:
<a class="sprite download"
tal:condition="context/language_pack_base"
- tal:attributes="href context/language_pack_base/file/http_url">
+ tal:attributes="href context/language_pack_base/file/getURL">
<tal:export-date
replace="context/language_pack_base/date_exported/fmt:datetime" />
</a>
@@ -54,7 +54,7 @@
Update pack:
<a class="sprite download"
tal:condition="context/language_pack_delta"
- tal:attributes="href context/language_pack_delta/file/http_url">
+ tal:attributes="href context/language_pack_delta/file/getURL">
<tal:export-date
replace="context/language_pack_delta/date_exported/fmt:datetime" />
</a>
@@ -107,7 +107,7 @@
<dd>
Latest archive containing translation updates, applied on top
of the base pack.
- </dd>
+ </dd>
</dl>
</div>
<div id="testing-language-packs">
@@ -117,7 +117,7 @@
<tal:type content="context/language_pack_proposed/type/name" />
language pack:
<a tal:attributes="
- href context/language_pack_proposed/file/http_url">
+ href context/language_pack_proposed/file/getURL">
<tal:export-date
condition="context/language_pack_proposed"
replace="context/language_pack_proposed/date_exported/fmt:datetime"
@@ -133,7 +133,7 @@
<p tal:condition="not:context/language_pack_proposed">
No pack is being tested right now.
</p>
- </div>
+ </div>
</div>
</div>
</div>
@@ -148,8 +148,8 @@
<h2>Currently unused language packs</h2>
<ul>
<li tal:repeat="lang_pack view/unused_language_packs">
- <tal:type content="lang_pack/type/title" /> language pack:
- <a tal:attributes="href lang_pack/file/http_url">
+ <tal:type content="lang_pack/type/title" /> language pack:
+ <a tal:attributes="href lang_pack/file/getURL">
<tal:date-exported
content="lang_pack/date_exported/fmt:datetime" />
<img alt="download icon" src="/@@/download" />
@@ -164,4 +164,3 @@
</div>
</body>
</html>
-