This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathcheck_resolver.sh
executable file
·271 lines (214 loc) · 7.29 KB
/
check_resolver.sh
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/sh
@INCLUDE_COMMON@
echo
echo ELEKTRA CHECK RESOLVER
echo
# Adds the specified namespace to a key name if the key does not have one.
# If the key already has a namespace, the namespace remains unchanged.
# The result is printed to stdout.
# $1 ... namespace
# $2 ... key name
prepend_namespace_if_not_present() {
local present_namespace=$("$KDB" namespace "$2")
if [ -z "$present_namespace" ]; then
echo "$1":"$2"
else
echo "$2"
fi
}
#set tmp path (mainly for macOS compatibility)
TMPPATH=$(
cd /tmp || exit
pwd -P
)
#checks if resolver can be mounted and also partly checks if it resolves
#correctly (more tests welcome).
check_version
if is_plugin_available dump && is_plugin_available sync; then
echo "dump and sync available"
else
echo "dump or sync not available, skipping tests"
nbSkip=$((nbSkip + 100))
exit 0
fi
#enable with care: might remove more (empty) directories than it created
#root access required, writes into various paths (they are listed,
#even if WRITE_TO_SYSTEM is deactivated)
#WRITE_TO_SYSTEM=YES
WRITE_TO_SYSTEM=NO
ROOT_MOUNTPOINT=/test/script
#method that does all the checking
check_resolver() {
if [ "$1" = "user" ]; then
PLUGIN=$(echo "$PLUGINS_NEWLINES" | grep -m 1 "resolver_.*_$2.*_.*")
else
PLUGIN=$(echo "$PLUGINS_NEWLINES" | grep -m 1 "resolver_.*_.*_$2.*")
fi
if [ "$2" = "w" ]; then
if is_plugin_available wresolver; then
PLUGIN=wresolver
else
PLUGIN=""
fi
fi
if [ -z "$PLUGIN" ]; then
nbSkip=$((nbSkip + 1))
echo "skipping test because plugin variant $2 is missing, for $2 with $3"
return
fi
MOUNTPOINT=$1:$ROOT_MOUNTPOINT
"$KDB" mount --resolver "$PLUGIN" "$3" "$MOUNTPOINT" dump 1> /dev/null
succeed_if "could not mount root using: ""$KDB"" mount --resolver $PLUGIN $3 $MOUNTPOINT dump"
FILE=$("$KDB" file -n $(prepend_namespace_if_not_present "$1" $ROOT_MOUNTPOINT) 2> /dev/null)
echo "For $1 $2 $3 we got $FILE"
[ "x$FILE" = "x$4" ]
succeed_if "resolving of $MOUNTPOINT did not yield $4 but $FILE"
if [ "x$WRITE_TO_SYSTEM" = "xYES" ]; then
KEY=$ROOT_MOUNTPOINT/key
"$KDB" set $(prepend_namespace_if_not_present "$1" $KEY) value
succeed_if "could not set $KEY"
echo "remove $FILE and its directories"
rm "$FILE"
succeed_if "could not remove $FILE"
dirname "$FILE"
rmdir -p --ignore-fail-on-non-empty $(dirname "$FILE")
fi
"$KDB" umount "$MOUNTPOINT" > /dev/null
succeed_if "could not umount $MOUNTPOINT"
}
# need HOME to work
unset USER
# HOME on buildserver wrong...
#check_resolver system b '~/FOO' ~/FOO
#check_resolver system b '~/x' ~/x
#check_resolver system b '~/x/y' ~/x/y
#check_resolver system b '~//x' ~//x
#check_resolver system b '~/' ~/
#check_resolver system b '~' ~/
#
#check_resolver spec b '~/x' ~/x
#check_resolver spec b '~/x/y' ~/x/y
#check_resolver spec b '~//x' ~//x
#check_resolver spec b '~/' ~/
#check_resolver spec b '~' ~/
unset HOME
unset USER
if echo "@KDB_DEFAULT_RESOLVER@" | grep "resolver_.*_.*_x.*"; then
echo "skipping tests where XDG_CONFIG_DIRS is manipulated, because default resolver itself would use those paths"
nbSkip=$((nbSkip + 10))
else
unset XDG_CONFIG_DIRS
unset XDG_CONFIG_HOME
check_resolver system x app/config_file /etc/xdg/app/config_file
export XDG_CONFIG_DIRS="/xdg_dir"
check_resolver system x app/config_file /xdg_dir/app/config_file
export XDG_CONFIG_DIRS="/xdg_dir1:/xdg_dir2:/xdg_dir3"
check_resolver system x app/config_file /xdg_dir3/app/config_file
unset XDG_CONFIG_DIRS
export XDG_CONFIG_HOME="/xdg_dir1"
check_resolver system x app/config_file /etc/xdg/app/config_file
check_resolver user x app/config_file /xdg_dir1/app/config_file
export XDG_CONFIG_HOME="broken"
check_resolver system x app/config_file /etc/xdg/app/config_file
export XDG_CONFIG_HOME="(broken)"
check_resolver system x app/config_file /etc/xdg/app/config_file
export XDG_CONFIG_HOME="(even):(more):(broken):"
check_resolver system x app/config_file /etc/xdg/app/config_file
export XDG_CONFIG_HOME=""
check_resolver system x app/config_file /etc/xdg/app/config_file
unset XDG_CONFIG_HOME
check_resolver system x app/config_file /etc/xdg/app/config_file
OD=$(pwd)
cd "$TMPPATH" || exit # hopefully no @KDB_DB_DIR@ is in $TMPPATH
check_resolver dir x /a "$TMPPATH"/a
check_resolver dir x /a/b "$TMPPATH"/a/b
check_resolver dir x a "$TMPPATH/@KDB_DB_DIR@/a"
check_resolver dir x a/b "$TMPPATH/@KDB_DB_DIR@/a/b"
cd "$OD" || exit
fi # end of XDG tests
# FIXME [new_backend]: tests disabled, wresolver not working properly
# export ALLUSERSPROFILE="/C"
# check_resolver spec w /app/config_file /C/app/config_file
# check_resolver spec w app/config_file "/C@KDB_DB_SPEC@/app/config_file"
# check_resolver system w /app/config_file /C/app/config_file
# check_resolver system w app/config_file "/C@KDB_DB_SYSTEM@/app/config_file"
# unset ALLUSERSPROFILE
#
# export HOME="/D"
# check_resolver user w /app/config_file /D//app/config_file
# check_resolver user w app/config_file /D/app/config_file #@KDB_DB_USER@ not impl
# unset HOME
#
# OD="$(pwd)"
# cd $TMPPATH # hopefully no @KDB_DB_DIR@ is in $TMPPATH
# check_resolver dir w /a $TMPPATH//a
# check_resolver dir w /a/b $TMPPATH//a/b
# check_resolver dir w a $TMPPATH/a #@KDB_DB_DIR@ not impl
# check_resolver dir w a/b $TMPPATH/a/b #@KDB_DB_DIR@ not impl
# cd "$OD"
# resolve ~ in paths
SYSTEM_DIR="$(echo @KDB_DB_SYSTEM@)"
SPEC_DIR="$(echo @KDB_DB_SPEC@)"
check_resolver system b x "$SYSTEM_DIR/x"
check_resolver system b x/a "$SYSTEM_DIR/x/a"
check_resolver system b /a /a
check_resolver system b /a/b/c /a/b/c
check_resolver spec b x "$SPEC_DIR/x"
check_resolver spec b x/a "$SPEC_DIR/x/a"
check_resolver spec b /x /x
check_resolver spec b /x/a /x/a
check_resolver user b x "@KDB_DB_HOME@/@KDB_DB_USER@/x"
check_resolver user b x/a "@KDB_DB_HOME@/@KDB_DB_USER@/x/a"
check_resolver user b /a "@KDB_DB_HOME@/a"
# empty env must have no influence
export HOME=""
export USER=""
check_resolver system b x "$SYSTEM_DIR/x"
check_resolver system b x/a "$SYSTEM_DIR/x/a"
check_resolver system b /a /a
check_resolver system b /a/b/c /a/b/c
check_resolver spec b x "$SPEC_DIR/x"
check_resolver spec b x/a "$SPEC_DIR/x/a"
check_resolver spec b /x /x
check_resolver spec b /x/a /x/a
check_resolver user b x "@KDB_DB_HOME@/@KDB_DB_USER@/x"
check_resolver user b x/a "@KDB_DB_HOME@/@KDB_DB_USER@/x/a"
check_resolver user b /a "@KDB_DB_HOME@/a"
OD=$(pwd)
cd "$TMPPATH" || exit # hopefully no @KDB_DB_DIR@ is in $TMPPATH
check_resolver dir b /a "$TMPPATH/a"
check_resolver dir b /a/b "$TMPPATH/a/b"
check_resolver dir b a "$TMPPATH/@KDB_DB_DIR@/a"
check_resolver dir b a/b "$TMPPATH/@KDB_DB_DIR@/a/b"
T="$(
cd $(mktempdir_elektra) || exit
pwd -P
)"
cleanup() {
rm -rf "$T"
}
cd "$T" || exit
check_resolver dir b /a "$T"/a
check_resolver dir b /a/b "$T"/a/b
check_resolver dir b a "$T/@KDB_DB_DIR@/a"
check_resolver dir b a/b "$T/@KDB_DB_DIR@/a/b"
mkdir "$T"/sub
cd "$T"/sub || exit
touch "$T"/a
check_resolver dir b /a "$T"/a
check_resolver dir b /a/b "$T"/sub/a/b
rm "$T"/a
mkdir "$T/@KDB_DB_DIR@"
touch "$T/@KDB_DB_DIR@/a"
check_resolver dir b a "$T/@KDB_DB_DIR@/a"
check_resolver dir b a/b "$T/sub/@KDB_DB_DIR@/a/b"
rm "$T/@KDB_DB_DIR@/a"
cd "$OD" || exit
unset HOME
unset USER
export HOME=/nowhere/below
check_resolver user h x "$HOME/@KDB_DB_USER@/x"
unset HOME
export USER=markus/somewhere/test
check_resolver user u abc "@KDB_DB_HOME@/$USER/@KDB_DB_USER@/abc"
end_script resolver