зеркало из https://github.com/mozilla/kitsune.git
Check the django version from the web. [bug 656094]
This commit is contained in:
Родитель
5da7134fa1
Коммит
db8b1b76cd
|
@ -1,3 +1,6 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
import django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
||||||
|
@ -7,6 +10,7 @@ from nose.tools import eq_
|
||||||
from pyquery import PyQuery as pq
|
from pyquery import PyQuery as pq
|
||||||
from test_utils import RequestFactory
|
from test_utils import RequestFactory
|
||||||
|
|
||||||
|
from sumo.helpers import urlparams
|
||||||
from sumo.middleware import LocaleURLMiddleware
|
from sumo.middleware import LocaleURLMiddleware
|
||||||
from sumo.tests import TestCase
|
from sumo.tests import TestCase
|
||||||
from sumo.urlresolvers import reverse
|
from sumo.urlresolvers import reverse
|
||||||
|
@ -66,3 +70,28 @@ class RobotsTestCase(TestCase):
|
||||||
response = self.client.get('/robots.txt')
|
response = self.client.get('/robots.txt')
|
||||||
eq_('text/plain', response['content-type'])
|
eq_('text/plain', response['content-type'])
|
||||||
assert len(response.content) > len('User-agent: *\nDisallow: /')
|
assert len(response.content) > len('User-agent: *\nDisallow: /')
|
||||||
|
|
||||||
|
|
||||||
|
class VersionCheckTests(TestCase):
|
||||||
|
url = reverse('sumo.version')
|
||||||
|
|
||||||
|
def _is_forbidden(self, url):
|
||||||
|
res = self.client.get(url)
|
||||||
|
eq_(403, res.status_code)
|
||||||
|
eq_('', res.content)
|
||||||
|
|
||||||
|
@mock.patch.object(settings._wrapped, 'VERSION_CHECK_TOKEN', None)
|
||||||
|
def token_is_none(self):
|
||||||
|
self._is_forbidden(self.url)
|
||||||
|
self._is_forbidden(urlparams(self.url, token='foo'))
|
||||||
|
|
||||||
|
@mock.patch.object(settings._wrapped, 'VERSION_CHECK_TOKEN', 'foo')
|
||||||
|
def token_is_wrong(self):
|
||||||
|
self._is_forbidden(urlparams(self.url, token='bar'))
|
||||||
|
|
||||||
|
@mock.patch.object(settings._wrapped, 'VERSION_CHECK_TOKEN', 'foo')
|
||||||
|
def token_is_right(self):
|
||||||
|
res = self.client.get(urlparams(self.url, token='foo'))
|
||||||
|
eq_(200, res.status_code)
|
||||||
|
versions = json.loads(res.content)
|
||||||
|
eq_('.'.join(map(str, django.VERSION)), versions['django'])
|
||||||
|
|
|
@ -7,6 +7,7 @@ from sumo import views
|
||||||
|
|
||||||
services_patterns = patterns('',
|
services_patterns = patterns('',
|
||||||
url('^/monitor$', views.monitor, name='sumo.monitor'),
|
url('^/monitor$', views.monitor, name='sumo.monitor'),
|
||||||
|
url('^/version$', views.version_check, name='sumo.version'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import StringIO
|
import StringIO
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
import django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.core.cache import parse_backend_uri
|
from django.core.cache import parse_backend_uri
|
||||||
from django.http import (HttpResponsePermanentRedirect, HttpResponseRedirect,
|
from django.http import (HttpResponsePermanentRedirect, HttpResponseRedirect,
|
||||||
HttpResponse)
|
HttpResponse)
|
||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
|
from django.views.decorators.http import require_GET
|
||||||
|
|
||||||
from celery.messaging import establish_connection
|
from celery.messaging import establish_connection
|
||||||
from commonware.decorators import xframe_allow
|
from commonware.decorators import xframe_allow
|
||||||
|
@ -174,6 +177,21 @@ def monitor(request):
|
||||||
status=status)
|
status=status)
|
||||||
|
|
||||||
|
|
||||||
|
@require_GET
|
||||||
|
@never_cache
|
||||||
|
def version_check(request):
|
||||||
|
mime = 'application/x-json'
|
||||||
|
token = settings.VERSION_CHECK_TOKEN
|
||||||
|
if (token is None or not 'token' in request.GET or
|
||||||
|
token != request.GET['token']):
|
||||||
|
return HttpResponse(status=403, mimetype=mime)
|
||||||
|
|
||||||
|
versions = {
|
||||||
|
'django': '.'.join(map(str, django.VERSION)),
|
||||||
|
}
|
||||||
|
return HttpResponse(json.dumps(versions), mimetype=mime)
|
||||||
|
|
||||||
|
|
||||||
# Allows another site to embed the QUnit suite
|
# Allows another site to embed the QUnit suite
|
||||||
# in an iframe (for CI).
|
# in an iframe (for CI).
|
||||||
@xframe_allow
|
@xframe_allow
|
||||||
|
|
|
@ -643,3 +643,6 @@ MOBILE_COOKIE = 'msumo'
|
||||||
|
|
||||||
# Directory of JavaScript test files for django_qunit to run
|
# Directory of JavaScript test files for django_qunit to run
|
||||||
QUNIT_TEST_DIRECTORY = os.path.join(MEDIA_ROOT, 'js', 'tests')
|
QUNIT_TEST_DIRECTORY = os.path.join(MEDIA_ROOT, 'js', 'tests')
|
||||||
|
|
||||||
|
# Key to access /services/version. Set to None to disallow.
|
||||||
|
VERSION_CHECK_TOKEN = None
|
||||||
|
|
Загрузка…
Ссылка в новой задаче