xref: /freebsd/tests/sys/geom/class/eli/attach_test.sh (revision b00ab754)
1# $FreeBSD$
2
3atf_test_case attach_d cleanup
4attach_d_head()
5{
6	atf_set "descr" "geli attach -d will cause the provider to detach on last close"
7	atf_set "require.user" "root"
8}
9attach_d_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=keyfile bs=512 count=16 status=none
17
18	atf_check geli init -B none -P -K keyfile ${md}
19	atf_check geli attach -d -p -k keyfile ${md}
20
21	# Be sure it doesn't detach on read.
22	atf_check dd if=/dev/${md}.eli of=/dev/null status=none
23	sleep 1
24	if [ ! -c /dev/${md}.eli ]; then
25		atf_fail "Detached on last close of a reader"
26	fi
27
28	# It should detach on last close of a writer
29	true > /dev/${md}.eli
30	sleep 1
31	if [ -c /dev/${md}.eli ]; then
32		atf_fail "Did not detach on last close of a writer"
33	fi
34
35}
36attach_d_cleanup()
37{
38	. $(atf_get_srcdir)/conf.sh
39	geli_test_cleanup
40}
41
42atf_test_case attach_r cleanup
43attach_r_head()
44{
45	atf_set "descr" "geli attach -r will create a readonly provider"
46	atf_set "require.user" "root"
47}
48attach_r_body()
49{
50	. $(atf_get_srcdir)/conf.sh
51
52	sectors=100
53	md=$(attach_md -t malloc -s `expr $sectors + 1`)
54	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
55
56	atf_check geli init -B none -P -K keyfile ${md}
57	atf_check geli attach -r -p -k keyfile ${md}
58
59	atf_check -o match:"^Flags: .*READ-ONLY" geli list ${md}.eli
60
61	# Verify that writes are verbotten
62	atf_check -s not-exit:0 -e match:"Read-only" \
63		dd if=/dev/zero of=/dev/${md}.eli count=1
64}
65attach_r_cleanup()
66{
67	. $(atf_get_srcdir)/conf.sh
68	geli_test_cleanup
69}
70
71atf_test_case nokey cleanup
72nokey_head()
73{
74	atf_set "descr" "geli attach fails if called with no key component"
75	atf_set "require.user" "root"
76}
77nokey_body()
78{
79	. $(atf_get_srcdir)/conf.sh
80
81	sectors=100
82	md=$(attach_md -t malloc -s `expr $sectors + 1`)
83	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
84
85	atf_check geli init -B none -P -K keyfile ${md}
86	atf_check -s not-exit:0 -e match:"No key components given" \
87		geli attach -p ${md} 2>/dev/null
88}
89nokey_cleanup()
90{
91	. $(atf_get_srcdir)/conf.sh
92	geli_test_cleanup
93}
94
95atf_init_test_cases()
96{
97	atf_add_test_case attach_d
98	atf_add_test_case attach_r
99	atf_add_test_case nokey
100}
101