1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2018 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/redacted_send/redacted.kshlib
19
20#
21# Description:
22# Test that redacted send correctly detects invalid arguments.
23#
24
25typeset sendfs="$POOL2/sendfs"
26typeset recvfs="$POOL2/recvfs"
27typeset clone1="$POOL2/clone1"
28typeset clone2="$POOL2/clone2"
29typeset clone3="$POOL2/clone3"
30typeset clone3="$POOL2/clone4"
31typeset tmpdir="$(get_prop mountpoint $POOL)/tmp"
32typeset stream=$(mktemp $tmpdir/stream.XXXX)
33
34log_onexit redacted_cleanup $sendfs $recvfs $clone3
35
36log_must zfs create $sendfs
37log_must zfs snapshot $sendfs@snap1
38log_must zfs snapshot $sendfs@snap2
39log_must zfs snapshot $sendfs@snap3
40log_must zfs clone $sendfs@snap2 $clone1
41log_must zfs snapshot $clone1@snap
42log_must zfs bookmark $clone1@snap $clone1#book
43log_must zfs clone $sendfs@snap2 $clone2
44log_must zfs snapshot $clone2@snap
45
46# Incompatible flags
47log_must zfs redact $sendfs@snap2 book $clone1@snap
48log_mustnot eval "zfs send -R --redact book $sendfs@snap2 >$TEST_BASE_DIR/devnull"
49
50typeset arg
51for arg in "$sendfs" "$clone1#book"; do
52	log_mustnot eval "zfs send --redact book $arg >$TEST_BASE_DIR/devnull"
53done
54
55# Bad redaction list arguments
56log_mustnot zfs redact $sendfs@snap1
57log_mustnot zfs redact $sendfs@snap1 book
58log_mustnot zfs redact $sendfs#book1 book4 $clone1
59log_mustnot zfs redact $sendfs@snap1 book snap2 snap3
60log_mustnot zfs redact $sendfs@snap1 book @snap2 @snap3
61log_mustnot eval "zfs send --redact $sendfs#book $sendfs@snap >$TEST_BASE_DIR/devnull"
62
63# Redaction snapshots not a descendant of tosnap
64log_mustnot zfs redact $sendfs@snap2 book $sendfs@snap2
65log_must zfs redact $sendfs@snap2 book2 $clone1@snap $clone2@snap
66log_must eval "zfs send --redact book2 $sendfs@snap2 >$stream"
67log_must zfs redact $sendfs@snap2 book3 $clone1@snap $clone2@snap
68log_must eval "zfs send -i $sendfs@snap1 --redact book3 $sendfs@snap2 \
69    >$TEST_BASE_DIR/devnull"
70log_mustnot zfs redact $sendfs@snap3 $sendfs@snap3 $clone1@snap
71
72# Full redacted sends of redacted datasets are not allowed.
73log_must eval "zfs recv $recvfs <$stream"
74log_must zfs snapshot $recvfs@snap
75log_must zfs clone $recvfs@snap $clone3
76log_must zfs snapshot $clone3@snap
77log_mustnot zfs redact $recvfs@snap book5 $clone3@snap
78
79# Nor may a redacted dataset appear in the redaction list.
80log_mustnot zfs redact testpool2/recvfs@snap2 book7 testpool2/recvfs@snap
81
82# Non-redaction bookmark cannot be sent and produces invalid argument error
83log_must zfs bookmark "$sendfs@snap1" "$sendfs#book8"
84log_must eval "zfs send --redact book8 -i $sendfs@snap1 $sendfs@snap2 2>&1 | head -n 100 | grep 'not a redaction bookmark'"
85
86# Error messages for common usage errors
87log_mustnot_expect "not contain '#'"    zfs redact $sendfs@snap1 \#book $sendfs@snap2
88log_mustnot_expect "not contain '#'"    zfs redact $sendfs@snap1 $sendfs#book $sendfs@snap2
89log_mustnot_expect "full dataset names" zfs redact $sendfs@snap1 book @snap2
90log_mustnot_expect "full dataset names" zfs redact $sendfs@snap1 book @snap2
91log_mustnot_expect "full dataset names" zfs redact $sendfs@snap1 \#book @snap2
92log_mustnot_expect "descendent of snapshot" zfs redact $sendfs@snap2 book $sendfs@snap1
93
94log_pass "Verify that redacted send correctly detects invalid arguments."
95