xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key.ksh (revision a89c0811c892ec231725fe10817ef95dda813c06)
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 unload-key' should only unload the key of an unmounted dataset.
27#
28# STRATEGY:
29# 1. Attempt to unload the default dataset's key
30# 2. Unmount the dataset
31# 3. Attempt to unload the default dataset's key
32# 4. Create an encrypted dataset
33# 5. Attempt to unload the dataset's key
34# 6. Verify the key is loaded
35# 7. Unmount the dataset
36# 8. Attempt to unload the dataset's key
37# 9. Verify the key is not loaded
38# 10. Attempt to unload the dataset's key
39#
40
41verify_runnable "both"
42
43function cleanup
44{
45	datasetexists $TESTPOOL/$TESTFS1 && \
46		log_must zfs destroy $TESTPOOL/$TESTFS1
47}
48log_onexit cleanup
49
50log_assert "'zfs unload-key' should unload the key for an unmounted" \
51	"encrypted dataset"
52
53log_mustnot zfs unload-key $TESTPOOL/$TESTFS
54
55log_must zfs unmount $TESTPOOL/$TESTFS
56log_mustnot zfs unload-key $TESTPOOL/$TESTFS
57
58log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \
59	"-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1"
60log_mustnot zfs unload-key $TESTPOOL/$TESTFS1
61log_must key_available $TESTPOOL/$TESTFS1
62
63log_must zfs unmount $TESTPOOL/$TESTFS1
64log_must zfs unload-key $TESTPOOL/$TESTFS1
65log_must key_unavailable $TESTPOOL/$TESTFS1
66
67log_mustnot zfs unload-key $TESTPOOL/$TESTFS1
68
69log_pass "'zfs unload-key' unloads the key for an unmounted encrypted dataset"
70