3 set -e # quit script on error
6 { echo -e "==============================================================================\n$1"; } 2>/dev/null
9 copy_apks_into_repo() {
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
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() {
28 mkdir $1/platform-tools
30 mkdir $1/build-tools/19.0.2
31 touch $1/build-tools/19.0.2/aapt
35 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
36 mktemp -d $WORKSPACE/.testfiles/run-tests.XXXX
40 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
41 TMPDIR=$WORKSPACE/.testfiles mktemp
44 fdroid_init_with_prebuilt_keystore() {
46 keystore=$WORKSPACE/tests/keystore.jks
50 $fdroid init --keystore $keystore --repo-keyalias=sova
51 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
52 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
55 # the < is reverse since 0 means success in exit codes
57 python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version`
61 javac $WORKSPACE/tests/IsMD5Disabled.java && java -cp $WORKSPACE/tests IsMD5Disabled
65 #------------------------------------------------------------------------------#
68 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
70 echo "Usage: $0 '/path/to/folder/with/apks'"
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"
90 if [ -z $WORKSPACE ]; then
91 WORKSPACE=`dirname $(pwd)`
92 echo "Setting Workspace to $WORKSPACE"
95 # allow the location of the script to be overridden
96 if [ -z $fdroid ]; then
97 fdroid="$WORKSPACE/fdroid"
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`
105 # try to use GNU sed on OSX/BSD cuz BSD sed sucks
112 set -x # show each command as it is executed
114 #------------------------------------------------------------------------------#
115 echo_header "run commit hooks"
121 #------------------------------------------------------------------------------#
122 echo_header "test python getsig replacement"
124 cd $WORKSPACE/tests/getsig
128 for testcase in $WORKSPACE/tests/i*.TestCase; do
129 if [ $testcase == $WORKSPACE/tests/install.TestCase ]; then
130 echo "skipping install.TestCase, its too troublesome in CI builds"
137 #------------------------------------------------------------------------------#
138 echo_header "print fdroid version"
143 #------------------------------------------------------------------------------#
144 echo_header 'run process when building and signing are on separate machines'
146 REPOROOT=`create_test_dir`
148 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
149 $fdroid init --keystore keystore.jks --repo-keyalias=sova
150 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
151 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
152 echo "accepted_formats = ['txt', 'yml']" >> config.py
153 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
154 test -d archive || mkdir archive
155 test -d metadata || mkdir metadata
156 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
157 test -d repo || mkdir repo
158 test -d unsigned || mkdir unsigned
159 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
160 $fdroid publish --verbose
161 $fdroid update --verbose --nosign
162 $fdroid signindex --verbose
163 test -e repo/index.xml
164 test -e repo/index.jar
165 test -e repo/index-v1.jar
167 ! test -z tmp/apkcache
169 grep -F '<application id=' repo/index.xml > /dev/null
172 #------------------------------------------------------------------------------#
173 echo_header "test UTF-8 metadata"
175 REPOROOT=`create_test_dir`
178 fdroid_init_with_prebuilt_keystore
179 $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
180 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
182 cp $WORKSPACE/tests/urzip.apk $WORKSPACE/tests/bad-unicode*.apk repo/
183 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
189 #------------------------------------------------------------------------------#
190 echo_header 'run "fdroid build" in fresh git checkout from import.TestCase'
192 cd $WORKSPACE/tests/tmp/importer
195 # stick with known working commit, in case future commits break things for this code
196 git reset --hard fea54e1161d5eb9eb1a54e26253ef84d3ab63705
197 if [ -d $ANDROID_HOME/platforms/android-23 && -d $ANDROID_HOME/build-tools/23.0.3 ]; then
198 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
199 echo "force_build_tools = True" >> config.py
200 $fdroid build --verbose org.fdroid.ci.test.app:300
202 echo 'WARNING: Skipping "fdroid build" test since android-23 is missing!'
205 #------------------------------------------------------------------------------#
206 echo_header 'copy git import and run "fdroid scanner" on it'
208 REPOROOT=`create_test_dir`
210 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
212 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
213 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
214 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
215 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
216 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
217 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
218 echo "" >> metadata/org.fdroid.ci.test.app.txt
219 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
220 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
222 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
223 ls -l build/org.fdroid.ci.test.app
224 $fdroid scanner org.fdroid.ci.test.app --verbose
227 #------------------------------------------------------------------------------#
228 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
230 REPOROOT=`create_test_dir`
231 GNUPGHOME=$REPOROOT/gnupghome
233 fdroid_init_with_prebuilt_keystore
234 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
235 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
236 chmod 0700 $GNUPGHOME
237 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
238 echo "install_list = 'org.adaway'" >> config.py
239 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
240 echo "gpghome = '$GNUPGHOME'" >> config.py
241 echo "gpgkey = 'CE71F7FB'" >> config.py
242 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
243 $fdroid update --verbose --pretty
244 test -e repo/index.xml
245 test -e repo/index.jar
246 test -e repo/index-v1.jar
247 grep -F '<application id=' repo/index.xml > /dev/null
248 grep -F '<install packageName=' repo/index.xml > /dev/null
249 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
250 # OSX tests are run on Travis-CI, and gpg fails to launch gpg-agent there
251 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
252 $fdroid gpgsign --verbose
253 $fdroid gpgsign --verbose
254 test -e repo/obb.mainpatch.current_1619.apk.asc
255 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
256 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
257 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
258 ! test -e repo/index.xml.asc
261 v0timestamp=`$sed -n -e 's,.*timestamp="\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)".*,\1,p' repo/index.xml`
262 v1timestamp=`$sed -n -e 's,.*"timestamp": \([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*,\1,p' repo/index-v1.json`
263 test $v0timestamp -eq $v1timestamp
265 # we can't easily reproduce the timestamps for things, so just hardcode them
266 $sed -i.tmp -e 's,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
267 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
268 sed -i --expression='s,"timestamp": [0-9]*,"timestamp": 1502845383782,' repo/index-v1.json
269 diff -uw $WORKSPACE/tests/repo/index-v1.json repo/index-v1.json
272 #------------------------------------------------------------------------------#
273 echo_header 'test moving lots of APKs to the archive'
275 REPOROOT=`create_test_dir`
277 fdroid_init_with_prebuilt_keystore
278 echo "accepted_formats = ['txt']" >> config.py
279 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
280 test -d metadata || mkdir metadata
281 cp $WORKSPACE/tests/metadata/*.txt metadata/
282 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
283 echo 'Summary:good MD5 sig, which is disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
284 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
285 test -d repo || mkdir repo
286 cp $WORKSPACE/tests/urzip.apk \
287 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
288 $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
289 $WORKSPACE/tests/repo/obb.main.twoversions_110161[357].apk \
291 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
293 $fdroid update --pretty --nosign
294 echo "This will fail when jarsigner allows MD5 for APK signatures"
295 test `grep '<package>' archive/index.xml | wc -l` -eq 5
296 test `grep '<package>' repo/index.xml | wc -l` -eq 7
299 #------------------------------------------------------------------------------#
300 echo_header 'test per-app "Archive Policy"'
302 REPOROOT=`create_test_dir`
304 fdroid_init_with_prebuilt_keystore
305 echo "accepted_formats = ['txt']" >> config.py
306 test -d metadata || mkdir metadata
307 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
308 test -d repo || mkdir repo
309 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
310 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
312 $fdroid update --pretty --nosign
313 test `grep '<package>' archive/index.xml | wc -l` -eq 0
314 test `grep '<package>' repo/index.xml | wc -l` -eq 4
315 grep -F com.politedroid_3.apk repo/index.xml
316 grep -F com.politedroid_4.apk repo/index.xml
317 grep -F com.politedroid_5.apk repo/index.xml
318 grep -F com.politedroid_6.apk repo/index.xml
319 test -e repo/com.politedroid_3.apk
320 test -e repo/com.politedroid_4.apk
321 test -e repo/com.politedroid_5.apk
322 test -e repo/com.politedroid_6.apk
324 echo "enable one app in the repo"
325 $sed -i.tmp 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
326 $fdroid update --pretty --nosign
327 test `grep '<package>' archive/index.xml | wc -l` -eq 3
328 test `grep '<package>' repo/index.xml | wc -l` -eq 1
329 grep -F com.politedroid_3.apk archive/index.xml
330 grep -F com.politedroid_4.apk archive/index.xml
331 grep -F com.politedroid_5.apk archive/index.xml
332 grep -F com.politedroid_6.apk repo/index.xml
333 test -e archive/com.politedroid_3.apk
334 test -e archive/com.politedroid_4.apk
335 test -e archive/com.politedroid_5.apk
336 test -e repo/com.politedroid_6.apk
338 echo "remove all apps from the repo"
339 $sed -i.tmp 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
340 $fdroid update --pretty --nosign
341 test `grep '<package>' archive/index.xml | wc -l` -eq 4
342 test `grep '<package>' repo/index.xml | wc -l` -eq 0
343 grep -F com.politedroid_3.apk archive/index.xml
344 grep -F com.politedroid_4.apk archive/index.xml
345 grep -F com.politedroid_5.apk archive/index.xml
346 grep -F com.politedroid_6.apk archive/index.xml
347 test -e archive/com.politedroid_3.apk
348 test -e archive/com.politedroid_4.apk
349 test -e archive/com.politedroid_5.apk
350 test -e archive/com.politedroid_6.apk
351 ! test -e repo/com.politedroid_6.apk
353 echo "move back one from archive to the repo"
354 $sed -i.tmp 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
355 $fdroid update --pretty --nosign
356 test `grep '<package>' archive/index.xml | wc -l` -eq 3
357 test `grep '<package>' repo/index.xml | wc -l` -eq 1
358 grep -F com.politedroid_3.apk archive/index.xml
359 grep -F com.politedroid_4.apk archive/index.xml
360 grep -F com.politedroid_5.apk archive/index.xml
361 grep -F com.politedroid_6.apk repo/index.xml
362 test -e archive/com.politedroid_3.apk
363 test -e archive/com.politedroid_4.apk
364 test -e archive/com.politedroid_5.apk
365 ! test -e archive/com.politedroid_6.apk
366 test -e repo/com.politedroid_6.apk
370 #------------------------------------------------------------------------------#
371 echo_header 'test moving old APKs to and from the archive'
373 REPOROOT=`create_test_dir`
375 fdroid_init_with_prebuilt_keystore
376 echo "accepted_formats = ['txt']" >> config.py
377 test -d metadata || mkdir metadata
378 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
379 $sed -i.tmp '/Archive Policy:/d' metadata/com.politedroid.txt
380 test -d repo || mkdir repo
381 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
382 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
384 $fdroid update --pretty --nosign
385 test `grep '<package>' archive/index.xml | wc -l` -eq 1
386 test `grep '<package>' repo/index.xml | wc -l` -eq 3
387 grep -F com.politedroid_3.apk archive/index.xml
388 grep -F com.politedroid_4.apk repo/index.xml
389 grep -F com.politedroid_5.apk repo/index.xml
390 grep -F com.politedroid_6.apk repo/index.xml
391 test -e archive/com.politedroid_3.apk
392 test -e repo/com.politedroid_4.apk
393 test -e repo/com.politedroid_5.apk
394 test -e repo/com.politedroid_6.apk
396 $sed -i.tmp 's,archive_older = 3,archive_older = 1,' config.py
397 $fdroid update --pretty --nosign
398 test `grep '<package>' archive/index.xml | wc -l` -eq 3
399 test `grep '<package>' repo/index.xml | wc -l` -eq 1
400 grep -F com.politedroid_3.apk archive/index.xml
401 grep -F com.politedroid_4.apk archive/index.xml
402 grep -F com.politedroid_5.apk archive/index.xml
403 grep -F com.politedroid_6.apk repo/index.xml
404 test -e archive/com.politedroid_3.apk
405 test -e archive/com.politedroid_4.apk
406 test -e archive/com.politedroid_5.apk
407 test -e repo/com.politedroid_6.apk
409 # disabling deletes from the archive
410 $sed -i.tmp 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
411 $fdroid update --pretty --nosign
412 test `grep '<package>' archive/index.xml | wc -l` -eq 2
413 test `grep '<package>' repo/index.xml | wc -l` -eq 1
414 grep -F com.politedroid_3.apk archive/index.xml
415 ! grep -F com.politedroid_4.apk archive/index.xml
416 grep -F com.politedroid_5.apk archive/index.xml
417 grep -F com.politedroid_6.apk repo/index.xml
418 test -e archive/com.politedroid_3.apk
419 ! test -e archive/com.politedroid_4.apk
420 test -e archive/com.politedroid_5.apk
421 test -e repo/com.politedroid_6.apk
423 # disabling deletes from the repo, and promotes one from the archive
424 $sed -i.tmp 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
425 $fdroid update --pretty --nosign
426 test `grep '<package>' archive/index.xml | wc -l` -eq 1
427 test `grep '<package>' repo/index.xml | wc -l` -eq 1
428 grep -F com.politedroid_3.apk archive/index.xml
429 grep -F com.politedroid_5.apk repo/index.xml
430 ! grep -F com.politedroid_6.apk repo/index.xml
431 test -e archive/com.politedroid_3.apk
432 test -e repo/com.politedroid_5.apk
433 ! test -e repo/com.politedroid_6.apk
436 #------------------------------------------------------------------------------#
437 echo_header 'test allowing disabled signatures in repo and archive'
439 REPOROOT=`create_test_dir`
441 fdroid_init_with_prebuilt_keystore
442 echo "accepted_formats = ['txt']" >> config.py
443 echo 'allow_disabled_algorithms = True' >> config.py
444 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
445 test -d metadata || mkdir metadata
446 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
447 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
448 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
449 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
450 test -d repo || mkdir repo
451 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
452 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
453 $WORKSPACE/tests/urzip-badsig.apk \
456 $fdroid update --pretty --nosign
457 test `grep '<package>' archive/index.xml | wc -l` -eq 2
458 test `grep '<package>' repo/index.xml | wc -l` -eq 6
459 grep -F com.politedroid_3.apk archive/index.xml
460 grep -F com.politedroid_4.apk repo/index.xml
461 grep -F com.politedroid_5.apk repo/index.xml
462 grep -F com.politedroid_6.apk repo/index.xml
463 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
464 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
465 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
466 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
467 ! grep -F urzip-badsig.apk repo/index.xml
468 ! grep -F urzip-badsig.apk archive/index.xml
469 test -e archive/com.politedroid_3.apk
470 test -e repo/com.politedroid_4.apk
471 test -e repo/com.politedroid_5.apk
472 test -e repo/com.politedroid_6.apk
473 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
474 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
475 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
476 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
477 test -e archive/urzip-badsig.apk
479 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
480 $fdroid update --pretty --nosign
481 test `grep '<package>' archive/index.xml | wc -l` -eq 5
482 test `grep '<package>' repo/index.xml | wc -l` -eq 3
483 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
484 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
485 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
486 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
487 grep -F com.politedroid_3.apk archive/index.xml
488 grep -F com.politedroid_4.apk repo/index.xml
489 grep -F com.politedroid_5.apk repo/index.xml
490 grep -F com.politedroid_6.apk repo/index.xml
491 ! grep -F urzip-badsig.apk repo/index.xml
492 ! grep -F urzip-badsig.apk archive/index.xml
493 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
494 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
495 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
496 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
497 test -e archive/com.politedroid_3.apk
498 test -e archive/urzip-badsig.apk
499 test -e repo/com.politedroid_4.apk
500 test -e repo/com.politedroid_5.apk
501 test -e repo/com.politedroid_6.apk
504 #------------------------------------------------------------------------------#
505 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
507 REPOROOT=`create_test_dir`
509 fdroid_init_with_prebuilt_keystore
510 echo "accepted_formats = ['txt', 'yml']" >> config.py
511 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
512 test -d metadata || mkdir metadata
513 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
514 test -d repo || mkdir repo
515 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
516 $fdroid update --rename-apks --pretty --nosign
517 test -e repo/info.guardianproject.urzip_100.apk
518 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
519 cp $WORKSPACE/tests/urzip-release.apk repo/
520 $fdroid update --rename-apks --pretty --nosign
521 test -e repo/info.guardianproject.urzip_100.apk
522 test -e 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 cp $WORKSPACE/tests/urzip-release.apk repo/
527 $fdroid update --rename-apks --pretty --nosign
528 test -e repo/info.guardianproject.urzip_100.apk
529 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
530 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
531 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
532 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
533 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
536 #------------------------------------------------------------------------------#
537 echo_header "test metadata checks"
539 REPOROOT=`create_test_dir`
543 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
547 if [ $? -eq 0 ]; then
548 echo "This should have failed because there is no metadata!"
551 echo "testing metadata checks passed"
555 mkdir $REPOROOT/metadata/
556 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
559 # now make a fake duplicate
560 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
564 if [ $? -eq 0 ]; then
565 echo "This should have failed because there is a duplicate metadata file!"
568 echo "testing duplicate metadata checks passed"
573 #------------------------------------------------------------------------------#
574 echo_header "ensure commands that don't need the JDK work without a JDK configed"
576 REPOROOT=`create_test_dir`
580 echo "License:GPL-2.0" >> metadata/fake.txt
581 echo "Summary:Yup still fake" >> metadata/fake.txt
582 echo "Categories:Internet" >> metadata/fake.txt
583 echo "Description:" >> metadata/fake.txt
584 echo "this is fake" >> metadata/fake.txt
585 echo "." >> metadata/fake.txt
587 # fake that no JDKs are available
588 echo 'java_paths = {}' > config.py
590 LOCAL_COPY_DIR=`create_test_dir`/fdroid
591 mkdir -p $LOCAL_COPY_DIR/repo
592 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
594 $fdroid checkupdates --allow-dirty
598 $fdroid rewritemeta fake
599 $fdroid server update
602 # run these to get their output, but the are not setup, so don't fail
603 $fdroid build || true
604 $fdroid import || true
605 $fdroid install || true
608 #------------------------------------------------------------------------------#
609 echo_header "create a source tarball"
612 ./setup.py compile_catalog sdist
614 REPOROOT=`create_test_dir`
616 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
618 ./fdroidserver-*/fdroid init
619 copy_apks_into_repo $REPOROOT
620 ./fdroidserver-*/fdroid update --create-metadata --verbose
623 #------------------------------------------------------------------------------#
624 echo_header "test config checks of local_copy_dir"
626 REPOROOT=`create_test_dir`
629 $fdroid update --create-metadata --verbose
631 $fdroid server update --local-copy-dir=/tmp/fdroid
633 # now test the errors work
635 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
636 if [ $? -eq 0 ]; then
637 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
640 echo "testing absolute path checker passed"
642 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
643 if [ $? -eq 0 ]; then
644 echo "This should have failed because the path does not end with 'fdroid'!"
647 echo "testing dirname exists checker passed"
649 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
650 if [ $? -eq 0 ]; then
651 echo "This should have failed because the dirname path does not exist!"
654 echo "testing dirname exists checker passed"
659 #------------------------------------------------------------------------------#
660 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
662 REPOROOT=`create_test_dir`
664 fdroid_init_with_prebuilt_keystore
665 copy_apks_into_repo $REPOROOT
666 $fdroid update --create-metadata --verbose
668 grep -F '<application id=' repo/index.xml > /dev/null
670 LOCALCOPYDIR=`create_test_dir`/fdroid
671 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
672 NEWREPOROOT=`create_test_dir`
674 fdroid_init_with_prebuilt_keystore
675 echo "sync_from_local_copy_dir = True" >> config.py
676 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
679 #------------------------------------------------------------------------------#
680 # check that --android-home fails when dir does not exist or is not a dir
682 REPOROOT=`create_test_dir`
683 KEYSTORE=$REPOROOT/keystore.jks
686 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
687 if [ $? -eq 0 ]; then
688 echo "This should have failed because /opt/fakeandroidhome does not exist!"
691 echo "testing android-home path checker passed"
693 TESTFILE=`create_test_file`
694 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
695 if [ $? -eq 0 ]; then
696 echo "This should have failed because $TESTFILE is a file not a dir!"
699 echo "testing android-home not-dir checker passed"
704 #------------------------------------------------------------------------------#
705 echo_header "check that fake android home passes 'fdroid init'"
707 REPOROOT=`create_test_dir`
708 FAKE_ANDROID_HOME=`create_test_dir`
709 create_fake_android_home $FAKE_ANDROID_HOME
710 KEYSTORE=$REPOROOT/keystore.jks
712 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
715 #------------------------------------------------------------------------------#
716 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
718 if [ -e /usr/bin/aapt ]; then
719 echo "/usr/bin/aapt exists, not running test"
721 REPOROOT=`create_test_dir`
722 FAKE_ANDROID_HOME=`create_test_dir`
723 create_fake_android_home $FAKE_ANDROID_HOME
724 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
725 KEYSTORE=$REPOROOT/keystore.jks
728 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
729 [ $? -eq 0 ] && exit 1
734 #------------------------------------------------------------------------------#
735 echo_header "check that --android-home overrides ANDROID_HOME"
737 REPOROOT=`create_test_dir`
738 FAKE_ANDROID_HOME=`create_test_dir`
739 create_fake_android_home $FAKE_ANDROID_HOME
740 KEYSTORE=$REPOROOT/keystore.jks
742 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
744 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
745 if [ $? -ne 0 ]; then
746 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
752 #------------------------------------------------------------------------------#
753 # In this case, ANDROID_HOME is set to a fake, non-working version that will
754 # be detected by fdroid as an Android SDK install. It should use the path set
755 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
756 # in ANDROID_HOME, it won't work because it is a fake one. Only
757 # --android-home provides a working one.
758 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
760 REPOROOT=`create_test_dir`
761 KEYSTORE=$REPOROOT/keystore.jks
762 FAKE_ANDROID_HOME=`create_test_dir`
763 create_fake_android_home $FAKE_ANDROID_HOME
764 STORED_ANDROID_HOME=$ANDROID_HOME
766 echo "ANDROID_HOME: $ANDROID_HOME"
768 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
770 copy_apks_into_repo $REPOROOT
771 $fdroid update --create-metadata --verbose
773 grep -F '<application id=' repo/index.xml > /dev/null
774 test -e repo/index.xml
775 test -e repo/index.jar
776 test -e repo/index-v1.jar
778 ! test -z tmp/apkcache
779 export ANDROID_HOME=$STORED_ANDROID_HOME
782 #------------------------------------------------------------------------------#
783 echo_header "check duplicate files are properly handled by fdroid update"
785 REPOROOT=`create_test_dir`
787 fdroid_init_with_prebuilt_keystore
788 mkdir $REPOROOT/metadata
789 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
790 echo "accepted_formats = ['txt']" >> config.py
791 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
792 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
793 $fdroid update --pretty
794 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
795 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
796 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
797 # die if there are exact duplicates
798 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
802 #------------------------------------------------------------------------------#
803 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
805 REPOROOT=`create_test_dir`
808 copy_apks_into_repo $REPOROOT
809 fdroid_init_with_prebuilt_keystore
810 $fdroid update --create-metadata --verbose
812 grep -F '<application id=' repo/index.xml > /dev/null
815 #------------------------------------------------------------------------------#
816 echo_header "setup a new repo from scratch and generate a keystore"
818 REPOROOT=`create_test_dir`
819 KEYSTORE=$REPOROOT/keystore.jks
821 $fdroid init --keystore $KEYSTORE
823 copy_apks_into_repo $REPOROOT
824 $fdroid update --create-metadata --verbose
826 test -e repo/index.xml
827 test -e repo/index.jar
828 test -e repo/index-v1.jar
830 ! test -z tmp/apkcache
831 grep -F '<application id=' repo/index.xml > /dev/null
834 #------------------------------------------------------------------------------#
835 echo_header "setup a new repo manually and generate a keystore"
837 REPOROOT=`create_test_dir`
838 KEYSTORE=$REPOROOT/keystore.jks
840 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
844 if [ $? -eq 0 ]; then
845 echo "This should have failed because this repo has no keystore!"
848 echo '`fdroid update` prompted to add keystore'
851 $fdroid update --create-key
853 copy_apks_into_repo $REPOROOT
854 $fdroid update --create-metadata --verbose
856 test -e repo/index.xml
857 test -e repo/index.jar
858 test -e repo/index-v1.jar
860 ! test -z tmp/apkcache
861 grep -F '<application id=' repo/index.xml > /dev/null
864 #------------------------------------------------------------------------------#
865 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
867 REPOROOT=`create_test_dir`
868 KEYSTORE=$REPOROOT/keystore.jks
870 $fdroid init --keystore $KEYSTORE
872 copy_apks_into_repo $REPOROOT
873 $fdroid update --create-metadata --verbose
875 test -e repo/index.xml
876 test -e repo/index.jar
877 test -e repo/index-v1.jar
878 grep -F '<application id=' repo/index.xml > /dev/null
879 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
880 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
881 $fdroid update --create-metadata --verbose
883 test -e repo/index.xml
884 test -e repo/index.jar
885 test -e repo/index-v1.jar
887 ! test -z tmp/apkcache
888 grep -F '<application id=' repo/index.xml > /dev/null
891 #------------------------------------------------------------------------------#
892 echo_header "setup a new repo from scratch with a HSM/smartcard"
893 REPOROOT=`create_test_dir`
895 $fdroid init --keystore NONE
896 test -e opensc-fdroid.cfg
900 #------------------------------------------------------------------------------#
901 echo_header "setup a new repo with no keystore, add APK, and update"
903 REPOROOT=`create_test_dir`
904 KEYSTORE=$REPOROOT/keystore.jks
906 touch fdroid-icon.png
908 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
910 $fdroid update --create-metadata --verbose
911 if [ $? -eq 0 ]; then
912 echo "This should have failed because this repo has no keystore!"
915 echo '`fdroid update` prompted to add keystore'
919 # now set up fake, non-working keystore setup
921 echo "keystore = \"$KEYSTORE\"" >> config.py
922 echo 'repo_keyalias = "foo"' >> config.py
923 echo 'keystorepass = "foo"' >> config.py
924 echo 'keypass = "foo"' >> config.py
926 $fdroid update --create-metadata --verbose
927 if [ $? -eq 0 ]; then
928 echo "This should have failed because this repo has a bad/fake keystore!"
931 echo '`fdroid update` prompted to add keystore'
936 #------------------------------------------------------------------------------#
937 echo_header "copy tests/repo, update with binary transparency log"
939 REPOROOT=`create_test_dir`
940 GIT_REMOTE=`create_test_dir`
941 GNUPGHOME=$REPOROOT/gnupghome
943 fdroid_init_with_prebuilt_keystore
944 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
945 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
946 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
947 $fdroid update --verbose
948 if have_git_2_3; then
949 $fdroid server update --verbose
950 test -e repo/index.xml
951 test -e repo/index.jar
952 test -e repo/index-v1.jar
953 grep -F '<application id=' repo/index.xml > /dev/null
954 cd binary_transparency
955 [ `git rev-list --count HEAD` == "2" ]
957 [ `git rev-list --count HEAD` == "2" ]
959 echo "Skipping test, `git --version` older than 2.3"
963 #------------------------------------------------------------------------------#
964 echo_header "setup a new repo with keystore with APK, update, then without key"
966 REPOROOT=`create_test_dir`
967 KEYSTORE=$REPOROOT/keystore.jks
969 cp $WORKSPACE/tests/keystore.jks $KEYSTORE
970 fdroid_init_with_prebuilt_keystore $KEYSTORE
972 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
973 $fdroid update --create-metadata --verbose
975 test -e repo/index.xml
976 test -e repo/index.jar
977 test -e repo/index-v1.jar
979 ! test -z tmp/apkcache
980 grep -F '<application id=' repo/index.xml > /dev/null
982 # now set fake repo_keyalias
983 $sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
986 if [ $? -eq 0 ]; then
987 echo "This should have failed because this repo has a bad repo_keyalias!"
990 echo '`fdroid update` prompted to add keystore'
994 # try creating a new keystore, but fail because the old one is there
997 $fdroid update --create-key
998 if [ $? -eq 0 ]; then
999 echo "This should have failed because a keystore is already there!"
1002 echo '`fdroid update` complained about existing keystore'
1006 # now actually create the key with the existing settings
1009 $fdroid update --create-key
1013 #------------------------------------------------------------------------------#
1014 echo_header "sign binary repo in offline box, then publishing from online box"
1016 OFFLINE_ROOT=`create_test_dir`
1017 KEYSTORE=$WORKSPACE/tests/keystore.jks
1018 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1019 mkdir $LOCAL_COPY_DIR
1020 ONLINE_ROOT=`create_test_dir`
1021 SERVERWEBROOT=`create_test_dir`
1023 # create offline binary transparency log
1025 mkdir binary_transparency
1026 cd binary_transparency
1029 # fake git remote server for binary transparency log
1030 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1032 # fake git remote server for repo mirror
1033 SERVER_GIT_MIRROR=`create_test_dir`
1034 cd $SERVER_GIT_MIRROR
1036 if have_git_2_3; then
1037 git config receive.denyCurrentBranch updateInstead
1041 fdroid_init_with_prebuilt_keystore
1042 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1044 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
1045 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1046 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1047 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1048 $fdroid update --pretty
1049 grep -F '<application id=' repo/index.xml > /dev/null
1050 grep -F '/fdroid/repo</mirror>' repo/index.xml
1051 grep -F '/fdroid/archive</mirror>' archive/index.xml
1052 test `grep '<mirror>' repo/index.xml | wc -l` -eq 2
1053 test `grep '<mirror>' archive/index.xml | wc -l` -eq 2
1054 cd binary_transparency
1055 [ `git rev-list --count HEAD` == "1" ]
1057 $fdroid server update --verbose
1058 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1060 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1061 echo "sync_from_local_copy_dir = True" >> config.py
1062 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1063 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1064 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1065 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1066 $fdroid server update --verbose
1067 cd $BINARY_TRANSPARENCY_REMOTE
1068 [ `git rev-list --count HEAD` == "1" ]
1069 cd $SERVER_GIT_MIRROR
1070 [ `git rev-list --count HEAD` == "1" ]
1073 #------------------------------------------------------------------------------#
1075 # remove this to prevent git conflicts and complaining
1076 rm -rf $WORKSPACE/fdroidserver.egg-info/