Skip to content

Commit 9d669c2

Browse files
committed
views: Raise 404 if downloading non-existent dependencies
If a patch was processed by Patchwork before series support was added, it will not have a series associated with it. As a result, it is not possible to extract the dependencies for that patch from the series and a 404 should be raised. This was not previously handled correctly. Signed-off-by: Stephen Finucane <stephen@that.guru> Reviewed-by: Daniel Axtens <dja@axtens.net> Reported-by: John McNamara <john.mcnamara@intel.com> Fixes: e2dfd49 ("views: Add 'series' parameter to '/mbox' endpoint") Closes: #189 (cherry picked from commit c975e20)
1 parent e338a3e commit 9d669c2

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

patchwork/tests/test_mboxviews.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from patchwork.tests.utils import create_patch
3232
from patchwork.tests.utils import create_project
3333
from patchwork.tests.utils import create_person
34+
from patchwork.tests.utils import create_series_patch
3435
from patchwork.tests.utils import create_user
3536

3637

@@ -206,3 +207,26 @@ def test_comment_unchanged(self):
206207

207208
self.assertContains(response, content)
208209
self.assertNotContains(response, content + '\n')
210+
211+
212+
class MboxSeriesDependencies(TestCase):
213+
214+
def test_patch_with_dependencies(self):
215+
patch_a = create_series_patch()
216+
patch_b = create_series_patch(series=patch_a.series)
217+
218+
response = self.client.get('%s?series=*' % reverse(
219+
'patch-mbox', args=[patch_b.patch.id]))
220+
221+
self.assertContains(response, patch_a.patch.content)
222+
self.assertContains(response, patch_b.patch.content)
223+
224+
def test_legacy_patch(self):
225+
"""Validate a patch with non-existent dependencies raises a 404."""
226+
# we're explicitly creating a patch without a series
227+
patch = create_patch()
228+
229+
response = self.client.get('%s?series=*' % reverse(
230+
'patch-mbox', args=[patch.id]))
231+
232+
self.assertEqual(response.status_code, 404)

patchwork/views/patch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def patch_mbox(request, patch_id):
139139

140140
response = HttpResponse(content_type='text/plain')
141141
if series_id:
142+
if not patch.series.count():
143+
raise Http404('Patch does not have an associated series. This is '
144+
'because the patch was processed with an older '
145+
'version of Patchwork. It is not possible to '
146+
'provide dependencies for this patch.')
142147
response.write(series_patch_to_mbox(patch, series_id))
143148
else:
144149
response.write(patch_to_mbox(patch))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
If a patch was processed by Patchwork before series support was added, it
5+
will not have a series associated with it. As a result, it is not possible
6+
to extract the dependencies for that patch from the series. This was not
7+
previously handled correctly. A 404 is now raised if this occurs.

0 commit comments

Comments
 (0)