зеркало из https://github.com/mozilla/kitsune.git
[bug 863528] Add sampling to redirecting inproduct to HTTPS.
This commit is contained in:
Родитель
e373e7fa02
Коммит
c2a4a76165
|
@ -1,5 +1,9 @@
|
|||
from urlparse import urlparse
|
||||
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
import mock
|
||||
import waffle
|
||||
from nose.tools import eq_
|
||||
|
||||
from sumo.tests import TestCase
|
||||
|
@ -63,3 +67,15 @@ class RedirectTestCase(TestCase):
|
|||
final = urlparse(r[0][0])
|
||||
eq_(output, final.path)
|
||||
eq_(querystring, final.query)
|
||||
|
||||
@mock.patch.object(Site.objects, 'get_current')
|
||||
@mock.patch.object(waffle, 'sample_is_active')
|
||||
def test_switch_to_https(self, sample_is_active, get_current):
|
||||
"""Verify we switch to https when sample is active."""
|
||||
get_current.return_value.domain = 'example.com'
|
||||
sample_is_active.return_value = True
|
||||
|
||||
response = self.client.get(
|
||||
u'/1/firefox/4.0/Linux/en-US/prefs-applications')
|
||||
eq_(302, response.status_code)
|
||||
assert response['location'].startswith('https://example.com/')
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.http import HttpResponseRedirect, Http404
|
||||
from django.views.decorators.cache import cache_page
|
||||
|
||||
import waffle
|
||||
|
||||
from inproduct.models import Redirect
|
||||
from sumo.helpers import urlparams
|
||||
|
||||
|
@ -91,5 +95,10 @@ def redirect(request, product, version, platform, locale, topic=None):
|
|||
target = u'/%s/%s' % (locale, destination.target.lstrip('/'))
|
||||
target = urlparams(target, **params)
|
||||
|
||||
# Switch over to HTTPS if we DEBUG=False and sample is active.
|
||||
if not settings.DEBUG and waffle.sample_is_active('inproduct-https'):
|
||||
domain = Site.objects.get_current().domain
|
||||
target = 'https://%s%s' % (domain, target)
|
||||
|
||||
# 302 because these can change over time.
|
||||
return HttpResponseRedirect(target)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
INSERT IGNORE INTO `waffle_sample` (`name`, `percent`, `note`, `created`, `modified`)
|
||||
VALUES ('inproduct-https', 0, 'Redirect inproduct links to HTTPS.', NOW(), NOW());
|
Загрузка…
Ссылка в новой задаче