1
|
#!/usr/bin/bash
|
2
|
|
3
|
doexit() {
|
4
|
if [[ -f test.txt ]]; then
|
5
|
chmod S-cR test.txt
|
6
|
fi
|
7
|
popd;
|
8
|
if [[ "$1" -ne 0 ]]; then
|
9
|
echo "TESTS FAILED"
|
10
|
else
|
11
|
echo "TESTS SUCCEEDED"
|
12
|
fi
|
13
|
exit $1;
|
14
|
}
|
15
|
|
16
|
pushd test-streams
|
17
|
|
18
|
touch test.txt
|
19
|
if [[ ! -f test.txt ]]; then
|
20
|
echo "failed to create test.txt"
|
21
|
doexit 1
|
22
|
fi
|
23
|
|
24
|
echo "write" > test.txt
|
25
|
if [[ "$(cat test.txt)" -ne "write" ]]; then
|
26
|
echo "failed to write to file"
|
27
|
doexit 2
|
28
|
fi
|
29
|
|
30
|
runat test.txt <<EOF
|
31
|
touch stream_rw
|
32
|
if [[ ! -f stream_rw ]]; then
|
33
|
echo "failed to create stream_rw"
|
34
|
exit 3
|
35
|
fi
|
36
|
|
37
|
echo "write" > stream_rw
|
38
|
if [[ "\$(cat stream_rw)" -ne "write" ]]; then
|
39
|
echo "failed to write to stream_rw"
|
40
|
exit 4
|
41
|
fi
|
42
|
|
43
|
exit 0
|
44
|
EOF
|
45
|
|
46
|
if [[ "$?" -ne 0 ]]; then
|
47
|
doexit $?
|
48
|
fi
|
49
|
|
50
|
chmod S+cR test.txt
|
51
|
runat test.txt <<EOF
|
52
|
touch stream_ro
|
53
|
if [[ -f stream_ro ]]; then
|
54
|
echo "created stream on read-only file"
|
55
|
exit 5
|
56
|
fi
|
57
|
|
58
|
echo "modified" > stream_rw
|
59
|
if [[ "\$(cat stream_rw)" -ne "write" ]]; then
|
60
|
echo "modified stream on read-only file"
|
61
|
exit 6
|
62
|
fi
|
63
|
|
64
|
exit 0
|
65
|
EOF
|
66
|
|
67
|
if [[ "$?" -ne 0 ]]; then
|
68
|
doexit $?
|
69
|
fi
|
70
|
|
71
|
echo "write" > test-denied.txt
|
72
|
if [[ "$(cat test-denied.txt)" == "write" ]]; then
|
73
|
echo "wrote to file without permission"
|
74
|
doexit 2
|
75
|
fi
|
76
|
|
77
|
runat test-denied.txt <<EOF
|
78
|
touch stream_ro
|
79
|
if [[ -f stream_ro ]]; then
|
80
|
echo "created stream on no-read file"
|
81
|
exit 5
|
82
|
fi
|
83
|
|
84
|
echo "modified" > stream_rw
|
85
|
if [[ "\$(cat stream_rw)" == "modified" ]]; then
|
86
|
echo "modified stream on no-read file"
|
87
|
exit 6
|
88
|
fi
|
89
|
|
90
|
exit 0
|
91
|
EOF
|
92
|
|
93
|
if [[ "$?" -ne 0 ]]; then
|
94
|
doexit $?
|
95
|
fi
|
96
|
|
97
|
mkdir test-dir
|
98
|
chmod 777 test-dir
|
99
|
|
100
|
touch test-dir/test.txt
|
101
|
if [[ ! -f test.txt ]]; then
|
102
|
echo "failed to create test.txt"
|
103
|
doexit 1
|
104
|
fi
|
105
|
|
106
|
runat testdirstream <<EOF
|
107
|
touch stream2
|
108
|
if [[ ! -f stream2 ]]; then
|
109
|
echo "failed to create stream_rw"
|
110
|
exit 3
|
111
|
fi
|
112
|
|
113
|
echo "write" > stream_rw
|
114
|
if [[ "\$(cat stream_rw)" -ne "write" ]]; then
|
115
|
echo "failed to write to stream_rw"
|
116
|
exit 4
|
117
|
fi
|
118
|
|
119
|
exit 0
|
120
|
EOF
|
121
|
|
122
|
if [[ "$?" -ne 0 ]]; then
|
123
|
doexit $?
|
124
|
fi
|
125
|
|
126
|
touch testdir-denied/test-denied.txt
|
127
|
if [[ -f testdir-denied/test-denied.txt ]]; then
|
128
|
echo "created file without permission"
|
129
|
doexit 2
|
130
|
fi
|
131
|
|
132
|
runat testdir-denied <<EOF
|
133
|
touch stream_ro
|
134
|
if [[ -f stream_ro ]]; then
|
135
|
echo "created stream on no-read dir"
|
136
|
exit 5
|
137
|
fi
|
138
|
|
139
|
echo "modified" > stream_rw
|
140
|
if [[ "\$(cat stream_rw)" -ne "write" ]]; then
|
141
|
echo "modified stream on no-read dir"
|
142
|
exit 6
|
143
|
fi
|
144
|
|
145
|
exit 0
|
146
|
EOF
|
147
|
|
148
|
if [[ "$?" -ne 0 ]]; then
|
149
|
doexit $?
|
150
|
fi
|
151
|
|
152
|
touch newfile.txt:stream
|
153
|
if [[ ! -f newfile.txt ]]; then
|
154
|
echo "failed to create newfile.txt:stream"
|
155
|
doexit 7
|
156
|
fi
|
157
|
|
158
|
runat newfile.txt <<EOF
|
159
|
if [[ ! -f stream ]]; then
|
160
|
echo "created newfile.txt, but failed to create stream"
|
161
|
exit 8
|
162
|
fi
|
163
|
exit 0
|
164
|
EOF
|
165
|
|
166
|
if [[ "$?" -ne 0 ]]; then
|
167
|
doexit $?
|
168
|
fi
|
169
|
|
170
|
touch testdir-denied/newfile.txt:stream
|
171
|
if [[ -f testdir-denied/newfile.txt ]]; then
|
172
|
echo "created newfile.txt:stream in no-read dir"
|
173
|
doexit 7
|
174
|
fi
|
175
|
|
176
|
doexit 0
|