From nobody Wed Jan 15 09:35:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of ovirt.org designates 66.187.230.42 as permitted sender) client-ip=66.187.230.42; envelope-from=kimchi-devel-bounces@ovirt.org; helo=lists.ovirt.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of ovirt.org designates 66.187.230.42 as permitted sender) smtp.mailfrom=kimchi-devel-bounces@ovirt.org; Return-Path: Received: from lists.ovirt.org (lists.phx.ovirt.org [66.187.230.42]) by mx.zohomail.com with SMTPS id 148726571549647.655575445997215; Thu, 16 Feb 2017 09:21:55 -0800 (PST) Received: from lists.phx.ovirt.org (localhost [127.0.0.1]) by lists.ovirt.org (Postfix) with ESMTP id 71ED682069D; Thu, 16 Feb 2017 17:21:54 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lists.ovirt.org (Postfix) with ESMTPS id 9D3FB82062B for ; Thu, 16 Feb 2017 17:21:04 +0000 (UTC) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1GHEL8j130561 for ; Thu, 16 Feb 2017 12:21:04 -0500 Received: from e24smtp02.br.ibm.com (e24smtp02.br.ibm.com [32.104.18.86]) by mx0a-001b2d01.pphosted.com with ESMTP id 28n7mg8841-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Feb 2017 12:21:03 -0500 Received: from localhost by e24smtp02.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Feb 2017 15:21:01 -0200 Received: from d24dlp01.br.ibm.com (9.18.248.204) by e24smtp02.br.ibm.com (10.172.0.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Feb 2017 15:20:59 -0200 Received: from d24relay04.br.ibm.com (d24relay04.br.ibm.com [9.18.232.146]) by d24dlp01.br.ibm.com (Postfix) with ESMTP id 05C92352006C for ; Thu, 16 Feb 2017 12:20:25 -0500 (EST) Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay04.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1GHKw8T35389508 for ; Thu, 16 Feb 2017 15:20:58 -0200 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v1GHKwgS007813 for ; Thu, 16 Feb 2017 15:20:58 -0200 Received: from alinefm-TP440.ibmmodules.com ([9.80.208.98]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v1GHKo5A007723 for ; Thu, 16 Feb 2017 15:20:57 -0200 X-Original-To: kimchi-devel@ovirt.org From: Aline Manera To: Kimchi Devel Date: Thu, 16 Feb 2017 15:20:47 -0200 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170216172048.9442-1-alinefm@linux.vnet.ibm.com> References: <20170216172048.9442-1-alinefm@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021617-0020-0000-0000-0000028850A0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021617-0021-0000-0000-000030A3531C Message-Id: <20170216172048.9442-3-alinefm@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-16_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702160162 Subject: [Kimchi-devel] [PATCH] [Wok 2/3] Specify user when doing a request instead of trying to override FakeUser class attribute X-BeenThere: kimchi-devel@ovirt.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: kimchi-devel-bounces@ovirt.org Errors-To: kimchi-devel-bounces@ovirt.org X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A class attribute (sudo) was added to FakeUser class to allow request with different type of access. But it will not work when FakeUser class instance is already in memory and login() function only calls a static method to authenticate user, ie, the class attribute will be the original o= ne. To avoid problems on that area, specify which user to do a request. Signed-off-by: Aline Manera --- tests/utils.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 9c18637..3c7e9da 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -42,7 +42,7 @@ from wok.utils import wok_log HOST =3D '0.0.0.0' PROXY_PORT =3D 8001 =20 -fake_user =3D {'root': 'letmein!'} +fake_user =3D {'admin': 'letmein!', 'user': 'letmein!'} =20 =20 def get_fake_user(): @@ -109,19 +109,19 @@ def running_as_root(): return os.geteuid() =3D=3D 0 =20 =20 -def _request(conn, path, data, method, headers): +def _request(conn, path, data, method, headers, user): if headers is None: headers =3D {'Content-Type': 'application/json', 'Accept': 'application/json'} if 'AUTHORIZATION' not in headers.keys(): - user, pw =3D fake_user.items()[0] + user, pw =3D user, fake_user[user] hdr =3D "Basic " + base64.b64encode("%s:%s" % (user, pw)) headers['AUTHORIZATION'] =3D hdr conn.request(method, path, data, headers) return conn.getresponse() =20 =20 -def request(path, data=3DNone, method=3D'GET', headers=3DNone): +def request(path, data=3DNone, method=3D'GET', headers=3DNone, user=3D'adm= in'): # verify if HTTPSConnection has context parameter if "context" in inspect.getargspec(httplib.HTTPSConnection.__init__).a= rgs: context =3D ssl._create_unverified_context() @@ -129,12 +129,11 @@ def request(path, data=3DNone, method=3D'GET', header= s=3DNone): else: conn =3D httplib.HTTPSConnection(HOST, PROXY_PORT) =20 - return _request(conn, path, data, method, headers) + return _request(conn, path, data, method, headers, user) =20 =20 class FakeUser(User): auth_type =3D "fake" - sudo =3D True =20 def __init__(self, username): super(FakeUser, self).__init__(username) @@ -143,9 +142,7 @@ class FakeUser(User): return sorted([group.gr_name for group in grp.getgrall()])[0:3] =20 def _get_role(self): - if self.sudo: - return 'admin' - return 'user' + return self.name =20 @staticmethod def authenticate(username, password, service=3D"passwd"): @@ -156,13 +153,12 @@ class FakeUser(User): 'code': e.message}) =20 =20 -def patch_auth(sudo=3DTrue): +def patch_auth(): """ Override the authenticate function with a simple test against an internal dict of users and passwords. """ config.set("authentication", "method", "fake") - FakeUser.sudo =3D sudo =20 =20 def wait_task(task_lookup, taskid, timeout=3D10): --=20 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel