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
285 echo "remove all apps from the repo"
286 sed -i 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
287 $fdroid update --pretty --nosign
288 test `grep '<package>' archive/index.xml | wc -l` -eq 4
289 test `grep '<package>' repo/index.xml | wc -l` -eq 0
290 grep -F com.politedroid_3.apk archive/index.xml
291 grep -F com.politedroid_4.apk archive/index.xml
292 grep -F com.politedroid_5.apk archive/index.xml
293 grep -F com.politedroid_6.apk archive/index.xml
294 test -e archive/com.politedroid_3.apk
295 test -e archive/com.politedroid_4.apk
296 test -e archive/com.politedroid_5.apk
297 test -e archive/com.politedroid_6.apk
298 ! test -e repo/com.politedroid_6.apk
300 echo "move back one from archive to the repo"
301 sed -i 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
302 $fdroid update --pretty --nosign
303 test `grep '<package>' archive/index.xml | wc -l` -eq 3
304 test `grep '<package>' repo/index.xml | wc -l` -eq 1
305 grep -F com.politedroid_3.apk archive/index.xml
306 grep -F com.politedroid_4.apk archive/index.xml
307 grep -F com.politedroid_5.apk archive/index.xml
308 grep -F com.politedroid_6.apk repo/index.xml
309 test -e archive/com.politedroid_3.apk
310 test -e archive/com.politedroid_4.apk
311 test -e archive/com.politedroid_5.apk
312 ! test -e archive/com.politedroid_6.apk
313 test -e repo/com.politedroid_6.apk
317 #------------------------------------------------------------------------------#
318 echo_header 'test moving old APKs to and from the archive'
320 REPOROOT=`create_test_dir`
322 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
323 $fdroid init --keystore keystore.jks --repo-keyalias=sova
324 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
325 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
326 echo "accepted_formats = ['txt']" >> config.py
327 test -d metadata || mkdir metadata
328 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
329 sed -i '/Archive Policy:/d' metadata/com.politedroid.txt
330 test -d repo || mkdir repo
331 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
332 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
334 $fdroid update --pretty --nosign
335 test `grep '<package>' archive/index.xml | wc -l` -eq 1
336 test `grep '<package>' repo/index.xml | wc -l` -eq 3
337 grep -F com.politedroid_3.apk archive/index.xml
338 grep -F com.politedroid_4.apk repo/index.xml
339 grep -F com.politedroid_5.apk repo/index.xml
340 grep -F com.politedroid_6.apk repo/index.xml
341 test -e archive/com.politedroid_3.apk
342 test -e repo/com.politedroid_4.apk
343 test -e repo/com.politedroid_5.apk
344 test -e repo/com.politedroid_6.apk
346 sed -i 's,archive_older = 3,archive_older = 1,' config.py
347 $fdroid update --pretty --nosign
348 test `grep '<package>' archive/index.xml | wc -l` -eq 3
349 test `grep '<package>' repo/index.xml | wc -l` -eq 1
350 grep -F com.politedroid_3.apk archive/index.xml
351 grep -F com.politedroid_4.apk archive/index.xml
352 grep -F com.politedroid_5.apk archive/index.xml
353 grep -F com.politedroid_6.apk repo/index.xml
354 test -e archive/com.politedroid_3.apk
355 test -e archive/com.politedroid_4.apk
356 test -e archive/com.politedroid_5.apk
357 test -e repo/com.politedroid_6.apk
359 # disabling deletes from the archive
360 sed -i 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
361 $fdroid update --pretty --nosign
362 test `grep '<package>' archive/index.xml | wc -l` -eq 2
363 test `grep '<package>' repo/index.xml | wc -l` -eq 1
364 grep -F com.politedroid_3.apk archive/index.xml
365 ! grep -F com.politedroid_4.apk archive/index.xml
366 grep -F com.politedroid_5.apk archive/index.xml
367 grep -F com.politedroid_6.apk repo/index.xml
368 test -e archive/com.politedroid_3.apk
369 ! test -e archive/com.politedroid_4.apk
370 test -e archive/com.politedroid_5.apk
371 test -e repo/com.politedroid_6.apk
373 # disabling deletes from the repo, and promotes one from the archive
374 sed -i 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
375 $fdroid update --pretty --nosign
376 test `grep '<package>' archive/index.xml | wc -l` -eq 1
377 test `grep '<package>' repo/index.xml | wc -l` -eq 1
378 grep -F com.politedroid_3.apk archive/index.xml
379 grep -F com.politedroid_5.apk repo/index.xml
380 ! grep -F com.politedroid_6.apk repo/index.xml
381 test -e archive/com.politedroid_3.apk
382 test -e repo/com.politedroid_5.apk
383 ! test -e repo/com.politedroid_6.apk
386 #------------------------------------------------------------------------------#
387 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
389 REPOROOT=`create_test_dir`
391 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
392 $fdroid init --keystore keystore.jks --repo-keyalias=sova
393 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
394 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
395 echo "accepted_formats = ['txt', 'yml']" >> config.py
396 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
397 test -d metadata || mkdir metadata
398 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
399 test -d repo || mkdir repo
400 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
401 $fdroid update --rename-apks --pretty --nosign
402 test -e repo/info.guardianproject.urzip_100.apk
403 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
404 cp $WORKSPACE/tests/urzip-release.apk repo/
405 $fdroid update --rename-apks --pretty --nosign
406 test -e repo/info.guardianproject.urzip_100.apk
407 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
408 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
409 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
410 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
411 cp $WORKSPACE/tests/urzip-release.apk repo/
412 $fdroid update --rename-apks --pretty --nosign
413 test -e repo/info.guardianproject.urzip_100.apk
414 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
415 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
416 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
417 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
418 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
421 #------------------------------------------------------------------------------#
422 echo_header "test metadata checks"
424 REPOROOT=`create_test_dir`
429 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
433 if [ $? -eq 0 ]; then
434 echo "This should have failed because there is no metadata!"
437 echo "testing metadata checks passed"
441 mkdir $REPOROOT/metadata/
442 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
445 # now make a fake duplicate
446 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
450 if [ $? -eq 0 ]; then
451 echo "This should have failed because there is a duplicate metadata file!"
454 echo "testing duplicate metadata checks passed"
459 #------------------------------------------------------------------------------#
460 echo_header "ensure commands that don't need the JDK work without a JDK configed"
462 REPOROOT=`create_test_dir`
466 echo "License:GPL-2.0" >> metadata/fake.txt
467 echo "Summary:Yup still fake" >> metadata/fake.txt
468 echo "Categories:Internet" >> metadata/fake.txt
469 echo "Description:" >> metadata/fake.txt
470 echo "this is fake" >> metadata/fake.txt
471 echo "." >> metadata/fake.txt
473 # fake that no JDKs are available
474 echo 'java_paths = {}' > config.py
476 LOCAL_COPY_DIR=`create_test_dir`/fdroid
477 mkdir -p $LOCAL_COPY_DIR/repo
478 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
484 $fdroid rewritemeta fake
485 $fdroid server update
488 # run these to get their output, but the are not setup, so don't fail
489 $fdroid build || true
490 $fdroid import || true
491 $fdroid install || true
494 #------------------------------------------------------------------------------#
495 echo_header "create a source tarball and use that to build a repo"
498 $python setup.py sdist
500 REPOROOT=`create_test_dir`
502 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
504 ./fdroidserver-*/fdroid init
505 copy_apks_into_repo $REPOROOT
506 ./fdroidserver-*/fdroid update --create-metadata --verbose
509 #------------------------------------------------------------------------------#
510 echo_header "test config checks of local_copy_dir"
512 REPOROOT=`create_test_dir`
515 $fdroid update --create-metadata --verbose
517 $fdroid server update --local-copy-dir=/tmp/fdroid
519 # now test the errors work
521 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
522 if [ $? -eq 0 ]; then
523 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
526 echo "testing absolute path checker passed"
528 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
529 if [ $? -eq 0 ]; then
530 echo "This should have failed because the path does not end with 'fdroid'!"
533 echo "testing dirname exists checker passed"
535 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
536 if [ $? -eq 0 ]; then
537 echo "This should have failed because the dirname path does not exist!"
540 echo "testing dirname exists checker passed"
545 #------------------------------------------------------------------------------#
546 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
548 REPOROOT=`create_test_dir`
551 copy_apks_into_repo $REPOROOT
552 $fdroid update --create-metadata --verbose
554 grep -F '<application id=' repo/index.xml > /dev/null
556 LOCALCOPYDIR=`create_test_dir`/fdroid
557 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
558 NEWREPOROOT=`create_test_dir`
561 echo "sync_from_local_copy_dir = True" >> config.py
562 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
565 #------------------------------------------------------------------------------#
566 # check that --android-home fails when dir does not exist or is not a dir
568 REPOROOT=`create_test_dir`
569 KEYSTORE=$REPOROOT/keystore.jks
572 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
573 if [ $? -eq 0 ]; then
574 echo "This should have failed because /opt/fakeandroidhome does not exist!"
577 echo "testing android-home path checker passed"
579 TESTFILE=`create_test_file`
580 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
581 if [ $? -eq 0 ]; then
582 echo "This should have failed because $TESTFILE is a file not a dir!"
585 echo "testing android-home not-dir checker passed"
590 #------------------------------------------------------------------------------#
591 echo_header "check that fake android home passes 'fdroid init'"
593 REPOROOT=`create_test_dir`
594 FAKE_ANDROID_HOME=`create_test_dir`
595 create_fake_android_home $FAKE_ANDROID_HOME
596 KEYSTORE=$REPOROOT/keystore.jks
598 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
601 #------------------------------------------------------------------------------#
602 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
604 if [ -e /usr/bin/aapt ]; then
605 echo "/usr/bin/aapt exists, not running test"
607 REPOROOT=`create_test_dir`
608 FAKE_ANDROID_HOME=`create_test_dir`
609 create_fake_android_home $FAKE_ANDROID_HOME
610 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
611 KEYSTORE=$REPOROOT/keystore.jks
614 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
615 [ $? -eq 0 ] && exit 1
620 #------------------------------------------------------------------------------#
621 echo_header "check that --android-home overrides ANDROID_HOME"
623 REPOROOT=`create_test_dir`
624 FAKE_ANDROID_HOME=`create_test_dir`
625 create_fake_android_home $FAKE_ANDROID_HOME
626 KEYSTORE=$REPOROOT/keystore.jks
628 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
630 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
631 if [ $? -ne 0 ]; then
632 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
638 #------------------------------------------------------------------------------#
639 # In this case, ANDROID_HOME is set to a fake, non-working version that will
640 # be detected by fdroid as an Android SDK install. It should use the path set
641 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
642 # in ANDROID_HOME, it won't work because it is a fake one. Only
643 # --android-home provides a working one.
644 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
646 REPOROOT=`create_test_dir`
647 KEYSTORE=$REPOROOT/keystore.jks
648 FAKE_ANDROID_HOME=`create_test_dir`
649 create_fake_android_home $FAKE_ANDROID_HOME
650 STORED_ANDROID_HOME=$ANDROID_HOME
652 echo "ANDROID_HOME: $ANDROID_HOME"
654 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
656 copy_apks_into_repo $REPOROOT
657 $fdroid update --create-metadata --verbose
659 grep -F '<application id=' repo/index.xml > /dev/null
660 test -e repo/index.xml
661 test -e repo/index.jar
662 test -e repo/index-v1.jar
663 export ANDROID_HOME=$STORED_ANDROID_HOME
666 #------------------------------------------------------------------------------#
667 echo_header "check duplicate files are properly handled by fdroid update"
669 REPOROOT=`create_test_dir`
670 KEYSTORE=$WORKSPACE/tests/keystore.jks
672 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
673 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
674 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
675 mkdir $REPOROOT/metadata
676 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
677 echo "accepted_formats = ['txt']" >> config.py
678 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
679 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
680 $fdroid update --pretty
681 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
682 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
683 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
684 # die if there are exact duplicates
685 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
689 #------------------------------------------------------------------------------#
690 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
692 REPOROOT=`create_test_dir`
695 copy_apks_into_repo $REPOROOT
697 $fdroid update --create-metadata --verbose
699 grep -F '<application id=' repo/index.xml > /dev/null
702 #------------------------------------------------------------------------------#
703 echo_header "setup a new repo from scratch and generate a keystore"
705 REPOROOT=`create_test_dir`
706 KEYSTORE=$REPOROOT/keystore.jks
708 $fdroid init --keystore $KEYSTORE
710 copy_apks_into_repo $REPOROOT
711 $fdroid update --create-metadata --verbose
713 test -e repo/index.xml
714 test -e repo/index.jar
715 test -e repo/index-v1.jar
716 grep -F '<application id=' repo/index.xml > /dev/null
719 #------------------------------------------------------------------------------#
720 echo_header "setup a new repo manually and generate a keystore"
722 REPOROOT=`create_test_dir`
723 KEYSTORE=$REPOROOT/keystore.jks
726 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
730 if [ $? -eq 0 ]; then
731 echo "This should have failed because this repo has no keystore!"
734 echo '`fdroid update` prompted to add keystore'
737 $fdroid update --create-key
739 copy_apks_into_repo $REPOROOT
740 $fdroid update --create-metadata --verbose
742 test -e repo/index.xml
743 test -e repo/index.jar
744 test -e repo/index-v1.jar
745 grep -F '<application id=' repo/index.xml > /dev/null
748 #------------------------------------------------------------------------------#
749 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
751 REPOROOT=`create_test_dir`
752 KEYSTORE=$REPOROOT/keystore.jks
754 $fdroid init --keystore $KEYSTORE
756 copy_apks_into_repo $REPOROOT
757 $fdroid update --create-metadata --verbose
759 test -e repo/index.xml
760 test -e repo/index.jar
761 test -e repo/index-v1.jar
762 grep -F '<application id=' repo/index.xml > /dev/null
763 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
764 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
765 $fdroid update --create-metadata --verbose
767 test -e repo/index.xml
768 test -e repo/index.jar
769 test -e repo/index-v1.jar
770 grep -F '<application id=' repo/index.xml > /dev/null
773 #------------------------------------------------------------------------------#
774 echo_header "setup a new repo from scratch with a HSM/smartcard"
775 REPOROOT=`create_test_dir`
777 $fdroid init --keystore NONE
778 test -e opensc-fdroid.cfg
782 #------------------------------------------------------------------------------#
783 echo_header "setup a new repo with no keystore, add APK, and update"
785 REPOROOT=`create_test_dir`
786 KEYSTORE=$REPOROOT/keystore.jks
789 touch fdroid-icon.png
791 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
793 $fdroid update --create-metadata --verbose
794 if [ $? -eq 0 ]; then
795 echo "This should have failed because this repo has no keystore!"
798 echo '`fdroid update` prompted to add keystore'
802 # now set up fake, non-working keystore setup
804 echo "keystore = \"$KEYSTORE\"" >> config.py
805 echo 'repo_keyalias = "foo"' >> config.py
806 echo 'keystorepass = "foo"' >> config.py
807 echo 'keypass = "foo"' >> config.py
809 $fdroid update --create-metadata --verbose
810 if [ $? -eq 0 ]; then
811 echo "This should have failed because this repo has a bad/fake keystore!"
814 echo '`fdroid update` prompted to add keystore'
819 #------------------------------------------------------------------------------#
820 echo_header "copy tests/repo, update with binary transparency log"
822 REPOROOT=`create_test_dir`
823 GIT_REMOTE=`create_test_dir`
824 GNUPGHOME=$REPOROOT/gnupghome
825 KEYSTORE=$WORKSPACE/tests/keystore.jks
827 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
828 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
829 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
830 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
831 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
832 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
833 $fdroid update --verbose
834 if have_git_2_3; then
835 $fdroid server update --verbose
836 test -e repo/index.xml
837 test -e repo/index.jar
838 test -e repo/index-v1.jar
839 grep -F '<application id=' repo/index.xml > /dev/null
840 cd binary_transparency
841 [ `git rev-list --count HEAD` == "2" ]
843 [ `git rev-list --count HEAD` == "2" ]
845 echo "Skipping test, `git --version` older than 2.3"
849 #------------------------------------------------------------------------------#
850 echo_header "setup a new repo with keystore with APK, update, then without key"
852 REPOROOT=`create_test_dir`
853 KEYSTORE=$REPOROOT/keystore.jks
855 $fdroid init --keystore $KEYSTORE
857 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
858 $fdroid update --create-metadata --verbose
860 test -e repo/index.xml
861 test -e repo/index.jar
862 test -e repo/index-v1.jar
863 grep -F '<application id=' repo/index.xml > /dev/null
865 # now set fake repo_keyalias
866 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
869 if [ $? -eq 0 ]; then
870 echo "This should have failed because this repo has a bad repo_keyalias!"
873 echo '`fdroid update` prompted to add keystore'
877 # try creating a new keystore, but fail because the old one is there
880 $fdroid update --create-key
881 if [ $? -eq 0 ]; then
882 echo "This should have failed because a keystore is already there!"
885 echo '`fdroid update` complained about existing keystore'
889 # now actually create the key with the existing settings
892 $fdroid update --create-key
896 #------------------------------------------------------------------------------#
897 echo_header "sign binary repo in offline box, then publishing from online box"
899 OFFLINE_ROOT=`create_test_dir`
900 KEYSTORE=$WORKSPACE/tests/keystore.jks
901 LOCAL_COPY_DIR=`create_test_dir`/fdroid
902 mkdir $LOCAL_COPY_DIR
903 ONLINE_ROOT=`create_test_dir`
904 SERVERWEBROOT=`create_test_dir`
906 # create offline binary transparency log
908 mkdir binary_transparency
909 cd binary_transparency
912 # fake git remote server for binary transparency log
913 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
915 # fake git remote server for repo mirror
916 SERVER_GIT_MIRROR=`create_test_dir`
917 cd $SERVER_GIT_MIRROR
919 if have_git_2_3; then
920 git config receive.denyCurrentBranch updateInstead
924 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
925 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
927 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
928 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
929 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
930 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
931 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
932 $fdroid update --verbose
933 grep -F '<application id=' repo/index.xml > /dev/null
934 cd binary_transparency
935 [ `git rev-list --count HEAD` == "1" ]
937 if have_git_2_3; then
938 $fdroid server update --verbose
939 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
941 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
942 echo "sync_from_local_copy_dir = True" >> config.py
943 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
944 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
945 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
946 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
947 $fdroid server update --verbose
948 cd $BINARY_TRANSPARENCY_REMOTE
949 [ `git rev-list --count HEAD` == "1" ]
950 cd $SERVER_GIT_MIRROR
951 [ `git rev-list --count HEAD` == "1" ]
953 echo "Skipping test, `git --version` older than 2.3"
957 #------------------------------------------------------------------------------#
959 # remove this to prevent git conflicts and complaining
960 rm -rf $WORKSPACE/fdroidserver.egg-info/