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/*.TestCase; do
133 #------------------------------------------------------------------------------#
134 echo_header "print fdroid version"
139 #------------------------------------------------------------------------------#
140 echo_header 'run process when building and signing are on separate machines'
142 REPOROOT=`create_test_dir`
144 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
145 $fdroid init --keystore keystore.jks --repo-keyalias=sova
146 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
147 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
148 echo "accepted_formats = ['txt', 'yml']" >> config.py
149 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
150 test -d archive || mkdir archive
151 test -d metadata || mkdir metadata
152 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
153 test -d repo || mkdir repo
154 test -d unsigned || mkdir unsigned
155 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
156 $fdroid publish --verbose
157 $fdroid update --verbose --nosign
158 $fdroid signindex --verbose
159 test -e repo/index.xml
160 test -e repo/index.jar
161 test -e repo/index-v1.jar
163 ! test -z tmp/apkcache
165 grep -F '<application id=' repo/index.xml > /dev/null
168 #------------------------------------------------------------------------------#
169 echo_header "test UTF-8 metadata"
171 REPOROOT=`create_test_dir`
174 fdroid_init_with_prebuilt_keystore
175 $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
176 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
178 cp $WORKSPACE/tests/urzip.apk $WORKSPACE/tests/bad-unicode*.apk repo/
179 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
185 #------------------------------------------------------------------------------#
186 echo_header 'run "fdroid build" in fresh git checkout from import.TestCase'
188 cd $WORKSPACE/tests/tmp/importer
191 # stick with known working commit, in case future commits break things for this code
192 git reset --hard fea54e1161d5eb9eb1a54e26253ef84d3ab63705
193 if [ -d $ANDROID_HOME/platforms/android-23 && -d $ANDROID_HOME/build-tools/23.0.3 ]; then
194 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
195 echo "force_build_tools = True" >> config.py
196 $fdroid build --verbose org.fdroid.ci.test.app:300
198 echo 'WARNING: Skipping "fdroid build" test since android-23 is missing!'
201 #------------------------------------------------------------------------------#
202 echo_header 'copy git import and run "fdroid scanner" on it'
204 REPOROOT=`create_test_dir`
206 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
208 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
209 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
210 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
211 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
212 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
213 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
214 echo "" >> metadata/org.fdroid.ci.test.app.txt
215 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
216 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
218 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
219 ls -l build/org.fdroid.ci.test.app
220 $fdroid scanner org.fdroid.ci.test.app --verbose
223 #------------------------------------------------------------------------------#
224 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
226 REPOROOT=`create_test_dir`
227 GNUPGHOME=$REPOROOT/gnupghome
229 fdroid_init_with_prebuilt_keystore
230 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
231 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
232 chmod 0700 $GNUPGHOME
233 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
234 echo "install_list = 'org.adaway'" >> config.py
235 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
236 echo "gpghome = '$GNUPGHOME'" >> config.py
237 echo "gpgkey = 'CE71F7FB'" >> config.py
238 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
239 $fdroid update --verbose --pretty
240 test -e repo/index.xml
241 test -e repo/index.jar
242 test -e repo/index-v1.jar
243 grep -F '<application id=' repo/index.xml > /dev/null
244 grep -F '<install packageName=' repo/index.xml > /dev/null
245 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
246 # OSX tests are run on Travis-CI, and gpg fails to launch gpg-agent there
247 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
248 $fdroid gpgsign --verbose
249 $fdroid gpgsign --verbose
250 test -e repo/obb.mainpatch.current_1619.apk.asc
251 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
252 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
253 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
254 ! test -e repo/index.xml.asc
257 # we can't easily reproduce the timestamps for things, so just hardcode them
258 $sed -i.tmp -e 's,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
259 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
260 sed -i --expression='s,"timestamp": [0-9]*,"timestamp": 1502845383782,' repo/index-v1.json
261 diff -uw $WORKSPACE/tests/repo/index-v1.json repo/index-v1.json
264 #------------------------------------------------------------------------------#
265 echo_header 'test moving lots of APKs to the archive'
267 REPOROOT=`create_test_dir`
269 fdroid_init_with_prebuilt_keystore
270 echo "accepted_formats = ['txt']" >> config.py
271 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
272 test -d metadata || mkdir metadata
273 cp $WORKSPACE/tests/metadata/*.txt metadata/
274 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
275 echo 'Summary:good MD5 sig, which is disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
276 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
277 test -d repo || mkdir repo
278 cp $WORKSPACE/tests/urzip.apk \
279 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
280 $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
281 $WORKSPACE/tests/repo/obb.main.twoversions_110161[357].apk \
283 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
285 $fdroid update --pretty --nosign
286 echo "This will fail when jarsigner allows MD5 for APK signatures"
287 test `grep '<package>' archive/index.xml | wc -l` -eq 5
288 test `grep '<package>' repo/index.xml | wc -l` -eq 7
291 #------------------------------------------------------------------------------#
292 echo_header 'test per-app "Archive Policy"'
294 REPOROOT=`create_test_dir`
296 fdroid_init_with_prebuilt_keystore
297 echo "accepted_formats = ['txt']" >> config.py
298 test -d metadata || mkdir metadata
299 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
300 test -d repo || mkdir repo
301 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
302 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
304 $fdroid update --pretty --nosign
305 test `grep '<package>' archive/index.xml | wc -l` -eq 0
306 test `grep '<package>' repo/index.xml | wc -l` -eq 4
307 grep -F com.politedroid_3.apk repo/index.xml
308 grep -F com.politedroid_4.apk repo/index.xml
309 grep -F com.politedroid_5.apk repo/index.xml
310 grep -F com.politedroid_6.apk repo/index.xml
311 test -e repo/com.politedroid_3.apk
312 test -e repo/com.politedroid_4.apk
313 test -e repo/com.politedroid_5.apk
314 test -e repo/com.politedroid_6.apk
316 echo "enable one app in the repo"
317 $sed -i.tmp 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
318 $fdroid update --pretty --nosign
319 test `grep '<package>' archive/index.xml | wc -l` -eq 3
320 test `grep '<package>' repo/index.xml | wc -l` -eq 1
321 grep -F com.politedroid_3.apk archive/index.xml
322 grep -F com.politedroid_4.apk archive/index.xml
323 grep -F com.politedroid_5.apk archive/index.xml
324 grep -F com.politedroid_6.apk repo/index.xml
325 test -e archive/com.politedroid_3.apk
326 test -e archive/com.politedroid_4.apk
327 test -e archive/com.politedroid_5.apk
328 test -e repo/com.politedroid_6.apk
330 echo "remove all apps from the repo"
331 $sed -i.tmp 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
332 $fdroid update --pretty --nosign
333 test `grep '<package>' archive/index.xml | wc -l` -eq 4
334 test `grep '<package>' repo/index.xml | wc -l` -eq 0
335 grep -F com.politedroid_3.apk archive/index.xml
336 grep -F com.politedroid_4.apk archive/index.xml
337 grep -F com.politedroid_5.apk archive/index.xml
338 grep -F com.politedroid_6.apk archive/index.xml
339 test -e archive/com.politedroid_3.apk
340 test -e archive/com.politedroid_4.apk
341 test -e archive/com.politedroid_5.apk
342 test -e archive/com.politedroid_6.apk
343 ! test -e repo/com.politedroid_6.apk
345 echo "move back one from archive to the repo"
346 $sed -i.tmp 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
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 archive/com.politedroid_6.apk
358 test -e repo/com.politedroid_6.apk
362 #------------------------------------------------------------------------------#
363 echo_header 'test moving old APKs to and from the archive'
365 REPOROOT=`create_test_dir`
367 fdroid_init_with_prebuilt_keystore
368 echo "accepted_formats = ['txt']" >> config.py
369 test -d metadata || mkdir metadata
370 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
371 $sed -i.tmp '/Archive Policy:/d' metadata/com.politedroid.txt
372 test -d repo || mkdir repo
373 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
374 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
376 $fdroid update --pretty --nosign
377 test `grep '<package>' archive/index.xml | wc -l` -eq 1
378 test `grep '<package>' repo/index.xml | wc -l` -eq 3
379 grep -F com.politedroid_3.apk archive/index.xml
380 grep -F com.politedroid_4.apk repo/index.xml
381 grep -F com.politedroid_5.apk repo/index.xml
382 grep -F com.politedroid_6.apk repo/index.xml
383 test -e archive/com.politedroid_3.apk
384 test -e repo/com.politedroid_4.apk
385 test -e repo/com.politedroid_5.apk
386 test -e repo/com.politedroid_6.apk
388 $sed -i.tmp 's,archive_older = 3,archive_older = 1,' config.py
389 $fdroid update --pretty --nosign
390 test `grep '<package>' archive/index.xml | wc -l` -eq 3
391 test `grep '<package>' repo/index.xml | wc -l` -eq 1
392 grep -F com.politedroid_3.apk archive/index.xml
393 grep -F com.politedroid_4.apk archive/index.xml
394 grep -F com.politedroid_5.apk archive/index.xml
395 grep -F com.politedroid_6.apk repo/index.xml
396 test -e archive/com.politedroid_3.apk
397 test -e archive/com.politedroid_4.apk
398 test -e archive/com.politedroid_5.apk
399 test -e repo/com.politedroid_6.apk
401 # disabling deletes from the archive
402 $sed -i.tmp 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
403 $fdroid update --pretty --nosign
404 test `grep '<package>' archive/index.xml | wc -l` -eq 2
405 test `grep '<package>' repo/index.xml | wc -l` -eq 1
406 grep -F com.politedroid_3.apk archive/index.xml
407 ! grep -F com.politedroid_4.apk archive/index.xml
408 grep -F com.politedroid_5.apk archive/index.xml
409 grep -F com.politedroid_6.apk repo/index.xml
410 test -e archive/com.politedroid_3.apk
411 ! test -e archive/com.politedroid_4.apk
412 test -e archive/com.politedroid_5.apk
413 test -e repo/com.politedroid_6.apk
415 # disabling deletes from the repo, and promotes one from the archive
416 $sed -i.tmp 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
417 $fdroid update --pretty --nosign
418 test `grep '<package>' archive/index.xml | wc -l` -eq 1
419 test `grep '<package>' repo/index.xml | wc -l` -eq 1
420 grep -F com.politedroid_3.apk archive/index.xml
421 grep -F com.politedroid_5.apk repo/index.xml
422 ! grep -F com.politedroid_6.apk repo/index.xml
423 test -e archive/com.politedroid_3.apk
424 test -e repo/com.politedroid_5.apk
425 ! test -e repo/com.politedroid_6.apk
428 #------------------------------------------------------------------------------#
429 echo_header 'test allowing disabled signatures in repo and archive'
431 REPOROOT=`create_test_dir`
433 fdroid_init_with_prebuilt_keystore
434 echo "accepted_formats = ['txt']" >> config.py
435 echo 'allow_disabled_algorithms = True' >> config.py
436 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
437 test -d metadata || mkdir metadata
438 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
439 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
440 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
441 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
442 test -d repo || mkdir repo
443 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
444 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
445 $WORKSPACE/tests/urzip-badsig.apk \
448 $fdroid update --pretty --nosign
449 test `grep '<package>' archive/index.xml | wc -l` -eq 2
450 test `grep '<package>' repo/index.xml | wc -l` -eq 6
451 grep -F com.politedroid_3.apk archive/index.xml
452 grep -F com.politedroid_4.apk repo/index.xml
453 grep -F com.politedroid_5.apk repo/index.xml
454 grep -F com.politedroid_6.apk repo/index.xml
455 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
456 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
457 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
458 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
459 ! grep -F urzip-badsig.apk repo/index.xml
460 ! grep -F urzip-badsig.apk archive/index.xml
461 test -e archive/com.politedroid_3.apk
462 test -e repo/com.politedroid_4.apk
463 test -e repo/com.politedroid_5.apk
464 test -e repo/com.politedroid_6.apk
465 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
466 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
467 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
468 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
469 test -e archive/urzip-badsig.apk
471 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
472 $fdroid update --pretty --nosign
473 test `grep '<package>' archive/index.xml | wc -l` -eq 5
474 test `grep '<package>' repo/index.xml | wc -l` -eq 3
475 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
476 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
477 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
478 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
479 grep -F com.politedroid_3.apk archive/index.xml
480 grep -F com.politedroid_4.apk repo/index.xml
481 grep -F com.politedroid_5.apk repo/index.xml
482 grep -F com.politedroid_6.apk repo/index.xml
483 ! grep -F urzip-badsig.apk repo/index.xml
484 ! grep -F urzip-badsig.apk archive/index.xml
485 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
486 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
487 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
488 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
489 test -e archive/com.politedroid_3.apk
490 test -e archive/urzip-badsig.apk
491 test -e repo/com.politedroid_4.apk
492 test -e repo/com.politedroid_5.apk
493 test -e repo/com.politedroid_6.apk
496 #------------------------------------------------------------------------------#
497 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
499 REPOROOT=`create_test_dir`
501 fdroid_init_with_prebuilt_keystore
502 echo "accepted_formats = ['txt', 'yml']" >> config.py
503 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
504 test -d metadata || mkdir metadata
505 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
506 test -d repo || mkdir repo
507 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
508 $fdroid update --rename-apks --pretty --nosign
509 test -e repo/info.guardianproject.urzip_100.apk
510 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
511 cp $WORKSPACE/tests/urzip-release.apk repo/
512 $fdroid update --rename-apks --pretty --nosign
513 test -e repo/info.guardianproject.urzip_100.apk
514 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
515 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
516 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
517 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
518 cp $WORKSPACE/tests/urzip-release.apk repo/
519 $fdroid update --rename-apks --pretty --nosign
520 test -e repo/info.guardianproject.urzip_100.apk
521 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
522 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
523 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
524 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
525 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
528 #------------------------------------------------------------------------------#
529 echo_header "test metadata checks"
531 REPOROOT=`create_test_dir`
535 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
539 if [ $? -eq 0 ]; then
540 echo "This should have failed because there is no metadata!"
543 echo "testing metadata checks passed"
547 mkdir $REPOROOT/metadata/
548 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
551 # now make a fake duplicate
552 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
556 if [ $? -eq 0 ]; then
557 echo "This should have failed because there is a duplicate metadata file!"
560 echo "testing duplicate metadata checks passed"
565 #------------------------------------------------------------------------------#
566 echo_header "ensure commands that don't need the JDK work without a JDK configed"
568 REPOROOT=`create_test_dir`
572 echo "License:GPL-2.0" >> metadata/fake.txt
573 echo "Summary:Yup still fake" >> metadata/fake.txt
574 echo "Categories:Internet" >> metadata/fake.txt
575 echo "Description:" >> metadata/fake.txt
576 echo "this is fake" >> metadata/fake.txt
577 echo "." >> metadata/fake.txt
579 # fake that no JDKs are available
580 echo 'java_paths = {}' > config.py
582 LOCAL_COPY_DIR=`create_test_dir`/fdroid
583 mkdir -p $LOCAL_COPY_DIR/repo
584 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
590 $fdroid rewritemeta fake
591 $fdroid server update
594 # run these to get their output, but the are not setup, so don't fail
595 $fdroid build || true
596 $fdroid import || true
597 $fdroid install || true
600 #------------------------------------------------------------------------------#
601 echo_header "create a source tarball"
604 ./setup.py compile_catalog sdist
606 REPOROOT=`create_test_dir`
608 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
610 ./fdroidserver-*/fdroid init
611 copy_apks_into_repo $REPOROOT
612 ./fdroidserver-*/fdroid update --create-metadata --verbose
615 #------------------------------------------------------------------------------#
616 echo_header "test config checks of local_copy_dir"
618 REPOROOT=`create_test_dir`
621 $fdroid update --create-metadata --verbose
623 $fdroid server update --local-copy-dir=/tmp/fdroid
625 # now test the errors work
627 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
628 if [ $? -eq 0 ]; then
629 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
632 echo "testing absolute path checker passed"
634 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
635 if [ $? -eq 0 ]; then
636 echo "This should have failed because the path does not end with 'fdroid'!"
639 echo "testing dirname exists checker passed"
641 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
642 if [ $? -eq 0 ]; then
643 echo "This should have failed because the dirname path does not exist!"
646 echo "testing dirname exists checker passed"
651 #------------------------------------------------------------------------------#
652 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
654 REPOROOT=`create_test_dir`
656 fdroid_init_with_prebuilt_keystore
657 copy_apks_into_repo $REPOROOT
658 $fdroid update --create-metadata --verbose
660 grep -F '<application id=' repo/index.xml > /dev/null
662 LOCALCOPYDIR=`create_test_dir`/fdroid
663 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
664 NEWREPOROOT=`create_test_dir`
666 fdroid_init_with_prebuilt_keystore
667 echo "sync_from_local_copy_dir = True" >> config.py
668 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
671 #------------------------------------------------------------------------------#
672 # check that --android-home fails when dir does not exist or is not a dir
674 REPOROOT=`create_test_dir`
675 KEYSTORE=$REPOROOT/keystore.jks
678 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
679 if [ $? -eq 0 ]; then
680 echo "This should have failed because /opt/fakeandroidhome does not exist!"
683 echo "testing android-home path checker passed"
685 TESTFILE=`create_test_file`
686 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
687 if [ $? -eq 0 ]; then
688 echo "This should have failed because $TESTFILE is a file not a dir!"
691 echo "testing android-home not-dir checker passed"
696 #------------------------------------------------------------------------------#
697 echo_header "check that fake android home passes 'fdroid init'"
699 REPOROOT=`create_test_dir`
700 FAKE_ANDROID_HOME=`create_test_dir`
701 create_fake_android_home $FAKE_ANDROID_HOME
702 KEYSTORE=$REPOROOT/keystore.jks
704 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
707 #------------------------------------------------------------------------------#
708 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
710 if [ -e /usr/bin/aapt ]; then
711 echo "/usr/bin/aapt exists, not running test"
713 REPOROOT=`create_test_dir`
714 FAKE_ANDROID_HOME=`create_test_dir`
715 create_fake_android_home $FAKE_ANDROID_HOME
716 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
717 KEYSTORE=$REPOROOT/keystore.jks
720 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
721 [ $? -eq 0 ] && exit 1
726 #------------------------------------------------------------------------------#
727 echo_header "check that --android-home overrides ANDROID_HOME"
729 REPOROOT=`create_test_dir`
730 FAKE_ANDROID_HOME=`create_test_dir`
731 create_fake_android_home $FAKE_ANDROID_HOME
732 KEYSTORE=$REPOROOT/keystore.jks
734 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
736 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
737 if [ $? -ne 0 ]; then
738 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
744 #------------------------------------------------------------------------------#
745 # In this case, ANDROID_HOME is set to a fake, non-working version that will
746 # be detected by fdroid as an Android SDK install. It should use the path set
747 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
748 # in ANDROID_HOME, it won't work because it is a fake one. Only
749 # --android-home provides a working one.
750 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
752 REPOROOT=`create_test_dir`
753 KEYSTORE=$REPOROOT/keystore.jks
754 FAKE_ANDROID_HOME=`create_test_dir`
755 create_fake_android_home $FAKE_ANDROID_HOME
756 STORED_ANDROID_HOME=$ANDROID_HOME
758 echo "ANDROID_HOME: $ANDROID_HOME"
760 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
762 copy_apks_into_repo $REPOROOT
763 $fdroid update --create-metadata --verbose
765 grep -F '<application id=' repo/index.xml > /dev/null
766 test -e repo/index.xml
767 test -e repo/index.jar
768 test -e repo/index-v1.jar
770 ! test -z tmp/apkcache
771 export ANDROID_HOME=$STORED_ANDROID_HOME
774 #------------------------------------------------------------------------------#
775 echo_header "check duplicate files are properly handled by fdroid update"
777 REPOROOT=`create_test_dir`
779 fdroid_init_with_prebuilt_keystore
780 mkdir $REPOROOT/metadata
781 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
782 echo "accepted_formats = ['txt']" >> config.py
783 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
784 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
785 $fdroid update --pretty
786 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
787 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
788 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
789 # die if there are exact duplicates
790 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
794 #------------------------------------------------------------------------------#
795 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
797 REPOROOT=`create_test_dir`
800 copy_apks_into_repo $REPOROOT
801 fdroid_init_with_prebuilt_keystore
802 $fdroid update --create-metadata --verbose
804 grep -F '<application id=' repo/index.xml > /dev/null
807 #------------------------------------------------------------------------------#
808 echo_header "setup a new repo from scratch and generate a keystore"
810 REPOROOT=`create_test_dir`
811 KEYSTORE=$REPOROOT/keystore.jks
813 $fdroid init --keystore $KEYSTORE
815 copy_apks_into_repo $REPOROOT
816 $fdroid update --create-metadata --verbose
818 test -e repo/index.xml
819 test -e repo/index.jar
820 test -e repo/index-v1.jar
822 ! test -z tmp/apkcache
823 grep -F '<application id=' repo/index.xml > /dev/null
826 #------------------------------------------------------------------------------#
827 echo_header "setup a new repo manually and generate a keystore"
829 REPOROOT=`create_test_dir`
830 KEYSTORE=$REPOROOT/keystore.jks
832 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
836 if [ $? -eq 0 ]; then
837 echo "This should have failed because this repo has no keystore!"
840 echo '`fdroid update` prompted to add keystore'
843 $fdroid update --create-key
845 copy_apks_into_repo $REPOROOT
846 $fdroid update --create-metadata --verbose
848 test -e repo/index.xml
849 test -e repo/index.jar
850 test -e repo/index-v1.jar
852 ! test -z tmp/apkcache
853 grep -F '<application id=' repo/index.xml > /dev/null
856 #------------------------------------------------------------------------------#
857 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
859 REPOROOT=`create_test_dir`
860 KEYSTORE=$REPOROOT/keystore.jks
862 $fdroid init --keystore $KEYSTORE
864 copy_apks_into_repo $REPOROOT
865 $fdroid update --create-metadata --verbose
867 test -e repo/index.xml
868 test -e repo/index.jar
869 test -e repo/index-v1.jar
870 grep -F '<application id=' repo/index.xml > /dev/null
871 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
872 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
873 $fdroid update --create-metadata --verbose
875 test -e repo/index.xml
876 test -e repo/index.jar
877 test -e repo/index-v1.jar
879 ! test -z tmp/apkcache
880 grep -F '<application id=' repo/index.xml > /dev/null
883 #------------------------------------------------------------------------------#
884 echo_header "setup a new repo from scratch with a HSM/smartcard"
885 REPOROOT=`create_test_dir`
887 $fdroid init --keystore NONE
888 test -e opensc-fdroid.cfg
892 #------------------------------------------------------------------------------#
893 echo_header "setup a new repo with no keystore, add APK, and update"
895 REPOROOT=`create_test_dir`
896 KEYSTORE=$REPOROOT/keystore.jks
898 touch fdroid-icon.png
900 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
902 $fdroid update --create-metadata --verbose
903 if [ $? -eq 0 ]; then
904 echo "This should have failed because this repo has no keystore!"
907 echo '`fdroid update` prompted to add keystore'
911 # now set up fake, non-working keystore setup
913 echo "keystore = \"$KEYSTORE\"" >> config.py
914 echo 'repo_keyalias = "foo"' >> config.py
915 echo 'keystorepass = "foo"' >> config.py
916 echo 'keypass = "foo"' >> config.py
918 $fdroid update --create-metadata --verbose
919 if [ $? -eq 0 ]; then
920 echo "This should have failed because this repo has a bad/fake keystore!"
923 echo '`fdroid update` prompted to add keystore'
928 #------------------------------------------------------------------------------#
929 echo_header "copy tests/repo, update with binary transparency log"
931 REPOROOT=`create_test_dir`
932 GIT_REMOTE=`create_test_dir`
933 GNUPGHOME=$REPOROOT/gnupghome
935 fdroid_init_with_prebuilt_keystore
936 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
937 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
938 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
939 $fdroid update --verbose
940 if have_git_2_3; then
941 $fdroid server update --verbose
942 test -e repo/index.xml
943 test -e repo/index.jar
944 test -e repo/index-v1.jar
945 grep -F '<application id=' repo/index.xml > /dev/null
946 cd binary_transparency
947 [ `git rev-list --count HEAD` == "2" ]
949 [ `git rev-list --count HEAD` == "2" ]
951 echo "Skipping test, `git --version` older than 2.3"
955 #------------------------------------------------------------------------------#
956 echo_header "setup a new repo with keystore with APK, update, then without key"
958 REPOROOT=`create_test_dir`
959 KEYSTORE=$REPOROOT/keystore.jks
961 cp $WORKSPACE/tests/keystore.jks $KEYSTORE
962 fdroid_init_with_prebuilt_keystore $KEYSTORE
964 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
965 $fdroid update --create-metadata --verbose
967 test -e repo/index.xml
968 test -e repo/index.jar
969 test -e repo/index-v1.jar
971 ! test -z tmp/apkcache
972 grep -F '<application id=' repo/index.xml > /dev/null
974 # now set fake repo_keyalias
975 $sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
978 if [ $? -eq 0 ]; then
979 echo "This should have failed because this repo has a bad repo_keyalias!"
982 echo '`fdroid update` prompted to add keystore'
986 # try creating a new keystore, but fail because the old one is there
989 $fdroid update --create-key
990 if [ $? -eq 0 ]; then
991 echo "This should have failed because a keystore is already there!"
994 echo '`fdroid update` complained about existing keystore'
998 # now actually create the key with the existing settings
1001 $fdroid update --create-key
1005 #------------------------------------------------------------------------------#
1006 echo_header "sign binary repo in offline box, then publishing from online box"
1008 OFFLINE_ROOT=`create_test_dir`
1009 KEYSTORE=$WORKSPACE/tests/keystore.jks
1010 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1011 mkdir $LOCAL_COPY_DIR
1012 ONLINE_ROOT=`create_test_dir`
1013 SERVERWEBROOT=`create_test_dir`
1015 # create offline binary transparency log
1017 mkdir binary_transparency
1018 cd binary_transparency
1021 # fake git remote server for binary transparency log
1022 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1024 # fake git remote server for repo mirror
1025 SERVER_GIT_MIRROR=`create_test_dir`
1026 cd $SERVER_GIT_MIRROR
1028 if have_git_2_3; then
1029 git config receive.denyCurrentBranch updateInstead
1033 fdroid_init_with_prebuilt_keystore
1034 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1036 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
1037 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1038 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1039 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1040 $fdroid update --pretty
1041 grep -F '<application id=' repo/index.xml > /dev/null
1042 grep -F '/fdroid/repo</mirror>' repo/index.xml
1043 grep -F '/fdroid/archive</mirror>' archive/index.xml
1044 test `grep '<mirror>' repo/index.xml | wc -l` -eq 2
1045 test `grep '<mirror>' archive/index.xml | wc -l` -eq 2
1046 cd binary_transparency
1047 [ `git rev-list --count HEAD` == "1" ]
1049 $fdroid server update --verbose
1050 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1052 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1053 echo "sync_from_local_copy_dir = True" >> config.py
1054 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1055 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1056 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1057 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1058 $fdroid server update --verbose
1059 cd $BINARY_TRANSPARENCY_REMOTE
1060 [ `git rev-list --count HEAD` == "1" ]
1061 cd $SERVER_GIT_MIRROR
1062 [ `git rev-list --count HEAD` == "1" ]
1065 #------------------------------------------------------------------------------#
1067 # remove this to prevent git conflicts and complaining
1068 rm -rf $WORKSPACE/fdroidserver.egg-info/