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