1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or https://opensource.org/licenses/CDDL-1.0.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23. $STF_SUITE/include/libtest.shlib
24. $STF_SUITE/tests/functional/rsend/rsend.kshlib
25
26#
27# Description:
28# Incrementally receiving a snapshot to an encrypted filesystem succeeds.
29#
30# Strategy:
31# 1) Create a pool and an encrypted fs
32# 2) Create some files and snapshots
33# 3) Send the first snapshot to a second encrypted as well as an
34#	unencrypted fs.
35# 4) Incrementally send the second snapshot to the unencrypted fs.
36# 5) Rollback the second encrypted fs to the first snapshot.
37# 6) Incrementally send the second snapshot from the unencrypted to the
38#	second encrypted fs.
39# 7) Incrementally send the third snapshot from the first encrypted to the
40#	unencrypted fs.
41# 8) Incrementally send the third snapshot from the unencrypted to the second
42#	encrypted fs.
43#
44
45verify_runnable "both"
46
47log_assert "Incrementally receiving a snapshot to an encrypted filesystem succeeds"
48
49function cleanup
50{
51	destroy_pool pool_lb
52	log_must rm -f $TESTDIR/vdev_a
53}
54
55log_onexit cleanup
56
57typeset passphrase="password"
58typeset passphrase2="password2"
59
60typeset file="/pool_lb/encryptme/$TESTFILE0"
61typeset file1="/pool_lb/encryptme/$TESTFILE1"
62typeset file2="/pool_lb/encryptme/$TESTFILE2"
63
64# Create pool
65truncate -s $MINVDEVSIZE $TESTDIR/vdev_a
66log_must zpool create -f pool_lb $TESTDIR/vdev_a
67log_must eval "echo $passphrase > /pool_lb/pwd"
68log_must eval "echo $passphrase2 > /pool_lb/pwd2"
69
70log_must zfs create -o encryption=on -o keyformat=passphrase \
71	-o keylocation=file:///pool_lb/pwd pool_lb/encryptme
72log_must dd if=/dev/urandom of=$file bs=1024 count=1024
73log_must zfs snapshot pool_lb/encryptme@snap1
74log_must dd if=/dev/urandom of=$file1 bs=1024 count=1024
75log_must zfs snapshot pool_lb/encryptme@snap2
76log_must dd if=/dev/urandom of=$file2 bs=1024 count=1024
77log_must zfs snapshot pool_lb/encryptme@snap3
78log_must eval "zfs send -Lc pool_lb/encryptme@snap1 | zfs recv \
79	-o encryption=on -o keyformat=passphrase -o keylocation=file:///pool_lb/pwd2 \
80	pool_lb/encrypttwo"
81log_must eval "zfs send -Lc pool_lb/encryptme@snap1 | zfs recv \
82	pool_lb/unencryptme"
83log_must eval "zfs send -Lc -i pool_lb/encryptme@{snap1,snap2} | zfs recv \
84	pool_lb/unencryptme"
85log_must zfs rollback pool_lb/encrypttwo@snap1
86log_must eval "zfs send -Lc -i pool_lb/unencryptme@{snap1,snap2} | zfs recv \
87	pool_lb/encrypttwo"
88log_must eval "zfs send -Lc -i pool_lb/encryptme@{snap2,snap3} | zfs recv \
89	pool_lb/unencryptme"
90log_must eval "zfs send -Lc -i pool_lb/unencryptme@{snap2,snap3} | zfs recv \
91	-F pool_lb/encrypttwo"
92
93log_pass "Incrementally receiving a snapshot to an encrypted filesystem succeeds"
94