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 # the < is reverse since 0 means success in exit codes
46 python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version`
49 #------------------------------------------------------------------------------#
52 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
54 echo "Usage: $0 '/path/to/folder/with/apks'"
58 if [ -z "$ANDROID_HOME" ]; then
59 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
60 echo " export ANDROID_HOME=/opt/android-sdk"
74 if [ -z $WORKSPACE ]; then
75 WORKSPACE=`dirname $(pwd)`
76 echo "Setting Workspace to $WORKSPACE"
79 # allow the location of the script to be overridden
80 if [ -z $fdroid ]; then
81 fdroid="$WORKSPACE/fdroid"
84 # allow the location of aapt to be overridden
86 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
89 # allow the location of python to be overridden
90 if [ -z $python ]; then
94 set -x # show each command as it is executed
96 #------------------------------------------------------------------------------#
97 echo_header "run commit hooks"
103 #------------------------------------------------------------------------------#
104 echo_header "test python getsig replacement"
106 cd $WORKSPACE/tests/getsig
110 for testcase in $WORKSPACE/tests/*.TestCase; do
115 #------------------------------------------------------------------------------#
116 echo_header "print fdroid version"
121 #------------------------------------------------------------------------------#
122 echo_header 'run process when building and signing are on separate machines'
124 REPOROOT=`create_test_dir`
126 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
127 $fdroid init --keystore keystore.jks --repo-keyalias=sova
128 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
129 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
130 echo "accepted_formats = ['txt', 'yml']" >> config.py
131 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
132 test -d archive || mkdir archive
133 test -d metadata || mkdir metadata
134 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
135 test -d repo || mkdir repo
136 test -d unsigned || mkdir unsigned
137 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
138 $fdroid publish --verbose
139 $fdroid update --verbose --nosign
140 $fdroid signindex --verbose
141 test -e repo/index.xml
142 test -e repo/index.jar
143 test -e repo/index-v1.jar
145 grep -F '<application id=' repo/index.xml > /dev/null
148 #------------------------------------------------------------------------------#
149 echo_header "test UTF-8 metadata"
151 REPOROOT=`create_test_dir`
155 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
156 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
158 cp $WORKSPACE/tests/urzip.apk repo/
159 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
165 #------------------------------------------------------------------------------#
166 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
168 cd $WORKSPACE/tests/tmp/importer
171 # stick with known working commit, in case future commits break things for this code
172 git reset --hard cecf00c08aec56ae7a5eba444150c4d1ae868814
173 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
174 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
175 echo "force_build_tools = True" >> config.py
176 $fdroid build --verbose org.fdroid.ci.test.app:300
178 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
181 #------------------------------------------------------------------------------#
182 echo_header 'copy git import and run `fdroid scanner` on it'
184 REPOROOT=`create_test_dir`
187 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
189 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
190 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
191 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
192 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
193 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
194 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
195 echo "" >> metadata/org.fdroid.ci.test.app.txt
196 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
197 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
199 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
200 ls -l build/org.fdroid.ci.test.app
201 $fdroid scanner org.fdroid.ci.test.app --verbose
204 #------------------------------------------------------------------------------#
205 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
207 REPOROOT=`create_test_dir`
208 GNUPGHOME=$REPOROOT/gnupghome
209 KEYSTORE=$WORKSPACE/tests/keystore.jks
211 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
212 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
213 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
214 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
215 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
216 chmod 0700 $GNUPGHOME
217 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
218 echo "install_list = 'org.adaway'" >> config.py
219 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
220 echo "gpghome = '$GNUPGHOME'" >> config.py
221 echo "gpgkey = 'CE71F7FB'" >> config.py
222 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
223 $fdroid update --verbose --pretty
224 test -e repo/index.xml
225 test -e repo/index.jar
226 test -e repo/index-v1.jar
227 grep -F '<application id=' repo/index.xml > /dev/null
228 grep -F '<install packageName=' repo/index.xml > /dev/null
229 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
230 $fdroid gpgsign --verbose
231 $fdroid gpgsign --verbose
232 test -e repo/obb.mainpatch.current_1619.apk.asc
233 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
234 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
235 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
236 ! test -e repo/index.xml.asc
238 # we can't easily reproduce the timestamps for things, so just hardcode them
239 sed -i --expression='s,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
240 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
243 #------------------------------------------------------------------------------#
244 echo_header 'test per-app "Archive Policy"'
246 REPOROOT=`create_test_dir`
248 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
249 $fdroid init --keystore keystore.jks --repo-keyalias=sova
250 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
251 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
252 echo "accepted_formats = ['txt']" >> config.py
253 test -d metadata || mkdir metadata
254 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
255 test -d repo || mkdir repo
256 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
257 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
259 $fdroid update --pretty --nosign
260 test `grep '<package>' archive/index.xml | wc -l` -eq 0
261 test `grep '<package>' repo/index.xml | wc -l` -eq 4
262 grep -F com.politedroid_3.apk repo/index.xml
263 grep -F com.politedroid_4.apk repo/index.xml
264 grep -F com.politedroid_5.apk repo/index.xml
265 grep -F com.politedroid_6.apk repo/index.xml
266 test -e repo/com.politedroid_3.apk
267 test -e repo/com.politedroid_4.apk
268 test -e repo/com.politedroid_5.apk
269 test -e repo/com.politedroid_6.apk
271 echo "enable one app in the repo"
272 sed -i 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
273 $fdroid update --pretty --nosign
274 test `grep '<package>' archive/index.xml | wc -l` -eq 3
275 test `grep '<package>' repo/index.xml | wc -l` -eq 1
276 grep -F com.politedroid_3.apk archive/index.xml
277 grep -F com.politedroid_4.apk archive/index.xml
278 grep -F com.politedroid_5.apk archive/index.xml
279 grep -F com.politedroid_6.apk repo/index.xml
280 test -e archive/com.politedroid_3.apk
281 test -e archive/com.politedroid_4.apk
282 test -e archive/com.politedroid_5.apk
283 test -e repo/com.politedroid_6.apk
286 #------------------------------------------------------------------------------#
287 echo_header 'test moving old APKs to and from the archive'
289 REPOROOT=`create_test_dir`
291 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
292 $fdroid init --keystore keystore.jks --repo-keyalias=sova
293 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
294 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
295 echo "accepted_formats = ['txt']" >> config.py
296 test -d metadata || mkdir metadata
297 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
298 sed -i '/Archive Policy:/d' metadata/com.politedroid.txt
299 test -d repo || mkdir repo
300 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
301 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
303 $fdroid update --pretty --nosign
304 test `grep '<package>' archive/index.xml | wc -l` -eq 1
305 test `grep '<package>' repo/index.xml | wc -l` -eq 3
306 grep -F com.politedroid_3.apk archive/index.xml
307 grep -F com.politedroid_4.apk repo/index.xml
308 grep -F com.politedroid_5.apk repo/index.xml
309 grep -F com.politedroid_6.apk repo/index.xml
310 test -e archive/com.politedroid_3.apk
311 test -e repo/com.politedroid_4.apk
312 test -e repo/com.politedroid_5.apk
313 test -e repo/com.politedroid_6.apk
315 sed -i 's,archive_older = 3,archive_older = 1,' config.py
316 $fdroid update --pretty --nosign
317 test `grep '<package>' archive/index.xml | wc -l` -eq 3
318 test `grep '<package>' repo/index.xml | wc -l` -eq 1
319 grep -F com.politedroid_3.apk archive/index.xml
320 grep -F com.politedroid_4.apk archive/index.xml
321 grep -F com.politedroid_5.apk archive/index.xml
322 grep -F com.politedroid_6.apk repo/index.xml
323 test -e archive/com.politedroid_3.apk
324 test -e archive/com.politedroid_4.apk
325 test -e archive/com.politedroid_5.apk
326 test -e repo/com.politedroid_6.apk
328 # disabling deletes from the archive
329 sed -i 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
330 $fdroid update --pretty --nosign
331 test `grep '<package>' archive/index.xml | wc -l` -eq 2
332 test `grep '<package>' repo/index.xml | wc -l` -eq 1
333 grep -F com.politedroid_3.apk archive/index.xml
334 ! grep -F com.politedroid_4.apk archive/index.xml
335 grep -F com.politedroid_5.apk archive/index.xml
336 grep -F com.politedroid_6.apk repo/index.xml
337 test -e archive/com.politedroid_3.apk
338 ! test -e archive/com.politedroid_4.apk
339 test -e archive/com.politedroid_5.apk
340 test -e repo/com.politedroid_6.apk
342 # disabling deletes from the repo, and promotes one from the archive
343 sed -i 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
344 $fdroid update --pretty --nosign
345 test `grep '<package>' archive/index.xml | wc -l` -eq 1
346 test `grep '<package>' repo/index.xml | wc -l` -eq 1
347 grep -F com.politedroid_3.apk archive/index.xml
348 grep -F com.politedroid_5.apk repo/index.xml
349 ! grep -F com.politedroid_6.apk repo/index.xml
350 test -e archive/com.politedroid_3.apk
351 test -e repo/com.politedroid_5.apk
352 ! test -e repo/com.politedroid_6.apk
355 #------------------------------------------------------------------------------#
356 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
358 REPOROOT=`create_test_dir`
360 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
361 $fdroid init --keystore keystore.jks --repo-keyalias=sova
362 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
363 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
364 echo "accepted_formats = ['txt', 'yml']" >> config.py
365 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
366 test -d metadata || mkdir metadata
367 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
368 test -d repo || mkdir repo
369 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
370 $fdroid update --rename-apks --pretty --nosign
371 test -e repo/info.guardianproject.urzip_100.apk
372 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
373 cp $WORKSPACE/tests/urzip-release.apk repo/
374 $fdroid update --rename-apks --pretty --nosign
375 test -e repo/info.guardianproject.urzip_100.apk
376 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
377 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
378 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
379 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
380 cp $WORKSPACE/tests/urzip-release.apk repo/
381 $fdroid update --rename-apks --pretty --nosign
382 test -e repo/info.guardianproject.urzip_100.apk
383 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
384 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
385 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
386 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
387 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
390 #------------------------------------------------------------------------------#
391 echo_header "test metadata checks"
393 REPOROOT=`create_test_dir`
398 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
402 if [ $? -eq 0 ]; then
403 echo "This should have failed because there is no metadata!"
406 echo "testing metadata checks passed"
410 mkdir $REPOROOT/metadata/
411 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
414 # now make a fake duplicate
415 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
419 if [ $? -eq 0 ]; then
420 echo "This should have failed because there is a duplicate metadata file!"
423 echo "testing duplicate metadata checks passed"
428 #------------------------------------------------------------------------------#
429 echo_header "ensure commands that don't need the JDK work without a JDK configed"
431 REPOROOT=`create_test_dir`
435 echo "License:GPL-2.0" >> metadata/fake.txt
436 echo "Summary:Yup still fake" >> metadata/fake.txt
437 echo "Categories:Internet" >> metadata/fake.txt
438 echo "Description:" >> metadata/fake.txt
439 echo "this is fake" >> metadata/fake.txt
440 echo "." >> metadata/fake.txt
442 # fake that no JDKs are available
443 echo 'java_paths = {}' > config.py
445 LOCAL_COPY_DIR=`create_test_dir`/fdroid
446 mkdir -p $LOCAL_COPY_DIR/repo
447 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
453 $fdroid rewritemeta fake
454 $fdroid server update
457 # run these to get their output, but the are not setup, so don't fail
458 $fdroid build || true
459 $fdroid import || true
460 $fdroid install || true
463 #------------------------------------------------------------------------------#
464 echo_header "create a source tarball and use that to build a repo"
467 $python setup.py sdist
469 REPOROOT=`create_test_dir`
471 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
473 ./fdroidserver-*/fdroid init
474 copy_apks_into_repo $REPOROOT
475 ./fdroidserver-*/fdroid update --create-metadata --verbose
478 #------------------------------------------------------------------------------#
479 echo_header "test config checks of local_copy_dir"
481 REPOROOT=`create_test_dir`
484 $fdroid update --create-metadata --verbose
486 $fdroid server update --local-copy-dir=/tmp/fdroid
488 # now test the errors work
490 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
491 if [ $? -eq 0 ]; then
492 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
495 echo "testing absolute path checker passed"
497 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
498 if [ $? -eq 0 ]; then
499 echo "This should have failed because the path does not end with 'fdroid'!"
502 echo "testing dirname exists checker passed"
504 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
505 if [ $? -eq 0 ]; then
506 echo "This should have failed because the dirname path does not exist!"
509 echo "testing dirname exists checker passed"
514 #------------------------------------------------------------------------------#
515 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
517 REPOROOT=`create_test_dir`
520 copy_apks_into_repo $REPOROOT
521 $fdroid update --create-metadata --verbose
523 grep -F '<application id=' repo/index.xml > /dev/null
525 LOCALCOPYDIR=`create_test_dir`/fdroid
526 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
527 NEWREPOROOT=`create_test_dir`
530 echo "sync_from_local_copy_dir = True" >> config.py
531 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
534 #------------------------------------------------------------------------------#
535 # check that --android-home fails when dir does not exist or is not a dir
537 REPOROOT=`create_test_dir`
538 KEYSTORE=$REPOROOT/keystore.jks
541 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
542 if [ $? -eq 0 ]; then
543 echo "This should have failed because /opt/fakeandroidhome does not exist!"
546 echo "testing android-home path checker passed"
548 TESTFILE=`create_test_file`
549 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
550 if [ $? -eq 0 ]; then
551 echo "This should have failed because $TESTFILE is a file not a dir!"
554 echo "testing android-home not-dir checker passed"
559 #------------------------------------------------------------------------------#
560 echo_header "check that fake android home passes 'fdroid init'"
562 REPOROOT=`create_test_dir`
563 FAKE_ANDROID_HOME=`create_test_dir`
564 create_fake_android_home $FAKE_ANDROID_HOME
565 KEYSTORE=$REPOROOT/keystore.jks
567 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
570 #------------------------------------------------------------------------------#
571 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
573 if [ -e /usr/bin/aapt ]; then
574 echo "/usr/bin/aapt exists, not running test"
576 REPOROOT=`create_test_dir`
577 FAKE_ANDROID_HOME=`create_test_dir`
578 create_fake_android_home $FAKE_ANDROID_HOME
579 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
580 KEYSTORE=$REPOROOT/keystore.jks
583 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
584 [ $? -eq 0 ] && exit 1
589 #------------------------------------------------------------------------------#
590 echo_header "check that --android-home overrides ANDROID_HOME"
592 REPOROOT=`create_test_dir`
593 FAKE_ANDROID_HOME=`create_test_dir`
594 create_fake_android_home $FAKE_ANDROID_HOME
595 KEYSTORE=$REPOROOT/keystore.jks
597 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
599 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
600 if [ $? -ne 0 ]; then
601 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
607 #------------------------------------------------------------------------------#
608 # In this case, ANDROID_HOME is set to a fake, non-working version that will
609 # be detected by fdroid as an Android SDK install. It should use the path set
610 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
611 # in ANDROID_HOME, it won't work because it is a fake one. Only
612 # --android-home provides a working one.
613 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
615 REPOROOT=`create_test_dir`
616 KEYSTORE=$REPOROOT/keystore.jks
617 FAKE_ANDROID_HOME=`create_test_dir`
618 create_fake_android_home $FAKE_ANDROID_HOME
619 STORED_ANDROID_HOME=$ANDROID_HOME
621 echo "ANDROID_HOME: $ANDROID_HOME"
623 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
625 copy_apks_into_repo $REPOROOT
626 $fdroid update --create-metadata --verbose
628 grep -F '<application id=' repo/index.xml > /dev/null
629 test -e repo/index.xml
630 test -e repo/index.jar
631 test -e repo/index-v1.jar
632 export ANDROID_HOME=$STORED_ANDROID_HOME
635 #------------------------------------------------------------------------------#
636 echo_header "check duplicate files are properly handled by fdroid update"
638 REPOROOT=`create_test_dir`
639 KEYSTORE=$WORKSPACE/tests/keystore.jks
641 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
642 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
643 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
644 mkdir $REPOROOT/metadata
645 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
646 echo "accepted_formats = ['txt']" >> config.py
647 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
648 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
649 $fdroid update --pretty
650 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
651 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
652 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
653 # die if there are exact duplicates
654 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
658 #------------------------------------------------------------------------------#
659 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
661 REPOROOT=`create_test_dir`
664 copy_apks_into_repo $REPOROOT
666 $fdroid update --create-metadata --verbose
668 grep -F '<application id=' repo/index.xml > /dev/null
671 #------------------------------------------------------------------------------#
672 echo_header "setup a new repo from scratch and generate a keystore"
674 REPOROOT=`create_test_dir`
675 KEYSTORE=$REPOROOT/keystore.jks
677 $fdroid init --keystore $KEYSTORE
679 copy_apks_into_repo $REPOROOT
680 $fdroid update --create-metadata --verbose
682 test -e repo/index.xml
683 test -e repo/index.jar
684 test -e repo/index-v1.jar
685 grep -F '<application id=' repo/index.xml > /dev/null
688 #------------------------------------------------------------------------------#
689 echo_header "setup a new repo manually and generate a keystore"
691 REPOROOT=`create_test_dir`
692 KEYSTORE=$REPOROOT/keystore.jks
695 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
699 if [ $? -eq 0 ]; then
700 echo "This should have failed because this repo has no keystore!"
703 echo '`fdroid update` prompted to add keystore'
706 $fdroid update --create-key
708 copy_apks_into_repo $REPOROOT
709 $fdroid update --create-metadata --verbose
711 test -e repo/index.xml
712 test -e repo/index.jar
713 test -e repo/index-v1.jar
714 grep -F '<application id=' repo/index.xml > /dev/null
717 #------------------------------------------------------------------------------#
718 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
720 REPOROOT=`create_test_dir`
721 KEYSTORE=$REPOROOT/keystore.jks
723 $fdroid init --keystore $KEYSTORE
725 copy_apks_into_repo $REPOROOT
726 $fdroid update --create-metadata --verbose
728 test -e repo/index.xml
729 test -e repo/index.jar
730 test -e repo/index-v1.jar
731 grep -F '<application id=' repo/index.xml > /dev/null
732 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
733 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
734 $fdroid update --create-metadata --verbose
736 test -e repo/index.xml
737 test -e repo/index.jar
738 test -e repo/index-v1.jar
739 grep -F '<application id=' repo/index.xml > /dev/null
742 #------------------------------------------------------------------------------#
743 echo_header "setup a new repo from scratch with a HSM/smartcard"
744 REPOROOT=`create_test_dir`
746 $fdroid init --keystore NONE
747 test -e opensc-fdroid.cfg
751 #------------------------------------------------------------------------------#
752 echo_header "setup a new repo with no keystore, add APK, and update"
754 REPOROOT=`create_test_dir`
755 KEYSTORE=$REPOROOT/keystore.jks
758 touch fdroid-icon.png
760 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
762 $fdroid update --create-metadata --verbose
763 if [ $? -eq 0 ]; then
764 echo "This should have failed because this repo has no keystore!"
767 echo '`fdroid update` prompted to add keystore'
771 # now set up fake, non-working keystore setup
773 echo "keystore = \"$KEYSTORE\"" >> config.py
774 echo 'repo_keyalias = "foo"' >> config.py
775 echo 'keystorepass = "foo"' >> config.py
776 echo 'keypass = "foo"' >> config.py
778 $fdroid update --create-metadata --verbose
779 if [ $? -eq 0 ]; then
780 echo "This should have failed because this repo has a bad/fake keystore!"
783 echo '`fdroid update` prompted to add keystore'
788 #------------------------------------------------------------------------------#
789 echo_header "copy tests/repo, update with binary transparency log"
791 REPOROOT=`create_test_dir`
792 GIT_REMOTE=`create_test_dir`
793 GNUPGHOME=$REPOROOT/gnupghome
794 KEYSTORE=$WORKSPACE/tests/keystore.jks
796 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
797 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
798 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
799 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
800 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
801 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
802 $fdroid update --verbose
803 if have_git_2_3; then
804 $fdroid server update --verbose
805 test -e repo/index.xml
806 test -e repo/index.jar
807 test -e repo/index-v1.jar
808 grep -F '<application id=' repo/index.xml > /dev/null
809 cd binary_transparency
810 [ `git rev-list --count HEAD` == "2" ]
812 [ `git rev-list --count HEAD` == "2" ]
814 echo "Skipping test, `git --version` older than 2.3"
818 #------------------------------------------------------------------------------#
819 echo_header "setup a new repo with keystore with APK, update, then without key"
821 REPOROOT=`create_test_dir`
822 KEYSTORE=$REPOROOT/keystore.jks
824 $fdroid init --keystore $KEYSTORE
826 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
827 $fdroid update --create-metadata --verbose
829 test -e repo/index.xml
830 test -e repo/index.jar
831 test -e repo/index-v1.jar
832 grep -F '<application id=' repo/index.xml > /dev/null
834 # now set fake repo_keyalias
835 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
838 if [ $? -eq 0 ]; then
839 echo "This should have failed because this repo has a bad repo_keyalias!"
842 echo '`fdroid update` prompted to add keystore'
846 # try creating a new keystore, but fail because the old one is there
849 $fdroid update --create-key
850 if [ $? -eq 0 ]; then
851 echo "This should have failed because a keystore is already there!"
854 echo '`fdroid update` complained about existing keystore'
858 # now actually create the key with the existing settings
861 $fdroid update --create-key
865 #------------------------------------------------------------------------------#
866 echo_header "sign binary repo in offline box, then publishing from online box"
868 OFFLINE_ROOT=`create_test_dir`
869 KEYSTORE=$WORKSPACE/tests/keystore.jks
870 LOCAL_COPY_DIR=`create_test_dir`/fdroid
871 mkdir $LOCAL_COPY_DIR
872 ONLINE_ROOT=`create_test_dir`
873 SERVERWEBROOT=`create_test_dir`
875 # create offline binary transparency log
877 mkdir binary_transparency
878 cd binary_transparency
881 # fake git remote server for binary transparency log
882 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
884 # fake git remote server for repo mirror
885 SERVER_GIT_MIRROR=`create_test_dir`
886 cd $SERVER_GIT_MIRROR
888 if have_git_2_3; then
889 git config receive.denyCurrentBranch updateInstead
893 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
894 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
896 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
897 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
898 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
899 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
900 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
901 $fdroid update --verbose
902 grep -F '<application id=' repo/index.xml > /dev/null
903 cd binary_transparency
904 [ `git rev-list --count HEAD` == "1" ]
906 if have_git_2_3; then
907 $fdroid server update --verbose
908 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
910 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
911 echo "sync_from_local_copy_dir = True" >> config.py
912 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
913 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
914 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
915 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
916 $fdroid server update --verbose
917 cd $BINARY_TRANSPARENCY_REMOTE
918 [ `git rev-list --count HEAD` == "1" ]
919 cd $SERVER_GIT_MIRROR
920 [ `git rev-list --count HEAD` == "1" ]
922 echo "Skipping test, `git --version` older than 2.3"
926 #------------------------------------------------------------------------------#
928 # remove this to prevent git conflicts and complaining
929 rm -rf $WORKSPACE/fdroidserver.egg-info/