tests: Split regressions -> various subdirectories of tests/
[libguestfs.git] / tests / luks / test-luks.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2010 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 # Test LUKS device creation, opening, key slots.
20
21 set -e
22
23 [ -n "$SKIP_TEST_LUKS_SH" ] && {
24     echo "test-luks.sh skipped (environment variable set)"
25     exit 0
26 }
27
28 rm -f test1.img
29
30 ../../fish/guestfish --keys-from-stdin <<EOF
31 sparse test1.img 1G
32 run
33 part-disk /dev/sda mbr
34
35 # Create LUKS device with key "key0" in slot 0.
36 luks-format /dev/sda1 0
37 key0
38
39 # Open the device.
40 luks-open /dev/sda1 lukstest
41 key0
42
43 # Put some LVM structures on the encrypted device.
44 pvcreate /dev/mapper/lukstest
45 vgcreate VG /dev/mapper/lukstest
46 lvcreate LV1 VG 64
47 lvcreate LV2 VG 64
48 vg-activate-all false
49
50 # Close the device.
51 luks-close /dev/mapper/lukstest
52
53 # Add keys in other slots.
54 luks-add-key /dev/sda1 1
55 key0
56 key1
57 luks-add-key /dev/sda1 2
58 key1
59 key2
60 luks-add-key /dev/sda1 3
61 key2
62 key3
63
64 # Check we can open the device with one of the new keys.
65 luks-open /dev/sda1 lukstest
66 key1
67 luks-close /dev/mapper/lukstest
68 luks-open /dev/sda1 lukstest
69 key3
70 luks-close /dev/mapper/lukstest
71
72 # Remove a key.
73 luks-kill-slot /dev/sda1 1
74 key0
75
76 # This is expected to fail.
77 -luks-open /dev/sda1 lukstest
78 key1
79
80 # Replace a key slot.
81 luks-kill-slot /dev/sda1 3
82 key2
83 luks-add-key /dev/sda1 3
84 key2
85 newkey3
86
87 luks-open /dev/sda1 lukstest
88 newkey3
89 luks-close /dev/mapper/lukstest
90
91 EOF
92
93 rm -f test1.img