]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
views: Raise 404 if downloading non-existent dependencies
authorStephen Finucane <stephen@that.guru>
Thu, 7 Jun 2018 13:04:47 +0000 (14:04 +0100)
committerStephen Finucane <stephen@that.guru>
Wed, 13 Jun 2018 09:30:20 +0000 (10:30 +0100)
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: e2dfd490 ("views: Add 'series' parameter to '/mbox' endpoint")
Closes: #189
patchwork/tests/test_mboxviews.py
patchwork/views/patch.py
releasenotes/notes/issue-189-fe4024f33e1b5203.yaml [new file with mode: 0644]

index 2d6cdc3030230f7603c918ec51e0312d93ffdc34..8eb3581adafe732e97632d370dd91c95c04f47b2 100644 (file)
@@ -31,6 +31,7 @@ from patchwork.tests.utils import create_comment
 from patchwork.tests.utils import create_patch
 from patchwork.tests.utils import create_project
 from patchwork.tests.utils import create_person
+from patchwork.tests.utils import create_series_patch
 from patchwork.tests.utils import create_user
 
 
@@ -206,3 +207,26 @@ class MboxCommentPostcriptUnchangedTest(TestCase):
 
         self.assertContains(response, content)
         self.assertNotContains(response, content + '\n')
+
+
+class MboxSeriesDependencies(TestCase):
+
+    def test_patch_with_dependencies(self):
+        patch_a = create_series_patch()
+        patch_b = create_series_patch(series=patch_a.series)
+
+        response = self.client.get('%s?series=*' % reverse(
+            'patch-mbox', args=[patch_b.patch.id]))
+
+        self.assertContains(response, patch_a.patch.content)
+        self.assertContains(response, patch_b.patch.content)
+
+    def test_legacy_patch(self):
+        """Validate a patch with non-existent dependencies raises a 404."""
+        # we're explicitly creating a patch without a series
+        patch = create_patch()
+
+        response = self.client.get('%s?series=*' % reverse(
+            'patch-mbox', args=[patch.id]))
+
+        self.assertEqual(response.status_code, 404)
index eccb5441559b597186af81390421b1f8a5ccd799..cbd4ec395d9963d9fc30dc7e687ec848e5bd4ca0 100644 (file)
@@ -139,6 +139,11 @@ def patch_mbox(request, patch_id):
 
     response = HttpResponse(content_type='text/plain')
     if series_id:
+        if not patch.series.count():
+            raise Http404('Patch does not have an associated series. This is '
+                          'because the patch was processed with an older '
+                          'version of Patchwork. It is not possible to '
+                          'provide dependencies for this patch.')
         response.write(series_patch_to_mbox(patch, series_id))
     else:
         response.write(patch_to_mbox(patch))
diff --git a/releasenotes/notes/issue-189-fe4024f33e1b5203.yaml b/releasenotes/notes/issue-189-fe4024f33e1b5203.yaml
new file mode 100644 (file)
index 0000000..ce9fe93
--- /dev/null
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    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. This was not
+    previously handled correctly. A 404 is now raised if this occurs.