summaryrefslogtreecommitdiffstats
path: root/generate-testcases.sh
blob: 6bf14648cb7123c3ce930990e8f19a8209736c2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash

# This is a script to generate "awkward" files and directories as test cases,
# to check that exa can actually handle them: symlinks that point at
# themselves, directories that you aren't allowed to view, files with strange
# extended attributes, that sort of thing.

## -- configuration --

# Directory that the files should be generated in.
DIR=testcases

if [[ -e "$DIR" ]]
then
    echo "'$DIR' already exists - aborting" >&2
    exit 2
fi

# You! Yes, you, the name of the user running this script.
YOU=`whoami`

# Someone with *higher* privileges than yourself, such as root.
ROOT=root

# A UID that doesn't map to any user on the system.
INVALID_UID=666

# A GID that doesn't map to any group on the system.
INVALID_GID=616

# List commands as they are run
# set -x

# Abort on any error!
abort() { echo 'Hit an error - aborting' >&2; exit 1; }
trap 'abort' ERR

# Get confirmation from the user before running.

# echo "This script will generate files into the $DIR directory."
# echo "It requires sudo for the '$ROOT' user."
# echo "You probably want to edit this file before running it."
# read -r -p "Continue? [y/N] " response
# if [[ ! $response =~ ^([yY][eE][sS]|[yY])$ ]]
# then
#     exit 2
# fi

mkdir "$DIR"


## -- links --

mkdir "$DIR/links"
ln -s / "$DIR/links/root"
ln -s /usr "$DIR/links/usr"
ln -s nowhere "$DIR/links/broken"


## -- users and groups --

mkdir "$DIR/passwd"

# sudo is needed for these because we technically aren't a member of the
# groups (because they don't exist), and chown and chgrp are smart enough to
# disallow it!

touch "$DIR/passwd/unknown-uid"
sudo -u "$ROOT" chown $INVALID_UID "$DIR/passwd/unknown-uid"

touch "$DIR/passwd/unknown-gid"
sudo -u "$ROOT" chgrp $INVALID_GID "$DIR/passwd/unknown-gid"


## -- permissions --

mkdir "$DIR/permissions"

touch "$DIR/permissions/all-permissions"
chmod 777 "$DIR/permissions/all-permissions"

touch "$DIR/permissions/no-permissions"
chmod 000 "$DIR/permissions/no-permissions"

mkdir "$DIR/permissions/forbidden-directory"
chmod 000 "$DIR/permissions/forbidden-directory"


## -- extended attributes --

mkdir "$DIR/attributes"

touch "$DIR/attributes/none"

touch "$DIR/attributes/one"
xattr -w greeting hello "$DIR/attributes/one"

touch "$DIR/attributes/two"
xattr -w greeting hello "$DIR/attributes/two"
xattr -w another_greeting hi "$DIR/attributes/two"

touch "$DIR/attributes/forbidden"
xattr -w greeting hello "$DIR/attributes/forbidden"
chmod +a "$YOU deny readextattr" "$DIR/attributes/forbidden"

mkdir "$DIR/attributes/dirs"

mkdir "$DIR/attributes/dirs/empty-with-attribute"
xattr -w greeting hello "$DIR/attributes/dirs/empty-with-attribute"

mkdir "$DIR/attributes/dirs/full-with-attribute"
touch "$DIR/attributes/dirs/full-with-attribute/file"
xattr -w greeting hello "$DIR/attributes/dirs/full-with-attribute"

mkdir "$DIR/attributes/dirs/full-but-forbidden"
touch "$DIR/attributes/dirs/full-but-forbidden/file"
xattr -w greeting hello "$DIR/attributes/dirs/full-but-forbidden"
chmod 000 "$DIR/attributes/dirs/full-but-forbidden"
chmod +a "$YOU deny readextattr" "$DIR/attributes/dirs/full-but-forbidden"