From nobody Fri Apr 26 02:20:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533726771216563.759573281688; Wed, 8 Aug 2018 04:12:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C68FD4E327; Wed, 8 Aug 2018 11:12:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B541A308BDB2; Wed, 8 Aug 2018 11:12:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A6CF64BB78; Wed, 8 Aug 2018 11:12:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w78BCmAM003398 for ; Wed, 8 Aug 2018 07:12:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB5216269F; Wed, 8 Aug 2018 11:12:48 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2EB52C334 for ; Wed, 8 Aug 2018 11:12:44 +0000 (UTC) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 780E785540 for ; Wed, 8 Aug 2018 11:12:43 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id a26-v6so986563pfo.4 for ; Wed, 08 Aug 2018 04:12:43 -0700 (PDT) Received: from localhost.localdomain ([182.74.40.122]) by smtp.gmail.com with ESMTPSA id 1-v6sm11432969pfk.134.2018.08.08.04.12.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Aug 2018 04:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Pa3lpjtpdQlcXgZ1haZTjsXqjPZeCZQqWFP8nlAdEMs=; b=E5UHkczsFUOlAhIHitkSlHdTUobZ0kzc31d0Y35wFUaAxMVKYCIKgC+7yrvh9vlAvF h1HzGdd3zVObYEWjuRu0OwNp8xDtcsAhbsImgYxqbdTMzsGj7dz8GuFaBZo8ii6/LoaR 78N+3qdIciQxt2N/HjM2sqTOQh5bmMaRGi2HEoZ5WgiRM8kACyDKYCoW9WTuCX2qbBuQ LmdCLqSlx9n1rgPJ+T4s0KVDTCpN2nb00/RdCj8jdmQN3Adl4y3oMNn6qz+Dv0HDxUs1 5wb9cc+QXRHPx5gviRaLPdLq1/gIZ8vvSzfWDUd5/58P6YJOGz0o0jKTNpxuJLHqDmiR y5CQ== 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; bh=Pa3lpjtpdQlcXgZ1haZTjsXqjPZeCZQqWFP8nlAdEMs=; b=YtGtVW8p+frKThEY5HhU6wdqKqC0n9SnwcYNasuf4jCMh5rv/A5cw4qwmo2ET+sRxE XgY1PDtuwkRf0RYUS5AGlNiB2EyZGvUcwTQ0oQWM2O3uVzpGrLwD0rfdaj5xRbIrE7ZU Q4L1jv+ClzTUaXOjkf4NS2v1iI0/wgOA5WnlY4MDyRRoI+6u/y0C8Vh0G1PSn2Z8hja4 +VxFR4Uavit4LrfJLoga+kGHoQP9MFe8qExOgJgv6IP6uaoMSOuiaONO4yZ9TTQ1nOu9 X6sb8U4DvHXyo9eMNx9z9wDgLCJzJYYh3GJDXXMZtnJmGaT/cW3SUsUkt1XCA429tCHZ h1ow== X-Gm-Message-State: AOUpUlE7iEKG6uxbC6s1dvcVOTgOncIrB+un9NXqEX9WtiUztqhgtX0L ny+alPxByv4LMKFMMTm4vj0L6azwU2I= X-Google-Smtp-Source: AA+uWPy91kemKttilpQAYaFAo0tRRQirmNTSMKKgFkZ+KIZ0vFt4IpYwX9Tog9ptvF02kOipgn1qNg== X-Received: by 2002:a62:4909:: with SMTP id w9-v6mr2513930pfa.154.1533726762475; Wed, 08 Aug 2018 04:12:42 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Wed, 8 Aug 2018 16:42:24 +0530 Message-Id: <20180808111226.55535-2-shubhamjain7495@gmail.com> In-Reply-To: <20180808111226.55535-1-shubhamjain7495@gmail.com> References: <20180808111226.55535-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 08 Aug 2018 11:12:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 08 Aug 2018 11:12:43 +0000 (UTC) for IP:'209.85.210.169' DOMAIN:'mail-pf1-f169.google.com' HELO:'mail-pf1-f169.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.14 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.169 mail-pf1-f169.google.com 209.85.210.169 mail-pf1-f169.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 1/3] Add ability to access projects by name X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 11:12:49 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now projects can also be accessed through urls by /projects/?name=3D --- api/rest.py | 6 ++++++ tests/test_rest.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/api/rest.py b/api/rest.py index a9b6be3..21f4609 100644 --- a/api/rest.py +++ b/api/rest.py @@ -148,6 +148,12 @@ class ProjectsViewSet(viewsets.ModelViewSet): permission_classes =3D (PatchewPermission,) authentication_classes =3D (CsrfExemptSessionAuthentication, ) =20 + def get_queryset(self): + name =3D self.request.query_params.get('name', None) + if name is not None: + return Project.objects.filter(name=3Dname).order_by('id') + return Project.objects.all().order_by('id') + @action(methods=3D['post'], detail=3DTrue, permission_classes=3D[Impor= tPermission]) def update_project_head(self, request, pk=3DNone): """ diff --git a/tests/test_rest.py b/tests/test_rest.py index 980d61a..937a39a 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -441,6 +441,12 @@ class RestTest(PatchewTestCase): self.assertEqual(resp.data['results'][3]['resource_uri'], self.PRO= JECT_BASE + 'messages/e0858c00-ccb6-e533-ee3e-9ba84ca45a7b@redhat.com/') self.assertEqual(resp.data['results'][3]['subject'], 'Re: [Qemu-de= vel] [PATCH v4 0/2] Report format specific info for LUKS block driver') =20 + def test_project_filter(self): + resp =3D self.api_client.get(self.REST_BASE + 'projects/?name=3DQE= MU') + project =3D resp.data['results'][0] + self.assertEquals(project['name'], "QEMU") + self.assertEquals(project['mailing_list'], "qemu-devel@nongnu.org") + def test_schema(self): resp =3D self.api_client.get(self.REST_BASE + 'schema/') self.assertEqual(resp.status_code, 200) --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Apr 26 02:20:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533726774214988.2611906135584; Wed, 8 Aug 2018 04:12:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6B693001C32; Wed, 8 Aug 2018 11:12:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B536E9CF0B; Wed, 8 Aug 2018 11:12:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A61434BB78; Wed, 8 Aug 2018 11:12:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w78BCpfU003408 for ; Wed, 8 Aug 2018 07:12:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 76D312010CC6; Wed, 8 Aug 2018 11:12:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D32F2010CA0 for ; Wed, 8 Aug 2018 11:12:49 +0000 (UTC) Received: from mail-pl0-f51.google.com (mail-pl0-f51.google.com [209.85.160.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B555C049D64 for ; Wed, 8 Aug 2018 11:12:48 +0000 (UTC) Received: by mail-pl0-f51.google.com with SMTP id e11-v6so896625plb.3 for ; Wed, 08 Aug 2018 04:12:48 -0700 (PDT) Received: from localhost.localdomain ([182.74.40.122]) by smtp.gmail.com with ESMTPSA id 1-v6sm11432969pfk.134.2018.08.08.04.12.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Aug 2018 04:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=E1w/BchjZ1S5EWzDP0ndqTkih8TkBJD4sU9bAk/67qE=; b=Jk0HVVNPLrPTgjsR3z8IY9rFBXEsNwhyQZm+HjqVKoJ5DlQHVWBRmEswSH4Zj1tgHJ vu1dOPCjvETJbYe3ZhPi7ic5P7sUmIVZmdETecPW9uU/aHYCfP/zp8XhKMvWsxUsb+Qi tkNHMSxJUkDcWVklNtKt2HMNkQMskk9S3gun/kOTk7rK0YxhcYZqpiOOZ/SVvNgRpcqW nS3PQARtk656JpDTjvZz3ms8JXBfte8HaSkkkKuihlyJtu7v8VVXk+bqE/jgKhkDfPg3 ocZ0FZ04gq+8S1aWbNAuNRnJ356nlEvdNOQexgZTPgGMYy54inlnqt17QPRy/UUpENG3 ItFQ== 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; bh=E1w/BchjZ1S5EWzDP0ndqTkih8TkBJD4sU9bAk/67qE=; b=FjsCbel2nbWTFwy9fONXRc0QU1d/3pIwPiaJVtuC9IlCGM8pmFs914lxMcVdC9ocx1 0yFMbfl19pMnuzGfPwR2n7dqIJoHiLCeub+uejZ0cJU7c/9n/TS38d2t7qJiCZvoEYqq aECnDZWSqYx49DHMtVfdAZhmxdtT8dqW9A7yrW4WfT5OC/OfoU09lYhYVfl+HC4xHbDH 9BbELNoVbtZfuJi6iH0luX3eRhVw6QF0llwp7Y0lmSvG8q3YiBSufBjhNc1eQ+9Jm5/k nWaqzqB2GJ0XzCeQZAtUfUbiPYrZVXeX9ya/hBwTrioioVbRxn1mprXWpkSSW7pWLap8 l3UA== X-Gm-Message-State: AOUpUlFnGFdmBr2liDHg1dR6suzZ7sXxjR4reJj7ZnumwNlGtWzQLWi2 80FMD4p5Of2UoFmLA0Fan0IIkaJkrLE= X-Google-Smtp-Source: AA+uWPzpnfm6Kk0rqGRZLHnwnD3kyefx5YoflXqKw2TTVsz4hr+orlNNZMwDdZn4V+qNTSVHjOcvWA== X-Received: by 2002:a17:902:6b44:: with SMTP id g4-v6mr2190757plt.50.1533726767317; Wed, 08 Aug 2018 04:12:47 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Wed, 8 Aug 2018 16:42:25 +0530 Message-Id: <20180808111226.55535-3-shubhamjain7495@gmail.com> In-Reply-To: <20180808111226.55535-1-shubhamjain7495@gmail.com> References: <20180808111226.55535-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 11:12:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 11:12:48 +0000 (UTC) for IP:'209.85.160.51' DOMAIN:'mail-pl0-f51.google.com' HELO:'mail-pl0-f51.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.14 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.51 mail-pl0-f51.google.com 209.85.160.51 mail-pl0-f51.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 2/3] add support for result PUT to mods/* X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 08 Aug 2018 11:12:52 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Added serializer to validate data field in the PUT of the result --- mods/git.py | 11 ++++++++++- mods/testing.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mods/git.py b/mods/git.py index 924547a..0e1de86 100644 --- a/mods/git.py +++ b/mods/git.py @@ -23,6 +23,9 @@ from api.rest import PluginMethodField from api.views import APILoginRequiredView, prepare_series from patchew.logviewer import LogView from schema import * +from rest_framework import serializers +from rest_framework import serializers +from rest_framework.fields import CharField =20 _instance =3D None =20 @@ -42,11 +45,17 @@ class GitLogViewer(LogView): raise Http404("Object not found: " + series) return obj.git_result =20 +class DataSerializer(serializers.Serializer): + repo =3D CharField() + url =3D CharField() + base =3D CharField() + tag =3D CharField() =20 class GitModule(PatchewModule): """Git module""" name =3D "git" - + allowed_groups =3D ('importers', ) + result_data_serializer_class =3D DataSerializer project_property_schema =3D \ ArraySchema("git", desc=3D"Configuration for git module", members=3D[ diff --git a/mods/testing.py b/mods/testing.py index 0a80b3d..37831b7 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -24,7 +24,8 @@ from api.search import SearchEngine from event import emit_event, declare_event, register_handler from patchew.logviewer import LogView from schema import * - +from rest_framework import serializers +from rest_framework.fields import CharField, BooleanField _instance =3D None =20 TESTING_SCRIPT_DEFAULT =3D """#!/bin/bash @@ -46,12 +47,17 @@ class TestingLogViewer(LogView): raise Http404("Object not found: " + project_or_series) return _instance.get_testing_result(obj, testing_name) =20 +class DataSerializer(serializers.Serializer): + is_timeout =3D BooleanField() + head =3D CharField() + tester =3D CharField() =20 class TestingModule(PatchewModule): """Testing module""" =20 name =3D "testing" - + allowed_groups =3D ('testers', ) + result_data_serializer_class =3D DataSerializer test_schema =3D \ ArraySchema("{name}", "Test", desc=3D"Test spec", members=3D[ --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Apr 26 02:20:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533726784455617.2057826223136; Wed, 8 Aug 2018 04:13:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A1C24E327; Wed, 8 Aug 2018 11:13:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 068AE6253C; Wed, 8 Aug 2018 11:13:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EC6474BB78; Wed, 8 Aug 2018 11:13:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w78BD1q3003419 for ; Wed, 8 Aug 2018 07:13:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7836965976; Wed, 8 Aug 2018 11:13:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7008A4C47C for ; Wed, 8 Aug 2018 11:12:53 +0000 (UTC) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 642B63082140 for ; Wed, 8 Aug 2018 11:12:52 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id j8-v6so983384pff.6 for ; Wed, 08 Aug 2018 04:12:52 -0700 (PDT) Received: from localhost.localdomain ([182.74.40.122]) by smtp.gmail.com with ESMTPSA id 1-v6sm11432969pfk.134.2018.08.08.04.12.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Aug 2018 04:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0phN5xm0BYKjQWpMt9nZe2hnq+/zwF6u87l/55liKdM=; b=C38KVgYQjbfojZdDXZh8efUo3IGiMx35u9RoGeaj0k7PyT0wo8DkStsMz4jLV6fDhB A/tabY/3jz2OYWdGy58aHrf27p88lVlBHEuwnVnMPVLkbA5GO0vIGYVFB9dkpmmyaXFr yzBm8l0jYPkjA5mP//LAtif3YlKo1vGag9U1WBVT+DOWe2Xrb6Fj6avsXMLa07852jKZ PXXqb2KalsSWX/m0N6z+K1WJ7iWniQghp0PV7OKS6/NarZ9ipW1xLyUqU3YIOlC7Cj3F ydH130+wZu7gO0Pba8KefE/sh5kMD1FEXDGNPBvBGxWdKi1R3fr1uD0A4cTNucQfEbAB 6S0w== 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; bh=0phN5xm0BYKjQWpMt9nZe2hnq+/zwF6u87l/55liKdM=; b=OhVn3DgRet4i4vnQZwe7Yt9DyX8rIM+/6y1sDDjzkZ2HsoqLeDpcPeHu0AbQTUgaPx 3Og9+k8qrlheW8oi40X+7RDX3VGvN+PTv1F+3aA4vyU/gVksYlvNQVwTOXUPdInWc3sv 0IVX3YswUjZYL4eWc23nrB5T/wNWxNiIFFjOldX9ilV+90phfn4lmrFDBnt9T4xkxLvU wfszfxqGf2JEjHDSYwM33jDFWgr5wUuHequKi6HSD+5xtCrzAqXsKX9IRK8XBdwQGL1W om/dN7ekACqUHMM+Oey7fautrcGQAV9azE+XExG2jJiiRxLWcK5eC2QaHTh6sNLg8ybJ e9QA== X-Gm-Message-State: AOUpUlFU6exinov7JmxQ+CMCnjq6+EsjxSnUOucOpswcqeHb7aac22ZR aDQirzgdCOcJaCV/SrTfPns1ru8nGVY= X-Google-Smtp-Source: AA+uWPyOgW1DSH8WX6EGxeZCD205gNOApjknOZayXk9SlLXkVfvVo8jTE8zu3hMTuNinXytH7JAHtg== X-Received: by 2002:a63:eb0e:: with SMTP id t14-v6mr2134215pgh.198.1533726771283; Wed, 08 Aug 2018 04:12:51 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Wed, 8 Aug 2018 16:42:26 +0530 Message-Id: <20180808111226.55535-4-shubhamjain7495@gmail.com> In-Reply-To: <20180808111226.55535-1-shubhamjain7495@gmail.com> References: <20180808111226.55535-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 08 Aug 2018 11:12:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 08 Aug 2018 11:12:52 +0000 (UTC) for IP:'209.85.210.172' DOMAIN:'mail-pf1-f172.google.com' HELO:'mail-pf1-f172.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.14 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.172 mail-pf1-f172.google.com 209.85.210.172 mail-pf1-f172.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 3/3] Add Infra for PUT X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Aug 2018 11:13:03 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Added authentications and validation of the data for PUT of the result --- api/rest.py | 47 +++++++++++++++++++++++++++++++++++++++++++---- tests/test_git.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ tests/test_testing.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 4 deletions(-) diff --git a/api/rest.py b/api/rest.py index 21f4609..dd3a947 100644 --- a/api/rest.py +++ b/api/rest.py @@ -26,6 +26,9 @@ import rest_framework from mbox import addr_db_to_rest, MboxMessage from rest_framework.parsers import JSONParser, BaseParser from rest_framework.authentication import SessionAuthentication +from rest_framework.exceptions import ValidationError +import re +import mod =20 class CsrfExemptSessionAuthentication(SessionAuthentication): =20 @@ -65,8 +68,9 @@ class PatchewPermission(permissions.BasePermission): =20 def has_generic_permission(self, request, view): return (request.method in permissions.SAFE_METHODS) or \ - self.is_superuser(request) or \ - self.has_group_permission(request, view) + self.is_superuser(request) or \ + self.has_group_permission(request, view) or \ + self.has_result_group_permission(request, view)=20 =20 def has_permission(self, request, view): return self.has_generic_permission(request, view) or \ @@ -78,7 +82,22 @@ class PatchewPermission(permissions.BasePermission): (isinstance(obj, Message) and \ self.has_message_permission(request, view, obj)) or \ (isinstance(obj, Project) and \ - self.has_project_permission(request, view, obj)) + self.has_project_permission(request, view, obj)) or \ + (isinstance(obj, Result) and \ + self.has_result_permission(request, view, obj)) + + def has_result_group_permission(self, request, view): + name =3D request.resolver_match.kwargs.get('name') + if name: + found =3D re.match("^[^.]*", name) + module =3D mod.get_module(found.group(0)) if found else None + for grp in request.user.groups.all(): + if grp.name in module.allowed_groups: + return True + return False + + def has_result_permission(self, request, view, result_obj): + return self.has_object_permission(request, view, result_obj.projec= t) =20 class ImportPermission(PatchewPermission): allowed_groups =3D ('importers',) @@ -475,6 +494,14 @@ class ResultSerializer(serializers.ModelSerializer): request =3D self.context['request'] return obj.get_log_url(request) =20 + def validate(self, data): + found =3D re.match("^[^.]*", self.instance.name) + module =3D mod.get_module(found.group(0)) if found else None + is_valid =3D module.result_data_serializer_class(data=3Ddata['data= ']).is_valid(raise_exception=3DTrue) + if found is None and not is_valid: + raise ValidationError("Invalid") + return data + class ResultSerializerFull(ResultSerializer): class Meta: model =3D Result @@ -484,18 +511,30 @@ class ResultSerializerFull(ResultSerializer): log =3D CharField(required=3DFalse) =20 class ResultsViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, - viewsets.GenericViewSet): + mixins.UpdateModelMixin, viewsets.GenericViewSet): lookup_field =3D 'name' lookup_value_regex =3D '[^/]+' filter_backends =3D (filters.OrderingFilter,) ordering_fields =3D ('name',) ordering =3D ('name',) + authentication_classes =3D (CsrfExemptSessionAuthentication, ) + permission_classes =3D (PatchewPermission, ) =20 def get_serializer_class(self, *args, **kwargs): if self.lookup_field in self.kwargs: return ResultSerializerFull return ResultSerializer =20 + @property + def project(self): + if hasattr(self, '__project'): + return self.__project + try: + self.__project =3D Project.objects.get(id=3Dself.kwargs['proje= cts_pk']) + except: + self.__project =3D None + return self.__project + class ProjectResultsViewSet(ResultsViewSet): def get_queryset(self): return ProjectResult.objects.filter(project=3Dself.kwargs['project= s_pk']) diff --git a/tests/test_git.py b/tests/test_git.py index b2802d5..e22a498 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -15,6 +15,7 @@ from tests.patchewtest import PatchewTestCase, main import shutil import subprocess from api.models import Message, Result +import json =20 class GitTest(PatchewTestCase): =20 @@ -101,6 +102,52 @@ class GitTest(PatchewTestCase): self.assertEqual(resp.data['log_url'], None) self.assertEqual(resp.data['log'], None) =20 + def test_auth_importer(self): + self.cli_import("0013-foo-patch.mbox.gz") + MESSAGE_ID =3D '20160628014747.20971-1-famz@redhat.com' + test =3D self.create_user(username=3D"test", password=3D"userpass"= , groups=3D['importers']) + self.api_client.login(username=3D"test", password=3D"userpass") + data =3D { + "name": "testing.a", + "status": "failure", + "data": {"tag": "test_tag", "url": "test_url", "repo": "te= st_repo", "base": "test_base"}, + "log": "test", + "last_update": '2018-08-07T03:51:13.262213'} + + resp=3D self.api_client.put('%sseries/%s/results/git/' % (self.PRO= JECT_BASE, MESSAGE_ID), data=3Djson.dumps(data), content_type=3D'applicatio= n/json') + self.assertEquals(resp.status_code, 200) + self.assertEquals(resp.data['log'], "test") + + def test_data_validation(self): + self.cli_import("0013-foo-patch.mbox.gz") + MESSAGE_ID =3D '20160628014747.20971-1-famz@redhat.com' + test =3D self.create_user(username=3D"test", password=3D"userpass"= , groups=3D['importers']) + self.api_client.login(username=3D"test", password=3D"userpass") + data =3D { + "name": "testing.a", + "status": "failure", + "data": "", + "log": "test", + "last_update": '2018-08-07T03:51:13.262213'} + + resp=3D self.api_client.put('%sseries/%s/results/git/' % (self.PRO= JECT_BASE, MESSAGE_ID), data=3Djson.dumps(data), content_type=3D'applicatio= n/json') + self.assertEquals(resp.status_code, 400) + + def test_auth_without_permission(self): + self.cli_import("0013-foo-patch.mbox.gz") + MESSAGE_ID =3D '20160628014747.20971-1-famz@redhat.com' + test =3D self.create_user(username=3D"test", password=3D"userpass") + self.api_client.login(username=3D"test", password=3D"userpass") + data =3D { + "name": "testing.a", + "status": "failure", + "data": {"tag": "test_tag", "url": "test_url", "repo": "te= st_repo", "base": "test_base"}, + "log": "test", + "last_update": '2018-08-07T03:51:13.262213'} + + resp=3D self.api_client.put('%sseries/%s/results/git/' % (self.PRO= JECT_BASE, MESSAGE_ID), data=3Djson.dumps(data), content_type=3D'applicatio= n/json') + self.assertEquals(resp.status_code, 403) + def test_rest_git_base(self): self.cli_import("0013-foo-patch.mbox.gz") self.do_apply() diff --git a/tests/test_testing.py b/tests/test_testing.py index 7ca4625..85b16a6 100755 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -15,6 +15,7 @@ import subprocess sys.path.append(os.path.dirname(__file__)) from tests.patchewtest import PatchewTestCase, main from api.models import Message, Result +import json =20 def create_test(project, name): prefix =3D "testing.tests." + name + "." @@ -214,6 +215,7 @@ class TesterTest(PatchewTestCase): =20 self.p1 =3D self.add_project("QEMU", "qemu-devel@nongnu.org") create_test(self.p1, "a") + self.PROJECT_BASE =3D '%sprojects/%d/' % (self.REST_BASE, self.p1.= id) self.p2 =3D self.add_project("UMEQ", "qemu-devel@nongnu.org") create_test(self.p2, "b") =20 @@ -248,6 +250,51 @@ class TesterTest(PatchewTestCase): cwd=3Dself.repo).decode() p.set_property("git.head", head) =20 + def test_auth_tester(self): + resp =3D self.api_client.get('%sresults/' % ( + self.PROJECT_BASE)) + test =3D self.create_user(username=3D"test", password=3D"userpass"= , groups=3D['testers']) + self.api_client.login(username=3D"test", password=3D"userpass") + data =3D { + "name": "testing.a", + "status": "failure", + "data": {"head": "test_head", "tester": "test_tester", "is= _timeout": False}, + "log": "test", + "last_update": '2018-08-07T03:51:13.262213'} + + resp1=3D self.api_client.put(resp.data['results'][0]['resource_uri= '],data=3Djson.dumps(data), content_type=3D'application/json') + self.assertEquals(resp1.status_code, 200) + self.assertEquals(resp1.data['log'], "test") + + def test_data_validation(self): + resp =3D self.api_client.get('%sresults/' % ( + self.PROJECT_BASE)) + test =3D self.create_user(username=3D"test", password=3D"userpass"= , groups=3D['testers']) + self.api_client.login(username=3D"test", password=3D"userpass") + data =3D { + "name":"testing.a", + "status":"failure", + "data":"", + "log":"test", + "last_update": '2018-08-07T03:51:13.262213'} + resp1=3D self.api_client.put(resp.data['results'][0]['resource_uri= '],data=3Djson.dumps(data), content_type=3D'application/json') + self.assertEquals(resp1.status_code, 400) + + def test_auth_without_permission(self): + resp =3D self.api_client.get('%sresults/' % ( + self.PROJECT_BASE)) + test =3D self.create_user(username=3D"test", password=3D"userpass") + self.api_client.login(username=3D"test", password=3D"userpass") + data =3D { + "name": "testing.a", + "status": "failure", + "data": {"head": "test_head", "tester": "test_tester", "is= _timeout": False}, + "log": "test", + "last_update": '2018-08-07T03:51:13.262213'} + + resp1=3D self.api_client.put(resp.data['results'][0]['resource_uri= '],data=3Djson.dumps(data), content_type=3D'application/json') + self.assertEquals(resp1.status_code, 403) + def test_tester(self): self.cli_login() out, err =3D self.check_cli(["tester", "-p", "QEMU,UMEQ", --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel