18bb3b023SDaniel Henrique Barboza#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw img quick 38bb3b023SDaniel Henrique Barboza# 48bb3b023SDaniel Henrique Barboza# Test qemu-img file cleanup for LUKS when using a non-UTF8 secret 58bb3b023SDaniel Henrique Barboza# 68bb3b023SDaniel Henrique Barboza# Copyright (C) 2020, IBM Corporation. 78bb3b023SDaniel Henrique Barboza# 88bb3b023SDaniel Henrique Barboza# This program is free software; you can redistribute it and/or modify 98bb3b023SDaniel Henrique Barboza# it under the terms of the GNU General Public License as published by 108bb3b023SDaniel Henrique Barboza# the Free Software Foundation; either version 2 of the License, or 118bb3b023SDaniel Henrique Barboza# (at your option) any later version. 128bb3b023SDaniel Henrique Barboza# 138bb3b023SDaniel Henrique Barboza# This program is distributed in the hope that it will be useful, 148bb3b023SDaniel Henrique Barboza# but WITHOUT ANY WARRANTY; without even the implied warranty of 158bb3b023SDaniel Henrique Barboza# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 168bb3b023SDaniel Henrique Barboza# GNU General Public License for more details. 178bb3b023SDaniel Henrique Barboza# 188bb3b023SDaniel Henrique Barboza# You should have received a copy of the GNU General Public License 198bb3b023SDaniel Henrique Barboza# along with this program. If not, see <http://www.gnu.org/licenses/>. 208bb3b023SDaniel Henrique Barboza# 218bb3b023SDaniel Henrique Barboza 228bb3b023SDaniel Henrique Barbozaseq=`basename $0` 238bb3b023SDaniel Henrique Barbozaecho "QA output created by $seq" 248bb3b023SDaniel Henrique Barboza 258bb3b023SDaniel Henrique Barbozastatus=1 # failure is the default! 268bb3b023SDaniel Henrique BarbozaTEST_IMAGE_FILE='vol.img' 278bb3b023SDaniel Henrique Barboza 288bb3b023SDaniel Henrique Barboza_cleanup() 298bb3b023SDaniel Henrique Barboza{ 308bb3b023SDaniel Henrique Barboza _cleanup_test_img 318bb3b023SDaniel Henrique Barboza rm non_utf8_secret 328bb3b023SDaniel Henrique Barboza rm -f $TEST_IMAGE_FILE 338bb3b023SDaniel Henrique Barboza} 348bb3b023SDaniel Henrique Barbozatrap "_cleanup; exit \$status" 0 1 2 3 15 358bb3b023SDaniel Henrique Barboza 368bb3b023SDaniel Henrique Barboza# get standard environment, filters and checks 378bb3b023SDaniel Henrique Barboza. ./common.rc 388bb3b023SDaniel Henrique Barboza. ./common.filter 398bb3b023SDaniel Henrique Barboza 408bb3b023SDaniel Henrique Barboza_supported_fmt luks 418bb3b023SDaniel Henrique Barboza_supported_proto generic 428bb3b023SDaniel Henrique Barboza 438bb3b023SDaniel Henrique Barbozaecho "== Create non-UTF8 secret ==" 448bb3b023SDaniel Henrique Barbozaecho -n -e '\x3a\x3c\x3b\xff' > non_utf8_secret 458bb3b023SDaniel Henrique BarbozaSECRET="secret,id=sec0,file=non_utf8_secret" 468bb3b023SDaniel Henrique Barboza 478bb3b023SDaniel Henrique Barbozaecho "== Throws an error because of invalid UTF-8 secret ==" 488bb3b023SDaniel Henrique Barboza$QEMU_IMG create -f $IMGFMT --object $SECRET -o "key-secret=sec0" $TEST_IMAGE_FILE 4M 498bb3b023SDaniel Henrique Barboza 508bb3b023SDaniel Henrique Barbozaecho "== Image file should not exist after the error ==" 518bb3b023SDaniel Henrique Barbozaif test -f "$TEST_IMAGE_FILE"; then 528bb3b023SDaniel Henrique Barboza exit 1 538bb3b023SDaniel Henrique Barbozafi 548bb3b023SDaniel Henrique Barboza 558bb3b023SDaniel Henrique Barbozaecho "== Create a stub image file and run qemu-img again ==" 568bb3b023SDaniel Henrique Barbozatouch $TEST_IMAGE_FILE 578bb3b023SDaniel Henrique Barboza$QEMU_IMG create -f $IMGFMT --object $SECRET -o "key-secret=sec0" $TEST_IMAGE_FILE 4M 588bb3b023SDaniel Henrique Barboza 598bb3b023SDaniel Henrique Barbozaecho "== Pre-existing image file should also be deleted after the error ==" 608bb3b023SDaniel Henrique Barbozaif test -f "$TEST_IMAGE_FILE"; then 618bb3b023SDaniel Henrique Barboza exit 1 628bb3b023SDaniel Henrique Barbozafi 638bb3b023SDaniel Henrique Barboza 648bb3b023SDaniel Henrique Barboza# success, all done 658bb3b023SDaniel Henrique Barbozaecho "*** done" 668bb3b023SDaniel Henrique Barbozarm -f $seq.full 678bb3b023SDaniel Henrique Barbozastatus=0 68