Initial release for Tizen
[platform/upstream/ecryptfs-utils.git] / tests / kernel / lp-509180.sh
1 #!/bin/bash
2 #
3 # lp-509180.sh: Test for https://launchpad.net/bugs/509180
4 # Author: Colin Ian King <colin.king@canonical.com>
5 #
6 # Copyright (C) 2012 Canonical, Ltd.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21
22 test_script_dir=$(dirname $0)
23 rc=1
24 test_dir=""
25
26 . ${test_script_dir}/../lib/etl_funcs.sh
27
28 test_cleanup()
29 {
30         etl_remove_test_dir $test_dir
31         etl_umount
32         etl_lumount
33         etl_unlink_keys
34         exit $rc
35 }
36 trap test_cleanup 0 1 2 3 15
37
38 # This test is mainly for the filename encryption case, but it is also valid for
39 # plaintext filename support
40 etl_add_keys || exit
41 etl_lmount || exit
42 etl_mount_i || exit
43 test_dir=$(etl_create_test_dir) || exit
44
45 # Test method: https://bugs.launchpad.net/ecryptfs/+bug/509180/comments/50
46 # Create 1 byte test file
47 echo "testing 1 2 3" > $test_dir/test_file
48 old_sum=`md5sum $test_dir/test_file | cut -d ' ' -f 1`
49 lower_file=`ls $ETL_MOUNT_SRC/ECRYPTFS*/*`
50
51 # Increment 9th byte so that eCryptfs marker fails validation
52 ${test_script_dir}/lp-509180/test -i $lower_file || exit
53 etl_umount
54
55 etl_mount_i || exit
56 cat $test_dir/test_file &> /dev/null
57 # Decrement 9th byte so that eCryptfs marker passes validation
58 ${test_script_dir}/lp-509180/test -d $lower_file || exit
59 new_sum=`md5sum $test_dir/test_file | cut -d ' ' -f 1`
60
61 # md5sums should be the same
62 if [ $old_sum = $new_sum ]; then
63         rc=0
64 fi
65
66 exit