From nobody Sun Apr 28 21:10:26 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 1526611044161586.0536474633197; Thu, 17 May 2018 19:37:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 254F830D8FBD; Fri, 18 May 2018 02:37:23 +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 11476608EF; Fri, 18 May 2018 02:37:23 +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 00C2B4BB78; Fri, 18 May 2018 02:37:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4I2bLtv007331 for ; Thu, 17 May 2018 22:37:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B2369CB9B; Fri, 18 May 2018 02:37:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 748399CB97 for ; Fri, 18 May 2018 02:37:19 +0000 (UTC) Received: from mail-pl0-f41.google.com (mail-pl0-f41.google.com [209.85.160.41]) (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 6F427241B1E for ; Fri, 18 May 2018 02:37:08 +0000 (UTC) Received: by mail-pl0-f41.google.com with SMTP id w19-v6so3680266plq.4 for ; Thu, 17 May 2018 19:37:08 -0700 (PDT) Received: from localhost.localdomain ([188.166.187.36]) by smtp.gmail.com with ESMTPSA id 67-v6sm9135497pgg.91.2018.05.17.19.37.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 19:37:06 -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; bh=u42K117vRktSyUOsiBowkxLWc7nJZxSaztq5CAtQmVU=; b=Uv664YUs0RLtlaRXqV+CmERd/HGIM3F55QWjMOO5aUuytZA6xnPo2nkZE4G1cDimXe c8Og2ihAnygmAs1HgPkOun9Q2ipGWchDDiSJ8nDDjclZVCndl8/Lcsjoj/R4msb6drvg 0YMpkWsS7aWAUkt/pGgJ9xL3YJXIwRr+FE2MECNfb03qTmIJG9cCavavpFbbWPh2nqGv eytPAhY921hMmb1sY9Pu4oSTqhB3A6YhNR2sp8ZyDcepXSDANNwme4CuPDzFvvwx2MIq f5KXkcfd1LPNKCD/0sIJsTZTSbGZgB+qns+9XBS74zOIUX6mIJacZ/mx/U5jRNtSaGCX mowA== 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; bh=u42K117vRktSyUOsiBowkxLWc7nJZxSaztq5CAtQmVU=; b=TMxM3Nj//aT6ZEqzZBVT8UBWRCJkDsuthm9PkhLNUAWxMb8NGY/u4/ovfoyI0T5Ygx nIwsVyBb5kf1Bx2rFfeoXM8hOU766iIRARx87VcduzZSaQ3tdZ5qbbqw4uDUkaWTNsps bvwFK/cHoqeBqFheSgTuur0BKxsFMeVn88X7CxH8Yi/GxOSVwE6HNS8yYaImQraspGT4 Uss1qOsDzBUz6Ocf1M5o2Ppr0sCnJPZTWULyWI4b0qIwlv8+kJwNPINAPDRBRD86+4Aj PLsNNO03R7nPIhcpV5Is0QLVYzhCgUX0Ihmd8B3K2nIsfjxgVSH4n6CMBjtLrJ0R9S3m Q9Rg== X-Gm-Message-State: ALKqPwd8k+6QyR5wq87Hs1x+RQG6jgGa9r/iOYv65ecCIztqyUaWwEzH ZqbBEwcDxAdlFX+PseKYfl9jFNIk X-Google-Smtp-Source: AB8JxZqKIqirdYvjkx73SXtwlhwA7VZRbjLzoX3xFSIWKBFmVRg40jHJgd9nZ/mwOSCSdGZHwAFFjg== X-Received: by 2002:a17:902:1023:: with SMTP id b32-v6mr7588762pla.145.1526611027291; Thu, 17 May 2018 19:37:07 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Fri, 18 May 2018 08:06:58 +0530 Message-Id: <20180518023658.6008-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 18 May 2018 02:37:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 18 May 2018 02:37:08 +0000 (UTC) for IP:'209.85.160.41' DOMAIN:'mail-pl0-f41.google.com' HELO:'mail-pl0-f41.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.551 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.160.41 mail-pl0-f41.google.com 209.85.160.41 mail-pl0-f41.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v2] test: more testcases around authorization 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 18 May 2018 02:37:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The test check for: - user that is not a maintainer of any project should not result in any mes= sage being imported - user that is not a maintainer of a project, but is in the importer groups= , should result in the message being imported to all recognized projects - user that is a maintainer of a project and is not in the importer group, = should result in the message being imported to maintained and recognized pr= ojects Also, changed the permission level of the MessageView to just authenticated= users. Now, each authenticated user would be able to create a message but = the result of the message would only be imported to the projects according = to the conditions ie recognized by mbox or maintained by the users --- api/rest.py | 10 +++++++--- tests/test_rest.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/api/rest.py b/api/rest.py index fd321b3..af6fe31 100644 --- a/api/rest.py +++ b/api/rest.py @@ -391,12 +391,16 @@ class ProjectMessagesViewSet(ProjectMessagesViewSetMi= xin, =20 class MessagesViewSet(BaseMessageViewSet): serializer_class =3D MessageSerializer + permission_classes =3D (permissions.IsAuthenticated,) parser_classes =3D (JSONParser, MessagePlainTextParser, ) =20 def create(self, request, *args, **kwargs): - projects =3D [p for p in Project.objects.all() if p.recognizes(Mbo= xMessage(self.request.data['mbox']))] - if 'importers' not in self.request.user.groups.all(): - projects =3D (p for p in projects if p.maintained_by(self.requ= est.user)) + m =3D MboxMessage(request.data['mbox']) + projects =3D [p for p in Project.objects.all() if p.recognizes(m)] + grps =3D request.user.groups.all() + grps_name =3D [grp.name for grp in grps] + if 'importers' not in grps_name: + projects =3D set(projects) & set([p for p in projects if p.mai= ntained_by(self.request.user)]) results =3D [] for project in projects: serializer =3D self.get_serializer(data=3Drequest.data) diff --git a/tests/test_rest.py b/tests/test_rest.py index 2da5459..9b4647a 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -325,6 +325,57 @@ class RestTest(PatchewTestCase): resp_get2 =3D self.api_client.get(self.PROJECT_BASE_2 + "messages/= 20180223132311.26555-2-marcandre.lureau@redhat.com/") self.assertEqual(resp_get2.status_code, 200) =20 + def test_without_login_create_message(self): + dp =3D self.get_data_path("0022-another-simple-patch.json.gz") + with open(dp, "r") as f: + data =3D f.read() + resp =3D self.api_client.post(self.PROJECT_BASE + "messages/", dat= a, content_type=3D'message/rfc822') + self.assertEqual(resp.status_code, 403) + + def test_non_maintainer_create_message(self): + self.create_user(username=3D"test", password=3D"userpass") + self.api_client.login(username=3D"test", password=3D"userpass") + dp =3D self.get_data_path("0023-multiple-project-patch.mbox.gz") + with open(dp, "r") as f: + data =3D f.read() + resp =3D self.api_client.post(self.REST_BASE + "messages/", data, = content_type=3D'message/rfc822') + self.assertEqual(resp.status_code, 201) + self.assertEqual(resp.data['count'], 0) + resp_get =3D self.api_client.get(self.PROJECT_BASE + "messages/201= 80223132311.26555-2-marcandre.lureau@redhat.com/") + self.assertEqual(resp_get.status_code, 404) + resp_get2 =3D self.api_client.get(self.PROJECT_BASE_2 + "messages/= 20180223132311.26555-2-marcandre.lureau@redhat.com/") + self.assertEqual(resp_get2.status_code, 404) + + def test_maintainer_create_message(self): + test =3D self.create_user(username=3D"test", password=3D"userpass") + self.api_client.login(username=3D"test", password=3D"userpass") + self.p.maintainers =3D (test, ) + dp =3D self.get_data_path("0023-multiple-project-patch.mbox.gz") + with open(dp, "r") as f: + data =3D f.read() + resp =3D self.api_client.post(self.REST_BASE + "messages/", data, = content_type=3D'message/rfc822') + self.assertEqual(resp.status_code, 201) + self.assertEqual(resp.data['count'], 1) + resp_get =3D self.api_client.get(self.PROJECT_BASE + "messages/201= 80223132311.26555-2-marcandre.lureau@redhat.com/") + self.assertEqual(resp_get.status_code, 200) + resp_get2 =3D self.api_client.get(self.PROJECT_BASE_2 + "messages/= 20180223132311.26555-2-marcandre.lureau@redhat.com/") + self.assertEqual(resp_get2.status_code, 404) + + def test_importer_create_message(self): + dp =3D self.get_data_path("0023-multiple-project-patch.mbox.gz") + with open(dp, "r") as f: + data =3D f.read() + test =3D self.create_user(username=3D"test", password=3D"userpass"= , groups=3D['importers']) + self.api_client.login(username=3D"test", password=3D"userpass") + resp =3D self.api_client.post(self.REST_BASE + "messages/", data, = content_type=3D'message/rfc822') + self.assertEqual(resp.status_code, 201) + self.assertEqual(resp.data['count'], 2) + resp_get =3D self.api_client.get(self.PROJECT_BASE + "messages/201= 80223132311.26555-2-marcandre.lureau@redhat.com/") + self.assertEqual(resp_get.status_code, 200) + self.assertEqual(resp_get.data['subject'], "[Qemu-devel] [PATCH 1/= 7] SecurityPkg/Tcg2Pei: drop Tcg2PhysicalPresenceLib dependency") + resp_get2 =3D self.api_client.get(self.PROJECT_BASE_2 + "messages/= 20180223132311.26555-2-marcandre.lureau@redhat.com/") + self.assertEqual(resp_get2.status_code, 200) + =20 def test_message(self): series =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', self.p.id, '20160628014747.20971-= 1-famz@redhat.com') --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel