xref: /freebsd/tests/sys/geom/class/eli/kill_test.sh (revision 780fb4a2)
1# $FreeBSD$
2
3atf_test_case kill cleanup
4kill_head()
5{
6	atf_set "descr" "geli kill will wipe a provider's metadata"
7	atf_set "require.user" "root"
8}
9kill_body()
10{
11	. $(atf_get_srcdir)/conf.sh
12
13	sectors=100
14	md=$(attach_md -t malloc -s `expr $sectors + 1`)
15
16	atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
17	atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
18
19	atf_check geli init -B none -P -K keyfile1 ${md}
20	atf_check geli attach -p -k keyfile1 ${md}
21	atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile2 ${md}
22
23	# Kill attached provider.
24	atf_check geli kill ${md}
25	sleep 1
26	# Provider should be automatically detached.
27	if [ -c /dev/${md}.eli ]; then
28		atf_fail "Provider did not detach when killed"
29	fi
30
31	# We cannot use keyfile1 anymore.
32	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
33		geli attach -p -k keyfile1 ${md}
34
35	# We cannot use keyfile2 anymore.
36	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
37		geli attach -p -k keyfile2 ${md}
38
39	atf_check geli init -B none -P -K keyfile1 ${md}
40	atf_check -s exit:0 -o ignore \
41		geli setkey -n 1 -p -k keyfile1 -P -K keyfile2 ${md}
42
43	# Should be possible to attach with keyfile1.
44	atf_check geli attach -p -k keyfile1 ${md}
45	atf_check geli detach ${md}
46
47	# Should be possible to attach with keyfile2.
48	atf_check geli attach -p -k keyfile2 ${md}
49	atf_check geli detach ${md}
50
51	# Kill detached provider.
52	atf_check geli kill ${md}
53
54	# We cannot use keyfile1 anymore.
55	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
56		geli attach -p -k keyfile1 ${md}
57
58	# We cannot use keyfile2 anymore.
59	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
60		geli attach -p -k keyfile2 ${md}
61}
62kill_cleanup()
63{
64	. $(atf_get_srcdir)/conf.sh
65	geli_test_cleanup
66}
67
68atf_test_case kill_readonly cleanup
69kill_readonly_head()
70{
71	atf_set "descr" "geli kill will not destroy the keys of a readonly provider"
72	atf_set "require.user" "root"
73}
74kill_readonly_body()
75{
76	. $(atf_get_srcdir)/conf.sh
77
78	sectors=100
79	md=$(attach_md -t malloc -s `expr $sectors + 1`)
80	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
81
82	atf_check geli init -B none -P -K keyfile ${md}
83	# Attach read-only
84	atf_check geli attach -r -p -k keyfile ${md}
85
86	atf_check geli kill ${md}
87	# The provider will be detached
88	atf_check [ ! -c /dev/${md}.eli ]
89	# But its keys should not be destroyed
90	atf_check geli attach -p -k keyfile ${md}
91}
92kill_readonly_cleanup()
93{
94	. $(atf_get_srcdir)/conf.sh
95	geli_test_cleanup
96}
97
98atf_init_test_cases()
99{
100	atf_add_test_case kill
101	atf_add_test_case kill_readonly
102}
103