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 "test UTF-8 metadata"
119 REPOROOT=`create_test_dir`
123 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
124 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
126 cp $WORKSPACE/tests/urzip.apk repo/
127 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.txt metadata/
133 #------------------------------------------------------------------------------#
134 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
136 cd $WORKSPACE/tests/tmp/importer
139 # stick with known working commit, in case future commits break things for this code
140 git reset --hard cecf00c08aec56ae7a5eba444150c4d1ae868814
141 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
142 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
143 echo "force_build_tools = True" >> config.py
144 $fdroid build --verbose org.fdroid.ci.test.app:300
146 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
150 #------------------------------------------------------------------------------#
151 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
153 REPOROOT=`create_test_dir`
154 GNUPGHOME=$REPOROOT/gnupghome
155 KEYSTORE=$WORKSPACE/tests/keystore.jks
157 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
158 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
159 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
160 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
161 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
162 chmod 0700 $GNUPGHOME
163 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
164 echo "install_list = 'org.adaway'" >> config.py
165 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
166 echo "gpghome = '$GNUPGHOME'" >> config.py
167 echo "gpgkey = 'CE71F7FB'" >> config.py
168 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
169 $fdroid update --verbose --pretty
170 test -e repo/index.xml
171 test -e repo/index.jar
172 grep -F '<application id=' repo/index.xml > /dev/null
173 grep -F '<install packageName=' repo/index.xml > /dev/null
174 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
175 $fdroid gpgsign --verbose
176 $fdroid gpgsign --verbose
177 test -e repo/obb.mainpatch.current_1619.apk.asc
178 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
179 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
180 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
181 ! test -e repo/index.xml.asc
183 # we can't easily reproduce the timestamps for things, so just hardcode them
184 sed -i --expression='s,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
185 diff $WORKSPACE/tests/repo/index.xml repo/index.xml
187 #------------------------------------------------------------------------------#
188 echo_header "test metadata checks"
190 REPOROOT=`create_test_dir`
195 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
199 if [ $? -eq 0 ]; then
200 echo "This should have failed because there is no metadata!"
203 echo "testing metadata checks passed"
207 mkdir $REPOROOT/metadata/
208 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
211 # now make a fake duplicate
212 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
216 if [ $? -eq 0 ]; then
217 echo "This should have failed because there is a duplicate metadata file!"
220 echo "testing duplicate metadata checks passed"
225 #------------------------------------------------------------------------------#
226 echo_header "ensure commands that don't need the JDK work without a JDK configed"
228 REPOROOT=`create_test_dir`
232 echo "License:GPL" >> metadata/fake.txt
233 echo "Summary:Yup still fake" >> metadata/fake.txt
234 echo "Categories:Internet" >> metadata/fake.txt
235 echo "Description:" >> metadata/fake.txt
236 echo "this is fake" >> metadata/fake.txt
237 echo "." >> metadata/fake.txt
239 # fake that no JDKs are available
240 echo 'java_paths = {}' > config.py
242 LOCAL_COPY_DIR=`create_test_dir`/fdroid
243 mkdir -p $LOCAL_COPY_DIR/repo
244 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
250 $fdroid rewritemeta fake
251 $fdroid server update
254 # run these to get their output, but the are not setup, so don't fail
255 $fdroid build || true
256 $fdroid import || true
257 $fdroid install || true
260 #------------------------------------------------------------------------------#
261 echo_header "create a source tarball and use that to build a repo"
264 $python setup.py sdist
266 REPOROOT=`create_test_dir`
268 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
270 ./fdroidserver-*/fdroid init
271 copy_apks_into_repo $REPOROOT
272 ./fdroidserver-*/fdroid update --create-metadata --verbose
275 #------------------------------------------------------------------------------#
276 echo_header "test config checks of local_copy_dir"
278 REPOROOT=`create_test_dir`
281 $fdroid update --create-metadata --verbose
283 $fdroid server update --local-copy-dir=/tmp/fdroid
285 # now test the errors work
287 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
288 if [ $? -eq 0 ]; then
289 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
292 echo "testing absolute path checker passed"
294 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
295 if [ $? -eq 0 ]; then
296 echo "This should have failed because the path does not end with 'fdroid'!"
299 echo "testing dirname exists checker passed"
301 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
302 if [ $? -eq 0 ]; then
303 echo "This should have failed because the dirname path does not exist!"
306 echo "testing dirname exists checker passed"
311 #------------------------------------------------------------------------------#
312 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
314 REPOROOT=`create_test_dir`
317 copy_apks_into_repo $REPOROOT
318 $fdroid update --create-metadata --verbose
320 grep -F '<application id=' repo/index.xml > /dev/null
322 LOCALCOPYDIR=`create_test_dir`/fdroid
323 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
324 NEWREPOROOT=`create_test_dir`
327 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
330 #------------------------------------------------------------------------------#
331 # check that --android-home fails when dir does not exist or is not a dir
333 REPOROOT=`create_test_dir`
334 KEYSTORE=$REPOROOT/keystore.jks
337 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
338 if [ $? -eq 0 ]; then
339 echo "This should have failed because /opt/fakeandroidhome does not exist!"
342 echo "testing android-home path checker passed"
344 TESTFILE=`create_test_file`
345 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
346 if [ $? -eq 0 ]; then
347 echo "This should have failed because $TESTFILE is a file not a dir!"
350 echo "testing android-home not-dir checker passed"
355 #------------------------------------------------------------------------------#
356 echo_header "check that fake android home passes 'fdroid init'"
358 REPOROOT=`create_test_dir`
359 FAKE_ANDROID_HOME=`create_test_dir`
360 create_fake_android_home $FAKE_ANDROID_HOME
361 KEYSTORE=$REPOROOT/keystore.jks
363 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
366 #------------------------------------------------------------------------------#
367 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
369 if [ -e /usr/bin/aapt ]; then
370 echo "/usr/bin/aapt exists, not running test"
372 REPOROOT=`create_test_dir`
373 FAKE_ANDROID_HOME=`create_test_dir`
374 create_fake_android_home $FAKE_ANDROID_HOME
375 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
376 KEYSTORE=$REPOROOT/keystore.jks
379 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
380 [ $? -eq 0 ] && exit 1
385 #------------------------------------------------------------------------------#
386 echo_header "check that --android-home overrides ANDROID_HOME"
388 REPOROOT=`create_test_dir`
389 FAKE_ANDROID_HOME=`create_test_dir`
390 create_fake_android_home $FAKE_ANDROID_HOME
391 KEYSTORE=$REPOROOT/keystore.jks
393 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
395 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
396 if [ $? -ne 0 ]; then
397 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
403 #------------------------------------------------------------------------------#
404 # In this case, ANDROID_HOME is set to a fake, non-working version that will
405 # be detected by fdroid as an Android SDK install. It should use the path set
406 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
407 # in ANDROID_HOME, it won't work because it is a fake one. Only
408 # --android-home provides a working one.
409 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
411 REPOROOT=`create_test_dir`
412 KEYSTORE=$REPOROOT/keystore.jks
413 FAKE_ANDROID_HOME=`create_test_dir`
414 create_fake_android_home $FAKE_ANDROID_HOME
415 STORED_ANDROID_HOME=$ANDROID_HOME
417 echo "ANDROID_HOME: $ANDROID_HOME"
419 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
421 copy_apks_into_repo $REPOROOT
422 $fdroid update --create-metadata --verbose
424 grep -F '<application id=' repo/index.xml > /dev/null
425 test -e repo/index.xml
426 test -e repo/index.jar
427 export ANDROID_HOME=$STORED_ANDROID_HOME
430 #------------------------------------------------------------------------------#
431 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
433 REPOROOT=`create_test_dir`
436 copy_apks_into_repo $REPOROOT
438 $fdroid update --create-metadata --verbose
440 grep -F '<application id=' repo/index.xml > /dev/null
443 #------------------------------------------------------------------------------#
444 echo_header "setup a new repo from scratch and generate a keystore"
446 REPOROOT=`create_test_dir`
447 KEYSTORE=$REPOROOT/keystore.jks
449 $fdroid init --keystore $KEYSTORE
451 copy_apks_into_repo $REPOROOT
452 $fdroid update --create-metadata --verbose
454 test -e repo/index.xml
455 test -e repo/index.jar
456 grep -F '<application id=' repo/index.xml > /dev/null
459 #------------------------------------------------------------------------------#
460 echo_header "setup a new repo manually and generate a keystore"
462 REPOROOT=`create_test_dir`
463 KEYSTORE=$REPOROOT/keystore.jks
466 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
470 if [ $? -eq 0 ]; then
471 echo "This should have failed because this repo has no keystore!"
474 echo '`fdroid update` prompted to add keystore'
477 $fdroid update --create-key
479 copy_apks_into_repo $REPOROOT
480 $fdroid update --create-metadata --verbose
482 test -e repo/index.xml
483 test -e repo/index.jar
484 grep -F '<application id=' repo/index.xml > /dev/null
487 #------------------------------------------------------------------------------#
488 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
490 REPOROOT=`create_test_dir`
491 KEYSTORE=$REPOROOT/keystore.jks
493 $fdroid init --keystore $KEYSTORE
495 copy_apks_into_repo $REPOROOT
496 $fdroid update --create-metadata --verbose
498 test -e repo/index.xml
499 test -e repo/index.jar
500 grep -F '<application id=' repo/index.xml > /dev/null
501 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
502 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
503 $fdroid update --create-metadata --verbose
505 test -e repo/index.xml
506 test -e repo/index.jar
507 grep -F '<application id=' repo/index.xml > /dev/null
510 #------------------------------------------------------------------------------#
511 echo_header "setup a new repo from scratch with a HSM/smartcard"
512 REPOROOT=`create_test_dir`
514 $fdroid init --keystore NONE
515 test -e opensc-fdroid.cfg
519 #------------------------------------------------------------------------------#
520 echo_header "setup a new repo with no keystore, add APK, and update"
522 REPOROOT=`create_test_dir`
523 KEYSTORE=$REPOROOT/keystore.jks
526 touch fdroid-icon.png
528 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
530 $fdroid update --create-metadata --verbose
531 if [ $? -eq 0 ]; then
532 echo "This should have failed because this repo has no keystore!"
535 echo '`fdroid update` prompted to add keystore'
539 # now set up fake, non-working keystore setup
541 echo "keystore = \"$KEYSTORE\"" >> config.py
542 echo 'repo_keyalias = "foo"' >> config.py
543 echo 'keystorepass = "foo"' >> config.py
544 echo 'keypass = "foo"' >> config.py
546 $fdroid update --create-metadata --verbose
547 if [ $? -eq 0 ]; then
548 echo "This should have failed because this repo has a bad/fake keystore!"
551 echo '`fdroid update` prompted to add keystore'
556 #------------------------------------------------------------------------------#
557 echo_header "copy tests/repo, update with binary transparency log"
559 REPOROOT=`create_test_dir`
560 GNUPGHOME=$REPOROOT/gnupghome
561 KEYSTORE=$WORKSPACE/tests/keystore.jks
563 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
564 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
565 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
566 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
567 echo 'binary_transparency_remote = "git@gitlab.com:fdroid-continuous-integration/binary-transparency.git"' >> config.py
568 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
569 $fdroid update --verbose --pretty
570 test -e repo/index.xml
571 test -e repo/index.jar
572 grep -F '<application id=' repo/index.xml > /dev/null
573 cd binary_transparency
574 [ `git rev-list --count HEAD` == "2" ]
577 #------------------------------------------------------------------------------#
578 echo_header "setup a new repo with keystore with APK, update, then without key"
580 REPOROOT=`create_test_dir`
581 KEYSTORE=$REPOROOT/keystore.jks
583 $fdroid init --keystore $KEYSTORE
585 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
586 $fdroid update --create-metadata --verbose
588 test -e repo/index.xml
589 test -e repo/index.jar
590 grep -F '<application id=' repo/index.xml > /dev/null
592 # now set fake repo_keyalias
593 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
596 if [ $? -eq 0 ]; then
597 echo "This should have failed because this repo has a bad repo_keyalias!"
600 echo '`fdroid update` prompted to add keystore'
604 # try creating a new keystore, but fail because the old one is there
607 $fdroid update --create-key
608 if [ $? -eq 0 ]; then
609 echo "This should have failed because a keystore is already there!"
612 echo '`fdroid update` complained about existing keystore'
616 # now actually create the key with the existing settings
619 $fdroid update --create-key
623 #------------------------------------------------------------------------------#
625 # remove this to prevent git conflicts and complaining
626 rm -rf $WORKSPACE/fdroidserver.egg-info/