mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
tests: Add a regression test for libvirt authentication (RHBZ#1044014).
This tests the virConnectAuthPtrDefault wrapper path.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -489,6 +489,8 @@ Makefile.in
|
||||
/tests/regressions/rhbz501893
|
||||
/tests/regressions/rhbz790721
|
||||
/tests/regressions/rhbz914931
|
||||
/tests/regressions/rhbz1044014
|
||||
/tests/regressions/rhbz1044014.out
|
||||
/tests/rsync/rsyncd.pid
|
||||
/tests/syslinux/extlinux-guest.img
|
||||
/tests/syslinux/syslinux-guest.img
|
||||
|
||||
@@ -38,6 +38,10 @@ TESTS = \
|
||||
rhbz1001875.sh \
|
||||
test-noexec-stack.pl
|
||||
|
||||
if HAVE_LIBVIRT
|
||||
TESTS += rhbz1044014.sh
|
||||
endif
|
||||
|
||||
tests_not_run = \
|
||||
rhbz727178.sh \
|
||||
rhbz909624.sh
|
||||
@@ -51,6 +55,10 @@ check_PROGRAMS = \
|
||||
rhbz790721 \
|
||||
rhbz914931
|
||||
|
||||
if HAVE_LIBVIRT
|
||||
check_PROGRAMS += rhbz1044014
|
||||
endif
|
||||
|
||||
rhbz501893_SOURCES = rhbz501893.c
|
||||
rhbz501893_CPPFLAGS = \
|
||||
-I$(top_srcdir)/src -I$(top_builddir)/src
|
||||
@@ -81,11 +89,30 @@ 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
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(TESTS) \
|
||||
$(tests_not_run) \
|
||||
rhbz557655-expected.stdout \
|
||||
rhbz557655-expected.stderr
|
||||
rhbz557655-expected.stderr \
|
||||
rhbz1044014.in \
|
||||
rhbz1044014.xml
|
||||
|
||||
check-slow:
|
||||
$(MAKE) TESTS="rhbz909624.sh" check
|
||||
|
||||
69
tests/regressions/rhbz1044014.c
Normal file
69
tests/regressions/rhbz1044014.c
Normal file
@@ -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 <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <libvirt/libvirt.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
1
tests/regressions/rhbz1044014.in
Normal file
1
tests/regressions/rhbz1044014.in
Normal file
@@ -0,0 +1 @@
|
||||
rich
|
||||
70
tests/regressions/rhbz1044014.sh
Executable file
70
tests/regressions/rhbz1044014.sh
Executable file
@@ -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
|
||||
5
tests/regressions/rhbz1044014.xml
Normal file
5
tests/regressions/rhbz1044014.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<node>
|
||||
<auth>
|
||||
<user>rich</user>
|
||||
</auth>
|
||||
</node>
|
||||
Reference in New Issue
Block a user