chiark / gitweb /
added test case for common.isApkDebuggable()
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e # quit script on error
4 set -x # show each command as it is executed
5
6 echo_header() {
7     echo "=============================================================================="
8     echo $1
9 }
10
11 copy_apks_into_repo() {
12     set +x
13     for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned -e badsig -e badcert`; do
14         name=$(basename $(dirname `dirname $f`))
15         apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
16         test $f -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
17         if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
18             echo "$f --> repo/$apk"
19             ln $f $1/repo/$apk || \
20                 rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
21         fi
22     done
23     set -x
24 }
25
26 # keep this as an old version to test the automatic parsing of build-tools
27 # verion numbers in `fdroid init`
28 create_fake_android_home() {
29     mkdir $1/tools
30     mkdir $1/platform-tools
31     mkdir $1/build-tools
32     mkdir $1/build-tools/19.0.2
33     touch $1/build-tools/19.0.2/aapt
34 }
35
36 create_test_dir() {
37     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
38     mktemp --directory --tmpdir=$WORKSPACE/.testfiles
39 }
40
41 create_test_file() {
42     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
43     mktemp --tmpdir=$WORKSPACE/.testfiles
44 }
45
46 #------------------------------------------------------------------------------#
47 # "main"
48
49 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
50     set +x
51     echo "Usage: $0 '/path/to/folder/with/apks'"
52     exit 1
53 fi
54
55 if [ -z "$ANDROID_HOME" ]; then
56     echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
57     echo "  export ANDROID_HOME=/opt/android-sdk"
58     exit 1
59 fi
60
61 if [ -z "$1" ]; then
62     APKDIR=`pwd`
63 else
64     APKDIR=$1
65 fi
66
67 if [ -z $WORKSPACE ]; then
68     WORKSPACE=`dirname $(pwd)`
69     echo "Setting Workspace to $WORKSPACE"
70 fi
71
72 # allow the location of the script to be overridden
73 if [ -z $fdroid ]; then
74     fdroid="$WORKSPACE/fdroid"
75 fi
76
77 # allow the location of aapt to be overridden
78 if [ -z $aapt ]; then
79     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
80 fi
81
82 # allow the location of python to be overridden
83 if [ -z $python ]; then
84     python=python2
85 fi
86
87
88 #------------------------------------------------------------------------------#
89 echo_header "run commit hooks"
90
91 cd $WORKSPACE
92 ./hooks/pre-commit
93
94
95 #------------------------------------------------------------------------------#
96 echo_header "test python getsig replacement"
97
98 cd $WORKSPACE/tests/getsig
99 ./make.sh
100 cd $WORKSPACE/tests
101 ./common.TestCase
102 ./update.TestCase
103
104
105 #------------------------------------------------------------------------------#
106 echo_header "create a source tarball and use that to build a repo"
107
108 cd $WORKSPACE
109 $python setup.py sdist
110
111 REPOROOT=`create_test_dir`
112 cd $REPOROOT
113 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
114 cd $REPOROOT
115 ./fdroidserver-*/fdroid init
116 copy_apks_into_repo $REPOROOT
117 ./fdroidserver-*/fdroid update --create-metadata
118
119
120 #------------------------------------------------------------------------------#
121 echo_header "test config checks of local_copy_dir"
122
123 REPOROOT=`create_test_dir`
124 cd $REPOROOT
125 $fdroid init
126 $fdroid update --create-metadata
127 $fdroid server update --local-copy-dir=/tmp/fdroid
128
129 # now test the errors work
130 set +e
131 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
132 if [ $? -eq 0 ]; then
133     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
134     exit 1
135 else
136     echo "testing absolute path checker passed"
137 fi
138 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
139 if [ $? -eq 0 ]; then
140     echo "This should have failed because the path does not end with 'fdroid'!"
141     exit 1
142 else
143     echo "testing dirname exists checker passed"
144 fi
145 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
146 if [ $? -eq 0 ]; then
147     echo "This should have failed because the dirname path does not exist!"
148     exit 1
149 else
150     echo "testing dirname exists checker passed"
151 fi
152 set -e
153
154
155 #------------------------------------------------------------------------------#
156 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
157
158 REPOROOT=`create_test_dir`
159 cd $REPOROOT
160 $fdroid init
161 copy_apks_into_repo $REPOROOT
162 $fdroid update --create-metadata
163 grep -F '<application id=' repo/index.xml
164
165 LOCALCOPYDIR=`create_test_dir`/fdroid
166 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
167 NEWREPOROOT=`create_test_dir`
168 cd $NEWREPOROOT
169 $fdroid init
170 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
171
172
173 #------------------------------------------------------------------------------#
174 # check that --android-home fails when dir does not exist or is not a dir
175
176 REPOROOT=`create_test_dir`
177 KEYSTORE=$REPOROOT/keystore.jks
178 cd $REPOROOT
179 set +e
180 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
181 if [ $? -eq 0 ]; then
182     echo "This should have failed because /opt/fakeandroidhome does not exist!"
183     exit 1
184 else
185     echo "testing android-home path checker passed"
186 fi
187 TESTFILE=`create_test_file`
188 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
189 if [ $? -eq 0 ]; then
190     echo "This should have failed because $TESTFILE is a file not a dir!"
191     exit 1
192 else
193     echo "testing android-home not-dir checker passed"
194 fi
195 set -e
196
197
198 #------------------------------------------------------------------------------#
199 echo_header "check that fake android home passes 'fdroid init'"
200
201 REPOROOT=`create_test_dir`
202 FAKE_ANDROID_HOME=`create_test_dir`
203 create_fake_android_home $FAKE_ANDROID_HOME
204 KEYSTORE=$REPOROOT/keystore.jks
205 cd $REPOROOT
206 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
207
208
209 #------------------------------------------------------------------------------#
210 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
211
212 REPOROOT=`create_test_dir`
213 FAKE_ANDROID_HOME=`create_test_dir`
214 create_fake_android_home $FAKE_ANDROID_HOME
215 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
216 KEYSTORE=$REPOROOT/keystore.jks
217 cd $REPOROOT
218 set +e
219 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
220 [ $? -eq 0 ] && exit 1
221 set -e
222
223
224 #------------------------------------------------------------------------------#
225 echo_header "check that --android-home overrides ANDROID_HOME"
226
227 REPOROOT=`create_test_dir`
228 FAKE_ANDROID_HOME=`create_test_dir`
229 create_fake_android_home $FAKE_ANDROID_HOME
230 KEYSTORE=$REPOROOT/keystore.jks
231 cd $REPOROOT
232 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
233 set +e
234 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
235 if [ $? -ne 0 ]; then
236     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
237     exit 1
238 fi
239 set -e
240
241
242 #------------------------------------------------------------------------------#
243 # In this case, ANDROID_HOME is set to a fake, non-working version that will
244 # be detected by fdroid as an Android SDK install.  It should use the path set
245 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
246 # in ANDROID_HOME, it won't work because it is a fake one.  Only
247 # --android-home provides a working one.
248 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
249
250 REPOROOT=`create_test_dir`
251 KEYSTORE=$REPOROOT/keystore.jks
252 FAKE_ANDROID_HOME=`create_test_dir`
253 create_fake_android_home $FAKE_ANDROID_HOME
254 STORED_ANDROID_HOME=$ANDROID_HOME
255 unset ANDROID_HOME
256 echo "ANDROID_HOME: $ANDROID_HOME"
257 cd $REPOROOT
258 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
259 test -e $KEYSTORE
260 copy_apks_into_repo $REPOROOT
261 $fdroid update --create-metadata
262 grep -F '<application id=' repo/index.xml
263 test -e repo/index.xml
264 test -e repo/index.jar
265 export ANDROID_HOME=$STORED_ANDROID_HOME
266
267
268 #------------------------------------------------------------------------------#
269 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
270
271 REPOROOT=`create_test_dir`
272 cd $REPOROOT
273 mkdir repo
274 copy_apks_into_repo $REPOROOT
275 $fdroid init
276 $fdroid update --create-metadata
277 grep -F '<application id=' repo/index.xml
278
279
280 #------------------------------------------------------------------------------#
281 echo_header "setup a new repo from scratch and generate a keystore"
282
283 REPOROOT=`create_test_dir`
284 KEYSTORE=$REPOROOT/keystore.jks
285 cd $REPOROOT
286 $fdroid init --keystore $KEYSTORE
287 test -e $KEYSTORE
288 copy_apks_into_repo $REPOROOT
289 $fdroid update --create-metadata
290 test -e repo/index.xml
291 test -e repo/index.jar
292 grep -F '<application id=' repo/index.xml
293
294
295 #------------------------------------------------------------------------------#
296 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
297
298 REPOROOT=`create_test_dir`
299 KEYSTORE=$REPOROOT/keystore.jks
300 cd $REPOROOT
301 $fdroid init --keystore $KEYSTORE
302 test -e $KEYSTORE
303 copy_apks_into_repo $REPOROOT
304 $fdroid update --create-metadata
305 test -e repo/index.xml
306 test -e repo/index.jar
307 grep -F '<application id=' repo/index.xml
308 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
309 $fdroid update --create-metadata
310 test -e repo/index.xml
311 test -e repo/index.jar
312 grep -F '<application id=' repo/index.xml
313
314
315 #------------------------------------------------------------------------------#
316 echo_header "setup a new repo from scratch with a HSM/smartcard"
317
318 REPOROOT=`create_test_dir`
319 cd $REPOROOT
320 $fdroid init --keystore NONE
321 test -e opensc-fdroid.cfg
322 test ! -e NONE
323
324 rm -rf $WORKSPACE/fdroidserver.egg-info/
325
326 echo SUCCESS