From 1d4b79f6aac921f806b05aa1671b49c42f9fa6f6 Mon Sep 17 00:00:00 2001 From: Tim Heap Date: Mon, 5 Oct 2015 12:55:37 +1100 Subject: [PATCH 1/2] Check for the correct filename in document headers --- wagtail/wagtaildocs/tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtaildocs/tests.py b/wagtail/wagtaildocs/tests.py index 105c6c425f..c55404eb97 100644 --- a/wagtail/wagtaildocs/tests.py +++ b/wagtail/wagtaildocs/tests.py @@ -563,9 +563,10 @@ class TestServeView(TestCase): def test_response_code(self): self.assertEqual(self.get().status_code, 200) - @unittest.expectedFailure # Filename has a random string appended to it def test_content_disposition_header(self): - self.assertEqual(self.get()['Content-Disposition'], 'attachment; filename=example.doc') + self.assertEqual( + self.get()['Content-Disposition'], + 'attachment; filename="{}"'.format(self.document.filename)) def test_content_length_header(self): self.assertEqual(self.get()['Content-Length'], '25') From f7b6f805ecf807eaa07973e908328c2b7ad77fba Mon Sep 17 00:00:00 2001 From: Tim Heap Date: Mon, 5 Oct 2015 13:02:43 +1100 Subject: [PATCH 2/2] Document filenames in the URL should not be checked Wagtail should be forgiving with filenames at the end of the URL. These filenames are to make the URL look nice, and to provide a fallback for browsers that do not handle the 'Content-Disposition' header filename component. They should not be validated. --- wagtail/wagtaildocs/tests.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtaildocs/tests.py b/wagtail/wagtaildocs/tests.py index c55404eb97..05cda49dde 100644 --- a/wagtail/wagtaildocs/tests.py +++ b/wagtail/wagtaildocs/tests.py @@ -594,10 +594,15 @@ class TestServeView(TestCase): response = self.client.get(reverse('wagtaildocs_serve', args=(1000, 'blahblahblah', ))) self.assertEqual(response.status_code, 404) - @unittest.expectedFailure def test_with_incorrect_filename(self): + """ + Wagtail should be forgiving with filenames at the end of the URL. These + filenames are to make the URL look nice, and to provide a fallback for + browsers that do not handle the 'Content-Disposition' header filename + component. They should not be validated. + """ response = self.client.get(reverse('wagtaildocs_serve', args=(self.document.id, 'incorrectfilename'))) - self.assertEqual(response.status_code, 404) + self.assertEqual(response.status_code, 200) def clear_sendfile_cache(self): from wagtail.utils.sendfile import _get_sendfile