xref: /openbmc/qemu/tests/qemu-iotests/282 (revision 8bb3b023f2055054ee119cb45b42d2b14be7fc8a)
1*8bb3b023SDaniel Henrique Barboza#!/usr/bin/env bash
2*8bb3b023SDaniel Henrique Barboza#
3*8bb3b023SDaniel Henrique Barboza# Test qemu-img file cleanup for LUKS when using a non-UTF8 secret
4*8bb3b023SDaniel Henrique Barboza#
5*8bb3b023SDaniel Henrique Barboza# Copyright (C) 2020, IBM Corporation.
6*8bb3b023SDaniel Henrique Barboza#
7*8bb3b023SDaniel Henrique Barboza# This program is free software; you can redistribute it and/or modify
8*8bb3b023SDaniel Henrique Barboza# it under the terms of the GNU General Public License as published by
9*8bb3b023SDaniel Henrique Barboza# the Free Software Foundation; either version 2 of the License, or
10*8bb3b023SDaniel Henrique Barboza# (at your option) any later version.
11*8bb3b023SDaniel Henrique Barboza#
12*8bb3b023SDaniel Henrique Barboza# This program is distributed in the hope that it will be useful,
13*8bb3b023SDaniel Henrique Barboza# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*8bb3b023SDaniel Henrique Barboza# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*8bb3b023SDaniel Henrique Barboza# GNU General Public License for more details.
16*8bb3b023SDaniel Henrique Barboza#
17*8bb3b023SDaniel Henrique Barboza# You should have received a copy of the GNU General Public License
18*8bb3b023SDaniel Henrique Barboza# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*8bb3b023SDaniel Henrique Barboza#
20*8bb3b023SDaniel Henrique Barboza
21*8bb3b023SDaniel Henrique Barbozaseq=`basename $0`
22*8bb3b023SDaniel Henrique Barbozaecho "QA output created by $seq"
23*8bb3b023SDaniel Henrique Barboza
24*8bb3b023SDaniel Henrique Barbozastatus=1	# failure is the default!
25*8bb3b023SDaniel Henrique BarbozaTEST_IMAGE_FILE='vol.img'
26*8bb3b023SDaniel Henrique Barboza
27*8bb3b023SDaniel Henrique Barboza_cleanup()
28*8bb3b023SDaniel Henrique Barboza{
29*8bb3b023SDaniel Henrique Barboza  _cleanup_test_img
30*8bb3b023SDaniel Henrique Barboza  rm non_utf8_secret
31*8bb3b023SDaniel Henrique Barboza  rm -f $TEST_IMAGE_FILE
32*8bb3b023SDaniel Henrique Barboza}
33*8bb3b023SDaniel Henrique Barbozatrap "_cleanup; exit \$status" 0 1 2 3 15
34*8bb3b023SDaniel Henrique Barboza
35*8bb3b023SDaniel Henrique Barboza# get standard environment, filters and checks
36*8bb3b023SDaniel Henrique Barboza. ./common.rc
37*8bb3b023SDaniel Henrique Barboza. ./common.filter
38*8bb3b023SDaniel Henrique Barboza
39*8bb3b023SDaniel Henrique Barboza_supported_fmt luks
40*8bb3b023SDaniel Henrique Barboza_supported_proto generic
41*8bb3b023SDaniel Henrique Barboza_unsupported_proto vxhs
42*8bb3b023SDaniel Henrique Barboza
43*8bb3b023SDaniel Henrique Barbozaecho "== Create non-UTF8 secret =="
44*8bb3b023SDaniel Henrique Barbozaecho -n -e '\x3a\x3c\x3b\xff' > non_utf8_secret
45*8bb3b023SDaniel Henrique BarbozaSECRET="secret,id=sec0,file=non_utf8_secret"
46*8bb3b023SDaniel Henrique Barboza
47*8bb3b023SDaniel Henrique Barbozaecho "== Throws an error because of invalid UTF-8 secret =="
48*8bb3b023SDaniel Henrique Barboza$QEMU_IMG create -f $IMGFMT --object $SECRET -o "key-secret=sec0" $TEST_IMAGE_FILE 4M
49*8bb3b023SDaniel Henrique Barboza
50*8bb3b023SDaniel Henrique Barbozaecho "== Image file should not exist after the error =="
51*8bb3b023SDaniel Henrique Barbozaif test -f "$TEST_IMAGE_FILE"; then
52*8bb3b023SDaniel Henrique Barboza    exit 1
53*8bb3b023SDaniel Henrique Barbozafi
54*8bb3b023SDaniel Henrique Barboza
55*8bb3b023SDaniel Henrique Barbozaecho "== Create a stub image file and run qemu-img again =="
56*8bb3b023SDaniel Henrique Barbozatouch $TEST_IMAGE_FILE
57*8bb3b023SDaniel Henrique Barboza$QEMU_IMG create -f $IMGFMT --object $SECRET -o "key-secret=sec0" $TEST_IMAGE_FILE 4M
58*8bb3b023SDaniel Henrique Barboza
59*8bb3b023SDaniel Henrique Barbozaecho "== Pre-existing image file should also be deleted after the error =="
60*8bb3b023SDaniel Henrique Barbozaif test -f "$TEST_IMAGE_FILE"; then
61*8bb3b023SDaniel Henrique Barboza    exit 1
62*8bb3b023SDaniel Henrique Barbozafi
63*8bb3b023SDaniel Henrique Barboza
64*8bb3b023SDaniel Henrique Barboza# success, all done
65*8bb3b023SDaniel Henrique Barbozaecho "*** done"
66*8bb3b023SDaniel Henrique Barbozarm -f $seq.full
67*8bb3b023SDaniel Henrique Barbozastatus=0
68