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 "build the TeX manual"
120 # this is only ever generated officially on GNU/Linux
121 if [ `uname -s` == "Linux" ]; then
122 ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
126 #------------------------------------------------------------------------------#
127 echo_header "test UTF-8 metadata"
129 REPOROOT=`create_test_dir`
133 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
134 echo "mirrors = {'https://foo.bar/fdroid', 'http://secret.onion/fdroid'}" >> config.py
136 cp $WORKSPACE/tests/urzip.apk repo/
137 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.txt metadata/
143 #------------------------------------------------------------------------------#
144 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
146 cd $WORKSPACE/tests/tmp/importer
149 # stick with known working commit, in case future commits break things for this code
150 git reset --hard cecf00c08aec56ae7a5eba444150c4d1ae868814
151 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
152 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
153 echo "force_build_tools = True" >> config.py
154 $fdroid build --verbose org.fdroid.ci.test.app:300
156 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
160 #------------------------------------------------------------------------------#
161 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
163 REPOROOT=`create_test_dir`
164 GNUPGHOME=$REPOROOT/gnupghome
165 KEYSTORE=$WORKSPACE/tests/keystore.jks
167 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
168 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
169 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
170 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
171 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
172 chmod 0700 $GNUPGHOME
173 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
174 echo "install_list = 'org.adaway'" >> config.py
175 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
176 echo "gpghome = '$GNUPGHOME'" >> config.py
177 echo "gpgkey = 'CE71F7FB'" >> config.py
178 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
179 $fdroid update --verbose --pretty
180 test -e repo/index.xml
181 test -e repo/index.jar
182 grep -F '<application id=' repo/index.xml > /dev/null
183 grep -F '<install packageName=' repo/index.xml > /dev/null
184 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
185 $fdroid gpgsign --verbose
186 $fdroid gpgsign --verbose
187 test -e repo/obb.mainpatch.current_1619.apk.asc
188 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
189 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
190 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
191 ! test -e repo/index.xml.asc
193 # we can't easily reproduce the timestamps for things, so just hardcode them
194 sed -i --expression='s,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
195 diff $WORKSPACE/tests/repo/index.xml repo/index.xml
197 #------------------------------------------------------------------------------#
198 echo_header "test metadata checks"
200 REPOROOT=`create_test_dir`
205 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
209 if [ $? -eq 0 ]; then
210 echo "This should have failed because there is no metadata!"
213 echo "testing metadata checks passed"
217 mkdir $REPOROOT/metadata/
218 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
221 # now make a fake duplicate
222 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
226 if [ $? -eq 0 ]; then
227 echo "This should have failed because there is a duplicate metadata file!"
230 echo "testing duplicate metadata checks passed"
235 #------------------------------------------------------------------------------#
236 echo_header "ensure commands that don't need the JDK work without a JDK configed"
238 REPOROOT=`create_test_dir`
242 echo "License:GPL" >> metadata/fake.txt
243 echo "Summary:Yup still fake" >> metadata/fake.txt
244 echo "Categories:Internet" >> metadata/fake.txt
245 echo "Description:" >> metadata/fake.txt
246 echo "this is fake" >> metadata/fake.txt
247 echo "." >> metadata/fake.txt
249 # fake that no JDKs are available
250 echo 'java_paths = {}' > config.py
252 LOCAL_COPY_DIR=`create_test_dir`/fdroid
253 mkdir -p $LOCAL_COPY_DIR/repo
254 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
260 $fdroid rewritemeta fake
261 $fdroid server update
264 # run these to get their output, but the are not setup, so don't fail
265 $fdroid build || true
266 $fdroid import || true
267 $fdroid install || true
270 #------------------------------------------------------------------------------#
271 echo_header "create a source tarball and use that to build a repo"
274 $python setup.py sdist
276 REPOROOT=`create_test_dir`
278 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
280 ./fdroidserver-*/fdroid init
281 copy_apks_into_repo $REPOROOT
282 ./fdroidserver-*/fdroid update --create-metadata --verbose
285 #------------------------------------------------------------------------------#
286 echo_header "test config checks of local_copy_dir"
288 REPOROOT=`create_test_dir`
291 $fdroid update --create-metadata --verbose
293 $fdroid server update --local-copy-dir=/tmp/fdroid
295 # now test the errors work
297 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
298 if [ $? -eq 0 ]; then
299 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
302 echo "testing absolute path checker passed"
304 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
305 if [ $? -eq 0 ]; then
306 echo "This should have failed because the path does not end with 'fdroid'!"
309 echo "testing dirname exists checker passed"
311 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
312 if [ $? -eq 0 ]; then
313 echo "This should have failed because the dirname path does not exist!"
316 echo "testing dirname exists checker passed"
321 #------------------------------------------------------------------------------#
322 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
324 REPOROOT=`create_test_dir`
327 copy_apks_into_repo $REPOROOT
328 $fdroid update --create-metadata --verbose
330 grep -F '<application id=' repo/index.xml > /dev/null
332 LOCALCOPYDIR=`create_test_dir`/fdroid
333 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
334 NEWREPOROOT=`create_test_dir`
337 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
340 #------------------------------------------------------------------------------#
341 # check that --android-home fails when dir does not exist or is not a dir
343 REPOROOT=`create_test_dir`
344 KEYSTORE=$REPOROOT/keystore.jks
347 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
348 if [ $? -eq 0 ]; then
349 echo "This should have failed because /opt/fakeandroidhome does not exist!"
352 echo "testing android-home path checker passed"
354 TESTFILE=`create_test_file`
355 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
356 if [ $? -eq 0 ]; then
357 echo "This should have failed because $TESTFILE is a file not a dir!"
360 echo "testing android-home not-dir checker passed"
365 #------------------------------------------------------------------------------#
366 echo_header "check that fake android home passes 'fdroid init'"
368 REPOROOT=`create_test_dir`
369 FAKE_ANDROID_HOME=`create_test_dir`
370 create_fake_android_home $FAKE_ANDROID_HOME
371 KEYSTORE=$REPOROOT/keystore.jks
373 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
376 #------------------------------------------------------------------------------#
377 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
379 if [ -e /usr/bin/aapt ]; then
380 echo "/usr/bin/aapt exists, not running test"
382 REPOROOT=`create_test_dir`
383 FAKE_ANDROID_HOME=`create_test_dir`
384 create_fake_android_home $FAKE_ANDROID_HOME
385 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
386 KEYSTORE=$REPOROOT/keystore.jks
389 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
390 [ $? -eq 0 ] && exit 1
395 #------------------------------------------------------------------------------#
396 echo_header "check that --android-home overrides ANDROID_HOME"
398 REPOROOT=`create_test_dir`
399 FAKE_ANDROID_HOME=`create_test_dir`
400 create_fake_android_home $FAKE_ANDROID_HOME
401 KEYSTORE=$REPOROOT/keystore.jks
403 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
405 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
406 if [ $? -ne 0 ]; then
407 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
413 #------------------------------------------------------------------------------#
414 # In this case, ANDROID_HOME is set to a fake, non-working version that will
415 # be detected by fdroid as an Android SDK install. It should use the path set
416 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
417 # in ANDROID_HOME, it won't work because it is a fake one. Only
418 # --android-home provides a working one.
419 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
421 REPOROOT=`create_test_dir`
422 KEYSTORE=$REPOROOT/keystore.jks
423 FAKE_ANDROID_HOME=`create_test_dir`
424 create_fake_android_home $FAKE_ANDROID_HOME
425 STORED_ANDROID_HOME=$ANDROID_HOME
427 echo "ANDROID_HOME: $ANDROID_HOME"
429 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
431 copy_apks_into_repo $REPOROOT
432 $fdroid update --create-metadata --verbose
434 grep -F '<application id=' repo/index.xml > /dev/null
435 test -e repo/index.xml
436 test -e repo/index.jar
437 export ANDROID_HOME=$STORED_ANDROID_HOME
440 #------------------------------------------------------------------------------#
441 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
443 REPOROOT=`create_test_dir`
446 copy_apks_into_repo $REPOROOT
448 $fdroid update --create-metadata --verbose
450 grep -F '<application id=' repo/index.xml > /dev/null
453 #------------------------------------------------------------------------------#
454 echo_header "setup a new repo from scratch and generate a keystore"
456 REPOROOT=`create_test_dir`
457 KEYSTORE=$REPOROOT/keystore.jks
459 $fdroid init --keystore $KEYSTORE
461 copy_apks_into_repo $REPOROOT
462 $fdroid update --create-metadata --verbose
464 test -e repo/index.xml
465 test -e repo/index.jar
466 grep -F '<application id=' repo/index.xml > /dev/null
469 #------------------------------------------------------------------------------#
470 echo_header "setup a new repo manually and generate a keystore"
472 REPOROOT=`create_test_dir`
473 KEYSTORE=$REPOROOT/keystore.jks
476 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
480 if [ $? -eq 0 ]; then
481 echo "This should have failed because this repo has no keystore!"
484 echo '`fdroid update` prompted to add keystore'
487 $fdroid update --create-key
489 copy_apks_into_repo $REPOROOT
490 $fdroid update --create-metadata --verbose
492 test -e repo/index.xml
493 test -e repo/index.jar
494 grep -F '<application id=' repo/index.xml > /dev/null
497 #------------------------------------------------------------------------------#
498 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
500 REPOROOT=`create_test_dir`
501 KEYSTORE=$REPOROOT/keystore.jks
503 $fdroid init --keystore $KEYSTORE
505 copy_apks_into_repo $REPOROOT
506 $fdroid update --create-metadata --verbose
508 test -e repo/index.xml
509 test -e repo/index.jar
510 grep -F '<application id=' repo/index.xml > /dev/null
511 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
512 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
513 $fdroid update --create-metadata --verbose
515 test -e repo/index.xml
516 test -e repo/index.jar
517 grep -F '<application id=' repo/index.xml > /dev/null
520 #------------------------------------------------------------------------------#
521 echo_header "setup a new repo from scratch with a HSM/smartcard"
522 REPOROOT=`create_test_dir`
524 $fdroid init --keystore NONE
525 test -e opensc-fdroid.cfg
529 #------------------------------------------------------------------------------#
530 echo_header "setup a new repo with no keystore, add APK, and update"
532 REPOROOT=`create_test_dir`
533 KEYSTORE=$REPOROOT/keystore.jks
536 touch fdroid-icon.png
538 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
540 $fdroid update --create-metadata --verbose
541 if [ $? -eq 0 ]; then
542 echo "This should have failed because this repo has no keystore!"
545 echo '`fdroid update` prompted to add keystore'
549 # now set up fake, non-working keystore setup
551 echo "keystore = \"$KEYSTORE\"" >> config.py
552 echo 'repo_keyalias = "foo"' >> config.py
553 echo 'keystorepass = "foo"' >> config.py
554 echo 'keypass = "foo"' >> config.py
556 $fdroid update --create-metadata --verbose
557 if [ $? -eq 0 ]; then
558 echo "This should have failed because this repo has a bad/fake keystore!"
561 echo '`fdroid update` prompted to add keystore'
566 #------------------------------------------------------------------------------#
567 echo_header "setup a new repo with keystore with APK, update, then without key"
569 REPOROOT=`create_test_dir`
570 KEYSTORE=$REPOROOT/keystore.jks
572 $fdroid init --keystore $KEYSTORE
574 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
575 $fdroid update --create-metadata --verbose
577 test -e repo/index.xml
578 test -e repo/index.jar
579 grep -F '<application id=' repo/index.xml > /dev/null
581 # now set fake repo_keyalias
582 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
585 if [ $? -eq 0 ]; then
586 echo "This should have failed because this repo has a bad repo_keyalias!"
589 echo '`fdroid update` prompted to add keystore'
593 # try creating a new keystore, but fail because the old one is there
596 $fdroid update --create-key
597 if [ $? -eq 0 ]; then
598 echo "This should have failed because a keystore is already there!"
601 echo '`fdroid update` complained about existing keystore'
605 # now actually create the key with the existing settings
608 $fdroid update --create-key
612 #------------------------------------------------------------------------------#
614 # remove this to prevent git conflicts and complaining
615 rm -rf $WORKSPACE/fdroidserver.egg-info/