cb55a5bbf705a9866189d0c95c45744520f0a1f7
[xfstests-dev.git] / tests / generic / 419
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test generic/419
6 #
7 # Try to rename files in an encrypted directory, without access to the
8 # encryption key.  This should fail with ENOKEY.  Test both a regular rename and
9 # a cross rename.  This is a regression test for:
10 #       173b8439e1ba ("ext4: don't allow encrypted operations without keys")
11 #       363fa4e078cb ("f2fs: don't allow encrypted operations without keys")
12 #
13 . ./common/preamble
14 _begin_fstest auto quick encrypt
15
16 # Import common functions.
17 . ./common/filter
18 . ./common/encrypt
19 . ./common/renameat2
20
21 # real QA test starts here
22 _supported_fs generic
23 _require_scratch_encryption
24 _require_command "$KEYCTL_PROG" keyctl
25 _require_renameat2 exchange
26
27 _new_session_keyring
28
29 _scratch_mkfs_encrypted &>> $seqres.full
30 _scratch_mount
31
32 mkdir $SCRATCH_MNT/edir
33 keydesc=$(_generate_session_encryption_key)
34 _set_encpolicy $SCRATCH_MNT/edir $keydesc
35 echo a > $SCRATCH_MNT/edir/a
36 echo b > $SCRATCH_MNT/edir/b
37 _unlink_session_encryption_key $keydesc
38 _scratch_cycle_mount
39
40 # Note that because encrypted filenames are unpredictable, this needs to be
41 # written in a way that does not assume any particular filenames.
42 efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
43 efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
44 mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
45 $here/src/renameat2 -x $efile1 $efile2
46
47 # success, all done
48 status=0
49 exit