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
147 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
148 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
149 echo "force_build_tools = True" >> config.py
150 $fdroid build --verbose org.fdroid.ci.test.app:300
152 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
156 #------------------------------------------------------------------------------#
157 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
159 REPOROOT=`create_test_dir`
160 GNUPGHOME=$REPOROOT/gnupghome
163 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $REPOROOT/
164 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
165 chmod 0700 $GNUPGHOME
166 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
167 echo "install_list = 'org.adaway'" >> config.py
168 echo "uninstall_list = {'com.android.vending', 'com.facebook.orca',}" >> config.py
169 echo "gpghome = '$GNUPGHOME'" >> config.py
170 echo "gpgkey = 'CE71F7FB'" >> config.py
171 $fdroid update --verbose
172 test -e repo/index.xml
173 test -e repo/index.jar
174 grep -F '<application id=' repo/index.xml > /dev/null
175 grep -F '<install packageName=' repo/index.xml > /dev/null
176 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
177 $fdroid gpgsign --verbose
178 $fdroid gpgsign --verbose
179 test -e repo/obb.mainpatch.current_1619.apk.asc
180 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
181 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
182 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
183 ! test -e repo/index.xml.asc
186 #------------------------------------------------------------------------------#
187 echo_header "test metadata checks"
189 REPOROOT=`create_test_dir`
194 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
198 if [ $? -eq 0 ]; then
199 echo "This should have failed because there is no metadata!"
202 echo "testing metadata checks passed"
206 mkdir $REPOROOT/metadata/
207 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
210 # now make a fake duplicate
211 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
215 if [ $? -eq 0 ]; then
216 echo "This should have failed because there is a duplicate metadata file!"
219 echo "testing duplicate metadata checks passed"
224 #------------------------------------------------------------------------------#
225 echo_header "ensure commands that don't need the JDK work without a JDK configed"
227 REPOROOT=`create_test_dir`
231 echo "License:GPL" >> metadata/fake.txt
232 echo "Summary:Yup still fake" >> metadata/fake.txt
233 echo "Categories:Internet" >> metadata/fake.txt
234 echo "Description:" >> metadata/fake.txt
235 echo "this is fake" >> metadata/fake.txt
236 echo "." >> metadata/fake.txt
238 # fake that no JDKs are available
239 echo 'java_paths = {}' > config.py
241 LOCAL_COPY_DIR=`create_test_dir`/fdroid
242 mkdir -p $LOCAL_COPY_DIR/repo
243 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
249 $fdroid rewritemeta fake
250 $fdroid server update
253 # run these to get their output, but the are not setup, so don't fail
254 $fdroid build || true
255 $fdroid import || true
256 $fdroid install || true
259 #------------------------------------------------------------------------------#
260 echo_header "create a source tarball and use that to build a repo"
263 $python setup.py sdist
265 REPOROOT=`create_test_dir`
267 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
269 ./fdroidserver-*/fdroid init
270 copy_apks_into_repo $REPOROOT
271 ./fdroidserver-*/fdroid update --create-metadata --verbose
274 #------------------------------------------------------------------------------#
275 echo_header "test config checks of local_copy_dir"
277 REPOROOT=`create_test_dir`
280 $fdroid update --create-metadata --verbose
282 $fdroid server update --local-copy-dir=/tmp/fdroid
284 # now test the errors work
286 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
287 if [ $? -eq 0 ]; then
288 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
291 echo "testing absolute path checker passed"
293 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
294 if [ $? -eq 0 ]; then
295 echo "This should have failed because the path does not end with 'fdroid'!"
298 echo "testing dirname exists checker passed"
300 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
301 if [ $? -eq 0 ]; then
302 echo "This should have failed because the dirname path does not exist!"
305 echo "testing dirname exists checker passed"
310 #------------------------------------------------------------------------------#
311 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
313 REPOROOT=`create_test_dir`
316 copy_apks_into_repo $REPOROOT
317 $fdroid update --create-metadata --verbose
319 grep -F '<application id=' repo/index.xml > /dev/null
321 LOCALCOPYDIR=`create_test_dir`/fdroid
322 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
323 NEWREPOROOT=`create_test_dir`
326 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
329 #------------------------------------------------------------------------------#
330 # check that --android-home fails when dir does not exist or is not a dir
332 REPOROOT=`create_test_dir`
333 KEYSTORE=$REPOROOT/keystore.jks
336 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
337 if [ $? -eq 0 ]; then
338 echo "This should have failed because /opt/fakeandroidhome does not exist!"
341 echo "testing android-home path checker passed"
343 TESTFILE=`create_test_file`
344 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
345 if [ $? -eq 0 ]; then
346 echo "This should have failed because $TESTFILE is a file not a dir!"
349 echo "testing android-home not-dir checker passed"
354 #------------------------------------------------------------------------------#
355 echo_header "check that fake android home passes 'fdroid init'"
357 REPOROOT=`create_test_dir`
358 FAKE_ANDROID_HOME=`create_test_dir`
359 create_fake_android_home $FAKE_ANDROID_HOME
360 KEYSTORE=$REPOROOT/keystore.jks
362 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
365 #------------------------------------------------------------------------------#
366 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
368 if [ -e /usr/bin/aapt ]; then
369 echo "/usr/bin/aapt exists, not running test"
371 REPOROOT=`create_test_dir`
372 FAKE_ANDROID_HOME=`create_test_dir`
373 create_fake_android_home $FAKE_ANDROID_HOME
374 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
375 KEYSTORE=$REPOROOT/keystore.jks
378 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
379 [ $? -eq 0 ] && exit 1
384 #------------------------------------------------------------------------------#
385 echo_header "check that --android-home overrides ANDROID_HOME"
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
394 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
395 if [ $? -ne 0 ]; then
396 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
402 #------------------------------------------------------------------------------#
403 # In this case, ANDROID_HOME is set to a fake, non-working version that will
404 # be detected by fdroid as an Android SDK install. It should use the path set
405 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
406 # in ANDROID_HOME, it won't work because it is a fake one. Only
407 # --android-home provides a working one.
408 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
410 REPOROOT=`create_test_dir`
411 KEYSTORE=$REPOROOT/keystore.jks
412 FAKE_ANDROID_HOME=`create_test_dir`
413 create_fake_android_home $FAKE_ANDROID_HOME
414 STORED_ANDROID_HOME=$ANDROID_HOME
416 echo "ANDROID_HOME: $ANDROID_HOME"
418 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
420 copy_apks_into_repo $REPOROOT
421 $fdroid update --create-metadata --verbose
423 grep -F '<application id=' repo/index.xml > /dev/null
424 test -e repo/index.xml
425 test -e repo/index.jar
426 export ANDROID_HOME=$STORED_ANDROID_HOME
429 #------------------------------------------------------------------------------#
430 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
432 REPOROOT=`create_test_dir`
435 copy_apks_into_repo $REPOROOT
437 $fdroid update --create-metadata --verbose
439 grep -F '<application id=' repo/index.xml > /dev/null
442 #------------------------------------------------------------------------------#
443 echo_header "setup a new repo from scratch and generate a keystore"
445 REPOROOT=`create_test_dir`
446 KEYSTORE=$REPOROOT/keystore.jks
448 $fdroid init --keystore $KEYSTORE
450 copy_apks_into_repo $REPOROOT
451 $fdroid update --create-metadata --verbose
453 test -e repo/index.xml
454 test -e repo/index.jar
455 grep -F '<application id=' repo/index.xml > /dev/null
458 #------------------------------------------------------------------------------#
459 echo_header "setup a new repo manually and generate a keystore"
461 REPOROOT=`create_test_dir`
462 KEYSTORE=$REPOROOT/keystore.jks
465 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
469 if [ $? -eq 0 ]; then
470 echo "This should have failed because this repo has no keystore!"
473 echo '`fdroid update` prompted to add keystore'
476 $fdroid update --create-key
478 copy_apks_into_repo $REPOROOT
479 $fdroid update --create-metadata --verbose
481 test -e repo/index.xml
482 test -e repo/index.jar
483 grep -F '<application id=' repo/index.xml > /dev/null
486 #------------------------------------------------------------------------------#
487 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
489 REPOROOT=`create_test_dir`
490 KEYSTORE=$REPOROOT/keystore.jks
492 $fdroid init --keystore $KEYSTORE
494 copy_apks_into_repo $REPOROOT
495 $fdroid update --create-metadata --verbose
497 test -e repo/index.xml
498 test -e repo/index.jar
499 grep -F '<application id=' repo/index.xml > /dev/null
500 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
501 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
502 $fdroid update --create-metadata --verbose
504 test -e repo/index.xml
505 test -e repo/index.jar
506 grep -F '<application id=' repo/index.xml > /dev/null
509 #------------------------------------------------------------------------------#
510 echo_header "setup a new repo from scratch with a HSM/smartcard"
511 REPOROOT=`create_test_dir`
513 $fdroid init --keystore NONE
514 test -e opensc-fdroid.cfg
518 #------------------------------------------------------------------------------#
519 echo_header "setup a new repo with no keystore, add APK, and update"
521 REPOROOT=`create_test_dir`
522 KEYSTORE=$REPOROOT/keystore.jks
525 touch fdroid-icon.png
527 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
529 $fdroid update --create-metadata --verbose
530 if [ $? -eq 0 ]; then
531 echo "This should have failed because this repo has no keystore!"
534 echo '`fdroid update` prompted to add keystore'
538 # now set up fake, non-working keystore setup
540 echo "keystore = \"$KEYSTORE\"" >> config.py
541 echo 'repo_keyalias = "foo"' >> config.py
542 echo 'keystorepass = "foo"' >> config.py
543 echo 'keypass = "foo"' >> config.py
545 $fdroid update --create-metadata --verbose
546 if [ $? -eq 0 ]; then
547 echo "This should have failed because this repo has a bad/fake keystore!"
550 echo '`fdroid update` prompted to add keystore'
555 #------------------------------------------------------------------------------#
556 echo_header "setup a new repo with keystore with APK, update, then without key"
558 REPOROOT=`create_test_dir`
559 KEYSTORE=$REPOROOT/keystore.jks
561 $fdroid init --keystore $KEYSTORE
563 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
564 $fdroid update --create-metadata --verbose
566 test -e repo/index.xml
567 test -e repo/index.jar
568 grep -F '<application id=' repo/index.xml > /dev/null
570 # now set fake repo_keyalias
571 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
574 if [ $? -eq 0 ]; then
575 echo "This should have failed because this repo has a bad repo_keyalias!"
578 echo '`fdroid update` prompted to add keystore'
582 # try creating a new keystore, but fail because the old one is there
585 $fdroid update --create-key
586 if [ $? -eq 0 ]; then
587 echo "This should have failed because a keystore is already there!"
590 echo '`fdroid update` complained about existing keystore'
594 # now actually create the key with the existing settings
597 $fdroid update --create-key
601 #------------------------------------------------------------------------------#
603 # remove this to prevent git conflicts and complaining
604 rm -rf $WORKSPACE/fdroidserver.egg-info/