xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_location.ksh (revision 4c87aefe8930bd07275b8dd2e96ea5f24d93a52e)
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 change-key -o' should change the keylocation.
27#
28# STRATEGY:
29# 1. Create an encryption dataset with a file key location
30# 2. Change the key location to 'prompt'
31# 3. Verify the key location
32# 4. Unmount the dataset and unload its key
33# 5. Attempt to load the dataset's key
34# 6. Attempt to change the key location to 'none'
35# 7. Attempt to change the key location to an invalid value
36#
37
38verify_runnable "both"
39
40function cleanup
41{
42	datasetexists $TESTPOOL/$TESTFS1 && \
43		log_must zfs destroy -f $TESTPOOL/$TESTFS1
44}
45log_onexit cleanup
46
47log_assert "'zfs change-key -o' should change the keylocation"
48
49log_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey"
50log_must zfs create -o encryption=on -o keyformat=passphrase \
51	-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1
52log_must verify_keylocation $TESTPOOL/$TESTFS1 "file:///$TESTPOOL/pkey"
53
54log_must eval "echo $PASSPHRASE1 | zfs change-key -o keylocation=prompt" \
55	"$TESTPOOL/$TESTFS1"
56log_must verify_keylocation $TESTPOOL/$TESTFS1 "prompt"
57
58log_must zfs unmount $TESTPOOL/$TESTFS1
59log_must zfs unload-key $TESTPOOL/$TESTFS1
60log_must eval "echo $PASSPHRASE1 | zfs load-key $TESTPOOL/$TESTFS1"
61
62log_mustnot zfs change-key -o keylocation=none $TESTPOOL/$TESTFS1
63log_mustnot zfs change-key -o keylocation=foobar $TESTPOOL/$TESTFS1
64
65log_pass "'zfs change-key -o' changes the keylocation"
66