From a1843b9d727d0eddb54b5e93b4c3aa0d6901e5f4 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 6 Mar 2017 14:27:19 +0000 Subject: [PATCH] v2v: Add extra tests for malformed OVA files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: - Bad SHA1 sum - Bad SHA256 sum - Invalid lines in manifest (x2) - Good checksum and manifest These tests were originally written by Tomáš Golembiovský. All I have done is to integrate them into the virt-v2v test suite. --- .gitignore | 1 + v2v/Makefile.am | 22 +++++- v2v/test-v2v-i-ova-bad-sha1.sh | 66 +++++++++++++++++ v2v/test-v2v-i-ova-bad-sha256.sh | 66 +++++++++++++++++ v2v/test-v2v-i-ova-checksums.ovf | 95 +++++++++++++++++++++++++ v2v/test-v2v-i-ova-good-checksums.sh | 67 +++++++++++++++++ v2v/test-v2v-i-ova-invalid-manifest1.sh | 65 +++++++++++++++++ v2v/test-v2v-i-ova-invalid-manifest2.sh | 64 +++++++++++++++++ 8 files changed, 445 insertions(+), 1 deletion(-) create mode 100755 v2v/test-v2v-i-ova-bad-sha1.sh create mode 100755 v2v/test-v2v-i-ova-bad-sha256.sh create mode 100644 v2v/test-v2v-i-ova-checksums.ovf create mode 100755 v2v/test-v2v-i-ova-good-checksums.sh create mode 100755 v2v/test-v2v-i-ova-invalid-manifest1.sh create mode 100755 v2v/test-v2v-i-ova-invalid-manifest2.sh diff --git a/.gitignore b/.gitignore index e3b6d7b1c..7dd49e24b 100644 --- a/.gitignore +++ b/.gitignore @@ -635,6 +635,7 @@ Makefile.in /v2v/virt-v2v.1 /v2v/virt-v2v-copy-to-local /v2v/virt-v2v-copy-to-local.1 +/v2v/windows.vmdk /website/*.html /website/README.txt /website/TODO.txt diff --git a/v2v/Makefile.am b/v2v/Makefile.am index 55f7e7012..9c685f96e 100644 --- a/v2v/Makefile.am +++ b/v2v/Makefile.am @@ -256,10 +256,15 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test TESTS = \ test-v2v-docs.sh \ - test-v2v-i-ova-tar.sh \ + test-v2v-i-ova-bad-sha1.sh \ + test-v2v-i-ova-bad-sha256.sh \ test-v2v-i-ova-formats.sh \ + test-v2v-i-ova-good-checksums.sh \ test-v2v-i-ova-gz.sh \ + test-v2v-i-ova-invalid-manifest1.sh \ + test-v2v-i-ova-invalid-manifest2.sh \ test-v2v-i-ova-subfolders.sh \ + test-v2v-i-ova-tar.sh \ test-v2v-i-ova-two-disks.sh \ test-v2v-bad-networks-and-bridges.sh @@ -302,6 +307,20 @@ TESTS += \ endif endif ENABLE_APPLIANCE +# The VMDK file is used for some -i ova tests. +check_DATA = windows.vmdk +windows.vmdk: ../test-data/phony-guests/windows.img + rm -f $@ $@-t + if [ -s $< ]; then \ + qemu-img convert -f raw $< -O vmdk $@-t; \ + mv $@-t $@; \ + else \ + touch $@; \ + fi + +DISTCLEANFILES += \ + windows.vmdk + check-valgrind: $(MAKE) VG="@VG@" check @@ -355,6 +374,7 @@ EXTRA_DIST += \ test-v2v-floppy.sh \ test-v2v-floppy.xml \ test-v2v-i-disk.sh \ + test-v2v-i-ova-checksums.ovf \ test-v2v-i-ova-formats.expected \ test-v2v-i-ova-formats.ovf \ test-v2v-i-ova-formats.sh \ diff --git a/v2v/test-v2v-i-ova-bad-sha1.sh b/v2v/test-v2v-i-ova-bad-sha1.sh new file mode 100755 index 000000000..b19c57168 --- /dev/null +++ b/v2v/test-v2v-i-ova-bad-sha1.sh @@ -0,0 +1,66 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2017 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. + +# Test -i ova option with a good manifest containing a bad SHA1 checksum. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img + +if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then + echo "$0: test skipped because windows.vmdk was not created" + exit 77 +fi + +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" + +d=test-v2v-i-ova-bad-sha1.d +rm -rf $d +mkdir $d + +pushd $d + +# Create the test OVA. +cp ../test-v2v-i-ova-checksums.ovf test.ovf +cp ../windows.vmdk disk.vmdk +echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf +sha1=`do_sha1 disk.vmdk | tr '0-5a-f6789' 'a-f0-58967'` +echo "SHA1(disk.vmdk)=" $sha1 >> test.mf +tar cf test.ova test.ovf disk.vmdk test.mf + +# Run virt-v2v but only as far as the --print-source stage. +# It is expected to fail with an error. +if $VG virt-v2v --debug-gc --quiet \ + -i ova test.ova \ + --print-source >test.out 2>&1; then + cat test.out + echo "$0: expected virt-v2v to fail, but it succeeded" + exit 1 +fi +cat test.out +if ! grep "error: checksum of disk disk.vmdk does not match manifest" test.out +then + echo "$0: did not see the expected error in the output of virt-v2v" + exit 1 +fi + +popd +rm -rf $d diff --git a/v2v/test-v2v-i-ova-bad-sha256.sh b/v2v/test-v2v-i-ova-bad-sha256.sh new file mode 100755 index 000000000..a6b566d68 --- /dev/null +++ b/v2v/test-v2v-i-ova-bad-sha256.sh @@ -0,0 +1,66 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2017 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. + +# Test -i ova option with a good manifest containing a bad SHA256 checksum. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img + +if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then + echo "$0: test skipped because windows.vmdk was not created" + exit 77 +fi + +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" + +d=test-v2v-i-ova-bad-sha256.d +rm -rf $d +mkdir $d + +pushd $d + +# Create the test OVA. +cp ../test-v2v-i-ova-checksums.ovf test.ovf +cp ../windows.vmdk disk.vmdk +echo "SHA256(test.ovf)=" `do_sha256 test.ovf` > test.mf +sha256=`do_sha256 disk.vmdk | tr '0-5a-f6789' 'a-f0-58967'` +echo "SHA256(disk.vmdk)=" $sha256 >> test.mf +tar cf test.ova test.ovf disk.vmdk test.mf + +# Run virt-v2v but only as far as the --print-source stage. +# It is expected to fail with an error. +if $VG virt-v2v --debug-gc --quiet \ + -i ova test.ova \ + --print-source >test.out 2>&1; then + cat test.out + echo "$0: expected virt-v2v to fail, but it succeeded" + exit 1 +fi +cat test.out +if ! grep "error: checksum of disk disk.vmdk does not match manifest" test.out +then + echo "$0: did not see the expected error in the output of virt-v2v" + exit 1 +fi + +popd +rm -rf $d diff --git a/v2v/test-v2v-i-ova-checksums.ovf b/v2v/test-v2v-i-ova-checksums.ovf new file mode 100644 index 000000000..5bb7f6e9d --- /dev/null +++ b/v2v/test-v2v-i-ova-checksums.ovf @@ -0,0 +1,95 @@ + + + + + + + Virtual disk information + + + + A virtual machine + ova-test + + The kind of installed guest operating system + Microsoft Windows Server 2003 (32-bit) + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + ova-test + vmx-08 + + + hertz * 10^6 + Number of Virtual CPUs + 2 virtual CPU(s) + 1 + 3 + 2 + + + byte * 2^20 + Memory Size + 4096MB of memory + 2 + 4 + 4096 + + + 0 + SCSI Controller + SCSI controller 0 + 3 + lsilogic + 6 + + + 1 + IDE Controller + IDE 1 + 4 + 5 + + + 0 + IDE Controller + IDE 0 + 5 + 5 + + + false + Video card + 6 + 24 + + + false + VMCI device + 7 + vmware.vmci + 1 + + + 1 + false + CD/DVD drive 1 + 8 + 4 + vmware.cdrom.remotepassthrough + 15 + + + 0 + Hard disk 1 + ovf:/disk/vmdisk1 + 9 + 3 + 17 + + + + diff --git a/v2v/test-v2v-i-ova-good-checksums.sh b/v2v/test-v2v-i-ova-good-checksums.sh new file mode 100755 index 000000000..bc6195a18 --- /dev/null +++ b/v2v/test-v2v-i-ova-good-checksums.sh @@ -0,0 +1,67 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2017 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. + +# Test -i ova option with good checksums. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img + +if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then + echo "$0: test skipped because windows.vmdk was not created" + exit 77 +fi + +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" + +d=test-v2v-i-ova-good-checksums.d +rm -rf $d +mkdir $d + +pushd $d + +# Create the test OVA. +cp ../test-v2v-i-ova-checksums.ovf test.ovf +cp ../windows.vmdk disk.vmdk + +# Test all types of checksum supported by the OVA format. +echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf +echo "SHA256(disk.vmdk)=" `do_sha256 disk.vmdk` >> test.mf + +tar cf test.ova test.ovf disk.vmdk test.mf + +# Run virt-v2v but only as far as the --print-source stage. +# It should succeed with no warnings. +if ! $VG virt-v2v --debug-gc --quiet \ + -i ova test.ova \ + --print-source >test.out 2>&1; then + cat test.out + exit 1 +fi +cat test.out + +if grep -sq "warning: " test.out; then + echo "$0: unexpected warning in virt-v2v output: see messages above" + exit 1 +fi + +popd +rm -rf $d diff --git a/v2v/test-v2v-i-ova-invalid-manifest1.sh b/v2v/test-v2v-i-ova-invalid-manifest1.sh new file mode 100755 index 000000000..f26a9ab50 --- /dev/null +++ b/v2v/test-v2v-i-ova-invalid-manifest1.sh @@ -0,0 +1,65 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2017 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. + +# Test -i ova option with invalid manifest. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img + +if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then + echo "$0: test skipped because windows.vmdk was not created" + exit 77 +fi + +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" + +d=test-v2v-i-ova-invalid-manifest1.d +rm -rf $d +mkdir $d + +pushd $d + +# Create the test OVA. +cp ../test-v2v-i-ova-checksums.ovf test.ovf +cp ../windows.vmdk disk.vmdk +echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf +echo "SHA1(disk.vmdk)=" `do_sha1 disk.vmdk` >> test.mf +echo "garbage line" >> test.mf +tar cf test.ova test.ovf disk.vmdk test.mf + +# Run virt-v2v but only as far as the --print-source stage. +# It should succeed with a warning. +if ! $VG virt-v2v --debug-gc --quiet \ + -i ova test.ova \ + --print-source >test.out 2>&1; then + cat test.out + exit 1 +fi +cat test.out + +if ! grep -sq "warning: unable to parse line.*garbage" test.out; then + echo "$0: did not see the expected warning in the output of virt-v2v" + exit 1 +fi + +popd +rm -rf $d diff --git a/v2v/test-v2v-i-ova-invalid-manifest2.sh b/v2v/test-v2v-i-ova-invalid-manifest2.sh new file mode 100755 index 000000000..a336e5e6e --- /dev/null +++ b/v2v/test-v2v-i-ova-invalid-manifest2.sh @@ -0,0 +1,64 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2017 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. + +# Test -i ova option with invalid manifest. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img + +if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then + echo "$0: test skipped because windows.vmdk was not created" + exit 77 +fi + +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" + +d=test-v2v-i-ova-invalid-manifest2.d +rm -rf $d +mkdir $d + +pushd $d + +# Create the test OVA. +cp ../test-v2v-i-ova-checksums.ovf test.ovf +cp ../windows.vmdk disk.vmdk +echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf +echo "SHA1(disk.vmdk)=$(do_sha1 disk.vmdk)" >> test.mf +tar cf test.ova test.ovf disk.vmdk test.mf + +# Run virt-v2v but only as far as the --print-source stage. +# It should succeed with a warning. +if ! $VG virt-v2v --debug-gc --quiet \ + -i ova test.ova \ + --print-source >test.out 2>&1; then + cat test.out + exit 1 +fi +cat test.out + +if ! grep -sq "warning: unable to parse line" test.out; then + echo "$0: did not see the expected warning in the output of virt-v2v" + exit 1 +fi + +popd +rm -rf $d