3 [ -f testing.sh ] && . testing.sh
5 #testing "name" "command" "result" "infile" "stdin"
7 if [ "$(id -u)" -ne 0 ]
9 echo "$SHOWSKIP: chgrp (not root)"
19 _t="abcdefghijklmnopqrstuvwxyz"
21 testing "[-/+]i FILE[write]" "$IN && echo "$_t" > testFile &&
22 chattr +i testFile && lsattr testFile && echo "$_t" > testFile;
23 chattr -i testFile; rm -rf testFile; $OUT " "----i-------- testFile\n" "" ""
24 testing "[-/+]i FILE[re-write]" "$IN && echo "$_t" > testFile &&
25 chattr +i testFile && echo \"$_t\" > testFile || chattr -i testFile &&
26 echo \"$_t\" > testFile && lsattr testFile; rm -rf testFile; $OUT" \
27 "------------- testFile\n" "" ""
28 testing "[-/+]i FILE[append]" "$IN && echo "$_t" > testFile &&
29 chattr +i testFile && echo \"$_t\" >> testFile || lsattr testFile &&
30 chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
31 testing "[-/+]i FILE[move]" "$IN && echo "$_t" > testFile &&
32 chattr +i testFile && mv testFile testFile1 || lsattr testFile &&
33 chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
34 testing "[-/+]i FILE[delete]" "$IN && echo "$_t" > testFile &&
35 chattr +i testFile && rm -f testFile || lsattr testFile &&
36 chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
37 testing "[-/+]i FILE[read]" "$IN && echo "$_t" > testFile &&
38 chattr +i testFile && cat testFile && lsattr testFile &&
39 chattr -i testFile; rm -rf testFile; $OUT" "$_t\n----i-------- testFile\n" "" ""
40 testing "[-/+]a FILE[write]" "$IN && echo "$_t" > testFile &&
41 chattr +a testFile && echo $_t > testFile || lsattr testFile &&
42 chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
43 testing "[-/+]a FILE[re-write]" "$IN && echo "$_t" > testFile &&
44 chattr +a testFile && echo $_t > testFile || lsattr testFile &&
45 chattr -a testFile && echo $_t > testFile && cat testFile &&
46 lsattr testFile; rm -rf testFile;
47 $OUT" "-----a------- testFile\n$_t\n------------- testFile\n" "" ""
48 testing "[-/+]a FILE[append]" "$IN && echo "$_t" > testFile &&
49 chattr +a testFile && echo $_t >> testFile && cat testFile &&
50 lsattr testFile && chattr -a testFile; rm -rf testFile; $OUT" \
51 "$_t\n$_t\n-----a------- testFile\n" "" ""
52 testing "[-/+]a FILE[move]" "$IN && echo "$_t" > testFile &&
53 chattr +a testFile && mv testFile testFile1 || lsattr testFile &&
54 chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
55 testing "[-/+]a FILE[delete]" "$IN && echo "$_t" > testFile &&
56 chattr +a testFile && rm -f testFile || lsattr testFile &&
57 chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
58 testing "[-/+]a FILE[read]" "$IN && echo "$_t" > testFile &&
59 chattr +a testFile && cat testFile && lsattr testFile && chattr -a testFile;
60 rm -rf testFile; $OUT" "$_t\n-----a------- testFile\n" "" ""
62 for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u"
64 testing "[-/+]$attr FILE" "$IN && echo "$_t" > testFile &&
65 chattr +$attr testFile && cat testFile && chattr -$attr testFile &&
66 lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
69 for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u"
71 testing "-$attr FILE" "$IN && echo "$_t" > testFile && chattr -$attr testFile &&
72 cat testFile && lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
75 testing "[-/+]AacDdijsStTu FILE" "$IN && echo "$_t" > testFile &&
76 chattr +AacDdijsStTu testFile && cat testFile && chattr -AacDdijsStTu testFile &&
77 lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
78 testing "[-/+]AacDdijsStTu(random) FILE" \
79 "$IN && echo "$_t" > testFile &&
80 chattr +AacDdijsStTu testFile && cat testFile && chattr -A testFile &&
81 chattr -a testFile && chattr -c testFile && chattr -D testFile &&
82 chattr -d testFile && chattr -i testFile && chattr -j testFile &&
83 chattr -s testFile && chattr -S testFile && chattr -t testFile &&
84 chattr -T testFile && chattr -u testFile && lsattr testFile &&
85 chattr -AacDdijsStTu testFile; rm -rf testFile; $OUT" \
86 "$_t\n------------- testFile\n" "" ""
87 testing "[-/+]AacDdijsStTu FILE*" "$IN &&
88 echo "$_t" > testFile && echo "$_t" > testFile1 &&
89 echo "$_t" > testFile2 && echo "$_t" > testFile3 &&
90 echo "$_t" > testFile4 && echo "$_t" > testFile5 &&
91 echo "$_t" > testFile6 && echo "$_t" > testFile7 &&
92 echo "$_t" > testFile8 && echo "$_t" > testFile9 &&
93 echo "$_t" > testFile10 && echo "$_t" > testFile11 &&
94 chattr +AacDdijsStTu testFile* &&
95 cat testFile9 && chattr -AacDdijsStTu testFile* && lsattr testFile*; rm -rf testFile*; $OUT" \
96 "$_t\n------------- testFile\n------------- testFile1\n------------- testFile10\n------------- testFile11\n------------- testFile2\n------------- testFile3\n------------- testFile4\n------------- testFile5\n------------- testFile6\n------------- testFile7\n------------- testFile8\n------------- testFile9\n" "" ""
97 testing "[-/+]AacDdijsStTu(random) FILE*" \
98 "$IN && echo "$_t" > testFile &&
99 chattr +AacDdijsStTu testFile* && cat testFile && chattr -A testFile* &&
100 chattr -a testFile* && chattr -c testFile* && chattr -D testFile* &&
101 chattr -d testFile* && chattr -i testFile* && chattr -j testFile* &&
102 chattr -s testFile* && chattr -S testFile* && chattr -t testFile* &&
103 chattr -T testFile* && chattr -u testFile* && lsattr testFile;
104 rm -rf testFile; $OUT" \
105 "$_t\n------------- testFile\n" "" ""
106 testing "[-/+]i FILE[write]" \
107 "$IN && echo "$_t" > testFile &&
108 chattr +i testFile &&
109 echo \"$_t\" > testFile || lsattr testFile && chattr -i testFile;
110 rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
111 testing "[-/+]A FILE[write]" \
112 "$IN && echo "$_t" > testFile && chattr +A testFile &&
113 echo \"$_t\" > testFile && lsattr testFile && chattr -A testFile;
114 rm -rf testFile; $OUT" "-------A----- testFile\n" "" ""
115 testing "[-/+]s FILE[write]" \
116 "$IN && echo "$_t" > testFile && chattr +s testFile &&
117 echo \"$_t\" > testFile && lsattr testFile && chattr -s testFile
118 rm -rf testFile; $OUT" "s------------ testFile\n" "" ""
119 testing "-v version FILE[write]" \
120 "$IN && echo "$_t" > testFile &&
121 chattr -v 1234 testFile && echo \"$_t\" > testFile &&
122 lsattr -v testFile; rm -rf testFile" \
123 " 1234 ------------- testFile\n" "" ""
126 testing "-R [-/+]a FILE" "$IN && touch aa && chattr -R +A aa && lsattr aa &&
127 chattr -R -A aa; rm -rf aa; $OUT" "$_a aa\n" "" ""
128 testing "-R [-/+]a FILE.." "$IN && touch aa bb &&
129 chattr -R +A aa bb && lsattr aa bb &&
130 chattr -R -A aa bb; rm -rf aa bb; $OUT" "$_a aa\n$_a bb\n" "" ""