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 echo "sync_from_local_copy_dir = True" >> config.py
356 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
359 #------------------------------------------------------------------------------#
360 # check that --android-home fails when dir does not exist or is not a dir
362 REPOROOT=`create_test_dir`
363 KEYSTORE=$REPOROOT/keystore.jks
366 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
367 if [ $? -eq 0 ]; then
368 echo "This should have failed because /opt/fakeandroidhome does not exist!"
371 echo "testing android-home path checker passed"
373 TESTFILE=`create_test_file`
374 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
375 if [ $? -eq 0 ]; then
376 echo "This should have failed because $TESTFILE is a file not a dir!"
379 echo "testing android-home not-dir checker passed"
384 #------------------------------------------------------------------------------#
385 echo_header "check that fake android home passes 'fdroid init'"
387 REPOROOT=`create_test_dir`
388 FAKE_ANDROID_HOME=`create_test_dir`
389 create_fake_android_home $FAKE_ANDROID_HOME
390 KEYSTORE=$REPOROOT/keystore.jks
392 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
395 #------------------------------------------------------------------------------#
396 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
398 if [ -e /usr/bin/aapt ]; then
399 echo "/usr/bin/aapt exists, not running test"
401 REPOROOT=`create_test_dir`
402 FAKE_ANDROID_HOME=`create_test_dir`
403 create_fake_android_home $FAKE_ANDROID_HOME
404 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
405 KEYSTORE=$REPOROOT/keystore.jks
408 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
409 [ $? -eq 0 ] && exit 1
414 #------------------------------------------------------------------------------#
415 echo_header "check that --android-home overrides ANDROID_HOME"
417 REPOROOT=`create_test_dir`
418 FAKE_ANDROID_HOME=`create_test_dir`
419 create_fake_android_home $FAKE_ANDROID_HOME
420 KEYSTORE=$REPOROOT/keystore.jks
422 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
424 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
425 if [ $? -ne 0 ]; then
426 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
432 #------------------------------------------------------------------------------#
433 # In this case, ANDROID_HOME is set to a fake, non-working version that will
434 # be detected by fdroid as an Android SDK install. It should use the path set
435 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
436 # in ANDROID_HOME, it won't work because it is a fake one. Only
437 # --android-home provides a working one.
438 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
440 REPOROOT=`create_test_dir`
441 KEYSTORE=$REPOROOT/keystore.jks
442 FAKE_ANDROID_HOME=`create_test_dir`
443 create_fake_android_home $FAKE_ANDROID_HOME
444 STORED_ANDROID_HOME=$ANDROID_HOME
446 echo "ANDROID_HOME: $ANDROID_HOME"
448 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
450 copy_apks_into_repo $REPOROOT
451 $fdroid update --create-metadata --verbose
453 grep -F '<application id=' repo/index.xml > /dev/null
454 test -e repo/index.xml
455 test -e repo/index.jar
456 test -e repo/index-v1.jar
457 export ANDROID_HOME=$STORED_ANDROID_HOME
460 #------------------------------------------------------------------------------#
461 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
463 REPOROOT=`create_test_dir`
466 copy_apks_into_repo $REPOROOT
468 $fdroid update --create-metadata --verbose
470 grep -F '<application id=' repo/index.xml > /dev/null
473 #------------------------------------------------------------------------------#
474 echo_header "setup a new repo from scratch and generate a keystore"
476 REPOROOT=`create_test_dir`
477 KEYSTORE=$REPOROOT/keystore.jks
479 $fdroid init --keystore $KEYSTORE
481 copy_apks_into_repo $REPOROOT
482 $fdroid update --create-metadata --verbose
484 test -e repo/index.xml
485 test -e repo/index.jar
486 test -e repo/index-v1.jar
487 grep -F '<application id=' repo/index.xml > /dev/null
490 #------------------------------------------------------------------------------#
491 echo_header "setup a new repo manually and generate a keystore"
493 REPOROOT=`create_test_dir`
494 KEYSTORE=$REPOROOT/keystore.jks
497 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
501 if [ $? -eq 0 ]; then
502 echo "This should have failed because this repo has no keystore!"
505 echo '`fdroid update` prompted to add keystore'
508 $fdroid update --create-key
510 copy_apks_into_repo $REPOROOT
511 $fdroid update --create-metadata --verbose
513 test -e repo/index.xml
514 test -e repo/index.jar
515 test -e repo/index-v1.jar
516 grep -F '<application id=' repo/index.xml > /dev/null
519 #------------------------------------------------------------------------------#
520 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
522 REPOROOT=`create_test_dir`
523 KEYSTORE=$REPOROOT/keystore.jks
525 $fdroid init --keystore $KEYSTORE
527 copy_apks_into_repo $REPOROOT
528 $fdroid update --create-metadata --verbose
530 test -e repo/index.xml
531 test -e repo/index.jar
532 test -e repo/index-v1.jar
533 grep -F '<application id=' repo/index.xml > /dev/null
534 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
535 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
536 $fdroid update --create-metadata --verbose
538 test -e repo/index.xml
539 test -e repo/index.jar
540 test -e repo/index-v1.jar
541 grep -F '<application id=' repo/index.xml > /dev/null
544 #------------------------------------------------------------------------------#
545 echo_header "setup a new repo from scratch with a HSM/smartcard"
546 REPOROOT=`create_test_dir`
548 $fdroid init --keystore NONE
549 test -e opensc-fdroid.cfg
553 #------------------------------------------------------------------------------#
554 echo_header "setup a new repo with no keystore, add APK, and update"
556 REPOROOT=`create_test_dir`
557 KEYSTORE=$REPOROOT/keystore.jks
560 touch fdroid-icon.png
562 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
564 $fdroid update --create-metadata --verbose
565 if [ $? -eq 0 ]; then
566 echo "This should have failed because this repo has no keystore!"
569 echo '`fdroid update` prompted to add keystore'
573 # now set up fake, non-working keystore setup
575 echo "keystore = \"$KEYSTORE\"" >> config.py
576 echo 'repo_keyalias = "foo"' >> config.py
577 echo 'keystorepass = "foo"' >> config.py
578 echo 'keypass = "foo"' >> config.py
580 $fdroid update --create-metadata --verbose
581 if [ $? -eq 0 ]; then
582 echo "This should have failed because this repo has a bad/fake keystore!"
585 echo '`fdroid update` prompted to add keystore'
590 #------------------------------------------------------------------------------#
591 echo_header "copy tests/repo, update with binary transparency log"
593 REPOROOT=`create_test_dir`
594 GNUPGHOME=$REPOROOT/gnupghome
595 KEYSTORE=$WORKSPACE/tests/keystore.jks
596 mkdir $REPOROOT/git_remote
597 cd $REPOROOT/git_remote
600 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
601 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
602 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
603 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
604 echo "binary_transparency_remote = '$REPOROOT/git_remote'" >> config.py
605 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
606 $fdroid update --verbose
607 $fdroid server update --verbose
608 test -e repo/index.xml
609 test -e repo/index.jar
610 test -e repo/index-v1.jar
611 grep -F '<application id=' repo/index.xml > /dev/null
612 cd binary_transparency
613 [ `git rev-list --count HEAD` == "2" ]
614 cd $REPOROOT/git_remote
615 [ `git rev-list --count HEAD` == "2" ]
618 #------------------------------------------------------------------------------#
619 echo_header "setup a new repo with keystore with APK, update, then without key"
621 REPOROOT=`create_test_dir`
622 KEYSTORE=$REPOROOT/keystore.jks
624 $fdroid init --keystore $KEYSTORE
626 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
627 $fdroid update --create-metadata --verbose
629 test -e repo/index.xml
630 test -e repo/index.jar
631 test -e repo/index-v1.jar
632 grep -F '<application id=' repo/index.xml > /dev/null
634 # now set fake repo_keyalias
635 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
638 if [ $? -eq 0 ]; then
639 echo "This should have failed because this repo has a bad repo_keyalias!"
642 echo '`fdroid update` prompted to add keystore'
646 # try creating a new keystore, but fail because the old one is there
649 $fdroid update --create-key
650 if [ $? -eq 0 ]; then
651 echo "This should have failed because a keystore is already there!"
654 echo '`fdroid update` complained about existing keystore'
658 # now actually create the key with the existing settings
661 $fdroid update --create-key
665 #------------------------------------------------------------------------------#
667 # remove this to prevent git conflicts and complaining
668 rm -rf $WORKSPACE/fdroidserver.egg-info/