]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_encrypted.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_from_encrypted.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
23 #
24 # DESCRIPTION:
25 # ZFS should receive an unencrypted stream from an encrypted dataset
26 #
27 # STRATEGY:
28 # 1. Create an unencrypted dataset
29 # 2. Create an encrypted dataset
30 # 3. Create and checksum a file on the encrypted dataset
31 # 4. Snapshot the encrypted dataset
32 # 5. Attempt to receive the snapshot into an unencrypted child
33 # 6. Verify encryption is not enabled
34 # 7. Verify the checksum of the file is the same as the original
35 # 8. Attempt to receive the snapshot into an encrypted child
36 # 9. Verify the checksum of the file is the same as the original
37 #
38
39 verify_runnable "both"
40
41 function cleanup
42 {
43         datasetexists $TESTPOOL/$TESTFS1 && \
44                 log_must zfs destroy -r $TESTPOOL/$TESTFS1
45
46         datasetexists $TESTPOOL/$TESTFS2 && \
47                 log_must zfs destroy -r $TESTPOOL/$TESTFS2
48 }
49
50 log_onexit cleanup
51
52 log_assert "ZFS should receive an unencrypted stream from an encrypted dataset"
53
54 typeset passphrase="password"
55 typeset snap="$TESTPOOL/$TESTFS2@snap"
56
57 log_must zfs create $TESTPOOL/$TESTFS1
58 log_must eval "echo $passphrase | zfs create -o encryption=on" \
59         "-o keyformat=passphrase $TESTPOOL/$TESTFS2"
60
61 log_must mkfile 1M /$TESTPOOL/$TESTFS2/$TESTFILE0
62 typeset checksum=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0)
63
64 log_must zfs snapshot $snap
65
66 log_note "Verify ZFS can receive into an unencrypted child"
67 log_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS1/c1"
68
69 crypt=$(get_prop encryption $TESTPOOL/$TESTFS1/c1)
70 [[ "$crypt" == "off" ]] || log_fail "Received unencrypted stream as encrypted"
71
72 typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS1/c1/$TESTFILE0)
73 [[ "$cksum1" == "$checksum" ]] || \
74         log_fail "Checksums differ ($cksum1 != $checksum)"
75
76 log_note "Verify ZFS can receive into an encrypted child"
77 log_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS2/c1"
78
79 typeset cksum2=$(md5digest /$TESTPOOL/$TESTFS2/c1/$TESTFILE0)
80 [[ "$cksum2" == "$checksum" ]] || \
81         log_fail "Checksums differ ($cksum2 != $checksum)"
82
83 log_pass "ZFS can receive an unencrypted stream from an encrypted dataset"