Permalink
Browse files

mirrorlist: Accept GET parameters as filters

This fixes a regression. Originally request.REQUEST was used, but django
1.9 removed this. In its stead, request.POST was used unconditionally.
However, this results in any GET request returning *all* mirrors, rather
than filtering as requested in the parameters.

This patch uses POST or GET based on the request method. This fixes the
behavior of the [mirror-filter-form], and any scripts depending on the
generated URL format. Accordingly, make test_mirrorlist_filter() test
both the success and failure cases, rather than just success.

[mirror-filter-form]: https://www.archlinux.org/mirrorlist/

Signed-off-by: Genki Sky <sky@genki.is>
  • Loading branch information...
Genki Sky authored and jelly committed Apr 22, 2018
1 parent dad8fa4 commit a0ce797dedf5e31c6354917c51b16efc1d0508c8
Showing with 22 additions and 8 deletions.
  1. +6 −5 mirrors/tests/__init__.py
  2. +14 −2 mirrors/tests/test_mirrorlist.py
  3. +2 −1 mirrors/views/mirrorlist.py
View
@@ -1,12 +1,13 @@
from mirrors.models import MirrorUrl, MirrorProtocol, Mirror
def create_mirror_url():
mirror = Mirror.objects.create(name='mirror1',
def create_mirror_url(name='mirror1', country='US',
protocol='http', url='https://archlinux.org'):
mirror = Mirror.objects.create(name=name,
admin_email='admin@archlinux.org')
mirror_protocol = MirrorProtocol.objects.create(protocol='http')
mirror_url = MirrorUrl.objects.create(url='https://archlinux.org',
mirror_protocol = MirrorProtocol.objects.create(protocol=protocol)
mirror_url = MirrorUrl.objects.create(url=url,
protocol=mirror_protocol,
mirror=mirror,
country='US')
country=country)
return mirror_url
@@ -30,9 +30,21 @@ def test_mirrorlist_all_https(self):
# TODO: test 200 case
def test_mirrorlist_filter(self):
response = self.client.get('/mirrorlist/?country=all&protocol=http&ip_version=4')
jp_mirror_url = create_mirror_url(
name='jp_mirror',
country='JP',
protocol='https',
url='https://wikipedia.jp')
# First test that we correctly see the above mirror.
response = self.client.get('/mirrorlist/?country=JP&protocol=https')
self.assertEqual(response.status_code, 200)
self.assertIn(self.mirror_url.hostname, response.content)
self.assertIn(jp_mirror_url.hostname, response.content)
# Now confirm that the US mirror did not show up.
self.assertNotIn(self.mirror_url.hostname, response.content)
jp_mirror_url.delete()
def test_generate(self):
response = self.client.get('/mirrorlist/?country=all&protocol=http&ip_version=4')
@@ -55,7 +55,8 @@ def as_div(self):
@csrf_exempt
def generate_mirrorlist(request):
if request.method == 'POST' or len(request.GET) > 0:
form = MirrorlistForm(data=request.POST)
data = request.POST if request.method == 'POST' else request.GET
form = MirrorlistForm(data=data)
if form.is_valid():
countries = form.cleaned_data['country']
protocols = form.cleaned_data['protocol']

0 comments on commit a0ce797

Please sign in to comment.