2 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 # Copyright (c) 2019 Michael Zhilin
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 atf_test_case "basic" "cleanup"
30 atf_test_case "nested" "cleanup"
31 atf_test_case "commands" "cleanup"
35 atf_set descr 'Basic jail test'
36 atf_set require.user root
42 atf_check -s exit:0 -o ignore jail -c name=basejail persist ip4.addr=192.0.1.1
44 atf_check -s exit:0 -o ignore jls
45 atf_check -s exit:0 -o ignore jls -v
46 atf_check -s exit:0 -o ignore jls -n
48 atf_check -s exit:0 -o ignore jail -r basejail
49 jail -c name=basejail persist ip4.addr=192.0.1.1
51 atf_check -s exit:0 -o ignore jail -r `jls -j basejail jid`
53 atf_check -s exit:0 -o ignore jail -cm name=basejail persist ip4.addr=192.0.1.1
55 atf_check -s exit:0 -o ignore jail -rc name=basejail persist ip4.addr=192.0.1.1
65 atf_set descr 'Hierarchical jails test'
66 atf_set require.user root
71 # Create the first jail
72 jail -c name=basejail persist ip4.addr=192.0.1.1 children.max=1
73 atf_check -s exit:0 -o empty \
75 jail -c name=nestedjail persist ip4.addr=192.0.1.1
77 atf_check -s exit:1 -o empty -e inline:"jail: prison limit exceeded\n"\
79 jail -c name=secondnestedjail persist ip4.addr=192.0.1.1
81 atf_check -s exit:0 -o ignore \
83 atf_check -s exit:0 -o ignore \
85 atf_check -s exit:0 -o ignore \
87 # Create jail with no child - children.max should be 0 by default
88 jail -c name=basejail_nochild persist ip4.addr=192.0.1.1
89 atf_check -s exit:1 -o empty \
90 -e inline:"jail: jail_set: Operation not permitted\n" \
91 jexec basejail_nochild \
92 jail -c name=nestedjail persist ip4.addr=192.0.1.1
99 jail -r basejail_nochild
104 atf_set descr 'Commands jail test'
105 atf_set require.user root
111 atf_check -s exit:0 -o inline:"START\n" \
112 jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail
113 # exec.prestop by jailname
114 atf_check -s exit:0 -o inline:"STOP\n" \
115 jail -f $(atf_get_srcdir)/commands.jail.conf -qr basejail
116 # exec.prestop by jid
117 jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail
118 atf_check -s exit:0 -o inline:"STOP\n" \
119 jail -f $(atf_get_srcdir)/commands.jail.conf -qr `jls -j basejail jid`
124 jls -j basejail > /dev/null 2>&1
131 atf_init_test_cases()
133 atf_add_test_case "basic"
134 atf_add_test_case "nested"
135 atf_add_test_case "commands"