xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_002_neg.ksh (revision 4c87aefe8930bd07275b8dd2e96ea5f24d93a52e)
1#!/usr/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 http://www.opensolaris.org/os/licensing.
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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION:
36#
37# Malformed zpool set commands are rejected
38#
39# STRATEGY:
40#	1. Create an array of many different malformed zfs set arguments
41#	2. Run zpool set for each arg checking each will exit with status code 1
42#
43#
44
45verify_runnable "global"
46
47# note to self - need to make sure there isn't a pool called bootfs
48# before running this test...
49function cleanup {
50
51	zpool destroy bootfs
52	rm /tmp/zpool_set_002.$$.dat
53}
54
55log_assert "Malformed zpool set commands are rejected"
56
57if poolexists bootfs
58then
59	log_unsupported "Unable to run test on a machine with a pool called \
60 bootfs"
61fi
62
63log_onexit cleanup
64
65# build up an array of bad arguments.
66set -A arguments "rubbish " \
67		"foo@bar= " \
68		"@@@= +pool " \
69		"zpool bootfs " \
70		"bootfs " \
71		"bootfs +" \
72		"bootfs=bootfs/123 " \
73		"bootfs=bootfs@val " \
74		"Bootfs=bootfs " \
75		"- " \
76		"== " \
77		"set " \
78		"@@ " \
79		"12345 " \
80		"€にほんご " \
81		"/ " \
82		"bootfs=bootfs /" \
83		"bootfs=a%d%s "
84
85
86# here, we build up a large string.
87# a word to the ksh-wary, ${#array[@]} gives you the
88# total number of entries in an array, so array[${#array[@]}]
89# will index the last entry+1, ksh arrays start at index 0.
90COUNT=0
91while [ $COUNT -le 1025 ]
92do
93	bigname="${bigname}o"
94	COUNT=$(( $COUNT + 1 ))
95done
96
97# add an argument of maximum length property name
98arguments[${#arguments[@]}]="$bigname=value"
99
100# add an argument of maximum length property value
101arguments[${#arguments[@]}]="bootfs=$bigname"
102
103# Create a pool called bootfs (so-called, so as to trip any clashes between
104# property name, and pool name)
105# Also create a filesystem in this pool
106log_must mkfile $MINVDEVSIZE /tmp/zpool_set_002.$$.dat
107log_must zpool create bootfs /tmp/zpool_set_002.$$.dat
108log_must zfs create bootfs/root
109
110typeset -i i=0;
111while [ $i -lt "${#arguments[@]}" ]
112do
113	log_mustnot eval "zpool set ${arguments[$i]} > /dev/null 2>&1"
114
115	# now also try with a valid pool in the argument list
116	log_mustnot eval "zpool set ${arguments[$i]}bootfs > /dev/null 2>&1"
117
118	# now also try with two valid pools in the argument list
119	log_mustnot eval "zpool set ${arguments[$i]}bootfs bootfs > /dev/null"
120	i=$(( $i + 1))
121done
122
123log_pass "Malformed zpool set commands are rejected"
124