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 -a' should load keys for all datasets.
27#
28# STRATEGY:
29# 1. Create an encrypted filesystem, encrypted zvol, and an encrypted pool
30# 2. Unmount all datasets and unload their keys
31# 3. Attempt to load all dataset keys
32# 4. Verify each dataset has its key loaded
33# 5. Attempt to mount the pool and filesystem
34#
35
36verify_runnable "both"
37
38function cleanup
39{
40	datasetexists $TESTPOOL/$TESTFS1 && \
41		log_must zfs destroy $TESTPOOL/$TESTFS1
42	datasetexists $TESTPOOL/$TESTFS2 && \
43		log_must zfs destroy $TESTPOOL/$TESTFS2
44	datasetexists $TESTPOOL/zvol && log_must zfs destroy $TESTPOOL/zvol
45	poolexists $TESTPOOL1 && log_must destroy_pool $TESTPOOL1
46}
47log_onexit cleanup
48
49log_assert "'zfs load-key -a' should load keys for all datasets"
50
51log_must eval "echo $PASSPHRASE1 > /$TESTPOOL/pkey"
52log_must zfs create -o encryption=on -o keyformat=passphrase \
53	-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1
54
55log_must zfs create -o encryption=on -o keyformat=passphrase \
56	-o keylocation=$(get_https_base_url)/PASSPHRASE $TESTPOOL/$TESTFS2
57
58log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \
59	-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol
60
61typeset DISK2="$(echo $DISKS | awk '{ print $2}')"
62log_must zpool create -O encryption=on -O keyformat=passphrase \
63	-O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2
64
65log_must zfs unmount $TESTPOOL/$TESTFS1
66log_must zfs unload-key $TESTPOOL/$TESTFS1
67
68log_must zfs unmount $TESTPOOL/$TESTFS2
69log_must zfs unload-key $TESTPOOL/$TESTFS2
70
71log_must zfs unload-key $TESTPOOL/zvol
72
73log_must zfs unmount $TESTPOOL1
74log_must zfs unload-key $TESTPOOL1
75
76log_must zfs load-key -a
77
78log_must key_available $TESTPOOL1
79log_must key_available $TESTPOOL/zvol
80log_must key_available $TESTPOOL/$TESTFS1
81log_must key_available $TESTPOOL/$TESTFS2
82
83log_must zfs mount $TESTPOOL1
84log_must zfs mount $TESTPOOL/$TESTFS1
85log_must zfs mount $TESTPOOL/$TESTFS2
86
87log_pass "'zfs load-key -a' loads keys for all datasets"
88