]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_location.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_load-key / zfs_load-key_location.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
9 #
10 # A full copy of the text of the CDDL should have accompanied this
11 # source.  A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
13 #
14 # CDDL HEADER END
15 #
16
17 #
18 # Copyright (c) 2017 Datto, Inc. All rights reserved.
19 #
20
21 . $STF_SUITE/include/libtest.shlib
22 . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
23
24 #
25 # DESCRIPTION:
26 # 'zfs load-key -L' should override keylocation with provided value.
27 #
28 # STRATEGY:
29 # 1. Create a key file
30 # 2. Copy the key file to another location
31 # 3. Create an encrypted dataset using the keyfile
32 # 4. Unmount the dataset and unload its key
33 # 5. Attempt to load the dataset specifying a keylocation of file
34 # 6. Verify the key is loaded
35 # 7. Verify the keylocation is the original key file
36 # 8. Unload the dataset's key
37 # 9. Attempt to load the dataset specifying a keylocation of prompt
38 # 10. Verify the key is loaded
39 # 11. Verify the keylocation is the original key file
40 #
41
42 verify_runnable "both"
43
44 function cleanup
45 {
46         datasetexists $TESTPOOL/$TESTFS1 && \
47                 log_must zfs destroy $TESTPOOL/$TESTFS1
48 }
49 log_onexit cleanup
50
51 log_assert "'zfs load-key -L' should override keylocation with provided value"
52
53 typeset key_location="/$TESTPOOL/pkey1"
54
55 log_must eval "echo $PASSPHRASE > $key_location"
56 log_must cp $key_location /$TESTPOOL/pkey2
57
58 log_must zfs create -o encryption=on -o keyformat=passphrase \
59         -o keylocation=file://$key_location $TESTPOOL/$TESTFS1
60
61 log_must zfs unmount $TESTPOOL/$TESTFS1
62 log_must zfs unload-key $TESTPOOL/$TESTFS1
63
64 log_must zfs load-key -L file:///$TESTPOOL/pkey2 $TESTPOOL/$TESTFS1
65 log_must key_available $TESTPOOL/$TESTFS1
66 log_must verify_keylocation $TESTPOOL/$TESTFS1 "file://$key_location"
67
68 log_must zfs unload-key $TESTPOOL/$TESTFS1
69 log_must eval "echo $PASSPHRASE | zfs load-key -L prompt $TESTPOOL/$TESTFS1"
70 log_must key_available $TESTPOOL/$TESTFS1
71 log_must verify_keylocation $TESTPOOL/$TESTFS1 "file://$key_location"
72
73 log_pass "'zfs load-key -L' overrides keylocation with provided value"