From eb10843058334e17735e7e90ad40a8ef1fdfaa32 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 8 Jan 2014 20:22:21 +0000 Subject: [PATCH] tests: Add a regression test for libvirt authentication (RHBZ#1044014). This tests the virConnectAuthPtrDefault wrapper path. (cherry picked from commit 746a0b1f19667606ee63c8d3ab6a75531a8bd71c) --- .gitignore | 2 ++ tests/regressions/Makefile.am | 28 ++++++++++++++++ tests/regressions/rhbz1044014.c | 69 ++++++++++++++++++++++++++++++++++++++ tests/regressions/rhbz1044014.in | 1 + tests/regressions/rhbz1044014.sh | 70 +++++++++++++++++++++++++++++++++++++++ tests/regressions/rhbz1044014.xml | 5 +++ 6 files changed, 175 insertions(+) create mode 100644 tests/regressions/rhbz1044014.c create mode 100644 tests/regressions/rhbz1044014.in create mode 100755 tests/regressions/rhbz1044014.sh create mode 100644 tests/regressions/rhbz1044014.xml diff --git a/.gitignore b/.gitignore index bce35f0..2d61d77 100644 --- a/.gitignore +++ b/.gitignore @@ -485,6 +485,8 @@ Makefile.in /tests/regressions/rhbz501893 /tests/regressions/rhbz790721 /tests/regressions/rhbz914931 +/tests/regressions/rhbz1044014 +/tests/regressions/rhbz1044014.out /tests/regressions/rhbz1055452 /tests/rsync/rsyncd.pid /tests/syslinux/extlinux-guest.img diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am index 15333b7..563f87f 100644 --- a/tests/regressions/Makefile.am +++ b/tests/regressions/Makefile.am @@ -35,6 +35,9 @@ EXTRA_DIST = \ rhbz957772.sh \ rhbz975797.sh \ rhbz1001875.sh \ + rhbz1044014.sh \ + rhbz1044014.in \ + rhbz1044014.xml \ test-noexec-stack.pl TESTS = \ @@ -57,6 +60,10 @@ TESTS = \ rhbz1055452 \ test-noexec-stack.pl +if HAVE_LIBVIRT +TESTS += rhbz1044014.sh +endif + tests_not_run = \ rhbz727178.sh \ rhbz909624.sh @@ -71,6 +78,10 @@ check_PROGRAMS = \ rhbz914931 \ rhbz1055452 +if HAVE_LIBVIRT +check_PROGRAMS += rhbz1044014 +endif + rhbz501893_SOURCES = rhbz501893.c rhbz501893_CPPFLAGS = \ -I$(top_srcdir)/src -I$(top_builddir)/src @@ -101,6 +112,23 @@ rhbz914931_CFLAGS = \ rhbz914931_LDADD = \ $(top_builddir)/src/libguestfs.la +if HAVE_LIBVIRT +rhbz1044014_SOURCES = rhbz1044014.c +rhbz1044014_CPPFLAGS = \ + -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \ + -I$(top_srcdir)/src -I$(top_builddir)/src +rhbz1044014_CFLAGS = \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + $(GPROF_CFLAGS) $(GCOV_CFLAGS) \ + $(LIBVIRT_CFLAGS) +rhbz1044014_LDADD = \ + $(top_builddir)/src/libutils.la \ + $(top_builddir)/src/libguestfs.la \ + $(LIBVIRT_LIBS) \ + $(LIBXML2_LIBS) \ + $(top_builddir)/gnulib/lib/libgnu.la +endif + rhbz1055452_SOURCES = rhbz1055452.c rhbz1055452_CPPFLAGS = \ -I$(top_srcdir)/src -I$(top_builddir)/src \ diff --git a/tests/regressions/rhbz1044014.c b/tests/regressions/rhbz1044014.c new file mode 100644 index 0000000..18ce4a7 --- /dev/null +++ b/tests/regressions/rhbz1044014.c @@ -0,0 +1,69 @@ +/* libguestfs + * Copyright (C) 2014 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* Regression test for RHBZ#1044014. + * + * The only reason to write this in C is so we can easily check the + * version of libvirt >= 1.2.1. In the future when we can assume a + * newer libvirt, we can just have the main rhbz1044014.sh script set + * some environment variables and use guestfish. + */ + +#include + +#include +#include +#include +#include +#include + +#include + +#include "guestfs.h" +#include "guestfs-internal-frontend.h" + +int +main (int argc, char *argv[]) +{ + unsigned long ver; + guestfs_h *g; + + virInitialize (); + + /* Check that the version of libvirt we are linked against + * supports the new test-driver auth feature. + */ + virGetVersion (&ver, NULL, NULL); + if (ver < 1002001) { + fprintf (stderr, "%s: test skipped because libvirt is too old (%lu)\n", + argv[0], ver); + exit (77); + } + + g = guestfs_create (); + if (!g) + exit (EXIT_FAILURE); + + /* This will ask the user for credentials. It will also fail + * (expectedly) because the test driver does not support qemu/KVM. + */ + guestfs_launch (g); + + guestfs_close (g); + exit (EXIT_SUCCESS); +} diff --git a/tests/regressions/rhbz1044014.in b/tests/regressions/rhbz1044014.in new file mode 100644 index 0000000..3f382dd --- /dev/null +++ b/tests/regressions/rhbz1044014.in @@ -0,0 +1 @@ +rich diff --git a/tests/regressions/rhbz1044014.sh b/tests/regressions/rhbz1044014.sh new file mode 100755 index 0000000..f1e458c --- /dev/null +++ b/tests/regressions/rhbz1044014.sh @@ -0,0 +1,70 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2014 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Regression test for: +# https://bugzilla.redhat.com/show_bug.cgi?id=1044014 + +set -e +export LANG=C + +if [ -n "$SKIP_TEST_RHBZ1044014_SH" ]; then + echo "$0: test skipped because environment variable is set." + exit 77 +fi + +# Check we are running against the libvirt backend. +backend="$(../../fish/guestfish get-backend)" +if [[ ! ( "$backend" =~ ^libvirt ) ]]; then + echo "$0: test skipped because backend ($backend) is not libvirt." + exit 77 +fi + +# Set the backend to the test driver. +export LIBGUESTFS_BACKEND="libvirt:test://$(pwd)/$srcdir/rhbz1044014.xml" + +rm -f rhbz1044014.out + +./rhbz1044014 < $srcdir/rhbz1044014.in > rhbz1044014.out 2>&1 || { + r=$? + if [ $r -ne 0 ]; then + cat rhbz1044014.out + exit $r + fi +} + +# We are expecting this message to be printed (see commit which fixed +# RHBZ#1044014). +grep "libvirt needs authentication to connect to libvirt URI" rhbz1044014.out || { + echo "$0: expecting to see message from commit which fixed RHBZ#1044014" + echo + echo "actual output was:" + echo + cat rhbz1044014.out + exit 1 +} + +# This is the error we are expecting to see. If we see it then it +# indicates that authentication was successful. +grep "error: libvirt hypervisor doesn't support qemu or KVM" rhbz1044014.out || { + echo "$0: unexpected output:" + echo + cat rhbz1044014.out + exit 1 +} + +rm rhbz1044014.out diff --git a/tests/regressions/rhbz1044014.xml b/tests/regressions/rhbz1044014.xml new file mode 100644 index 0000000..72feaf4 --- /dev/null +++ b/tests/regressions/rhbz1044014.xml @@ -0,0 +1,5 @@ + + + rich + + -- 1.8.5.3