xref: /freebsd/tests/sys/geom/class/eli/attach_test.sh (revision 315ee00f)
1
2. $(atf_get_srcdir)/conf.sh
3
4atf_test_case attach_d cleanup
5attach_d_head()
6{
7	atf_set "descr" "geli attach -d will cause the provider to detach on last close"
8	atf_set "require.user" "root"
9}
10attach_d_body()
11{
12	geli_test_setup
13
14	sectors=100
15	md=$(attach_md -t malloc -s `expr $sectors + 1`)
16
17	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
18
19	atf_check geli init -B none -P -K keyfile ${md}
20	atf_check geli attach -d -p -k keyfile ${md}
21
22	# Be sure it doesn't detach on read.
23	atf_check dd if=/dev/${md}.eli of=/dev/null status=none
24	sleep 1
25	if [ ! -c /dev/${md}.eli ]; then
26		atf_fail "Detached on last close of a reader"
27	fi
28
29	# It should detach on last close of a writer
30	true > /dev/${md}.eli
31	sleep 1
32	if [ -c /dev/${md}.eli ]; then
33		atf_fail "Did not detach on last close of a writer"
34	fi
35
36}
37attach_d_cleanup()
38{
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	geli_test_setup
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	geli_test_cleanup
68}
69
70atf_test_case attach_multiple cleanup
71attach_multiple_head()
72{
73	atf_set "descr" "geli attach can attach multiple providers"
74	atf_set "require.user" "root"
75}
76attach_multiple_body()
77{
78	geli_test_setup
79
80	sectors=100
81	md0=$(attach_md -t malloc -s `expr $sectors + 1`)
82	md1=$(attach_md -t malloc -s `expr $sectors + 1`)
83	md2=$(attach_md -t malloc -s `expr $sectors + 1`)
84	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
85
86	atf_check geli init -B none -P -K keyfile ${md0}
87	atf_check geli init -B none -P -K keyfile ${md1}
88	atf_check geli init -B none -P -K keyfile ${md2}
89	atf_check geli attach -p -k keyfile ${md0} ${md1} ${md2}
90	# verify that it did create all 3 geli devices
91	atf_check -s exit:0 test -c /dev/${md0}.eli
92	atf_check -s exit:0 test -c /dev/${md1}.eli
93	atf_check -s exit:0 test -c /dev/${md2}.eli
94}
95attach_multiple_cleanup()
96{
97	geli_test_cleanup
98}
99
100atf_test_case nokey cleanup
101nokey_head()
102{
103	atf_set "descr" "geli attach fails if called with no key component"
104	atf_set "require.user" "root"
105}
106nokey_body()
107{
108	geli_test_setup
109
110	sectors=100
111	md=$(attach_md -t malloc -s `expr $sectors + 1`)
112	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
113
114	atf_check geli init -B none -P -K keyfile ${md}
115	atf_check -s not-exit:0 -e match:"No key components given" \
116		geli attach -p ${md} 2>/dev/null
117}
118nokey_cleanup()
119{
120	geli_test_cleanup
121}
122
123atf_init_test_cases()
124{
125	atf_add_test_case attach_d
126	atf_add_test_case attach_r
127	atf_add_test_case attach_multiple
128	atf_add_test_case nokey
129}
130