From patchwork Tue Apr 30 06:03:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1093000 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44tWH670LZz9s7T for ; Tue, 30 Apr 2019 16:05:54 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="Y7brguS8"; 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 44tWH64gCpzDqB5 for ; Tue, 30 Apr 2019 16:05:54 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::533; helo=mail-pg1-x533.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="Y7brguS8"; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44tWDY6RxxzDqQr for ; Tue, 30 Apr 2019 16:03:41 +1000 (AEST) Received: by mail-pg1-x533.google.com with SMTP id h1so6342584pgs.2 for ; Mon, 29 Apr 2019 23:03:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BU5/txA95pIcpxetb02GqPrOK10y4A2TRlOa9uUKYDM=; b=Y7brguS8FSf+ni9Odgasd1A59oqpAHWucLMOUvwbRqr+QDupaGqOZvsUmbhSB66fZv Fuja9kFAF04GbLZbUhWvPDr6BDQL3xln0fJxI/oepxeWERB6/SkyLsRb+cr/yTcFdPAI irSJinwMa49mPxuxTYf6l6n9x790jV7nl1xnk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BU5/txA95pIcpxetb02GqPrOK10y4A2TRlOa9uUKYDM=; b=p+6MgdqWnebnHh6CP8GB5RzUvfw9VPbAydb9V0RauI93RQt0NCTcRKnqni3/esgbZG nqSufJbdkX/dGpqD3t0xDGHxrZ27bKz8nCnNfj7vX/9p1P5DjKDO56BigZxSpsGrlYWB WTCLYJK4+A6PCqKbFRyRV36+GOGp4ClCMXKw+Z7sZsaVdbELu8dCsGlNyTy+geTodxdt TBMeguDeke6Vcnjp+p+YpZLpKj7xpqb3gxmgzBV4hQfYTMwdoCQmHmi8d9egaq8doBpm rN4JT4B8pfwxTxWwvol5mF6spnm0d23iPIeb7ugGYYFLwV73RzIMZcG3OHWBIr3Ryr1K OrsQ== X-Gm-Message-State: APjAAAXeoPA4grwFho1pRLOXlAbto9X3mMVCUaG/2q3hnFHdexSwtVwa 8YAxFtreOlt6bsUWfPSVaWmMzMcA0JU= X-Google-Smtp-Source: APXvYqx9iSwgNlD/8CLOlKrKmvXnsFqGLNBPF0lcOy6n6+Dt/2teG1Fl8ZsAxZR5afbYq2I3kwcV7g== X-Received: by 2002:a65:4185:: with SMTP id a5mr63585122pgq.82.1556604219241; Mon, 29 Apr 2019 23:03:39 -0700 (PDT) Received: from localhost (203-217-53-131.dyn.iinet.net.au. [203.217.53.131]) by smtp.gmail.com with ESMTPSA id y20sm48217802pfe.188.2019.04.29.23.03.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Apr 2019 23:03:38 -0700 (PDT) From: Daniel Axtens To: patchwork@lists.ozlabs.org Subject: [PATCH 05/10] REST: Handle regular form data requests for checks Date: Tue, 30 Apr 2019 16:03:03 +1000 Message-Id: <20190430060308.10432-6-dja@axtens.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190430060308.10432-1-dja@axtens.net> References: <20190430060308.10432-1-dja@axtens.net> MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 08d1459a4a40 ("Add REST API validation using OpenAPI schema") moved all API requests to JSON blobs rather than form data. dc48fbce99ef ("REST: Handle JSON requests") attempted to change the check serialiser to handle this. However, because both a JSON dict and a QueryDict satisfy isinstance(data, dict), everything was handled as JSON and the old style requests were broken. Found in the process of debugging issues from the OzLabs PW & Snowpatch crew - I'm not sure if they actually hit this one, but kudos to them anyway as we wouldn't have found it without them. Fixes: dc48fbce99ef ("REST: Handle JSON requests") (backported from commit 666de29ebada5990a8d69f4d71d6bb271e1a68c3 This does not need the new tests as we do not have 08d1459a4a40, so we just need the fix to the api. We do not add a JSON test to stable.) Signed-off-by: Daniel Axtens --- patchwork/api/check.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 67062132fef3..62e6fd19e761 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -19,6 +19,7 @@ from django.http import Http404 from django.shortcuts import get_object_or_404 +from django.http.request import QueryDict from rest_framework.exceptions import PermissionDenied from rest_framework.generics import ListCreateAPIView from rest_framework.generics import RetrieveAPIView @@ -53,9 +54,7 @@ class CheckSerializer(HyperlinkedModelSerializer): if label != data['state']: continue - if isinstance(data, dict): # json request - data['state'] = val - else: # form-data request + if isinstance(data, QueryDict): # form-data request # NOTE(stephenfin): 'data' is essentially 'request.POST', which # is immutable by default. However, there's no good reason for # this to be this way [1], so temporarily unset that mutability @@ -66,6 +65,8 @@ class CheckSerializer(HyperlinkedModelSerializer): data._mutable = True # noqa data['state'] = val data._mutable = mutable # noqa + else: # json request + data['state'] = val break return super(CheckSerializer, self).run_validation(data)