common/encrypt: add helper function for filtering no-key names
[xfstests-dev.git] / tests / generic / 419
index 0abbac90ea7aa6a1bf76f3703aea099529feabe0..6be7865ccce313ad4bf68b746736516514f0868c 100755 (executable)
 #      173b8439e1ba ("ext4: don't allow encrypted operations without keys")
 #      363fa4e078cb ("f2fs: don't allow encrypted operations without keys")
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. ./common/preamble
+_begin_fstest auto quick encrypt
 
-here=`pwd`
-tmp=/tmp/$$
-status=1       # failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-       cd /
-       rm -f $tmp.*
-}
-
-# get standard environment, filters and checks
-. ./common/rc
+# Import common functions.
 . ./common/filter
 . ./common/encrypt
 . ./common/renameat2
 
-# remove previous $seqres.full before test
-rm -f $seqres.full
-
 # real QA test starts here
 _supported_fs generic
-_supported_os Linux
 _require_scratch_encryption
 _require_command "$KEYCTL_PROG" keyctl
 _require_renameat2 exchange
@@ -47,19 +30,19 @@ _scratch_mkfs_encrypted &>> $seqres.full
 _scratch_mount
 
 mkdir $SCRATCH_MNT/edir
-keydesc=$(_generate_encryption_key)
+keydesc=$(_generate_session_encryption_key)
 _set_encpolicy $SCRATCH_MNT/edir $keydesc
 echo a > $SCRATCH_MNT/edir/a
 echo b > $SCRATCH_MNT/edir/b
-_unlink_encryption_key $keydesc
+_unlink_session_encryption_key $keydesc
 _scratch_cycle_mount
 
-# Note that because encrypted filenames are unpredictable, this needs to be
-# written in a way that does not assume any particular filenames.
+# Note that because no-key filenames are unpredictable, this needs to be written
+# in a way that does not assume any particular filenames.
 efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
 efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
-mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
-src/renameat2 -x $efile1 $efile2
+mv $efile1 $efile2 |& _filter_scratch | _filter_nokey_filenames edir
+$here/src/renameat2 -x $efile1 $efile2
 
 # success, all done
 status=0