From nobody Fri Apr 19 10:29:42 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=libvir-list-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=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1570648438; cv=none; d=zoho.com; s=zohoarc; b=LwVdt8RNpKJQP34y6HbVEGtqlD1NZjfEFFtVgMP4vVC95+74ZeYHy/oj76WWgkcmJBawdwdAfod2LsQO3R8xCMtjsohy1Tb/utwvSkYCU7lLpeQs7tOrtL5rAimMC57EvcUASNUJB2sBG8LFoDR7KrKocuPOA61Yh/zydOGbYsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570648438; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZGL+cmlpYG7kWX78Oc24dH4IIIVDwl4tACopdv94Pes=; b=GSrzRGzOL4Ykz+HDWkfTbk/N2iC1UhgMDi/b9XvqkRKu6KzPPu5vc0cHrBwyRU0FPNy2EtziZoV0vSIGzXp8fy2xn6iAF3+VhM3qxem5m4k7l+33XgrwHKb00CUb+BiQWU/qi2/EIXfykec8oRHlZh27RaIVLSgf/aAtwnLwMY4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 157064843849777.05983653764815; Wed, 9 Oct 2019 12:13:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CDA58666C; Wed, 9 Oct 2019 19:13:56 +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 53E441001B30; Wed, 9 Oct 2019 19:13:56 +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 C64354EE68; Wed, 9 Oct 2019 19:13:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x99JC3TY022799 for ; Wed, 9 Oct 2019 15:12:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 544075DA8D; Wed, 9 Oct 2019 19:12:03 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6E115D9E2; Wed, 9 Oct 2019 19:11:58 +0000 (UTC) Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) (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 CE0CE309BF13; Wed, 9 Oct 2019 19:11:57 +0000 (UTC) Received: by mail-qt1-f194.google.com with SMTP id 3so5053371qta.1; Wed, 09 Oct 2019 12:11:57 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:5962:94db:701d:b3ef:c7b9]) by smtp.gmail.com with ESMTPSA id c12sm1219450qkc.81.2019.10.09.12.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 12:11:56 -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 :mime-version:content-transfer-encoding; bh=IU4SDi8BpshBjo7rcTXvQvZ/SqFugzIaUvUE2HarfGE=; b=QsLyrFqxQefdCbcPrTsmZouLBboXMk6HPoqy0gk0v5WP1ycSeBeKFg4h23Y4YRllWd Ntrxe+kawL3PMvoADRFhWRSasVXMNnw/GzHTt8s6EMy58m16Z0Mlmkm6T7EoQhl70wMw ig6ZEGJmgOe50MOUad06CWOz7QhROXeI1gin3W7e+DX9EJfeJENRRGkp3AemNdjgNG5U Zi9D/xBoToFkWmwhexjZNSOE+n0QduWG0FGubp+GhRsf4kSi23PtVUKIKeKV/sxSWa53 Dl5BTpe28myEOeF7mSAxb5zWiEo1mJxsCEenPuLLsFfMQ/GLa7rox7wYmr/Yoa5B4jKP o47g== 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=IU4SDi8BpshBjo7rcTXvQvZ/SqFugzIaUvUE2HarfGE=; b=gAxUKyFF25FeTDZ0ng1xoysRB6J1gtCpsj0X2R99hGfnUknmiQIQicw5KUd8ik6XQC IdB4+rPe+19xY2Fw8L8i0mzJhKdADlwMvQCX738fM8siiTo8QiU/AQLS7veBYKE7veZN ZmgP964nda46i/BEfLL8zn95ivSCS8LXfZMHnZGIzieFh+zIO/tY/UTVzwHWFsyo/GB6 CkQMGUCkIk8kGo1Z/K+hqmJOUb6HZLU6Yeq2UFu7L1x4WZ7Tl3F64UbX3kWcAyqSlwQQ 9KeplKbv3RJZdS6R6Uajl/tH9VsUSPQKzL3lF23hY4o61WupEAamr9RZOGdpEeAgJAeT Rh/g== X-Gm-Message-State: APjAAAW6MEo/MsplmCs24k1aZgl+xH5vOmDyRlx1n7aMM7qAUp5ZLuhK HXj/AWnJy6NH1bq1YzF8SGTosnqj X-Google-Smtp-Source: APXvYqwDCsvgG3ssAzJ+N6SMo3OR3bneymgMpH+vrq1oYhhwdRWfMG1zbmaRv9BAyfNnu8YowRuzOQ== X-Received: by 2002:ac8:3512:: with SMTP id y18mr5649040qtb.106.1570648316699; Wed, 09 Oct 2019 12:11:56 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Wed, 9 Oct 2019 16:11:44 -0300 Message-Id: <20191009191144.7404-2-danielhb413@gmail.com> In-Reply-To: <20191009191144.7404-1-danielhb413@gmail.com> References: <20191009191144.7404-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 09 Oct 2019 19:11:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 09 Oct 2019 19:11:58 +0000 (UTC) for IP:'209.85.160.194' DOMAIN:'mail-qt1-f194.google.com' HELO:'mail-qt1-f194.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.153 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.194 mail-qt1-f194.google.com 209.85.160.194 mail-qt1-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v5 1/1] tests: add a test for driver.c:virConnectValidateURIPath() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 09 Oct 2019 19:13:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel Henrique Barboza Reviewed-by: Cole Robinson --- tests/Makefile.am | 7 ++- tests/virdriverconnvalidatetest.c | 90 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/virdriverconnvalidatetest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index d88ad7f686..c7f563d24d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -433,7 +433,8 @@ test_scripts +=3D $(libvirtd_test_scripts) =20 test_programs +=3D \ eventtest \ - virdrivermoduletest + virdrivermoduletest \ + virdriverconnvalidatetest else ! WITH_LIBVIRTD EXTRA_DIST +=3D $(libvirtd_test_scripts) endif ! WITH_LIBVIRTD @@ -1485,6 +1486,10 @@ if WITH_LIBVIRTD virdrivermoduletest_SOURCES =3D \ virdrivermoduletest.c testutils.h testutils.c virdrivermoduletest_LDADD =3D $(LDADDS) + +virdriverconnvalidatetest_SOURCES =3D \ + virdriverconnvalidatetest.c testutils.h testutils.c +virdriverconnvalidatetest_LDADD =3D $(LDADDS) endif WITH_LIBVIRTD =20 if WITH_LIBVIRTD diff --git a/tests/virdriverconnvalidatetest.c b/tests/virdriverconnvalidat= etest.c new file mode 100644 index 0000000000..6f4cefb61e --- /dev/null +++ b/tests/virdriverconnvalidatetest.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2019 IBM Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "testutils.h" +#include "virerror.h" +#include "viralloc.h" +#include "virlog.h" +#include "driver.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("tests.driverconnvalidatetest"); + +struct testDriverConnValidateData { + const char *uriPath; + const char *entityName; + bool privileged; + bool expectFailure; +}; + + +static int testDriverConnValidate(const void *args) +{ + const struct testDriverConnValidateData *data =3D args; + + bool ret =3D virConnectValidateURIPath(data->uriPath, + data->entityName, + data->privileged); + if (data->expectFailure) + ret =3D !ret; + + return ret ? 0 : -1; +} + + +static int +mymain(void) +{ + int ret =3D 0; + +#define DO_TEST_INTERNAL(name, entity, uri, _privileged, expectFail) \ + do { \ + static struct testDriverConnValidateData data =3D { \ + .entityName =3D entity, \ + .uriPath =3D uri, \ + .privileged =3D _privileged, \ + .expectFailure =3D expectFail, \ + }; \ + if (virTestRun("Test conn URI path validate ok " name, \ + testDriverConnValidate, &data) < 0) \ + ret =3D -1; \ + } while (0) + +#define DO_TEST_SUCCESS(name, entity, uri, _privileged) \ + DO_TEST_INTERNAL(name, entity, uri, _privileged, false) + +#define DO_TEST_FAIL(name, entity, uri, _privileged) \ + DO_TEST_INTERNAL(name, entity, uri, _privileged, true) + + DO_TEST_SUCCESS("non-privileged /session", "any", "/session", false); + DO_TEST_FAIL("non-privileged non-session fail", "any", "/system", fals= e); + + DO_TEST_SUCCESS("privileged /system", "any", "/system", true); + DO_TEST_FAIL("privileged non-system fail", "any", "any", true); + + DO_TEST_SUCCESS("privileged qemu /session", "qemu", "/session", true); + DO_TEST_SUCCESS("privileged vbox /session", "vbox", "/session", true); + DO_TEST_FAIL("privileged other /session fail", "any", "/session", true= ); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list