3 set -e # quit script on error
6 { echo -e "==============================================================================\n$1"; } 2>/dev/null
9 copy_apks_into_repo() {
11 for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned -e badsig -e badcert`; do
12 name=$(basename $(dirname `dirname $f`))
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 #------------------------------------------------------------------------------#
47 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
49 echo "Usage: $0 '/path/to/folder/with/apks'"
53 if [ -z "$ANDROID_HOME" ]; then
54 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
55 echo " export ANDROID_HOME=/opt/android-sdk"
69 if [ -z $WORKSPACE ]; then
70 WORKSPACE=`dirname $(pwd)`
71 echo "Setting Workspace to $WORKSPACE"
74 # allow the location of the script to be overridden
75 if [ -z $fdroid ]; then
76 fdroid="$WORKSPACE/fdroid"
79 # allow the location of aapt to be overridden
81 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
84 # allow the location of python to be overridden
85 if [ -z $python ]; then
89 set -x # show each command as it is executed
91 #------------------------------------------------------------------------------#
92 echo_header "run commit hooks"
98 #------------------------------------------------------------------------------#
99 echo_header "test python getsig replacement"
101 cd $WORKSPACE/tests/getsig
105 for testcase in $WORKSPACE/tests/*.TestCase; do
110 #------------------------------------------------------------------------------#
111 echo_header "print fdroid version"
116 #------------------------------------------------------------------------------#
117 echo_header 'run process when building and signing are on separate machines'
119 REPOROOT=`create_test_dir`
121 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
122 $fdroid init --keystore keystore.jks --repo-keyalias=sova
123 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
124 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
125 echo "accepted_formats = ['txt', 'yml']" >> config.py
126 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
127 test -d archive || mkdir archive
128 test -d metadata || mkdir metadata
129 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
130 test -d repo || mkdir repo
131 test -d unsigned || mkdir unsigned
132 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
133 $fdroid publish --verbose
134 $fdroid update --verbose --nosign
135 $fdroid signindex --verbose
136 test -e repo/index.xml
137 test -e repo/index.jar
138 test -e repo/index-v1.jar
140 grep -F '<application id=' repo/index.xml > /dev/null
143 #------------------------------------------------------------------------------#
144 echo_header "test UTF-8 metadata"
146 REPOROOT=`create_test_dir`
150 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
151 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
153 cp $WORKSPACE/tests/urzip.apk repo/
154 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
160 #------------------------------------------------------------------------------#
161 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
163 cd $WORKSPACE/tests/tmp/importer
166 # stick with known working commit, in case future commits break things for this code
167 git reset --hard cecf00c08aec56ae7a5eba444150c4d1ae868814
168 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
169 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
170 echo "force_build_tools = True" >> config.py
171 $fdroid build --verbose org.fdroid.ci.test.app:300
173 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
177 #------------------------------------------------------------------------------#
178 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
180 REPOROOT=`create_test_dir`
181 GNUPGHOME=$REPOROOT/gnupghome
182 KEYSTORE=$WORKSPACE/tests/keystore.jks
184 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
185 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
186 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
187 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
188 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
189 chmod 0700 $GNUPGHOME
190 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
191 echo "install_list = 'org.adaway'" >> config.py
192 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
193 echo "gpghome = '$GNUPGHOME'" >> config.py
194 echo "gpgkey = 'CE71F7FB'" >> config.py
195 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
196 $fdroid update --verbose --pretty
197 test -e repo/index.xml
198 test -e repo/index.jar
199 test -e repo/index-v1.jar
200 grep -F '<application id=' repo/index.xml > /dev/null
201 grep -F '<install packageName=' repo/index.xml > /dev/null
202 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
203 $fdroid gpgsign --verbose
204 $fdroid gpgsign --verbose
205 test -e repo/obb.mainpatch.current_1619.apk.asc
206 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
207 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
208 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
209 ! test -e repo/index.xml.asc
211 # we can't easily reproduce the timestamps for things, so just hardcode them
212 sed -i --expression='s,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
213 diff $WORKSPACE/tests/repo/index.xml repo/index.xml
215 #------------------------------------------------------------------------------#
216 echo_header "test metadata checks"
218 REPOROOT=`create_test_dir`
223 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
227 if [ $? -eq 0 ]; then
228 echo "This should have failed because there is no metadata!"
231 echo "testing metadata checks passed"
235 mkdir $REPOROOT/metadata/
236 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
239 # now make a fake duplicate
240 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
244 if [ $? -eq 0 ]; then
245 echo "This should have failed because there is a duplicate metadata file!"
248 echo "testing duplicate metadata checks passed"
253 #------------------------------------------------------------------------------#
254 echo_header "ensure commands that don't need the JDK work without a JDK configed"
256 REPOROOT=`create_test_dir`
260 echo "License:GPL" >> metadata/fake.txt
261 echo "Summary:Yup still fake" >> metadata/fake.txt
262 echo "Categories:Internet" >> metadata/fake.txt
263 echo "Description:" >> metadata/fake.txt
264 echo "this is fake" >> metadata/fake.txt
265 echo "." >> metadata/fake.txt
267 # fake that no JDKs are available
268 echo 'java_paths = {}' > config.py
270 LOCAL_COPY_DIR=`create_test_dir`/fdroid
271 mkdir -p $LOCAL_COPY_DIR/repo
272 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
278 $fdroid rewritemeta fake
279 $fdroid server update
282 # run these to get their output, but the are not setup, so don't fail
283 $fdroid build || true
284 $fdroid import || true
285 $fdroid install || true
288 #------------------------------------------------------------------------------#
289 echo_header "create a source tarball and use that to build a repo"
292 $python setup.py sdist
294 REPOROOT=`create_test_dir`
296 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
298 ./fdroidserver-*/fdroid init
299 copy_apks_into_repo $REPOROOT
300 ./fdroidserver-*/fdroid update --create-metadata --verbose
303 #------------------------------------------------------------------------------#
304 echo_header "test config checks of local_copy_dir"
306 REPOROOT=`create_test_dir`
309 $fdroid update --create-metadata --verbose
311 $fdroid server update --local-copy-dir=/tmp/fdroid
313 # now test the errors work
315 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
316 if [ $? -eq 0 ]; then
317 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
320 echo "testing absolute path checker passed"
322 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
323 if [ $? -eq 0 ]; then
324 echo "This should have failed because the path does not end with 'fdroid'!"
327 echo "testing dirname exists checker passed"
329 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
330 if [ $? -eq 0 ]; then
331 echo "This should have failed because the dirname path does not exist!"
334 echo "testing dirname exists checker passed"
339 #------------------------------------------------------------------------------#
340 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
342 REPOROOT=`create_test_dir`
345 copy_apks_into_repo $REPOROOT
346 $fdroid update --create-metadata --verbose
348 grep -F '<application id=' repo/index.xml > /dev/null
350 LOCALCOPYDIR=`create_test_dir`/fdroid
351 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
352 NEWREPOROOT=`create_test_dir`
355 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
358 #------------------------------------------------------------------------------#
359 # check that --android-home fails when dir does not exist or is not a dir
361 REPOROOT=`create_test_dir`
362 KEYSTORE=$REPOROOT/keystore.jks
365 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
366 if [ $? -eq 0 ]; then
367 echo "This should have failed because /opt/fakeandroidhome does not exist!"
370 echo "testing android-home path checker passed"
372 TESTFILE=`create_test_file`
373 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
374 if [ $? -eq 0 ]; then
375 echo "This should have failed because $TESTFILE is a file not a dir!"
378 echo "testing android-home not-dir checker passed"
383 #------------------------------------------------------------------------------#
384 echo_header "check that fake android home passes 'fdroid init'"
386 REPOROOT=`create_test_dir`
387 FAKE_ANDROID_HOME=`create_test_dir`
388 create_fake_android_home $FAKE_ANDROID_HOME
389 KEYSTORE=$REPOROOT/keystore.jks
391 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
394 #------------------------------------------------------------------------------#
395 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
397 if [ -e /usr/bin/aapt ]; then
398 echo "/usr/bin/aapt exists, not running test"
400 REPOROOT=`create_test_dir`
401 FAKE_ANDROID_HOME=`create_test_dir`
402 create_fake_android_home $FAKE_ANDROID_HOME
403 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
404 KEYSTORE=$REPOROOT/keystore.jks
407 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
408 [ $? -eq 0 ] && exit 1
413 #------------------------------------------------------------------------------#
414 echo_header "check that --android-home overrides ANDROID_HOME"
416 REPOROOT=`create_test_dir`
417 FAKE_ANDROID_HOME=`create_test_dir`
418 create_fake_android_home $FAKE_ANDROID_HOME
419 KEYSTORE=$REPOROOT/keystore.jks
421 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
423 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
424 if [ $? -ne 0 ]; then
425 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
431 #------------------------------------------------------------------------------#
432 # In this case, ANDROID_HOME is set to a fake, non-working version that will
433 # be detected by fdroid as an Android SDK install. It should use the path set
434 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
435 # in ANDROID_HOME, it won't work because it is a fake one. Only
436 # --android-home provides a working one.
437 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
439 REPOROOT=`create_test_dir`
440 KEYSTORE=$REPOROOT/keystore.jks
441 FAKE_ANDROID_HOME=`create_test_dir`
442 create_fake_android_home $FAKE_ANDROID_HOME
443 STORED_ANDROID_HOME=$ANDROID_HOME
445 echo "ANDROID_HOME: $ANDROID_HOME"
447 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
449 copy_apks_into_repo $REPOROOT
450 $fdroid update --create-metadata --verbose
452 grep -F '<application id=' repo/index.xml > /dev/null
453 test -e repo/index.xml
454 test -e repo/index.jar
455 test -e repo/index-v1.jar
456 export ANDROID_HOME=$STORED_ANDROID_HOME
459 #------------------------------------------------------------------------------#
460 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
462 REPOROOT=`create_test_dir`
465 copy_apks_into_repo $REPOROOT
467 $fdroid update --create-metadata --verbose
469 grep -F '<application id=' repo/index.xml > /dev/null
472 #------------------------------------------------------------------------------#
473 echo_header "setup a new repo from scratch and generate a keystore"
475 REPOROOT=`create_test_dir`
476 KEYSTORE=$REPOROOT/keystore.jks
478 $fdroid init --keystore $KEYSTORE
480 copy_apks_into_repo $REPOROOT
481 $fdroid update --create-metadata --verbose
483 test -e repo/index.xml
484 test -e repo/index.jar
485 test -e repo/index-v1.jar
486 grep -F '<application id=' repo/index.xml > /dev/null
489 #------------------------------------------------------------------------------#
490 echo_header "setup a new repo manually and generate a keystore"
492 REPOROOT=`create_test_dir`
493 KEYSTORE=$REPOROOT/keystore.jks
496 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
500 if [ $? -eq 0 ]; then
501 echo "This should have failed because this repo has no keystore!"
504 echo '`fdroid update` prompted to add keystore'
507 $fdroid update --create-key
509 copy_apks_into_repo $REPOROOT
510 $fdroid update --create-metadata --verbose
512 test -e repo/index.xml
513 test -e repo/index.jar
514 test -e repo/index-v1.jar
515 grep -F '<application id=' repo/index.xml > /dev/null
518 #------------------------------------------------------------------------------#
519 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
521 REPOROOT=`create_test_dir`
522 KEYSTORE=$REPOROOT/keystore.jks
524 $fdroid init --keystore $KEYSTORE
526 copy_apks_into_repo $REPOROOT
527 $fdroid update --create-metadata --verbose
529 test -e repo/index.xml
530 test -e repo/index.jar
531 test -e repo/index-v1.jar
532 grep -F '<application id=' repo/index.xml > /dev/null
533 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
534 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
535 $fdroid update --create-metadata --verbose
537 test -e repo/index.xml
538 test -e repo/index.jar
539 test -e repo/index-v1.jar
540 grep -F '<application id=' repo/index.xml > /dev/null
543 #------------------------------------------------------------------------------#
544 echo_header "setup a new repo from scratch with a HSM/smartcard"
545 REPOROOT=`create_test_dir`
547 $fdroid init --keystore NONE
548 test -e opensc-fdroid.cfg
552 #------------------------------------------------------------------------------#
553 echo_header "setup a new repo with no keystore, add APK, and update"
555 REPOROOT=`create_test_dir`
556 KEYSTORE=$REPOROOT/keystore.jks
559 touch fdroid-icon.png
561 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
563 $fdroid update --create-metadata --verbose
564 if [ $? -eq 0 ]; then
565 echo "This should have failed because this repo has no keystore!"
568 echo '`fdroid update` prompted to add keystore'
572 # now set up fake, non-working keystore setup
574 echo "keystore = \"$KEYSTORE\"" >> config.py
575 echo 'repo_keyalias = "foo"' >> config.py
576 echo 'keystorepass = "foo"' >> config.py
577 echo 'keypass = "foo"' >> config.py
579 $fdroid update --create-metadata --verbose
580 if [ $? -eq 0 ]; then
581 echo "This should have failed because this repo has a bad/fake keystore!"
584 echo '`fdroid update` prompted to add keystore'
589 #------------------------------------------------------------------------------#
590 echo_header "copy tests/repo, update with binary transparency log"
592 REPOROOT=`create_test_dir`
593 GNUPGHOME=$REPOROOT/gnupghome
594 KEYSTORE=$WORKSPACE/tests/keystore.jks
595 mkdir $REPOROOT/git_remote
596 cd $REPOROOT/git_remote
599 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
600 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
601 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
602 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
603 echo "binary_transparency_remote = '$REPOROOT/git_remote'" >> config.py
604 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
605 $fdroid update --verbose --pretty
606 test -e repo/index.xml
607 test -e repo/index.jar
608 test -e repo/index-v1.jar
609 grep -F '<application id=' repo/index.xml > /dev/null
610 cd binary_transparency
611 [ `git rev-list --count HEAD` == "2" ]
612 cd $REPOROOT/git_remote
613 [ `git rev-list --count HEAD` == "2" ]
616 #------------------------------------------------------------------------------#
617 echo_header "setup a new repo with keystore with APK, update, then without key"
619 REPOROOT=`create_test_dir`
620 KEYSTORE=$REPOROOT/keystore.jks
622 $fdroid init --keystore $KEYSTORE
624 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
625 $fdroid update --create-metadata --verbose
627 test -e repo/index.xml
628 test -e repo/index.jar
629 test -e repo/index-v1.jar
630 grep -F '<application id=' repo/index.xml > /dev/null
632 # now set fake repo_keyalias
633 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
636 if [ $? -eq 0 ]; then
637 echo "This should have failed because this repo has a bad repo_keyalias!"
640 echo '`fdroid update` prompted to add keystore'
644 # try creating a new keystore, but fail because the old one is there
647 $fdroid update --create-key
648 if [ $? -eq 0 ]; then
649 echo "This should have failed because a keystore is already there!"
652 echo '`fdroid update` complained about existing keystore'
656 # now actually create the key with the existing settings
659 $fdroid update --create-key
663 #------------------------------------------------------------------------------#
665 # remove this to prevent git conflicts and complaining
666 rm -rf $WORKSPACE/fdroidserver.egg-info/