chiark / gitweb /
build: enable watchdog timer for each build that kills in 2 hours
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e # quit script on error
4
5 echo_header() {
6     { echo -e "==============================================================================\n$1"; } 2>/dev/null
7 }
8
9 copy_apks_into_repo() {
10     set +x
11     find $APKDIR -type f -name '*.apk' -print0 | while IFS= read -r -d '' f; do
12         echo $f | grep -F -v -e unaligned -e unsigned -e badsig -e badcert -e bad-unicode -e janus.apk || continue
13         apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
14         test "$f" -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
15         if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
16             echo "$f --> repo/$apk"
17             ln "$f" $1/repo/$apk || \
18                 rsync -axv "$f" $1/repo/$apk # rsync if hard link is not possible
19         fi
20     done
21     set -x
22 }
23
24 # keep this as an old version to test the automatic parsing of build-tools
25 # verion numbers in `fdroid init`
26 create_fake_android_home() {
27     mkdir $1/tools
28     mkdir $1/platform-tools
29     mkdir $1/build-tools
30     mkdir $1/build-tools/19.0.2
31     touch $1/build-tools/19.0.2/aapt
32 }
33
34 create_test_dir() {
35     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
36     mktemp -d $WORKSPACE/.testfiles/run-tests.XXXX
37 }
38
39 create_test_file() {
40     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
41     TMPDIR=$WORKSPACE/.testfiles  mktemp
42 }
43
44 fdroid_init_with_prebuilt_keystore() {
45     if [ -z "$1" ]; then
46         keystore=$WORKSPACE/tests/keystore.jks
47     else
48         keystore="$1"
49     fi
50     $fdroid init --keystore $keystore --repo-keyalias=sova
51     echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
52     echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
53 }
54
55 # the < is reverse since 0 means success in exit codes
56 have_git_2_3() {
57     python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version`
58 }
59
60 is_MD5_disabled() {
61     javac $WORKSPACE/tests/IsMD5Disabled.java && java -cp $WORKSPACE/tests IsMD5Disabled
62     return $?
63 }
64
65 #------------------------------------------------------------------------------#
66 # "main"
67
68 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
69     set +x
70     echo "Usage: $0 '/path/to/folder/with/apks'"
71     exit 1
72 fi
73
74 if [ -z "$ANDROID_HOME" ]; then
75     echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
76     echo "  export ANDROID_HOME=/opt/android-sdk"
77     exit 1
78 fi
79
80 if [ -d tests ]; then
81     cd tests
82 fi
83
84 if [ -z "$1" ]; then
85     APKDIR=`pwd`
86 else
87     APKDIR=$1
88 fi
89
90 if [ -z $WORKSPACE ]; then
91     WORKSPACE=`dirname $(pwd)`
92     echo "Setting Workspace to $WORKSPACE"
93 fi
94
95 # allow the location of the script to be overridden
96 if [ -z $fdroid ]; then
97     fdroid="$WORKSPACE/fdroid"
98 fi
99
100 # allow the location of aapt to be overridden
101 if [ -z $aapt ]; then
102     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
103 fi
104
105 # try to use GNU sed on OSX/BSD cuz BSD sed sucks
106 if which gsed; then
107     sed=gsed
108 else
109     sed=sed
110 fi
111
112 set -x # show each command as it is executed
113
114 #------------------------------------------------------------------------------#
115 echo_header "run commit hooks"
116
117 cd $WORKSPACE
118 ./hooks/pre-commit
119
120
121 #------------------------------------------------------------------------------#
122 echo_header "test python getsig replacement"
123
124 cd $WORKSPACE/tests/getsig
125 ./make.sh
126
127 cd $WORKSPACE/tests
128 for testcase in $WORKSPACE/tests/*.TestCase; do
129     $testcase
130 done
131
132
133 #------------------------------------------------------------------------------#
134 echo_header "print fdroid version"
135
136 $fdroid --version
137
138
139 #------------------------------------------------------------------------------#
140 echo_header 'run process when building and signing are on separate machines'
141
142 REPOROOT=`create_test_dir`
143 cd $REPOROOT
144 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
145 $fdroid init --keystore keystore.jks --repo-keyalias=sova
146 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
147 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
148 echo "accepted_formats = ['txt', 'yml']" >> config.py
149 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
150 test -d archive || mkdir archive
151 test -d metadata || mkdir metadata
152 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
153 test -d repo || mkdir repo
154 test -d unsigned || mkdir unsigned
155 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
156 $fdroid publish --verbose
157 $fdroid update --verbose --nosign
158 $fdroid signindex --verbose
159 test -e repo/index.xml
160 test -e repo/index.jar
161 test -e repo/index-v1.jar
162 test -e tmp/apkcache
163 ! test -z tmp/apkcache
164 test -L urzip.apk
165 grep -F '<application id=' repo/index.xml > /dev/null
166
167
168 #------------------------------------------------------------------------------#
169 echo_header "test UTF-8 metadata"
170
171 REPOROOT=`create_test_dir`
172 cd $REPOROOT
173
174 fdroid_init_with_prebuilt_keystore
175 $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
176 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
177 mkdir metadata
178 cp $WORKSPACE/tests/urzip.apk $WORKSPACE/tests/bad-unicode*.apk repo/
179 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
180
181 $fdroid readmeta
182 $fdroid update
183
184
185 #------------------------------------------------------------------------------#
186 echo_header 'run "fdroid build" in fresh git checkout from import.TestCase'
187
188 cd $WORKSPACE/tests/tmp/importer
189 git remote update -p
190 git clean -fdx
191 # stick with known working commit, in case future commits break things for this code
192 git reset --hard fea54e1161d5eb9eb1a54e26253ef84d3ab63705
193 if [ -d $ANDROID_HOME/platforms/android-23 && -d $ANDROID_HOME/build-tools/23.0.3 ]; then
194     echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
195     echo "force_build_tools = True" >> config.py
196     $fdroid build --verbose org.fdroid.ci.test.app:300
197 else
198     echo 'WARNING: Skipping "fdroid build" test since android-23 is missing!'
199 fi
200
201 #------------------------------------------------------------------------------#
202 echo_header 'copy git import and run "fdroid scanner" on it'
203
204 REPOROOT=`create_test_dir`
205 cd $REPOROOT
206 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
207 mkdir metadata
208 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
209 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
210 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
211 echo "    commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
212 echo "    subdir=app" >> metadata/org.fdroid.ci.test.app.txt
213 echo "    gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
214 echo "" >> metadata/org.fdroid.ci.test.app.txt
215 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
216 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
217 mkdir build
218 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
219 ls -l build/org.fdroid.ci.test.app
220 $fdroid scanner org.fdroid.ci.test.app --verbose
221
222
223 #------------------------------------------------------------------------------#
224 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
225
226 REPOROOT=`create_test_dir`
227 GNUPGHOME=$REPOROOT/gnupghome
228 cd $REPOROOT
229 fdroid_init_with_prebuilt_keystore
230 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
231 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
232 chmod 0700 $GNUPGHOME
233 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
234 echo "install_list = 'org.adaway'" >> config.py
235 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
236 echo "gpghome = '$GNUPGHOME'" >> config.py
237 echo "gpgkey = 'CE71F7FB'" >> config.py
238 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
239 $fdroid update --verbose --pretty
240 test -e repo/index.xml
241 test -e repo/index.jar
242 test -e repo/index-v1.jar
243 grep -F '<application id=' repo/index.xml > /dev/null
244 grep -F '<install packageName=' repo/index.xml > /dev/null
245 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
246 # OSX tests are run on Travis-CI, and gpg fails to launch gpg-agent there
247 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
248     $fdroid gpgsign --verbose
249     $fdroid gpgsign --verbose
250     test -e repo/obb.mainpatch.current_1619.apk.asc
251     test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
252     ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
253     ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
254     ! test -e repo/index.xml.asc
255 fi
256
257 # we can't easily reproduce the timestamps for things, so just hardcode them
258 $sed -i.tmp -e 's,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
259 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
260 sed -i --expression='s,"timestamp": [0-9]*,"timestamp": 1502845383782,' repo/index-v1.json
261 diff -uw $WORKSPACE/tests/repo/index-v1.json repo/index-v1.json
262
263
264 #------------------------------------------------------------------------------#
265 echo_header 'test moving lots of APKs to the archive'
266
267 REPOROOT=`create_test_dir`
268 cd $REPOROOT
269 fdroid_init_with_prebuilt_keystore
270 echo "accepted_formats = ['txt']" >> config.py
271 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
272 test -d metadata || mkdir metadata
273 cp $WORKSPACE/tests/metadata/*.txt metadata/
274 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
275 echo 'Summary:good MD5 sig, which is disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
276 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
277 test -d repo || mkdir repo
278 cp $WORKSPACE/tests/urzip.apk \
279    $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
280    $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
281    $WORKSPACE/tests/repo/obb.main.twoversions_110161[357].apk \
282    repo/
283 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
284
285 $fdroid update --pretty --nosign
286 echo "This will fail when jarsigner allows MD5 for APK signatures"
287 test `grep '<package>' archive/index.xml | wc -l` -eq 5
288 test `grep '<package>' repo/index.xml | wc -l` -eq 7
289
290
291 #------------------------------------------------------------------------------#
292 echo_header 'test per-app "Archive Policy"'
293
294 REPOROOT=`create_test_dir`
295 cd $REPOROOT
296 fdroid_init_with_prebuilt_keystore
297 echo "accepted_formats = ['txt']" >> config.py
298 test -d metadata || mkdir metadata
299 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
300 test -d repo || mkdir repo
301 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
302 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
303
304 $fdroid update --pretty --nosign
305 test `grep '<package>' archive/index.xml | wc -l` -eq 0
306 test `grep '<package>' repo/index.xml | wc -l` -eq 4
307 grep -F com.politedroid_3.apk repo/index.xml
308 grep -F com.politedroid_4.apk repo/index.xml
309 grep -F com.politedroid_5.apk repo/index.xml
310 grep -F com.politedroid_6.apk repo/index.xml
311 test -e repo/com.politedroid_3.apk
312 test -e repo/com.politedroid_4.apk
313 test -e repo/com.politedroid_5.apk
314 test -e repo/com.politedroid_6.apk
315
316 echo "enable one app in the repo"
317 $sed -i.tmp 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
318 $fdroid update --pretty --nosign
319 test `grep '<package>' archive/index.xml | wc -l` -eq 3
320 test `grep '<package>' repo/index.xml | wc -l` -eq 1
321 grep -F com.politedroid_3.apk archive/index.xml
322 grep -F com.politedroid_4.apk archive/index.xml
323 grep -F com.politedroid_5.apk archive/index.xml
324 grep -F com.politedroid_6.apk repo/index.xml
325 test -e archive/com.politedroid_3.apk
326 test -e archive/com.politedroid_4.apk
327 test -e archive/com.politedroid_5.apk
328 test -e repo/com.politedroid_6.apk
329
330 echo "remove all apps from the repo"
331 $sed -i.tmp 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
332 $fdroid update --pretty --nosign
333 test `grep '<package>' archive/index.xml | wc -l` -eq 4
334 test `grep '<package>' repo/index.xml | wc -l` -eq 0
335 grep -F com.politedroid_3.apk archive/index.xml
336 grep -F com.politedroid_4.apk archive/index.xml
337 grep -F com.politedroid_5.apk archive/index.xml
338 grep -F com.politedroid_6.apk archive/index.xml
339 test -e archive/com.politedroid_3.apk
340 test -e archive/com.politedroid_4.apk
341 test -e archive/com.politedroid_5.apk
342 test -e archive/com.politedroid_6.apk
343 ! test -e repo/com.politedroid_6.apk
344
345 echo "move back one from archive to the repo"
346 $sed -i.tmp 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
347 $fdroid update --pretty --nosign
348 test `grep '<package>' archive/index.xml | wc -l` -eq 3
349 test `grep '<package>' repo/index.xml | wc -l` -eq 1
350 grep -F com.politedroid_3.apk archive/index.xml
351 grep -F com.politedroid_4.apk archive/index.xml
352 grep -F com.politedroid_5.apk archive/index.xml
353 grep -F com.politedroid_6.apk repo/index.xml
354 test -e archive/com.politedroid_3.apk
355 test -e archive/com.politedroid_4.apk
356 test -e archive/com.politedroid_5.apk
357 ! test -e archive/com.politedroid_6.apk
358 test -e repo/com.politedroid_6.apk
359
360
361
362 #------------------------------------------------------------------------------#
363 echo_header 'test moving old APKs to and from the archive'
364
365 REPOROOT=`create_test_dir`
366 cd $REPOROOT
367 fdroid_init_with_prebuilt_keystore
368 echo "accepted_formats = ['txt']" >> config.py
369 test -d metadata || mkdir metadata
370 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
371 $sed -i.tmp '/Archive Policy:/d' metadata/com.politedroid.txt
372 test -d repo || mkdir repo
373 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
374 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
375
376 $fdroid update --pretty --nosign
377 test `grep '<package>' archive/index.xml | wc -l` -eq 1
378 test `grep '<package>' repo/index.xml | wc -l` -eq 3
379 grep -F com.politedroid_3.apk archive/index.xml
380 grep -F com.politedroid_4.apk repo/index.xml
381 grep -F com.politedroid_5.apk repo/index.xml
382 grep -F com.politedroid_6.apk repo/index.xml
383 test -e archive/com.politedroid_3.apk
384 test -e repo/com.politedroid_4.apk
385 test -e repo/com.politedroid_5.apk
386 test -e repo/com.politedroid_6.apk
387
388 $sed -i.tmp 's,archive_older = 3,archive_older = 1,' config.py
389 $fdroid update --pretty --nosign
390 test `grep '<package>' archive/index.xml | wc -l` -eq 3
391 test `grep '<package>' repo/index.xml | wc -l` -eq 1
392 grep -F com.politedroid_3.apk archive/index.xml
393 grep -F com.politedroid_4.apk archive/index.xml
394 grep -F com.politedroid_5.apk archive/index.xml
395 grep -F com.politedroid_6.apk repo/index.xml
396 test -e archive/com.politedroid_3.apk
397 test -e archive/com.politedroid_4.apk
398 test -e archive/com.politedroid_5.apk
399 test -e repo/com.politedroid_6.apk
400
401 # disabling deletes from the archive
402 $sed -i.tmp 's/Build:1.3,4/Build:1.3,4\n    disable=testing deletion/' metadata/com.politedroid.txt
403 $fdroid update --pretty --nosign
404 test `grep '<package>' archive/index.xml | wc -l` -eq 2
405 test `grep '<package>' repo/index.xml | wc -l` -eq 1
406 grep -F com.politedroid_3.apk archive/index.xml
407 ! grep -F com.politedroid_4.apk archive/index.xml
408 grep -F com.politedroid_5.apk archive/index.xml
409 grep -F com.politedroid_6.apk repo/index.xml
410 test -e archive/com.politedroid_3.apk
411 ! test -e archive/com.politedroid_4.apk
412 test -e archive/com.politedroid_5.apk
413 test -e repo/com.politedroid_6.apk
414
415 # disabling deletes from the repo, and promotes one from the archive
416 $sed -i.tmp 's/Build:1.5,6/Build:1.5,6\n    disable=testing deletion/' metadata/com.politedroid.txt
417 $fdroid update --pretty --nosign
418 test `grep '<package>' archive/index.xml | wc -l` -eq 1
419 test `grep '<package>' repo/index.xml | wc -l` -eq 1
420 grep -F com.politedroid_3.apk archive/index.xml
421 grep -F com.politedroid_5.apk repo/index.xml
422 ! grep -F com.politedroid_6.apk repo/index.xml
423 test -e archive/com.politedroid_3.apk
424 test -e repo/com.politedroid_5.apk
425 ! test -e repo/com.politedroid_6.apk
426
427
428 #------------------------------------------------------------------------------#
429 echo_header 'test allowing disabled signatures in repo and archive'
430
431 REPOROOT=`create_test_dir`
432 cd $REPOROOT
433 fdroid_init_with_prebuilt_keystore
434 echo "accepted_formats = ['txt']" >> config.py
435 echo 'allow_disabled_algorithms = True' >> config.py
436 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
437 test -d metadata || mkdir metadata
438 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
439 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
440 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
441 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
442 test -d repo || mkdir repo
443 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
444    $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
445    $WORKSPACE/tests/urzip-badsig.apk \
446    repo/
447
448 $fdroid update --pretty --nosign
449 test `grep '<package>' archive/index.xml | wc -l` -eq 2
450 test `grep '<package>' repo/index.xml | wc -l` -eq 6
451 grep -F com.politedroid_3.apk archive/index.xml
452 grep -F com.politedroid_4.apk repo/index.xml
453 grep -F com.politedroid_5.apk repo/index.xml
454 grep -F com.politedroid_6.apk repo/index.xml
455 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
456 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
457 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
458 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
459 ! grep -F urzip-badsig.apk repo/index.xml
460 ! grep -F urzip-badsig.apk archive/index.xml
461 test -e archive/com.politedroid_3.apk
462 test -e repo/com.politedroid_4.apk
463 test -e repo/com.politedroid_5.apk
464 test -e repo/com.politedroid_6.apk
465 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
466 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
467 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
468 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
469 test -e archive/urzip-badsig.apk
470
471 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
472 $fdroid update --pretty --nosign
473 test `grep '<package>' archive/index.xml | wc -l` -eq 5
474 test `grep '<package>' repo/index.xml | wc -l` -eq 3
475 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
476 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
477 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
478 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
479 grep -F com.politedroid_3.apk archive/index.xml
480 grep -F com.politedroid_4.apk repo/index.xml
481 grep -F com.politedroid_5.apk repo/index.xml
482 grep -F com.politedroid_6.apk repo/index.xml
483 ! grep -F urzip-badsig.apk repo/index.xml
484 ! grep -F urzip-badsig.apk archive/index.xml
485 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
486 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
487 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
488 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
489 test -e archive/com.politedroid_3.apk
490 test -e archive/urzip-badsig.apk
491 test -e repo/com.politedroid_4.apk
492 test -e repo/com.politedroid_5.apk
493 test -e repo/com.politedroid_6.apk
494
495
496 #------------------------------------------------------------------------------#
497 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
498
499 REPOROOT=`create_test_dir`
500 cd $REPOROOT
501 fdroid_init_with_prebuilt_keystore
502 echo "accepted_formats = ['txt', 'yml']" >> config.py
503 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
504 test -d metadata || mkdir metadata
505 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
506 test -d repo || mkdir repo
507 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
508 $fdroid update --rename-apks --pretty --nosign
509 test -e repo/info.guardianproject.urzip_100.apk
510 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
511 cp $WORKSPACE/tests/urzip-release.apk repo/
512 $fdroid update --rename-apks --pretty --nosign
513 test -e repo/info.guardianproject.urzip_100.apk
514 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
515 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
516 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
517 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
518 cp $WORKSPACE/tests/urzip-release.apk repo/
519 $fdroid update --rename-apks --pretty --nosign
520 test -e repo/info.guardianproject.urzip_100.apk
521 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
522 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
523 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
524 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
525 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
526
527
528 #------------------------------------------------------------------------------#
529 echo_header "test metadata checks"
530
531 REPOROOT=`create_test_dir`
532 cd $REPOROOT
533
534 mkdir repo
535 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
536
537 set +e
538 $fdroid build
539 if [ $? -eq 0 ]; then
540     echo "This should have failed because there is no metadata!"
541     exit 1
542 else
543     echo "testing metadata checks passed"
544 fi
545 set -e
546
547 mkdir $REPOROOT/metadata/
548 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
549 $fdroid readmeta
550
551 # now make a fake duplicate
552 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
553
554 set +e
555 $fdroid readmeta
556 if [ $? -eq 0 ]; then
557     echo "This should have failed because there is a duplicate metadata file!"
558     exit 1
559 else
560     echo "testing duplicate metadata checks passed"
561 fi
562 set -e
563
564
565 #------------------------------------------------------------------------------#
566 echo_header "ensure commands that don't need the JDK work without a JDK configed"
567
568 REPOROOT=`create_test_dir`
569 cd $REPOROOT
570 mkdir repo
571 mkdir metadata
572 echo "License:GPL-2.0" >> metadata/fake.txt
573 echo "Summary:Yup still fake" >> metadata/fake.txt
574 echo "Categories:Internet" >> metadata/fake.txt
575 echo "Description:" >> metadata/fake.txt
576 echo "this is fake" >> metadata/fake.txt
577 echo "." >> metadata/fake.txt
578
579 # fake that no JDKs are available
580 echo 'java_paths = {}' > config.py
581
582 LOCAL_COPY_DIR=`create_test_dir`/fdroid
583 mkdir -p $LOCAL_COPY_DIR/repo
584 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
585
586 $fdroid checkupdates
587 $fdroid gpgsign
588 $fdroid lint
589 $fdroid readmeta
590 $fdroid rewritemeta fake
591 $fdroid server update
592 $fdroid scanner
593
594 # run these to get their output, but the are not setup, so don't fail
595 $fdroid build || true
596 $fdroid import || true
597 $fdroid install || true
598
599
600 #------------------------------------------------------------------------------#
601 echo_header "create a source tarball"
602
603 cd $WORKSPACE
604 ./setup.py compile_catalog sdist
605
606 REPOROOT=`create_test_dir`
607 cd $REPOROOT
608 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
609 cd $REPOROOT
610 ./fdroidserver-*/fdroid init
611 copy_apks_into_repo $REPOROOT
612 ./fdroidserver-*/fdroid update --create-metadata --verbose
613
614
615 #------------------------------------------------------------------------------#
616 echo_header "test config checks of local_copy_dir"
617
618 REPOROOT=`create_test_dir`
619 cd $REPOROOT
620 $fdroid init
621 $fdroid update --create-metadata --verbose
622 $fdroid readmeta
623 $fdroid server update --local-copy-dir=/tmp/fdroid
624
625 # now test the errors work
626 set +e
627 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
628 if [ $? -eq 0 ]; then
629     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
630     exit 1
631 else
632     echo "testing absolute path checker passed"
633 fi
634 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
635 if [ $? -eq 0 ]; then
636     echo "This should have failed because the path does not end with 'fdroid'!"
637     exit 1
638 else
639     echo "testing dirname exists checker passed"
640 fi
641 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
642 if [ $? -eq 0 ]; then
643     echo "This should have failed because the dirname path does not exist!"
644     exit 1
645 else
646     echo "testing dirname exists checker passed"
647 fi
648 set -e
649
650
651 #------------------------------------------------------------------------------#
652 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
653
654 REPOROOT=`create_test_dir`
655 cd $REPOROOT
656 fdroid_init_with_prebuilt_keystore
657 copy_apks_into_repo $REPOROOT
658 $fdroid update --create-metadata --verbose
659 $fdroid readmeta
660 grep -F '<application id=' repo/index.xml > /dev/null
661
662 LOCALCOPYDIR=`create_test_dir`/fdroid
663 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
664 NEWREPOROOT=`create_test_dir`
665 cd $NEWREPOROOT
666 fdroid_init_with_prebuilt_keystore
667 echo "sync_from_local_copy_dir = True" >> config.py
668 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
669
670
671 #------------------------------------------------------------------------------#
672 # check that --android-home fails when dir does not exist or is not a dir
673
674 REPOROOT=`create_test_dir`
675 KEYSTORE=$REPOROOT/keystore.jks
676 cd $REPOROOT
677 set +e
678 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
679 if [ $? -eq 0 ]; then
680     echo "This should have failed because /opt/fakeandroidhome does not exist!"
681     exit 1
682 else
683     echo "testing android-home path checker passed"
684 fi
685 TESTFILE=`create_test_file`
686 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
687 if [ $? -eq 0 ]; then
688     echo "This should have failed because $TESTFILE is a file not a dir!"
689     exit 1
690 else
691     echo "testing android-home not-dir checker passed"
692 fi
693 set -e
694
695
696 #------------------------------------------------------------------------------#
697 echo_header "check that fake android home passes 'fdroid init'"
698
699 REPOROOT=`create_test_dir`
700 FAKE_ANDROID_HOME=`create_test_dir`
701 create_fake_android_home $FAKE_ANDROID_HOME
702 KEYSTORE=$REPOROOT/keystore.jks
703 cd $REPOROOT
704 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
705
706
707 #------------------------------------------------------------------------------#
708 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
709
710 if [ -e /usr/bin/aapt ]; then
711     echo "/usr/bin/aapt exists, not running test"
712 else
713     REPOROOT=`create_test_dir`
714     FAKE_ANDROID_HOME=`create_test_dir`
715     create_fake_android_home $FAKE_ANDROID_HOME
716     rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
717     KEYSTORE=$REPOROOT/keystore.jks
718     cd $REPOROOT
719     set +e
720     $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
721     [ $? -eq 0 ] && exit 1
722     set -e
723 fi
724
725
726 #------------------------------------------------------------------------------#
727 echo_header "check that --android-home overrides ANDROID_HOME"
728
729 REPOROOT=`create_test_dir`
730 FAKE_ANDROID_HOME=`create_test_dir`
731 create_fake_android_home $FAKE_ANDROID_HOME
732 KEYSTORE=$REPOROOT/keystore.jks
733 cd $REPOROOT
734 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
735 set +e
736 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
737 if [ $? -ne 0 ]; then
738     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
739     exit 1
740 fi
741 set -e
742
743
744 #------------------------------------------------------------------------------#
745 # In this case, ANDROID_HOME is set to a fake, non-working version that will
746 # be detected by fdroid as an Android SDK install.  It should use the path set
747 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
748 # in ANDROID_HOME, it won't work because it is a fake one.  Only
749 # --android-home provides a working one.
750 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
751
752 REPOROOT=`create_test_dir`
753 KEYSTORE=$REPOROOT/keystore.jks
754 FAKE_ANDROID_HOME=`create_test_dir`
755 create_fake_android_home $FAKE_ANDROID_HOME
756 STORED_ANDROID_HOME=$ANDROID_HOME
757 unset ANDROID_HOME
758 echo "ANDROID_HOME: $ANDROID_HOME"
759 cd $REPOROOT
760 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
761 test -e $KEYSTORE
762 copy_apks_into_repo $REPOROOT
763 $fdroid update --create-metadata --verbose
764 $fdroid readmeta
765 grep -F '<application id=' repo/index.xml > /dev/null
766 test -e repo/index.xml
767 test -e repo/index.jar
768 test -e repo/index-v1.jar
769 test -e tmp/apkcache
770 ! test -z tmp/apkcache
771 export ANDROID_HOME=$STORED_ANDROID_HOME
772
773
774 #------------------------------------------------------------------------------#
775 echo_header "check duplicate files are properly handled by fdroid update"
776
777 REPOROOT=`create_test_dir`
778 cd $REPOROOT
779 fdroid_init_with_prebuilt_keystore
780 mkdir $REPOROOT/metadata
781 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
782 echo "accepted_formats = ['txt']" >> config.py
783 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
784 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
785 $fdroid update --pretty
786 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
787 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
788 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
789 # die if there are exact duplicates
790 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
791 ! $fdroid update
792
793
794 #------------------------------------------------------------------------------#
795 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
796
797 REPOROOT=`create_test_dir`
798 cd $REPOROOT
799 mkdir repo
800 copy_apks_into_repo $REPOROOT
801 fdroid_init_with_prebuilt_keystore
802 $fdroid update --create-metadata --verbose
803 $fdroid readmeta
804 grep -F '<application id=' repo/index.xml > /dev/null
805
806
807 #------------------------------------------------------------------------------#
808 echo_header "setup a new repo from scratch and generate a keystore"
809
810 REPOROOT=`create_test_dir`
811 KEYSTORE=$REPOROOT/keystore.jks
812 cd $REPOROOT
813 $fdroid init --keystore $KEYSTORE
814 test -e $KEYSTORE
815 copy_apks_into_repo $REPOROOT
816 $fdroid update --create-metadata --verbose
817 $fdroid readmeta
818 test -e repo/index.xml
819 test -e repo/index.jar
820 test -e repo/index-v1.jar
821 test -e tmp/apkcache
822 ! test -z tmp/apkcache
823 grep -F '<application id=' repo/index.xml > /dev/null
824
825
826 #------------------------------------------------------------------------------#
827 echo_header "setup a new repo manually and generate a keystore"
828
829 REPOROOT=`create_test_dir`
830 KEYSTORE=$REPOROOT/keystore.jks
831 cd $REPOROOT
832 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
833 ! test -e $KEYSTORE
834 set +e
835 $fdroid update
836 if [ $? -eq 0 ]; then
837     echo "This should have failed because this repo has no keystore!"
838     exit 1
839 else
840     echo '`fdroid update` prompted to add keystore'
841 fi
842 set -e
843 $fdroid update --create-key
844 test -e $KEYSTORE
845 copy_apks_into_repo $REPOROOT
846 $fdroid update --create-metadata --verbose
847 $fdroid readmeta
848 test -e repo/index.xml
849 test -e repo/index.jar
850 test -e repo/index-v1.jar
851 test -e tmp/apkcache
852 ! test -z tmp/apkcache
853 grep -F '<application id=' repo/index.xml > /dev/null
854
855
856 #------------------------------------------------------------------------------#
857 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
858
859 REPOROOT=`create_test_dir`
860 KEYSTORE=$REPOROOT/keystore.jks
861 cd $REPOROOT
862 $fdroid init --keystore $KEYSTORE
863 test -e $KEYSTORE
864 copy_apks_into_repo $REPOROOT
865 $fdroid update --create-metadata --verbose
866 $fdroid readmeta
867 test -e repo/index.xml
868 test -e repo/index.jar
869 test -e repo/index-v1.jar
870 grep -F '<application id=' repo/index.xml > /dev/null
871 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
872     cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
873 $fdroid update --create-metadata --verbose
874 $fdroid readmeta
875 test -e repo/index.xml
876 test -e repo/index.jar
877 test -e repo/index-v1.jar
878 test -e tmp/apkcache
879 ! test -z tmp/apkcache
880 grep -F '<application id=' repo/index.xml > /dev/null
881
882
883 #------------------------------------------------------------------------------#
884 echo_header "setup a new repo from scratch with a HSM/smartcard"
885 REPOROOT=`create_test_dir`
886 cd $REPOROOT
887 $fdroid init --keystore NONE
888 test -e opensc-fdroid.cfg
889 test ! -e NONE
890
891
892 #------------------------------------------------------------------------------#
893 echo_header "setup a new repo with no keystore, add APK, and update"
894
895 REPOROOT=`create_test_dir`
896 KEYSTORE=$REPOROOT/keystore.jks
897 cd $REPOROOT
898 touch fdroid-icon.png
899 mkdir repo
900 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
901 set +e
902 $fdroid update --create-metadata --verbose
903 if [ $? -eq 0 ]; then
904     echo "This should have failed because this repo has no keystore!"
905     exit 1
906 else
907     echo '`fdroid update` prompted to add keystore'
908 fi
909 set -e
910
911 # now set up fake, non-working keystore setup
912 touch $KEYSTORE
913 echo "keystore = \"$KEYSTORE\"" >> config.py
914 echo 'repo_keyalias = "foo"' >> config.py
915 echo 'keystorepass = "foo"' >> config.py
916 echo 'keypass = "foo"' >> config.py
917 set +e
918 $fdroid update --create-metadata --verbose
919 if [ $? -eq 0 ]; then
920     echo "This should have failed because this repo has a bad/fake keystore!"
921     exit 1
922 else
923     echo '`fdroid update` prompted to add keystore'
924 fi
925 set -e
926
927
928 #------------------------------------------------------------------------------#
929 echo_header "copy tests/repo, update with binary transparency log"
930
931 REPOROOT=`create_test_dir`
932 GIT_REMOTE=`create_test_dir`
933 GNUPGHOME=$REPOROOT/gnupghome
934 cd $REPOROOT
935 fdroid_init_with_prebuilt_keystore
936 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
937 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
938 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
939 $fdroid update --verbose
940 if have_git_2_3; then
941     $fdroid server update --verbose
942     test -e repo/index.xml
943     test -e repo/index.jar
944     test -e repo/index-v1.jar
945     grep -F '<application id=' repo/index.xml > /dev/null
946     cd binary_transparency
947     [ `git rev-list --count HEAD` == "2" ]
948     cd $GIT_REMOTE
949     [ `git rev-list --count HEAD` == "2" ]
950 else
951     echo "Skipping test, `git --version` older than 2.3"
952 fi
953
954
955 #------------------------------------------------------------------------------#
956 echo_header "setup a new repo with keystore with APK, update, then without key"
957
958 REPOROOT=`create_test_dir`
959 KEYSTORE=$REPOROOT/keystore.jks
960 cd $REPOROOT
961 cp $WORKSPACE/tests/keystore.jks $KEYSTORE
962 fdroid_init_with_prebuilt_keystore $KEYSTORE
963 test -e $KEYSTORE
964 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
965 $fdroid update --create-metadata --verbose
966 $fdroid readmeta
967 test -e repo/index.xml
968 test -e repo/index.jar
969 test -e repo/index-v1.jar
970 test -e tmp/apkcache
971 ! test -z tmp/apkcache
972 grep -F '<application id=' repo/index.xml > /dev/null
973
974 # now set fake repo_keyalias
975 $sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
976 set +e
977 $fdroid update
978 if [ $? -eq 0 ]; then
979     echo "This should have failed because this repo has a bad repo_keyalias!"
980     exit 1
981 else
982     echo '`fdroid update` prompted to add keystore'
983 fi
984 set -e
985
986 # try creating a new keystore, but fail because the old one is there
987 test -e $KEYSTORE
988 set +e
989 $fdroid update --create-key
990 if [ $? -eq 0 ]; then
991     echo "This should have failed because a keystore is already there!"
992     exit 1
993 else
994     echo '`fdroid update` complained about existing keystore'
995 fi
996 set -e
997
998 # now actually create the key with the existing settings
999 rm -f $KEYSTORE
1000 ! test -e $KEYSTORE
1001 $fdroid update --create-key
1002 test -e $KEYSTORE
1003
1004
1005 #------------------------------------------------------------------------------#
1006 echo_header "sign binary repo in offline box, then publishing from online box"
1007
1008 OFFLINE_ROOT=`create_test_dir`
1009 KEYSTORE=$WORKSPACE/tests/keystore.jks
1010 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1011 mkdir $LOCAL_COPY_DIR
1012 ONLINE_ROOT=`create_test_dir`
1013 SERVERWEBROOT=`create_test_dir`
1014
1015 # create offline binary transparency log
1016 cd $OFFLINE_ROOT
1017 mkdir binary_transparency
1018 cd binary_transparency
1019 git init
1020
1021 # fake git remote server for binary transparency log
1022 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1023
1024 # fake git remote server for repo mirror
1025 SERVER_GIT_MIRROR=`create_test_dir`
1026 cd $SERVER_GIT_MIRROR
1027 git init
1028 if have_git_2_3; then
1029     git config receive.denyCurrentBranch updateInstead
1030 fi
1031
1032 cd $OFFLINE_ROOT
1033 fdroid_init_with_prebuilt_keystore
1034 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1035
1036 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
1037 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1038 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1039 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1040 $fdroid update --pretty
1041 grep -F '<application id=' repo/index.xml > /dev/null
1042 grep -F '/fdroid/repo</mirror>' repo/index.xml
1043 grep -F '/fdroid/archive</mirror>' archive/index.xml
1044 test `grep '<mirror>' repo/index.xml | wc -l` -eq 2
1045 test `grep '<mirror>' archive/index.xml | wc -l` -eq 2
1046 cd binary_transparency
1047 [ `git rev-list --count HEAD` == "1" ]
1048 cd ..
1049 $fdroid server update --verbose
1050 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1051 cd $ONLINE_ROOT
1052 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1053 echo "sync_from_local_copy_dir = True" >> config.py
1054 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1055 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1056 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1057 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1058 $fdroid server update --verbose
1059 cd $BINARY_TRANSPARENCY_REMOTE
1060 [ `git rev-list --count HEAD` == "1" ]
1061 cd $SERVER_GIT_MIRROR
1062 [ `git rev-list --count HEAD` == "1" ]
1063
1064
1065 #------------------------------------------------------------------------------#
1066
1067 # remove this to prevent git conflicts and complaining
1068 rm -rf $WORKSPACE/fdroidserver.egg-info/
1069
1070 echo SUCCESS