3 set -e # quit script on error
6 { echo -e "==============================================================================\n$1"; } 2>/dev/null
9 copy_apks_into_repo() {
11 find $APKDIR -type f -name '*.apk' -print0 | while IFS= read -r -d '' f; do
12 echo $f | grep -F -v -e unaligned -e unsigned -e badsig -e badcert -e bad-unicode -e janus.apk || continue
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 fdroid_init_with_prebuilt_keystore() {
46 keystore=$WORKSPACE/tests/keystore.jks
50 $fdroid init --keystore $keystore --repo-keyalias=sova
51 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
52 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
55 # the < is reverse since 0 means success in exit codes
57 python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version`
61 javac $WORKSPACE/tests/IsMD5Disabled.java && java -cp $WORKSPACE/tests IsMD5Disabled
65 #------------------------------------------------------------------------------#
68 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
70 echo "Usage: $0 '/path/to/folder/with/apks'"
74 if [ -z "$ANDROID_HOME" ]; then
75 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
76 echo " export ANDROID_HOME=/opt/android-sdk"
90 if [ -z $WORKSPACE ]; then
91 WORKSPACE=`dirname $(pwd)`
92 echo "Setting Workspace to $WORKSPACE"
95 # allow the location of the script to be overridden
96 if [ -z $fdroid ]; then
97 fdroid="$WORKSPACE/fdroid"
100 # allow the location of aapt to be overridden
101 if [ -z $aapt ]; then
102 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
105 # try to use GNU sed on OSX/BSD cuz BSD sed sucks
112 set -x # show each command as it is executed
114 #------------------------------------------------------------------------------#
115 echo_header "run commit hooks"
121 #------------------------------------------------------------------------------#
122 echo_header "test python getsig replacement"
124 cd $WORKSPACE/tests/getsig
128 for testcase in $WORKSPACE/tests/i*.TestCase; do
129 if [ $testcase == $WORKSPACE/tests/install.TestCase ]; then
130 echo "skipping install.TestCase, its too troublesome in CI builds"
137 #------------------------------------------------------------------------------#
138 echo_header "print fdroid version"
143 #------------------------------------------------------------------------------#
144 echo_header 'run process when building and signing are on separate machines'
146 REPOROOT=`create_test_dir`
148 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
149 $fdroid init --keystore keystore.jks --repo-keyalias=sova
150 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
151 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
152 echo "accepted_formats = ['txt', 'yml']" >> config.py
153 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
154 test -d archive || mkdir archive
155 test -d metadata || mkdir metadata
156 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
157 test -d repo || mkdir repo
158 test -d unsigned || mkdir unsigned
159 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
160 $fdroid publish --verbose
161 $fdroid update --verbose --nosign
162 $fdroid signindex --verbose
163 test -e repo/index.xml
164 test -e repo/index.jar
165 test -e repo/index-v1.jar
167 ! test -z tmp/apkcache
169 grep -F '<application id=' repo/index.xml > /dev/null
172 #------------------------------------------------------------------------------#
173 echo_header "test UTF-8 metadata"
175 REPOROOT=`create_test_dir`
178 fdroid_init_with_prebuilt_keystore
179 $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
180 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
182 cp $WORKSPACE/tests/urzip.apk $WORKSPACE/tests/bad-unicode*.apk repo/
183 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
189 #------------------------------------------------------------------------------#
190 echo_header 'run "fdroid build" in fresh git checkout from import.TestCase'
192 cd $WORKSPACE/tests/tmp/importer
195 # stick with known working commit, in case future commits break things for this code
196 git reset --hard fea54e1161d5eb9eb1a54e26253ef84d3ab63705
197 if [ -d $ANDROID_HOME/platforms/android-23 && -d $ANDROID_HOME/build-tools/23.0.3 ]; then
198 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
199 echo "force_build_tools = True" >> config.py
200 $fdroid build --verbose org.fdroid.ci.test.app:300
202 echo 'WARNING: Skipping "fdroid build" test since android-23 is missing!'
205 #------------------------------------------------------------------------------#
206 echo_header 'copy git import and run "fdroid scanner" on it'
208 REPOROOT=`create_test_dir`
210 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
212 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
213 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
214 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
215 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
216 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
217 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
218 echo "" >> metadata/org.fdroid.ci.test.app.txt
219 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
220 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
222 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
223 ls -l build/org.fdroid.ci.test.app
224 $fdroid scanner org.fdroid.ci.test.app --verbose
227 #------------------------------------------------------------------------------#
228 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
230 REPOROOT=`create_test_dir`
231 GNUPGHOME=$REPOROOT/gnupghome
233 fdroid_init_with_prebuilt_keystore
234 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
235 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
236 chmod 0700 $GNUPGHOME
237 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
238 echo "install_list = 'org.adaway'" >> config.py
239 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
240 echo "gpghome = '$GNUPGHOME'" >> config.py
241 echo "gpgkey = 'CE71F7FB'" >> config.py
242 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
243 $fdroid update --verbose --pretty
244 test -e repo/index.xml
245 test -e repo/index.jar
246 test -e repo/index-v1.jar
247 grep -F '<application id=' repo/index.xml > /dev/null
248 grep -F '<install packageName=' repo/index.xml > /dev/null
249 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
250 # OSX tests are run on Travis-CI, and gpg fails to launch gpg-agent there
251 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
252 $fdroid gpgsign --verbose
253 $fdroid gpgsign --verbose
254 test -e repo/obb.mainpatch.current_1619.apk.asc
255 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
256 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
257 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
258 ! test -e repo/index.xml.asc
261 # we can't easily reproduce the timestamps for things, so just hardcode them
262 $sed -i.tmp -e 's,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
263 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
264 sed -i --expression='s,"timestamp": [0-9]*,"timestamp": 1502845383782,' repo/index-v1.json
265 diff -uw $WORKSPACE/tests/repo/index-v1.json repo/index-v1.json
268 #------------------------------------------------------------------------------#
269 echo_header 'test moving lots of APKs to the archive'
271 REPOROOT=`create_test_dir`
273 fdroid_init_with_prebuilt_keystore
274 echo "accepted_formats = ['txt']" >> config.py
275 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
276 test -d metadata || mkdir metadata
277 cp $WORKSPACE/tests/metadata/*.txt metadata/
278 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
279 echo 'Summary:good MD5 sig, which is disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
280 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
281 test -d repo || mkdir repo
282 cp $WORKSPACE/tests/urzip.apk \
283 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
284 $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
285 $WORKSPACE/tests/repo/obb.main.twoversions_110161[357].apk \
287 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
289 $fdroid update --pretty --nosign
290 echo "This will fail when jarsigner allows MD5 for APK signatures"
291 test `grep '<package>' archive/index.xml | wc -l` -eq 5
292 test `grep '<package>' repo/index.xml | wc -l` -eq 7
295 #------------------------------------------------------------------------------#
296 echo_header 'test per-app "Archive Policy"'
298 REPOROOT=`create_test_dir`
300 fdroid_init_with_prebuilt_keystore
301 echo "accepted_formats = ['txt']" >> config.py
302 test -d metadata || mkdir metadata
303 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
304 test -d repo || mkdir repo
305 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
306 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
308 $fdroid update --pretty --nosign
309 test `grep '<package>' archive/index.xml | wc -l` -eq 0
310 test `grep '<package>' repo/index.xml | wc -l` -eq 4
311 grep -F com.politedroid_3.apk repo/index.xml
312 grep -F com.politedroid_4.apk repo/index.xml
313 grep -F com.politedroid_5.apk repo/index.xml
314 grep -F com.politedroid_6.apk repo/index.xml
315 test -e repo/com.politedroid_3.apk
316 test -e repo/com.politedroid_4.apk
317 test -e repo/com.politedroid_5.apk
318 test -e repo/com.politedroid_6.apk
320 echo "enable one app in the repo"
321 $sed -i.tmp 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
322 $fdroid update --pretty --nosign
323 test `grep '<package>' archive/index.xml | wc -l` -eq 3
324 test `grep '<package>' repo/index.xml | wc -l` -eq 1
325 grep -F com.politedroid_3.apk archive/index.xml
326 grep -F com.politedroid_4.apk archive/index.xml
327 grep -F com.politedroid_5.apk archive/index.xml
328 grep -F com.politedroid_6.apk repo/index.xml
329 test -e archive/com.politedroid_3.apk
330 test -e archive/com.politedroid_4.apk
331 test -e archive/com.politedroid_5.apk
332 test -e repo/com.politedroid_6.apk
334 echo "remove all apps from the repo"
335 $sed -i.tmp 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
336 $fdroid update --pretty --nosign
337 test `grep '<package>' archive/index.xml | wc -l` -eq 4
338 test `grep '<package>' repo/index.xml | wc -l` -eq 0
339 grep -F com.politedroid_3.apk archive/index.xml
340 grep -F com.politedroid_4.apk archive/index.xml
341 grep -F com.politedroid_5.apk archive/index.xml
342 grep -F com.politedroid_6.apk archive/index.xml
343 test -e archive/com.politedroid_3.apk
344 test -e archive/com.politedroid_4.apk
345 test -e archive/com.politedroid_5.apk
346 test -e archive/com.politedroid_6.apk
347 ! test -e repo/com.politedroid_6.apk
349 echo "move back one from archive to the repo"
350 $sed -i.tmp 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
351 $fdroid update --pretty --nosign
352 test `grep '<package>' archive/index.xml | wc -l` -eq 3
353 test `grep '<package>' repo/index.xml | wc -l` -eq 1
354 grep -F com.politedroid_3.apk archive/index.xml
355 grep -F com.politedroid_4.apk archive/index.xml
356 grep -F com.politedroid_5.apk archive/index.xml
357 grep -F com.politedroid_6.apk repo/index.xml
358 test -e archive/com.politedroid_3.apk
359 test -e archive/com.politedroid_4.apk
360 test -e archive/com.politedroid_5.apk
361 ! test -e archive/com.politedroid_6.apk
362 test -e repo/com.politedroid_6.apk
366 #------------------------------------------------------------------------------#
367 echo_header 'test moving old APKs to and from the archive'
369 REPOROOT=`create_test_dir`
371 fdroid_init_with_prebuilt_keystore
372 echo "accepted_formats = ['txt']" >> config.py
373 test -d metadata || mkdir metadata
374 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
375 $sed -i.tmp '/Archive Policy:/d' metadata/com.politedroid.txt
376 test -d repo || mkdir repo
377 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
378 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
380 $fdroid update --pretty --nosign
381 test `grep '<package>' archive/index.xml | wc -l` -eq 1
382 test `grep '<package>' repo/index.xml | wc -l` -eq 3
383 grep -F com.politedroid_3.apk archive/index.xml
384 grep -F com.politedroid_4.apk repo/index.xml
385 grep -F com.politedroid_5.apk repo/index.xml
386 grep -F com.politedroid_6.apk repo/index.xml
387 test -e archive/com.politedroid_3.apk
388 test -e repo/com.politedroid_4.apk
389 test -e repo/com.politedroid_5.apk
390 test -e repo/com.politedroid_6.apk
392 $sed -i.tmp 's,archive_older = 3,archive_older = 1,' config.py
393 $fdroid update --pretty --nosign
394 test `grep '<package>' archive/index.xml | wc -l` -eq 3
395 test `grep '<package>' repo/index.xml | wc -l` -eq 1
396 grep -F com.politedroid_3.apk archive/index.xml
397 grep -F com.politedroid_4.apk archive/index.xml
398 grep -F com.politedroid_5.apk archive/index.xml
399 grep -F com.politedroid_6.apk repo/index.xml
400 test -e archive/com.politedroid_3.apk
401 test -e archive/com.politedroid_4.apk
402 test -e archive/com.politedroid_5.apk
403 test -e repo/com.politedroid_6.apk
405 # disabling deletes from the archive
406 $sed -i.tmp 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
407 $fdroid update --pretty --nosign
408 test `grep '<package>' archive/index.xml | wc -l` -eq 2
409 test `grep '<package>' repo/index.xml | wc -l` -eq 1
410 grep -F com.politedroid_3.apk archive/index.xml
411 ! grep -F com.politedroid_4.apk archive/index.xml
412 grep -F com.politedroid_5.apk archive/index.xml
413 grep -F com.politedroid_6.apk repo/index.xml
414 test -e archive/com.politedroid_3.apk
415 ! test -e archive/com.politedroid_4.apk
416 test -e archive/com.politedroid_5.apk
417 test -e repo/com.politedroid_6.apk
419 # disabling deletes from the repo, and promotes one from the archive
420 $sed -i.tmp 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
421 $fdroid update --pretty --nosign
422 test `grep '<package>' archive/index.xml | wc -l` -eq 1
423 test `grep '<package>' repo/index.xml | wc -l` -eq 1
424 grep -F com.politedroid_3.apk archive/index.xml
425 grep -F com.politedroid_5.apk repo/index.xml
426 ! grep -F com.politedroid_6.apk repo/index.xml
427 test -e archive/com.politedroid_3.apk
428 test -e repo/com.politedroid_5.apk
429 ! test -e repo/com.politedroid_6.apk
432 #------------------------------------------------------------------------------#
433 echo_header 'test allowing disabled signatures in repo and archive'
435 REPOROOT=`create_test_dir`
437 fdroid_init_with_prebuilt_keystore
438 echo "accepted_formats = ['txt']" >> config.py
439 echo 'allow_disabled_algorithms = True' >> config.py
440 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
441 test -d metadata || mkdir metadata
442 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
443 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
444 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
445 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
446 test -d repo || mkdir repo
447 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
448 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
449 $WORKSPACE/tests/urzip-badsig.apk \
452 $fdroid update --pretty --nosign
453 test `grep '<package>' archive/index.xml | wc -l` -eq 2
454 test `grep '<package>' repo/index.xml | wc -l` -eq 6
455 grep -F com.politedroid_3.apk archive/index.xml
456 grep -F com.politedroid_4.apk repo/index.xml
457 grep -F com.politedroid_5.apk repo/index.xml
458 grep -F com.politedroid_6.apk repo/index.xml
459 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
460 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
461 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
462 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
463 ! grep -F urzip-badsig.apk repo/index.xml
464 ! grep -F urzip-badsig.apk archive/index.xml
465 test -e archive/com.politedroid_3.apk
466 test -e repo/com.politedroid_4.apk
467 test -e repo/com.politedroid_5.apk
468 test -e repo/com.politedroid_6.apk
469 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
470 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
471 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
472 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
473 test -e archive/urzip-badsig.apk
475 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
476 $fdroid update --pretty --nosign
477 test `grep '<package>' archive/index.xml | wc -l` -eq 5
478 test `grep '<package>' repo/index.xml | wc -l` -eq 3
479 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
480 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
481 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
482 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
483 grep -F com.politedroid_3.apk archive/index.xml
484 grep -F com.politedroid_4.apk repo/index.xml
485 grep -F com.politedroid_5.apk repo/index.xml
486 grep -F com.politedroid_6.apk repo/index.xml
487 ! grep -F urzip-badsig.apk repo/index.xml
488 ! grep -F urzip-badsig.apk archive/index.xml
489 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
490 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
491 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
492 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
493 test -e archive/com.politedroid_3.apk
494 test -e archive/urzip-badsig.apk
495 test -e repo/com.politedroid_4.apk
496 test -e repo/com.politedroid_5.apk
497 test -e repo/com.politedroid_6.apk
500 #------------------------------------------------------------------------------#
501 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
503 REPOROOT=`create_test_dir`
505 fdroid_init_with_prebuilt_keystore
506 echo "accepted_formats = ['txt', 'yml']" >> config.py
507 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
508 test -d metadata || mkdir metadata
509 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
510 test -d repo || mkdir repo
511 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
512 $fdroid update --rename-apks --pretty --nosign
513 test -e repo/info.guardianproject.urzip_100.apk
514 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
515 cp $WORKSPACE/tests/urzip-release.apk repo/
516 $fdroid update --rename-apks --pretty --nosign
517 test -e repo/info.guardianproject.urzip_100.apk
518 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
519 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
520 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
521 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
522 cp $WORKSPACE/tests/urzip-release.apk repo/
523 $fdroid update --rename-apks --pretty --nosign
524 test -e repo/info.guardianproject.urzip_100.apk
525 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
526 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
527 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
528 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
529 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
532 #------------------------------------------------------------------------------#
533 echo_header "test metadata checks"
535 REPOROOT=`create_test_dir`
539 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
543 if [ $? -eq 0 ]; then
544 echo "This should have failed because there is no metadata!"
547 echo "testing metadata checks passed"
551 mkdir $REPOROOT/metadata/
552 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
555 # now make a fake duplicate
556 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
560 if [ $? -eq 0 ]; then
561 echo "This should have failed because there is a duplicate metadata file!"
564 echo "testing duplicate metadata checks passed"
569 #------------------------------------------------------------------------------#
570 echo_header "ensure commands that don't need the JDK work without a JDK configed"
572 REPOROOT=`create_test_dir`
576 echo "License:GPL-2.0" >> metadata/fake.txt
577 echo "Summary:Yup still fake" >> metadata/fake.txt
578 echo "Categories:Internet" >> metadata/fake.txt
579 echo "Description:" >> metadata/fake.txt
580 echo "this is fake" >> metadata/fake.txt
581 echo "." >> metadata/fake.txt
583 # fake that no JDKs are available
584 echo 'java_paths = {}' > config.py
586 LOCAL_COPY_DIR=`create_test_dir`/fdroid
587 mkdir -p $LOCAL_COPY_DIR/repo
588 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
590 $fdroid checkupdates --allow-dirty
594 $fdroid rewritemeta fake
595 $fdroid server update
598 # run these to get their output, but the are not setup, so don't fail
599 $fdroid build || true
600 $fdroid import || true
601 $fdroid install || true
604 #------------------------------------------------------------------------------#
605 echo_header "create a source tarball"
608 ./setup.py compile_catalog sdist
610 REPOROOT=`create_test_dir`
612 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
614 ./fdroidserver-*/fdroid init
615 copy_apks_into_repo $REPOROOT
616 ./fdroidserver-*/fdroid update --create-metadata --verbose
619 #------------------------------------------------------------------------------#
620 echo_header "test config checks of local_copy_dir"
622 REPOROOT=`create_test_dir`
625 $fdroid update --create-metadata --verbose
627 $fdroid server update --local-copy-dir=/tmp/fdroid
629 # now test the errors work
631 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
632 if [ $? -eq 0 ]; then
633 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
636 echo "testing absolute path checker passed"
638 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
639 if [ $? -eq 0 ]; then
640 echo "This should have failed because the path does not end with 'fdroid'!"
643 echo "testing dirname exists checker passed"
645 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
646 if [ $? -eq 0 ]; then
647 echo "This should have failed because the dirname path does not exist!"
650 echo "testing dirname exists checker passed"
655 #------------------------------------------------------------------------------#
656 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
658 REPOROOT=`create_test_dir`
660 fdroid_init_with_prebuilt_keystore
661 copy_apks_into_repo $REPOROOT
662 $fdroid update --create-metadata --verbose
664 grep -F '<application id=' repo/index.xml > /dev/null
666 LOCALCOPYDIR=`create_test_dir`/fdroid
667 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
668 NEWREPOROOT=`create_test_dir`
670 fdroid_init_with_prebuilt_keystore
671 echo "sync_from_local_copy_dir = True" >> config.py
672 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
675 #------------------------------------------------------------------------------#
676 # check that --android-home fails when dir does not exist or is not a dir
678 REPOROOT=`create_test_dir`
679 KEYSTORE=$REPOROOT/keystore.jks
682 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
683 if [ $? -eq 0 ]; then
684 echo "This should have failed because /opt/fakeandroidhome does not exist!"
687 echo "testing android-home path checker passed"
689 TESTFILE=`create_test_file`
690 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
691 if [ $? -eq 0 ]; then
692 echo "This should have failed because $TESTFILE is a file not a dir!"
695 echo "testing android-home not-dir checker passed"
700 #------------------------------------------------------------------------------#
701 echo_header "check that fake android home passes 'fdroid init'"
703 REPOROOT=`create_test_dir`
704 FAKE_ANDROID_HOME=`create_test_dir`
705 create_fake_android_home $FAKE_ANDROID_HOME
706 KEYSTORE=$REPOROOT/keystore.jks
708 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
711 #------------------------------------------------------------------------------#
712 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
714 if [ -e /usr/bin/aapt ]; then
715 echo "/usr/bin/aapt exists, not running test"
717 REPOROOT=`create_test_dir`
718 FAKE_ANDROID_HOME=`create_test_dir`
719 create_fake_android_home $FAKE_ANDROID_HOME
720 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
721 KEYSTORE=$REPOROOT/keystore.jks
724 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
725 [ $? -eq 0 ] && exit 1
730 #------------------------------------------------------------------------------#
731 echo_header "check that --android-home overrides ANDROID_HOME"
733 REPOROOT=`create_test_dir`
734 FAKE_ANDROID_HOME=`create_test_dir`
735 create_fake_android_home $FAKE_ANDROID_HOME
736 KEYSTORE=$REPOROOT/keystore.jks
738 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
740 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
741 if [ $? -ne 0 ]; then
742 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
748 #------------------------------------------------------------------------------#
749 # In this case, ANDROID_HOME is set to a fake, non-working version that will
750 # be detected by fdroid as an Android SDK install. It should use the path set
751 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
752 # in ANDROID_HOME, it won't work because it is a fake one. Only
753 # --android-home provides a working one.
754 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
756 REPOROOT=`create_test_dir`
757 KEYSTORE=$REPOROOT/keystore.jks
758 FAKE_ANDROID_HOME=`create_test_dir`
759 create_fake_android_home $FAKE_ANDROID_HOME
760 STORED_ANDROID_HOME=$ANDROID_HOME
762 echo "ANDROID_HOME: $ANDROID_HOME"
764 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
766 copy_apks_into_repo $REPOROOT
767 $fdroid update --create-metadata --verbose
769 grep -F '<application id=' repo/index.xml > /dev/null
770 test -e repo/index.xml
771 test -e repo/index.jar
772 test -e repo/index-v1.jar
774 ! test -z tmp/apkcache
775 export ANDROID_HOME=$STORED_ANDROID_HOME
778 #------------------------------------------------------------------------------#
779 echo_header "check duplicate files are properly handled by fdroid update"
781 REPOROOT=`create_test_dir`
783 fdroid_init_with_prebuilt_keystore
784 mkdir $REPOROOT/metadata
785 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
786 echo "accepted_formats = ['txt']" >> config.py
787 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
788 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
789 $fdroid update --pretty
790 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
791 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
792 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
793 # die if there are exact duplicates
794 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
798 #------------------------------------------------------------------------------#
799 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
801 REPOROOT=`create_test_dir`
804 copy_apks_into_repo $REPOROOT
805 fdroid_init_with_prebuilt_keystore
806 $fdroid update --create-metadata --verbose
808 grep -F '<application id=' repo/index.xml > /dev/null
811 #------------------------------------------------------------------------------#
812 echo_header "setup a new repo from scratch and generate a keystore"
814 REPOROOT=`create_test_dir`
815 KEYSTORE=$REPOROOT/keystore.jks
817 $fdroid init --keystore $KEYSTORE
819 copy_apks_into_repo $REPOROOT
820 $fdroid update --create-metadata --verbose
822 test -e repo/index.xml
823 test -e repo/index.jar
824 test -e repo/index-v1.jar
826 ! test -z tmp/apkcache
827 grep -F '<application id=' repo/index.xml > /dev/null
830 #------------------------------------------------------------------------------#
831 echo_header "setup a new repo manually and generate a keystore"
833 REPOROOT=`create_test_dir`
834 KEYSTORE=$REPOROOT/keystore.jks
836 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
840 if [ $? -eq 0 ]; then
841 echo "This should have failed because this repo has no keystore!"
844 echo '`fdroid update` prompted to add keystore'
847 $fdroid update --create-key
849 copy_apks_into_repo $REPOROOT
850 $fdroid update --create-metadata --verbose
852 test -e repo/index.xml
853 test -e repo/index.jar
854 test -e repo/index-v1.jar
856 ! test -z tmp/apkcache
857 grep -F '<application id=' repo/index.xml > /dev/null
860 #------------------------------------------------------------------------------#
861 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
863 REPOROOT=`create_test_dir`
864 KEYSTORE=$REPOROOT/keystore.jks
866 $fdroid init --keystore $KEYSTORE
868 copy_apks_into_repo $REPOROOT
869 $fdroid update --create-metadata --verbose
871 test -e repo/index.xml
872 test -e repo/index.jar
873 test -e repo/index-v1.jar
874 grep -F '<application id=' repo/index.xml > /dev/null
875 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
876 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
877 $fdroid update --create-metadata --verbose
879 test -e repo/index.xml
880 test -e repo/index.jar
881 test -e repo/index-v1.jar
883 ! test -z tmp/apkcache
884 grep -F '<application id=' repo/index.xml > /dev/null
887 #------------------------------------------------------------------------------#
888 echo_header "setup a new repo from scratch with a HSM/smartcard"
889 REPOROOT=`create_test_dir`
891 $fdroid init --keystore NONE
892 test -e opensc-fdroid.cfg
896 #------------------------------------------------------------------------------#
897 echo_header "setup a new repo with no keystore, add APK, and update"
899 REPOROOT=`create_test_dir`
900 KEYSTORE=$REPOROOT/keystore.jks
902 touch fdroid-icon.png
904 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
906 $fdroid update --create-metadata --verbose
907 if [ $? -eq 0 ]; then
908 echo "This should have failed because this repo has no keystore!"
911 echo '`fdroid update` prompted to add keystore'
915 # now set up fake, non-working keystore setup
917 echo "keystore = \"$KEYSTORE\"" >> config.py
918 echo 'repo_keyalias = "foo"' >> config.py
919 echo 'keystorepass = "foo"' >> config.py
920 echo 'keypass = "foo"' >> config.py
922 $fdroid update --create-metadata --verbose
923 if [ $? -eq 0 ]; then
924 echo "This should have failed because this repo has a bad/fake keystore!"
927 echo '`fdroid update` prompted to add keystore'
932 #------------------------------------------------------------------------------#
933 echo_header "copy tests/repo, update with binary transparency log"
935 REPOROOT=`create_test_dir`
936 GIT_REMOTE=`create_test_dir`
937 GNUPGHOME=$REPOROOT/gnupghome
939 fdroid_init_with_prebuilt_keystore
940 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
941 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
942 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
943 $fdroid update --verbose
944 if have_git_2_3; then
945 $fdroid server update --verbose
946 test -e repo/index.xml
947 test -e repo/index.jar
948 test -e repo/index-v1.jar
949 grep -F '<application id=' repo/index.xml > /dev/null
950 cd binary_transparency
951 [ `git rev-list --count HEAD` == "2" ]
953 [ `git rev-list --count HEAD` == "2" ]
955 echo "Skipping test, `git --version` older than 2.3"
959 #------------------------------------------------------------------------------#
960 echo_header "setup a new repo with keystore with APK, update, then without key"
962 REPOROOT=`create_test_dir`
963 KEYSTORE=$REPOROOT/keystore.jks
965 cp $WORKSPACE/tests/keystore.jks $KEYSTORE
966 fdroid_init_with_prebuilt_keystore $KEYSTORE
968 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
969 $fdroid update --create-metadata --verbose
971 test -e repo/index.xml
972 test -e repo/index.jar
973 test -e repo/index-v1.jar
975 ! test -z tmp/apkcache
976 grep -F '<application id=' repo/index.xml > /dev/null
978 # now set fake repo_keyalias
979 $sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
982 if [ $? -eq 0 ]; then
983 echo "This should have failed because this repo has a bad repo_keyalias!"
986 echo '`fdroid update` prompted to add keystore'
990 # try creating a new keystore, but fail because the old one is there
993 $fdroid update --create-key
994 if [ $? -eq 0 ]; then
995 echo "This should have failed because a keystore is already there!"
998 echo '`fdroid update` complained about existing keystore'
1002 # now actually create the key with the existing settings
1005 $fdroid update --create-key
1009 #------------------------------------------------------------------------------#
1010 echo_header "sign binary repo in offline box, then publishing from online box"
1012 OFFLINE_ROOT=`create_test_dir`
1013 KEYSTORE=$WORKSPACE/tests/keystore.jks
1014 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1015 mkdir $LOCAL_COPY_DIR
1016 ONLINE_ROOT=`create_test_dir`
1017 SERVERWEBROOT=`create_test_dir`
1019 # create offline binary transparency log
1021 mkdir binary_transparency
1022 cd binary_transparency
1025 # fake git remote server for binary transparency log
1026 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1028 # fake git remote server for repo mirror
1029 SERVER_GIT_MIRROR=`create_test_dir`
1030 cd $SERVER_GIT_MIRROR
1032 if have_git_2_3; then
1033 git config receive.denyCurrentBranch updateInstead
1037 fdroid_init_with_prebuilt_keystore
1038 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1040 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
1041 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1042 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1043 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1044 $fdroid update --pretty
1045 grep -F '<application id=' repo/index.xml > /dev/null
1046 grep -F '/fdroid/repo</mirror>' repo/index.xml
1047 grep -F '/fdroid/archive</mirror>' archive/index.xml
1048 test `grep '<mirror>' repo/index.xml | wc -l` -eq 2
1049 test `grep '<mirror>' archive/index.xml | wc -l` -eq 2
1050 cd binary_transparency
1051 [ `git rev-list --count HEAD` == "1" ]
1053 $fdroid server update --verbose
1054 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1056 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1057 echo "sync_from_local_copy_dir = True" >> config.py
1058 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1059 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1060 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1061 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1062 $fdroid server update --verbose
1063 cd $BINARY_TRANSPARENCY_REMOTE
1064 [ `git rev-list --count HEAD` == "1" ]
1065 cd $SERVER_GIT_MIRROR
1066 [ `git rev-list --count HEAD` == "1" ]
1069 #------------------------------------------------------------------------------#
1071 # remove this to prevent git conflicts and complaining
1072 rm -rf $WORKSPACE/fdroidserver.egg-info/