generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 454
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 454
6 #
7 # Create xattrs with multiple keys that all appear the same
8 # (in unicode, anyway) but point to different values.  In theory all
9 # Linux filesystems should allow this (filenames are a sequence of
10 # arbitrary bytes) even if the user implications are horrifying.
11 #
12 seq=`basename "$0"`
13 seqres="$RESULT_DIR/$seq"
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/attr
29
30 _supported_os Linux
31 _require_scratch
32 _require_attrs
33
34 echo "Format and mount"
35 _scratch_mkfs > $seqres.full 2>&1
36 _scratch_mount >> $seqres.full 2>&1
37
38 testdir="${SCRATCH_MNT}/test-${seq}"
39 mkdir $testdir
40 testfile="${testdir}/attrfile"
41 touch "${testfile}"
42
43 hexbytes() {
44         echo -n "$1" | od -tx1 -w99999 | head -n1 | sed -e 's/^0* //g'
45 }
46
47 setf() {
48         key="$(echo -e "$1")"
49         value="$2"
50
51         $SETFATTR_PROG -n "user.${key}" -v "${value}" "${testfile}" > $tmp.output 2>&1
52         if [ $? -ne 0 ]; then
53                 grep -q 'No space left on device' $tmp.output && \
54                         _notrun "ran out of space"
55                 cat $tmp.output
56         fi
57         echo "Storing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
58 }
59
60 testf() {
61         key="$(echo -e "$1")"
62         value="$2"
63
64         echo "Testing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
65
66         actual_value="$(_getfattr --absolute-names --only-values -n "user.${key}" "${testfile}")"
67         if [ "${actual_value}" != "${value}" ]; then
68                 echo "Key ${key} has value ${actual_value}, expected ${value}."
69         fi
70 }
71
72 filter_scrub() {
73         grep 'Unicode' | sed -e 's/^.*Duplicate/Duplicate/g'
74 }
75
76 echo "Create files"
77 # These two render the same
78 setf "french_caf\xc3\xa9.txt" "NFC"
79 setf "french_cafe\xcc\x81.txt" "NFD"
80
81 # These two may have different widths
82 setf "chinese_\xef\xbd\xb6.txt" "NFKC1"
83 setf "chinese_\xe3\x82\xab.txt" "NFKC2"
84
85 # Same point, different byte representations in NFC/NFD/NFKC/NFKD
86 setf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
87 setf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
88 setf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
89 setf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
90
91 # Arabic code point can expand into a muuuch longer series
92 setf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
93 setf "arabic_\xd8\xb5\xd9\x84\xd9\x89\x20\xd8\xa7\xd9\x84\xd9\x84\xd9\x87\x20\xd8\xb9\xd9\x84\xd9\x8a\xd9\x87\x20\xd9\x88\xd8\xb3\xd9\x84\xd9\x85.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFKC"
94
95 # Fake slash?
96 setf "urk\xc0\xafmoo" "FAKESLASH"
97
98 # Emoji: octopus butterfly owl giraffe
99 setf "emoji_\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89\xf0\x9f\xa6\x92.txt" "octopus butterfly owl giraffe emoji"
100
101 # Line draw characters, because why not?
102 setf "\x6c\x69\x6e\x65\x64\x72\x61\x77\x5f\x0a\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x97\x0a\xe2\x95\x91\x20\x6d\x65\x74\x61\x74\x61\x62\x6c\x65\x20\xe2\x95\x91\x0a\xe2\x95\x9f\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x95\xa2\x0a\xe2\x95\x91\x20\x5f\x5f\x69\x6e\x64\x65\x78\x20\x20\x20\xe2\x95\x91\x0a\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\x0a.txt" "ugly box because we can"
103
104 # unicode rtl widgets too...
105 setf "moo\xe2\x80\xaegnp.txt" "Well say hello,"
106 setf "mootxt.png" "Harvey"
107
108 # mixed-script confusables
109 setf "mixed_t\xce\xbfp.txt" "greek omicron instead of o"
110 setf "mixed_top.txt" "greek omicron instead of o"
111
112 # single-script spoofing
113 setf "hyphens_a\xe2\x80\x90b.txt" "hyphens"
114 setf "hyphens_a-b.txt" "hyphens"
115
116 setf "dz_digraph_dze.txt" "d-z digraph"
117 setf "dz_digraph_\xca\xa3e.txt" "d-z digraph"
118
119 # inadequate rendering
120 setf "inadequate_al.txt" "is it l or is it 1"
121 setf "inadequate_a1.txt" "is it l or is it 1"
122
123 # symbols
124 setf "prohibition_Rs.txt" "rupee symbol"
125 setf "prohibition_\xe2\x82\xa8.txt" "rupee symbol"
126
127 # zero width joiners
128 setf "zerojoin_moocow.txt" "zero width joiners"
129 setf "zerojoin_moo\xe2\x80\x8ccow.txt" "zero width joiners"
130
131 # combining marks
132 setf "combmark_\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.txt" "combining marks"
133 setf "combmark_\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.txt" "combining marks"
134
135 _getfattr --absolute-names -d "${testfile}" >> $seqres.full
136
137 echo "Test files"
138 testf "french_caf\xc3\xa9.txt" "NFC"
139 testf "french_cafe\xcc\x81.txt" "NFD"
140
141 testf "chinese_\xef\xbd\xb6.txt" "NFKC1"
142 testf "chinese_\xe3\x82\xab.txt" "NFKC2"
143
144 testf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
145 testf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
146 testf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
147 testf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
148
149 testf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
150 testf "arabic_\xd8\xb5\xd9\x84\xd9\x89\x20\xd8\xa7\xd9\x84\xd9\x84\xd9\x87\x20\xd8\xb9\xd9\x84\xd9\x8a\xd9\x87\x20\xd9\x88\xd8\xb3\xd9\x84\xd9\x85.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFKC"
151
152 testf "urk\xc0\xafmoo" "FAKESLASH"
153
154 testf "emoji_\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89\xf0\x9f\xa6\x92.txt" "octopus butterfly owl giraffe emoji"
155
156 testf "\x6c\x69\x6e\x65\x64\x72\x61\x77\x5f\x0a\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x97\x0a\xe2\x95\x91\x20\x6d\x65\x74\x61\x74\x61\x62\x6c\x65\x20\xe2\x95\x91\x0a\xe2\x95\x9f\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x95\xa2\x0a\xe2\x95\x91\x20\x5f\x5f\x69\x6e\x64\x65\x78\x20\x20\x20\xe2\x95\x91\x0a\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\x0a.txt" "ugly box because we can"
157
158 testf "moo\xe2\x80\xaegnp.txt" "Well say hello,"
159 testf "mootxt.png" "Harvey"
160
161 testf "mixed_t\xce\xbfp.txt" "greek omicron instead of o"
162 testf "mixed_top.txt" "greek omicron instead of o"
163
164 testf "hyphens_a\xe2\x80\x90b.txt" "hyphens"
165 testf "hyphens_a-b.txt" "hyphens"
166
167 testf "dz_digraph_dze.txt" "d-z digraph"
168 testf "dz_digraph_\xca\xa3e.txt" "d-z digraph"
169
170 testf "inadequate_al.txt" "is it l or is it 1"
171 testf "inadequate_a1.txt" "is it l or is it 1"
172
173 testf "prohibition_Rs.txt" "rupee symbol"
174 testf "prohibition_\xe2\x82\xa8.txt" "rupee symbol"
175
176 testf "zerojoin_moocow.txt" "zero width joiners"
177 testf "zerojoin_moo\xe2\x80\x8ccow.txt" "zero width joiners"
178
179 testf "combmark_\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.txt" "combining marks"
180 testf "combmark_\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.txt" "combining marks"
181
182 echo "Uniqueness of keys?"
183 crazy_keys="$(_getfattr --absolute-names -d "${testfile}" | egrep -c '(french_|chinese_|greek_|arabic_|urk)')"
184 expected_keys=11
185 test "${crazy_keys}" -ne "${expected_keys}" && echo "Expected ${expected_keys} keys, saw ${crazy_keys}."
186
187 echo "Test XFS online scrub, if applicable"
188
189 if _check_xfs_scrub_does_unicode "$SCRATCH_MNT" "$SCRATCH_DEV"; then
190         output="$(LC_ALL="C.UTF-8" ${XFS_SCRUB_PROG} -v -n "${SCRATCH_MNT}" 2>&1 | filter_scrub)"
191         echo "${output}" | grep -q "french_" || echo "No complaints about french e accent?"
192         echo "${output}" | grep -q "greek_" || echo "No complaints about greek letter mess?"
193         echo "${output}" | grep -q "arabic_" || echo "No complaints about arabic expanded string?"
194         echo "${output}" | grep -q "mixed_" || echo "No complaints about mixed script confusables?"
195         echo "${output}" | grep -q "hyphens_" || echo "No complaints about hyphenation confusables?"
196         echo "${output}" | grep -q "dz_digraph_" || echo "No complaints about single script confusables?"
197         echo "${output}" | grep -q "inadequate_" || echo "No complaints about inadequate rendering confusables?"
198         echo "${output}" | grep -q "prohibition_" || echo "No complaints about prohibited sequence confusables?"
199         echo "${output}" | grep -q "zerojoin_" || echo "No complaints about zero-width join confusables?"
200         echo "Actual xfs_scrub output:" >> $seqres.full
201         echo "${output}" >> $seqres.full
202 fi
203
204 # success, all done
205 status=0
206 exit