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#
24# Copyright (c) 2022 by Attila Fülöp <attila@fueloep.org>
25#
26
27. $STF_SUITE/include/libtest.shlib
28
29#
30# DESCRIPTION:
31#      ZFS should receive a raw send of a mix of unencrypted and encrypted
32#      child datasets
33#
34#      The layout of the datasets is:  enc/unenc/enc/unenc
35#
36# STRATEGY:
37# 1. Create the dataset hierarchy
38# 2. Snapshot the dataset hierarchy
39# 3. Send -Rw the dataset hierarchy and receive into a top-level dataset
40# 4. Check the encryption property of the received datasets
41
42verify_runnable "both"
43
44function cleanup
45{
46	datasetexists "$TESTPOOL/$TESTFS1" && \
47		destroy_dataset "$TESTPOOL/$TESTFS1" -r
48
49	datasetexists "$TESTPOOL/$TESTFS2" && \
50		destroy_dataset "$TESTPOOL/$TESTFS2" -r
51}
52
53log_onexit cleanup
54
55log_assert "ZFS should receive a mix of un/encrypted childs"
56
57typeset src="$TESTPOOL/$TESTFS1"
58typeset dst="$TESTPOOL/$TESTFS2"
59typeset snap="snap"
60
61echo "password" | \
62	create_dataset "$src" -o encryption=on -o keyformat=passphrase
63create_dataset "$src/u" "-o encryption=off"
64echo "password" | \
65	create_dataset "$src/u/e" -o encryption=on -o keyformat=passphrase
66create_dataset "$src/u/e/u" -o encryption=off
67
68log_must zfs snapshot -r "$src@$snap"
69log_must eval "zfs send -Rw $src@$snap | zfs receive -u $dst"
70log_must test "$(get_prop 'encryption' $dst)" != "off"
71log_must test "$(get_prop 'encryption' $dst/u)" == "off"
72log_must test "$(get_prop 'encryption' $dst/u/e)" != "off"
73log_must test "$(get_prop 'encryption' $dst/u/e/u)" == "off"
74
75log_pass "ZFS can receive a mix of un/encrypted childs"
76