xref: /freebsd/tests/sys/geom/class/eli/attach_test.sh (revision b9f654b163bce26de79705e77b872427c9f2afa1)
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 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	geli_test_setup
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	geli_test_cleanup
92}
93
94atf_init_test_cases()
95{
96	atf_add_test_case attach_d
97	atf_add_test_case attach_r
98	atf_add_test_case nokey
99}
100