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 || 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 # 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 # try to use GNU sed on OSX/BSD cuz BSD sed sucks
101 set -x # show each command as it is executed
103 #------------------------------------------------------------------------------#
104 echo_header "run commit hooks"
110 #------------------------------------------------------------------------------#
111 echo_header "test python getsig replacement"
113 cd $WORKSPACE/tests/getsig
117 for testcase in $WORKSPACE/tests/*.TestCase; do
122 #------------------------------------------------------------------------------#
123 echo_header "print fdroid version"
128 #------------------------------------------------------------------------------#
129 echo_header 'run process when building and signing are on separate machines'
131 REPOROOT=`create_test_dir`
133 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
134 $fdroid init --keystore keystore.jks --repo-keyalias=sova
135 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
136 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
137 echo "accepted_formats = ['txt', 'yml']" >> config.py
138 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
139 test -d archive || mkdir archive
140 test -d metadata || mkdir metadata
141 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
142 test -d repo || mkdir repo
143 test -d unsigned || mkdir unsigned
144 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
145 $fdroid publish --verbose
146 $fdroid update --verbose --nosign
147 $fdroid signindex --verbose
148 test -e repo/index.xml
149 test -e repo/index.jar
150 test -e repo/index-v1.jar
152 ! test -z tmp/apkcache
154 grep -F '<application id=' repo/index.xml > /dev/null
157 #------------------------------------------------------------------------------#
158 echo_header "test UTF-8 metadata"
160 REPOROOT=`create_test_dir`
164 $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
165 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
167 cp $WORKSPACE/tests/urzip.apk $WORKSPACE/tests/bad-unicode*.apk repo/
168 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
174 #------------------------------------------------------------------------------#
175 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
177 cd $WORKSPACE/tests/tmp/importer
180 # stick with known working commit, in case future commits break things for this code
181 git reset --hard cecf00c08aec56ae7a5eba444150c4d1ae868814
182 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
183 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
184 echo "force_build_tools = True" >> config.py
185 $fdroid build --verbose org.fdroid.ci.test.app:300
187 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
190 #------------------------------------------------------------------------------#
191 echo_header 'copy git import and run `fdroid scanner` on it'
193 REPOROOT=`create_test_dir`
195 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
197 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
198 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
199 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
200 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
201 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
202 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
203 echo "" >> metadata/org.fdroid.ci.test.app.txt
204 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
205 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
207 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
208 ls -l build/org.fdroid.ci.test.app
209 $fdroid scanner org.fdroid.ci.test.app --verbose
212 #------------------------------------------------------------------------------#
213 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
215 REPOROOT=`create_test_dir`
216 GNUPGHOME=$REPOROOT/gnupghome
217 KEYSTORE=$WORKSPACE/tests/keystore.jks
219 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
220 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
221 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
222 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
223 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
224 chmod 0700 $GNUPGHOME
225 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
226 echo "install_list = 'org.adaway'" >> config.py
227 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
228 echo "gpghome = '$GNUPGHOME'" >> config.py
229 echo "gpgkey = 'CE71F7FB'" >> config.py
230 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
231 $fdroid update --verbose --pretty
232 test -e repo/index.xml
233 test -e repo/index.jar
234 test -e repo/index-v1.jar
235 grep -F '<application id=' repo/index.xml > /dev/null
236 grep -F '<install packageName=' repo/index.xml > /dev/null
237 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
238 # OSX tests are run on Travis-CI, and gpg fails to launch gpg-agent there
239 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
240 $fdroid gpgsign --verbose
241 $fdroid gpgsign --verbose
242 test -e repo/obb.mainpatch.current_1619.apk.asc
243 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
244 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
245 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
246 ! test -e repo/index.xml.asc
249 # we can't easily reproduce the timestamps for things, so just hardcode them
250 $sed -i.tmp -e 's,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
251 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
254 #------------------------------------------------------------------------------#
255 echo_header 'test moving lots of APKs to the archive'
257 REPOROOT=`create_test_dir`
259 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
260 $fdroid init --keystore keystore.jks --repo-keyalias=sova
261 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
262 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
263 echo "accepted_formats = ['txt']" >> config.py
264 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
265 test -d metadata || mkdir metadata
266 cp $WORKSPACE/tests/metadata/*.txt metadata/
267 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
268 echo 'Summary:good MD5 sig, which is disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
269 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
270 test -d repo || mkdir repo
271 cp $WORKSPACE/tests/urzip.apk \
272 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
273 $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
274 $WORKSPACE/tests/repo/obb.main.twoversions_110161[357].apk \
276 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
278 $fdroid update --pretty --nosign
279 echo "This will fail when jarsigner allows MD5 for APK signatures"
280 test `grep '<package>' archive/index.xml | wc -l` -eq 5
281 test `grep '<package>' repo/index.xml | wc -l` -eq 7
284 #------------------------------------------------------------------------------#
285 echo_header 'test per-app "Archive Policy"'
287 REPOROOT=`create_test_dir`
289 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
290 $fdroid init --keystore keystore.jks --repo-keyalias=sova
291 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
292 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
293 echo "accepted_formats = ['txt']" >> config.py
294 test -d metadata || mkdir metadata
295 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
296 test -d repo || mkdir repo
297 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
298 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
300 $fdroid update --pretty --nosign
301 test `grep '<package>' archive/index.xml | wc -l` -eq 0
302 test `grep '<package>' repo/index.xml | wc -l` -eq 4
303 grep -F com.politedroid_3.apk repo/index.xml
304 grep -F com.politedroid_4.apk repo/index.xml
305 grep -F com.politedroid_5.apk repo/index.xml
306 grep -F com.politedroid_6.apk repo/index.xml
307 test -e repo/com.politedroid_3.apk
308 test -e repo/com.politedroid_4.apk
309 test -e repo/com.politedroid_5.apk
310 test -e repo/com.politedroid_6.apk
312 echo "enable one app in the repo"
313 $sed -i.tmp 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
314 $fdroid update --pretty --nosign
315 test `grep '<package>' archive/index.xml | wc -l` -eq 3
316 test `grep '<package>' repo/index.xml | wc -l` -eq 1
317 grep -F com.politedroid_3.apk archive/index.xml
318 grep -F com.politedroid_4.apk archive/index.xml
319 grep -F com.politedroid_5.apk archive/index.xml
320 grep -F com.politedroid_6.apk repo/index.xml
321 test -e archive/com.politedroid_3.apk
322 test -e archive/com.politedroid_4.apk
323 test -e archive/com.politedroid_5.apk
324 test -e repo/com.politedroid_6.apk
326 echo "remove all apps from the repo"
327 $sed -i.tmp 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
328 $fdroid update --pretty --nosign
329 test `grep '<package>' archive/index.xml | wc -l` -eq 4
330 test `grep '<package>' repo/index.xml | wc -l` -eq 0
331 grep -F com.politedroid_3.apk archive/index.xml
332 grep -F com.politedroid_4.apk archive/index.xml
333 grep -F com.politedroid_5.apk archive/index.xml
334 grep -F com.politedroid_6.apk archive/index.xml
335 test -e archive/com.politedroid_3.apk
336 test -e archive/com.politedroid_4.apk
337 test -e archive/com.politedroid_5.apk
338 test -e archive/com.politedroid_6.apk
339 ! test -e repo/com.politedroid_6.apk
341 echo "move back one from archive to the repo"
342 $sed -i.tmp 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
343 $fdroid update --pretty --nosign
344 test `grep '<package>' archive/index.xml | wc -l` -eq 3
345 test `grep '<package>' repo/index.xml | wc -l` -eq 1
346 grep -F com.politedroid_3.apk archive/index.xml
347 grep -F com.politedroid_4.apk archive/index.xml
348 grep -F com.politedroid_5.apk archive/index.xml
349 grep -F com.politedroid_6.apk repo/index.xml
350 test -e archive/com.politedroid_3.apk
351 test -e archive/com.politedroid_4.apk
352 test -e archive/com.politedroid_5.apk
353 ! test -e archive/com.politedroid_6.apk
354 test -e repo/com.politedroid_6.apk
358 #------------------------------------------------------------------------------#
359 echo_header 'test moving old APKs to and from the archive'
361 REPOROOT=`create_test_dir`
363 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
364 $fdroid init --keystore keystore.jks --repo-keyalias=sova
365 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
366 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
367 echo "accepted_formats = ['txt']" >> config.py
368 test -d metadata || mkdir metadata
369 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
370 $sed -i.tmp '/Archive Policy:/d' metadata/com.politedroid.txt
371 test -d repo || mkdir repo
372 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
373 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
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 3
378 grep -F com.politedroid_3.apk archive/index.xml
379 grep -F com.politedroid_4.apk repo/index.xml
380 grep -F com.politedroid_5.apk repo/index.xml
381 grep -F com.politedroid_6.apk repo/index.xml
382 test -e archive/com.politedroid_3.apk
383 test -e repo/com.politedroid_4.apk
384 test -e repo/com.politedroid_5.apk
385 test -e repo/com.politedroid_6.apk
387 $sed -i.tmp 's,archive_older = 3,archive_older = 1,' config.py
388 $fdroid update --pretty --nosign
389 test `grep '<package>' archive/index.xml | wc -l` -eq 3
390 test `grep '<package>' repo/index.xml | wc -l` -eq 1
391 grep -F com.politedroid_3.apk archive/index.xml
392 grep -F com.politedroid_4.apk archive/index.xml
393 grep -F com.politedroid_5.apk archive/index.xml
394 grep -F com.politedroid_6.apk repo/index.xml
395 test -e archive/com.politedroid_3.apk
396 test -e archive/com.politedroid_4.apk
397 test -e archive/com.politedroid_5.apk
398 test -e repo/com.politedroid_6.apk
400 # disabling deletes from the archive
401 $sed -i.tmp 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
402 $fdroid update --pretty --nosign
403 test `grep '<package>' archive/index.xml | wc -l` -eq 2
404 test `grep '<package>' repo/index.xml | wc -l` -eq 1
405 grep -F com.politedroid_3.apk archive/index.xml
406 ! grep -F com.politedroid_4.apk archive/index.xml
407 grep -F com.politedroid_5.apk archive/index.xml
408 grep -F com.politedroid_6.apk repo/index.xml
409 test -e archive/com.politedroid_3.apk
410 ! test -e archive/com.politedroid_4.apk
411 test -e archive/com.politedroid_5.apk
412 test -e repo/com.politedroid_6.apk
414 # disabling deletes from the repo, and promotes one from the archive
415 $sed -i.tmp 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
416 $fdroid update --pretty --nosign
417 test `grep '<package>' archive/index.xml | wc -l` -eq 1
418 test `grep '<package>' repo/index.xml | wc -l` -eq 1
419 grep -F com.politedroid_3.apk archive/index.xml
420 grep -F com.politedroid_5.apk repo/index.xml
421 ! grep -F com.politedroid_6.apk repo/index.xml
422 test -e archive/com.politedroid_3.apk
423 test -e repo/com.politedroid_5.apk
424 ! test -e repo/com.politedroid_6.apk
427 #------------------------------------------------------------------------------#
428 echo_header 'test allowing disabled signatures in repo and archive'
430 REPOROOT=`create_test_dir`
432 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
433 $fdroid init --keystore keystore.jks --repo-keyalias=sova
434 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
435 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
436 echo "accepted_formats = ['txt']" >> config.py
437 echo 'allow_disabled_algorithms = True' >> config.py
438 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
439 test -d metadata || mkdir metadata
440 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
441 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
442 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
443 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
444 test -d repo || mkdir repo
445 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
446 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
447 $WORKSPACE/tests/urzip-badsig.apk \
450 $fdroid update --pretty --nosign
451 test `grep '<package>' archive/index.xml | wc -l` -eq 2
452 test `grep '<package>' repo/index.xml | wc -l` -eq 6
453 grep -F com.politedroid_3.apk archive/index.xml
454 grep -F com.politedroid_4.apk repo/index.xml
455 grep -F com.politedroid_5.apk repo/index.xml
456 grep -F com.politedroid_6.apk repo/index.xml
457 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
458 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
459 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
460 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
461 ! grep -F urzip-badsig.apk repo/index.xml
462 ! grep -F urzip-badsig.apk archive/index.xml
463 test -e archive/com.politedroid_3.apk
464 test -e repo/com.politedroid_4.apk
465 test -e repo/com.politedroid_5.apk
466 test -e repo/com.politedroid_6.apk
467 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
468 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
469 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
470 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
471 test -e archive/urzip-badsig.apk
473 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
474 $fdroid update --pretty --nosign
475 test `grep '<package>' archive/index.xml | wc -l` -eq 5
476 test `grep '<package>' repo/index.xml | wc -l` -eq 3
477 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
478 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
479 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
480 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
481 grep -F com.politedroid_3.apk archive/index.xml
482 grep -F com.politedroid_4.apk repo/index.xml
483 grep -F com.politedroid_5.apk repo/index.xml
484 grep -F com.politedroid_6.apk repo/index.xml
485 ! grep -F urzip-badsig.apk repo/index.xml
486 ! grep -F urzip-badsig.apk archive/index.xml
487 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
488 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
489 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
490 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
491 test -e archive/com.politedroid_3.apk
492 test -e archive/urzip-badsig.apk
493 test -e repo/com.politedroid_4.apk
494 test -e repo/com.politedroid_5.apk
495 test -e repo/com.politedroid_6.apk
498 #------------------------------------------------------------------------------#
499 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
501 REPOROOT=`create_test_dir`
503 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
504 $fdroid init --keystore keystore.jks --repo-keyalias=sova
505 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
506 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
507 echo "accepted_formats = ['txt', 'yml']" >> config.py
508 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
509 test -d metadata || mkdir metadata
510 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
511 test -d repo || mkdir repo
512 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
513 $fdroid update --rename-apks --pretty --nosign
514 test -e repo/info.guardianproject.urzip_100.apk
515 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
516 cp $WORKSPACE/tests/urzip-release.apk repo/
517 $fdroid update --rename-apks --pretty --nosign
518 test -e repo/info.guardianproject.urzip_100.apk
519 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
520 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
521 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
522 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
523 cp $WORKSPACE/tests/urzip-release.apk repo/
524 $fdroid update --rename-apks --pretty --nosign
525 test -e repo/info.guardianproject.urzip_100.apk
526 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
527 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
528 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
529 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
530 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
533 #------------------------------------------------------------------------------#
534 echo_header "test metadata checks"
536 REPOROOT=`create_test_dir`
540 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
544 if [ $? -eq 0 ]; then
545 echo "This should have failed because there is no metadata!"
548 echo "testing metadata checks passed"
552 mkdir $REPOROOT/metadata/
553 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
556 # now make a fake duplicate
557 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
561 if [ $? -eq 0 ]; then
562 echo "This should have failed because there is a duplicate metadata file!"
565 echo "testing duplicate metadata checks passed"
570 #------------------------------------------------------------------------------#
571 echo_header "ensure commands that don't need the JDK work without a JDK configed"
573 REPOROOT=`create_test_dir`
577 echo "License:GPL-2.0" >> metadata/fake.txt
578 echo "Summary:Yup still fake" >> metadata/fake.txt
579 echo "Categories:Internet" >> metadata/fake.txt
580 echo "Description:" >> metadata/fake.txt
581 echo "this is fake" >> metadata/fake.txt
582 echo "." >> metadata/fake.txt
584 # fake that no JDKs are available
585 echo 'java_paths = {}' > config.py
587 LOCAL_COPY_DIR=`create_test_dir`/fdroid
588 mkdir -p $LOCAL_COPY_DIR/repo
589 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
595 $fdroid rewritemeta fake
596 $fdroid server update
599 # run these to get their output, but the are not setup, so don't fail
600 $fdroid build || true
601 $fdroid import || true
602 $fdroid install || true
605 #------------------------------------------------------------------------------#
606 echo_header "create a source tarball and use that to build a repo"
609 $python setup.py sdist
611 REPOROOT=`create_test_dir`
613 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
615 ./fdroidserver-*/fdroid init
616 copy_apks_into_repo $REPOROOT
617 ./fdroidserver-*/fdroid update --create-metadata --verbose
620 #------------------------------------------------------------------------------#
621 echo_header "test config checks of local_copy_dir"
623 REPOROOT=`create_test_dir`
626 $fdroid update --create-metadata --verbose
628 $fdroid server update --local-copy-dir=/tmp/fdroid
630 # now test the errors work
632 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
633 if [ $? -eq 0 ]; then
634 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
637 echo "testing absolute path checker passed"
639 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
640 if [ $? -eq 0 ]; then
641 echo "This should have failed because the path does not end with 'fdroid'!"
644 echo "testing dirname exists checker passed"
646 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
647 if [ $? -eq 0 ]; then
648 echo "This should have failed because the dirname path does not exist!"
651 echo "testing dirname exists checker passed"
656 #------------------------------------------------------------------------------#
657 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
659 REPOROOT=`create_test_dir`
662 copy_apks_into_repo $REPOROOT
663 $fdroid update --create-metadata --verbose
665 grep -F '<application id=' repo/index.xml > /dev/null
667 LOCALCOPYDIR=`create_test_dir`/fdroid
668 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
669 NEWREPOROOT=`create_test_dir`
672 echo "sync_from_local_copy_dir = True" >> config.py
673 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
676 #------------------------------------------------------------------------------#
677 # check that --android-home fails when dir does not exist or is not a dir
679 REPOROOT=`create_test_dir`
680 KEYSTORE=$REPOROOT/keystore.jks
683 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
684 if [ $? -eq 0 ]; then
685 echo "This should have failed because /opt/fakeandroidhome does not exist!"
688 echo "testing android-home path checker passed"
690 TESTFILE=`create_test_file`
691 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
692 if [ $? -eq 0 ]; then
693 echo "This should have failed because $TESTFILE is a file not a dir!"
696 echo "testing android-home not-dir checker passed"
701 #------------------------------------------------------------------------------#
702 echo_header "check that fake android home passes 'fdroid init'"
704 REPOROOT=`create_test_dir`
705 FAKE_ANDROID_HOME=`create_test_dir`
706 create_fake_android_home $FAKE_ANDROID_HOME
707 KEYSTORE=$REPOROOT/keystore.jks
709 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
712 #------------------------------------------------------------------------------#
713 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
715 if [ -e /usr/bin/aapt ]; then
716 echo "/usr/bin/aapt exists, not running test"
718 REPOROOT=`create_test_dir`
719 FAKE_ANDROID_HOME=`create_test_dir`
720 create_fake_android_home $FAKE_ANDROID_HOME
721 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
722 KEYSTORE=$REPOROOT/keystore.jks
725 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
726 [ $? -eq 0 ] && exit 1
731 #------------------------------------------------------------------------------#
732 echo_header "check that --android-home overrides ANDROID_HOME"
734 REPOROOT=`create_test_dir`
735 FAKE_ANDROID_HOME=`create_test_dir`
736 create_fake_android_home $FAKE_ANDROID_HOME
737 KEYSTORE=$REPOROOT/keystore.jks
739 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
741 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
742 if [ $? -ne 0 ]; then
743 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
749 #------------------------------------------------------------------------------#
750 # In this case, ANDROID_HOME is set to a fake, non-working version that will
751 # be detected by fdroid as an Android SDK install. It should use the path set
752 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
753 # in ANDROID_HOME, it won't work because it is a fake one. Only
754 # --android-home provides a working one.
755 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
757 REPOROOT=`create_test_dir`
758 KEYSTORE=$REPOROOT/keystore.jks
759 FAKE_ANDROID_HOME=`create_test_dir`
760 create_fake_android_home $FAKE_ANDROID_HOME
761 STORED_ANDROID_HOME=$ANDROID_HOME
763 echo "ANDROID_HOME: $ANDROID_HOME"
765 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
767 copy_apks_into_repo $REPOROOT
768 $fdroid update --create-metadata --verbose
770 grep -F '<application id=' repo/index.xml > /dev/null
771 test -e repo/index.xml
772 test -e repo/index.jar
773 test -e repo/index-v1.jar
775 ! test -z tmp/apkcache
776 export ANDROID_HOME=$STORED_ANDROID_HOME
779 #------------------------------------------------------------------------------#
780 echo_header "check duplicate files are properly handled by fdroid update"
782 REPOROOT=`create_test_dir`
783 KEYSTORE=$WORKSPACE/tests/keystore.jks
785 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
786 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
787 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
788 mkdir $REPOROOT/metadata
789 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
790 echo "accepted_formats = ['txt']" >> config.py
791 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
792 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
793 $fdroid update --pretty
794 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
795 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
796 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
797 # die if there are exact duplicates
798 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
802 #------------------------------------------------------------------------------#
803 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
805 REPOROOT=`create_test_dir`
808 copy_apks_into_repo $REPOROOT
810 $fdroid update --create-metadata --verbose
812 grep -F '<application id=' repo/index.xml > /dev/null
815 #------------------------------------------------------------------------------#
816 echo_header "setup a new repo from scratch and generate a keystore"
818 REPOROOT=`create_test_dir`
819 KEYSTORE=$REPOROOT/keystore.jks
821 $fdroid init --keystore $KEYSTORE
823 copy_apks_into_repo $REPOROOT
824 $fdroid update --create-metadata --verbose
826 test -e repo/index.xml
827 test -e repo/index.jar
828 test -e repo/index-v1.jar
830 ! test -z tmp/apkcache
831 grep -F '<application id=' repo/index.xml > /dev/null
834 #------------------------------------------------------------------------------#
835 echo_header "setup a new repo manually and generate a keystore"
837 REPOROOT=`create_test_dir`
838 KEYSTORE=$REPOROOT/keystore.jks
840 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
844 if [ $? -eq 0 ]; then
845 echo "This should have failed because this repo has no keystore!"
848 echo '`fdroid update` prompted to add keystore'
851 $fdroid update --create-key
853 copy_apks_into_repo $REPOROOT
854 $fdroid update --create-metadata --verbose
856 test -e repo/index.xml
857 test -e repo/index.jar
858 test -e repo/index-v1.jar
860 ! test -z tmp/apkcache
861 grep -F '<application id=' repo/index.xml > /dev/null
864 #------------------------------------------------------------------------------#
865 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
867 REPOROOT=`create_test_dir`
868 KEYSTORE=$REPOROOT/keystore.jks
870 $fdroid init --keystore $KEYSTORE
872 copy_apks_into_repo $REPOROOT
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
878 grep -F '<application id=' repo/index.xml > /dev/null
879 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
880 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
881 $fdroid update --create-metadata --verbose
883 test -e repo/index.xml
884 test -e repo/index.jar
885 test -e repo/index-v1.jar
887 ! test -z tmp/apkcache
888 grep -F '<application id=' repo/index.xml > /dev/null
891 #------------------------------------------------------------------------------#
892 echo_header "setup a new repo from scratch with a HSM/smartcard"
893 REPOROOT=`create_test_dir`
895 $fdroid init --keystore NONE
896 test -e opensc-fdroid.cfg
900 #------------------------------------------------------------------------------#
901 echo_header "setup a new repo with no keystore, add APK, and update"
903 REPOROOT=`create_test_dir`
904 KEYSTORE=$REPOROOT/keystore.jks
906 touch fdroid-icon.png
908 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
910 $fdroid update --create-metadata --verbose
911 if [ $? -eq 0 ]; then
912 echo "This should have failed because this repo has no keystore!"
915 echo '`fdroid update` prompted to add keystore'
919 # now set up fake, non-working keystore setup
921 echo "keystore = \"$KEYSTORE\"" >> config.py
922 echo 'repo_keyalias = "foo"' >> config.py
923 echo 'keystorepass = "foo"' >> config.py
924 echo 'keypass = "foo"' >> config.py
926 $fdroid update --create-metadata --verbose
927 if [ $? -eq 0 ]; then
928 echo "This should have failed because this repo has a bad/fake keystore!"
931 echo '`fdroid update` prompted to add keystore'
936 #------------------------------------------------------------------------------#
937 echo_header "copy tests/repo, update with binary transparency log"
939 REPOROOT=`create_test_dir`
940 GIT_REMOTE=`create_test_dir`
941 GNUPGHOME=$REPOROOT/gnupghome
942 KEYSTORE=$WORKSPACE/tests/keystore.jks
944 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
945 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
946 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
947 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
948 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
949 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
950 $fdroid update --verbose
951 if have_git_2_3; then
952 $fdroid server update --verbose
953 test -e repo/index.xml
954 test -e repo/index.jar
955 test -e repo/index-v1.jar
956 grep -F '<application id=' repo/index.xml > /dev/null
957 cd binary_transparency
958 [ `git rev-list --count HEAD` == "2" ]
960 [ `git rev-list --count HEAD` == "2" ]
962 echo "Skipping test, `git --version` older than 2.3"
966 #------------------------------------------------------------------------------#
967 echo_header "setup a new repo with keystore with APK, update, then without key"
969 REPOROOT=`create_test_dir`
970 KEYSTORE=$REPOROOT/keystore.jks
972 $fdroid init --keystore $KEYSTORE
974 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
975 $fdroid update --create-metadata --verbose
977 test -e repo/index.xml
978 test -e repo/index.jar
979 test -e repo/index-v1.jar
981 ! test -z tmp/apkcache
982 grep -F '<application id=' repo/index.xml > /dev/null
984 # now set fake repo_keyalias
985 $sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
988 if [ $? -eq 0 ]; then
989 echo "This should have failed because this repo has a bad repo_keyalias!"
992 echo '`fdroid update` prompted to add keystore'
996 # try creating a new keystore, but fail because the old one is there
999 $fdroid update --create-key
1000 if [ $? -eq 0 ]; then
1001 echo "This should have failed because a keystore is already there!"
1004 echo '`fdroid update` complained about existing keystore'
1008 # now actually create the key with the existing settings
1011 $fdroid update --create-key
1015 #------------------------------------------------------------------------------#
1016 echo_header "sign binary repo in offline box, then publishing from online box"
1018 OFFLINE_ROOT=`create_test_dir`
1019 KEYSTORE=$WORKSPACE/tests/keystore.jks
1020 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1021 mkdir $LOCAL_COPY_DIR
1022 ONLINE_ROOT=`create_test_dir`
1023 SERVERWEBROOT=`create_test_dir`
1025 # create offline binary transparency log
1027 mkdir binary_transparency
1028 cd binary_transparency
1031 # fake git remote server for binary transparency log
1032 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1034 # fake git remote server for repo mirror
1035 SERVER_GIT_MIRROR=`create_test_dir`
1036 cd $SERVER_GIT_MIRROR
1038 if have_git_2_3; then
1039 git config receive.denyCurrentBranch updateInstead
1043 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
1044 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1046 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1047 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1048 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
1049 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1050 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1051 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1052 $fdroid update --pretty
1053 grep -F '<application id=' repo/index.xml > /dev/null
1054 grep -F '/fdroid/repo</mirror>' repo/index.xml
1055 grep -F '/fdroid/archive</mirror>' archive/index.xml
1056 test `grep '<mirror>' repo/index.xml | wc -l` -eq 2
1057 test `grep '<mirror>' archive/index.xml | wc -l` -eq 2
1058 cd binary_transparency
1059 [ `git rev-list --count HEAD` == "1" ]
1061 $fdroid server update --verbose
1062 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1064 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1065 echo "sync_from_local_copy_dir = True" >> config.py
1066 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1067 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1068 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1069 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1070 $fdroid server update --verbose
1071 cd $BINARY_TRANSPARENCY_REMOTE
1072 [ `git rev-list --count HEAD` == "1" ]
1073 cd $SERVER_GIT_MIRROR
1074 [ `git rev-list --count HEAD` == "1" ]
1077 #------------------------------------------------------------------------------#
1079 # remove this to prevent git conflicts and complaining
1080 rm -rf $WORKSPACE/fdroidserver.egg-info/