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/zpool_import/zpool_import.cfg
23. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
24
25#
26# DESCRIPTION:
27# 'zpool import' should import a pool with an encrypted dataset without
28# mounting it.
29#
30# STRATEGY:
31# 1. Create an encrypted pool
32# 2. Export the pool
33# 3. Attempt to import the pool
34# 4. Verify the pool exists and the key is not loaded
35#
36
37verify_runnable "both"
38
39function cleanup
40{
41	destroy_pool $TESTPOOL1
42	log_must rm $VDEV0
43	log_must mkfile $FILE_SIZE $VDEV0
44}
45log_onexit cleanup
46
47log_assert "'zpool import' should import a pool with an encrypted dataset" \
48	"without mounting it"
49
50log_must eval "echo $PASSPHRASE | zpool create -O encryption=on" \
51	"-O keyformat=passphrase -O keylocation=prompt $TESTPOOL1 $VDEV0"
52log_must zpool export $TESTPOOL1
53log_must zpool import -d $DEVICE_DIR $TESTPOOL1
54log_must poolexists $TESTPOOL1
55log_must key_unavailable $TESTPOOL1
56log_must unmounted $TESTPOOL1
57
58log_pass "'zpool import' imports a pool with an encrypted dataset without" \
59	"mounting it"
60