2 # SPDX-License-Identifier: BSD-2-Clause
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
27 atf_test_case "basic" "cleanup"
28 atf_test_case "nested" "cleanup"
29 atf_test_case "commands" "cleanup"
33 atf_set descr 'Basic jail test'
34 atf_set require.user root
40 atf_check -s exit:0 -o ignore jail -c name=basejail persist ip4.addr=192.0.1.1
42 atf_check -s exit:0 -o ignore jls
43 atf_check -s exit:0 -o ignore jls -v
44 atf_check -s exit:0 -o ignore jls -n
46 atf_check -s exit:0 -o ignore jail -r basejail
47 jail -c name=basejail persist ip4.addr=192.0.1.1
49 atf_check -s exit:0 -o ignore jail -r `jls -j basejail jid`
51 atf_check -s exit:0 -o ignore jail -cm name=basejail persist ip4.addr=192.0.1.1
53 atf_check -s exit:0 -o ignore jail -rc name=basejail persist ip4.addr=192.0.1.1
63 atf_set descr 'Hierarchical jails test'
64 atf_set require.user root
69 # Create the first jail
70 jail -c name=basejail persist ip4.addr=192.0.1.1 children.max=1
71 atf_check -s exit:0 -o empty \
73 jail -c name=nestedjail persist ip4.addr=192.0.1.1
75 atf_check -s exit:1 -o empty -e inline:"jail: prison limit exceeded\n"\
77 jail -c name=secondnestedjail persist ip4.addr=192.0.1.1
79 atf_check -s exit:0 -o ignore \
81 atf_check -s exit:0 -o ignore \
83 atf_check -s exit:0 -o ignore \
85 # Create jail with no child - children.max should be 0 by default
86 jail -c name=basejail_nochild persist ip4.addr=192.0.1.1
87 atf_check -s exit:1 -o empty \
88 -e inline:"jail: jail_set: Operation not permitted\n" \
89 jexec basejail_nochild \
90 jail -c name=nestedjail persist ip4.addr=192.0.1.1
97 jail -r basejail_nochild
102 atf_set descr 'Commands jail test'
103 atf_set require.user root
109 atf_check -s exit:0 -o inline:"START\n" \
110 jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail
111 # exec.prestop by jailname
112 atf_check -s exit:0 -o inline:"STOP\n" \
113 jail -f $(atf_get_srcdir)/commands.jail.conf -qr basejail
114 # exec.prestop by jid
115 jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail
116 atf_check -s exit:0 -o inline:"STOP\n" \
117 jail -f $(atf_get_srcdir)/commands.jail.conf -qr `jls -j basejail jid`
122 jls -j basejail > /dev/null 2>&1
129 atf_init_test_cases()
131 atf_add_test_case "basic"
132 atf_add_test_case "nested"
133 atf_add_test_case "commands"