From patchwork Thu Jun 7 13:04:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 926299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 411m4114jwz9s5N for ; Thu, 7 Jun 2018 23:05:21 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="A/gDM3qt"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 411m404lGBzF34j for ; Thu, 7 Jun 2018 23:05:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="A/gDM3qt"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=23.83.214.17; helo=bird.maple.relay.mailchannels.net; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="A/gDM3qt"; dkim-atps=neutral Received: from bird.maple.relay.mailchannels.net (bird.maple.relay.mailchannels.net [23.83.214.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 411m3l583dzF34W for ; Thu, 7 Jun 2018 23:05:04 +1000 (AEST) X-Sender-Id: 5xi41l16bi|x-authuser|stephen@that.guru Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E1B903E208B for ; Thu, 7 Jun 2018 13:04:53 +0000 (UTC) Received: from one.mxroute.com (unknown [100.96.17.92]) (Authenticated sender: 5xi41l16bi) by relay.mailchannels.net (Postfix) with ESMTPA id 75E7E3E1553 for ; Thu, 7 Jun 2018 13:04:53 +0000 (UTC) X-Sender-Id: 5xi41l16bi|x-authuser|stephen@that.guru Received: from one.mxroute.com (one-outgoing.mxroute.com [172.18.56.151]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.15.2); Thu, 07 Jun 2018 13:04:53 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: 5xi41l16bi|x-authuser|stephen@that.guru X-MailChannels-Auth-Id: 5xi41l16bi X-Grain-Turn: 3a5356745a773e65_1528376693718_3357986347 X-MC-Loop-Signature: 1528376693718:4013047438 X-MC-Ingress-Time: 1528376693717 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=XkksbAOBuCYhntQWMlkJrgB+KkzhdZZgaVAVWSnh2Ss=; b=A/gDM3qto+Gr9qrom74GAq4h3a cxD2ZjWMVwk34XHAHl+uV4jm11Q+6I33/EgWCvkIl7qEiF3jzj7IeGn1RGSnydNvG0nudRGi3nlpP CSEAwJuTE5TqQArdb0XzAnf9E6pGVgxtm9X24PWH9Z8FzcLQTsErdh9zHn5AkJ6tO4bBJJ30tr9F5 GArUX9oKG6ldWytFm1FK7IIR+d185e/LgAm0q/aCaObGucmkFkyarrUnrw0T9b81P7plAK0CDswaB VZG1fJsEl8WVjtrKAiZNZW1HCGO1n4BMipFwQn43fil2S53TGCoTgJlnqKZqAR17sOtBR9GNxV8by s4qu3oSg==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH] views: Raise 404 if downloading non-existent dependencies Date: Thu, 7 Jun 2018 14:04:47 +0100 Message-Id: <20180607130447.25186-1-stephen@that.guru> X-Mailer: git-send-email 2.17.1 X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 Reported-by: John McNamara Fixes: e2dfd490 ("views: Add 'series' parameter to '/mbox' endpoint") Closes: #189 --- NOTE: This needs to be backported to stable/2.0 once merged to master as it's an issue there too. --- patchwork/tests/test_mboxviews.py | 24 +++++++++++++++++++ patchwork/views/patch.py | 5 ++++ .../notes/issue-189-fe4024f33e1b5203.yaml | 7 ++++++ 3 files changed, 36 insertions(+) create mode 100644 releasenotes/notes/issue-189-fe4024f33e1b5203.yaml diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py index 2d6cdc30..8eb3581a 100644 --- a/patchwork/tests/test_mboxviews.py +++ b/patchwork/tests/test_mboxviews.py @@ -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) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index eccb5441..cbd4ec39 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -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 index 00000000..ce9fe93c --- /dev/null +++ b/releasenotes/notes/issue-189-fe4024f33e1b5203.yaml @@ -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.