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 # 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`
50 javac $WORKSPACE/tests/IsMD5Disabled.java && java -cp $WORKSPACE/tests IsMD5Disabled
54 #------------------------------------------------------------------------------#
57 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
59 echo "Usage: $0 '/path/to/folder/with/apks'"
63 if [ -z "$ANDROID_HOME" ]; then
64 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
65 echo " export ANDROID_HOME=/opt/android-sdk"
79 if [ -z $WORKSPACE ]; then
80 WORKSPACE=`dirname $(pwd)`
81 echo "Setting Workspace to $WORKSPACE"
84 # allow the location of the script to be overridden
85 if [ -z $fdroid ]; then
86 fdroid="$WORKSPACE/fdroid"
89 # allow the location of aapt to be overridden
91 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
94 # allow the location of python to be overridden
95 if [ -z $python ]; then
99 # try to use GNU sed on OSX/BSD cuz BSD sed sucks
106 set -x # show each command as it is executed
108 #------------------------------------------------------------------------------#
109 echo_header "run commit hooks"
115 #------------------------------------------------------------------------------#
116 echo_header "test python getsig replacement"
118 cd $WORKSPACE/tests/getsig
122 for testcase in $WORKSPACE/tests/*.TestCase; do
127 #------------------------------------------------------------------------------#
128 echo_header "print fdroid version"
133 #------------------------------------------------------------------------------#
134 echo_header 'run process when building and signing are on separate machines'
136 REPOROOT=`create_test_dir`
138 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
139 $fdroid init --keystore keystore.jks --repo-keyalias=sova
140 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
141 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
142 echo "accepted_formats = ['txt', 'yml']" >> config.py
143 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
144 test -d archive || mkdir archive
145 test -d metadata || mkdir metadata
146 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
147 test -d repo || mkdir repo
148 test -d unsigned || mkdir unsigned
149 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
150 $fdroid publish --verbose
151 $fdroid update --verbose --nosign
152 $fdroid signindex --verbose
153 test -e repo/index.xml
154 test -e repo/index.jar
155 test -e repo/index-v1.jar
157 ! test -z tmp/apkcache
159 grep -F '<application id=' repo/index.xml > /dev/null
162 #------------------------------------------------------------------------------#
163 echo_header "test UTF-8 metadata"
165 REPOROOT=`create_test_dir`
169 $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
170 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
172 cp $WORKSPACE/tests/urzip.apk $WORKSPACE/tests/bad-unicode*.apk repo/
173 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
179 #------------------------------------------------------------------------------#
180 echo_header 'run "fdroid build" in fresh git checkout from import.TestCase'
182 cd $WORKSPACE/tests/tmp/importer
185 # stick with known working commit, in case future commits break things for this code
186 git reset --hard fea54e1161d5eb9eb1a54e26253ef84d3ab63705
187 if [ -d $ANDROID_HOME/platforms/android-23 && -d $ANDROID_HOME/build-tools/23.0.3 ]; then
188 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
189 echo "force_build_tools = True" >> config.py
190 $fdroid build --verbose org.fdroid.ci.test.app:300
192 echo 'WARNING: Skipping "fdroid build" test since android-23 is missing!'
195 #------------------------------------------------------------------------------#
196 echo_header 'copy git import and run "fdroid scanner" on it'
198 REPOROOT=`create_test_dir`
200 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
202 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
203 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
204 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
205 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
206 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
207 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
208 echo "" >> metadata/org.fdroid.ci.test.app.txt
209 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
210 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
212 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
213 ls -l build/org.fdroid.ci.test.app
214 $fdroid scanner org.fdroid.ci.test.app --verbose
217 #------------------------------------------------------------------------------#
218 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
220 REPOROOT=`create_test_dir`
221 GNUPGHOME=$REPOROOT/gnupghome
222 KEYSTORE=$WORKSPACE/tests/keystore.jks
224 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
225 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
226 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
227 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
228 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
229 chmod 0700 $GNUPGHOME
230 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
231 echo "install_list = 'org.adaway'" >> config.py
232 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
233 echo "gpghome = '$GNUPGHOME'" >> config.py
234 echo "gpgkey = 'CE71F7FB'" >> config.py
235 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
236 $fdroid update --verbose --pretty
237 test -e repo/index.xml
238 test -e repo/index.jar
239 test -e repo/index-v1.jar
240 grep -F '<application id=' repo/index.xml > /dev/null
241 grep -F '<install packageName=' repo/index.xml > /dev/null
242 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
243 # OSX tests are run on Travis-CI, and gpg fails to launch gpg-agent there
244 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
245 $fdroid gpgsign --verbose
246 $fdroid gpgsign --verbose
247 test -e repo/obb.mainpatch.current_1619.apk.asc
248 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
249 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
250 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
251 ! test -e repo/index.xml.asc
254 # we can't easily reproduce the timestamps for things, so just hardcode them
255 $sed -i.tmp -e 's,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
256 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
257 sed -i --expression='s,"timestamp": [0-9]*,"timestamp": 1502845383782,' repo/index-v1.json
258 diff -uw $WORKSPACE/tests/repo/index-v1.json repo/index-v1.json
261 #------------------------------------------------------------------------------#
262 echo_header 'test moving lots of APKs to the archive'
264 REPOROOT=`create_test_dir`
266 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
267 $fdroid init --keystore keystore.jks --repo-keyalias=sova
268 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
269 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
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 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
297 $fdroid init --keystore keystore.jks --repo-keyalias=sova
298 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
299 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
300 echo "accepted_formats = ['txt']" >> config.py
301 test -d metadata || mkdir metadata
302 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
303 test -d repo || mkdir repo
304 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
305 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
307 $fdroid update --pretty --nosign
308 test `grep '<package>' archive/index.xml | wc -l` -eq 0
309 test `grep '<package>' repo/index.xml | wc -l` -eq 4
310 grep -F com.politedroid_3.apk repo/index.xml
311 grep -F com.politedroid_4.apk repo/index.xml
312 grep -F com.politedroid_5.apk repo/index.xml
313 grep -F com.politedroid_6.apk repo/index.xml
314 test -e repo/com.politedroid_3.apk
315 test -e repo/com.politedroid_4.apk
316 test -e repo/com.politedroid_5.apk
317 test -e repo/com.politedroid_6.apk
319 echo "enable one app in the repo"
320 $sed -i.tmp 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
321 $fdroid update --pretty --nosign
322 test `grep '<package>' archive/index.xml | wc -l` -eq 3
323 test `grep '<package>' repo/index.xml | wc -l` -eq 1
324 grep -F com.politedroid_3.apk archive/index.xml
325 grep -F com.politedroid_4.apk archive/index.xml
326 grep -F com.politedroid_5.apk archive/index.xml
327 grep -F com.politedroid_6.apk repo/index.xml
328 test -e archive/com.politedroid_3.apk
329 test -e archive/com.politedroid_4.apk
330 test -e archive/com.politedroid_5.apk
331 test -e repo/com.politedroid_6.apk
333 echo "remove all apps from the repo"
334 $sed -i.tmp 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
335 $fdroid update --pretty --nosign
336 test `grep '<package>' archive/index.xml | wc -l` -eq 4
337 test `grep '<package>' repo/index.xml | wc -l` -eq 0
338 grep -F com.politedroid_3.apk archive/index.xml
339 grep -F com.politedroid_4.apk archive/index.xml
340 grep -F com.politedroid_5.apk archive/index.xml
341 grep -F com.politedroid_6.apk archive/index.xml
342 test -e archive/com.politedroid_3.apk
343 test -e archive/com.politedroid_4.apk
344 test -e archive/com.politedroid_5.apk
345 test -e archive/com.politedroid_6.apk
346 ! test -e repo/com.politedroid_6.apk
348 echo "move back one from archive to the repo"
349 $sed -i.tmp 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
350 $fdroid update --pretty --nosign
351 test `grep '<package>' archive/index.xml | wc -l` -eq 3
352 test `grep '<package>' repo/index.xml | wc -l` -eq 1
353 grep -F com.politedroid_3.apk archive/index.xml
354 grep -F com.politedroid_4.apk archive/index.xml
355 grep -F com.politedroid_5.apk archive/index.xml
356 grep -F com.politedroid_6.apk repo/index.xml
357 test -e archive/com.politedroid_3.apk
358 test -e archive/com.politedroid_4.apk
359 test -e archive/com.politedroid_5.apk
360 ! test -e archive/com.politedroid_6.apk
361 test -e repo/com.politedroid_6.apk
365 #------------------------------------------------------------------------------#
366 echo_header 'test moving old APKs to and from the archive'
368 REPOROOT=`create_test_dir`
370 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
371 $fdroid init --keystore keystore.jks --repo-keyalias=sova
372 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
373 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
374 echo "accepted_formats = ['txt']" >> config.py
375 test -d metadata || mkdir metadata
376 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
377 $sed -i.tmp '/Archive Policy:/d' metadata/com.politedroid.txt
378 test -d repo || mkdir repo
379 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
380 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
382 $fdroid update --pretty --nosign
383 test `grep '<package>' archive/index.xml | wc -l` -eq 1
384 test `grep '<package>' repo/index.xml | wc -l` -eq 3
385 grep -F com.politedroid_3.apk archive/index.xml
386 grep -F com.politedroid_4.apk repo/index.xml
387 grep -F com.politedroid_5.apk repo/index.xml
388 grep -F com.politedroid_6.apk repo/index.xml
389 test -e archive/com.politedroid_3.apk
390 test -e repo/com.politedroid_4.apk
391 test -e repo/com.politedroid_5.apk
392 test -e repo/com.politedroid_6.apk
394 $sed -i.tmp 's,archive_older = 3,archive_older = 1,' config.py
395 $fdroid update --pretty --nosign
396 test `grep '<package>' archive/index.xml | wc -l` -eq 3
397 test `grep '<package>' repo/index.xml | wc -l` -eq 1
398 grep -F com.politedroid_3.apk archive/index.xml
399 grep -F com.politedroid_4.apk archive/index.xml
400 grep -F com.politedroid_5.apk archive/index.xml
401 grep -F com.politedroid_6.apk repo/index.xml
402 test -e archive/com.politedroid_3.apk
403 test -e archive/com.politedroid_4.apk
404 test -e archive/com.politedroid_5.apk
405 test -e repo/com.politedroid_6.apk
407 # disabling deletes from the archive
408 $sed -i.tmp 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
409 $fdroid update --pretty --nosign
410 test `grep '<package>' archive/index.xml | wc -l` -eq 2
411 test `grep '<package>' repo/index.xml | wc -l` -eq 1
412 grep -F com.politedroid_3.apk archive/index.xml
413 ! grep -F com.politedroid_4.apk archive/index.xml
414 grep -F com.politedroid_5.apk archive/index.xml
415 grep -F com.politedroid_6.apk repo/index.xml
416 test -e archive/com.politedroid_3.apk
417 ! test -e archive/com.politedroid_4.apk
418 test -e archive/com.politedroid_5.apk
419 test -e repo/com.politedroid_6.apk
421 # disabling deletes from the repo, and promotes one from the archive
422 $sed -i.tmp 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
423 $fdroid update --pretty --nosign
424 test `grep '<package>' archive/index.xml | wc -l` -eq 1
425 test `grep '<package>' repo/index.xml | wc -l` -eq 1
426 grep -F com.politedroid_3.apk archive/index.xml
427 grep -F com.politedroid_5.apk repo/index.xml
428 ! grep -F com.politedroid_6.apk repo/index.xml
429 test -e archive/com.politedroid_3.apk
430 test -e repo/com.politedroid_5.apk
431 ! test -e repo/com.politedroid_6.apk
434 #------------------------------------------------------------------------------#
435 echo_header 'test allowing disabled signatures in repo and archive'
437 REPOROOT=`create_test_dir`
439 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
440 $fdroid init --keystore keystore.jks --repo-keyalias=sova
441 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
442 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
443 echo "accepted_formats = ['txt']" >> config.py
444 echo 'allow_disabled_algorithms = True' >> config.py
445 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
446 test -d metadata || mkdir metadata
447 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
448 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
449 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
450 $sed -i.tmp '/Archive Policy:/d' metadata/*.txt
451 test -d repo || mkdir repo
452 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
453 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
454 $WORKSPACE/tests/urzip-badsig.apk \
457 $fdroid update --pretty --nosign
458 test `grep '<package>' archive/index.xml | wc -l` -eq 2
459 test `grep '<package>' repo/index.xml | wc -l` -eq 6
460 grep -F com.politedroid_3.apk archive/index.xml
461 grep -F com.politedroid_4.apk repo/index.xml
462 grep -F com.politedroid_5.apk repo/index.xml
463 grep -F com.politedroid_6.apk repo/index.xml
464 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
465 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
466 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
467 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
468 ! grep -F urzip-badsig.apk repo/index.xml
469 ! grep -F urzip-badsig.apk archive/index.xml
470 test -e archive/com.politedroid_3.apk
471 test -e repo/com.politedroid_4.apk
472 test -e repo/com.politedroid_5.apk
473 test -e repo/com.politedroid_6.apk
474 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
475 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
476 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
477 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
478 test -e archive/urzip-badsig.apk
480 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
481 $fdroid update --pretty --nosign
482 test `grep '<package>' archive/index.xml | wc -l` -eq 5
483 test `grep '<package>' repo/index.xml | wc -l` -eq 3
484 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
485 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
486 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
487 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
488 grep -F com.politedroid_3.apk archive/index.xml
489 grep -F com.politedroid_4.apk repo/index.xml
490 grep -F com.politedroid_5.apk repo/index.xml
491 grep -F com.politedroid_6.apk repo/index.xml
492 ! grep -F urzip-badsig.apk repo/index.xml
493 ! grep -F urzip-badsig.apk archive/index.xml
494 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
495 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
496 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
497 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
498 test -e archive/com.politedroid_3.apk
499 test -e archive/urzip-badsig.apk
500 test -e repo/com.politedroid_4.apk
501 test -e repo/com.politedroid_5.apk
502 test -e repo/com.politedroid_6.apk
505 #------------------------------------------------------------------------------#
506 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
508 REPOROOT=`create_test_dir`
510 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
511 $fdroid init --keystore keystore.jks --repo-keyalias=sova
512 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
513 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
514 echo "accepted_formats = ['txt', 'yml']" >> config.py
515 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
516 test -d metadata || mkdir metadata
517 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
518 test -d repo || mkdir repo
519 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
520 $fdroid update --rename-apks --pretty --nosign
521 test -e repo/info.guardianproject.urzip_100.apk
522 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json 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 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
530 cp $WORKSPACE/tests/urzip-release.apk repo/
531 $fdroid update --rename-apks --pretty --nosign
532 test -e repo/info.guardianproject.urzip_100.apk
533 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
534 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
535 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
536 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
537 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
540 #------------------------------------------------------------------------------#
541 echo_header "test metadata checks"
543 REPOROOT=`create_test_dir`
547 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
551 if [ $? -eq 0 ]; then
552 echo "This should have failed because there is no metadata!"
555 echo "testing metadata checks passed"
559 mkdir $REPOROOT/metadata/
560 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
563 # now make a fake duplicate
564 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
568 if [ $? -eq 0 ]; then
569 echo "This should have failed because there is a duplicate metadata file!"
572 echo "testing duplicate metadata checks passed"
577 #------------------------------------------------------------------------------#
578 echo_header "ensure commands that don't need the JDK work without a JDK configed"
580 REPOROOT=`create_test_dir`
584 echo "License:GPL-2.0" >> metadata/fake.txt
585 echo "Summary:Yup still fake" >> metadata/fake.txt
586 echo "Categories:Internet" >> metadata/fake.txt
587 echo "Description:" >> metadata/fake.txt
588 echo "this is fake" >> metadata/fake.txt
589 echo "." >> metadata/fake.txt
591 # fake that no JDKs are available
592 echo 'java_paths = {}' > config.py
594 LOCAL_COPY_DIR=`create_test_dir`/fdroid
595 mkdir -p $LOCAL_COPY_DIR/repo
596 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
602 $fdroid rewritemeta fake
603 $fdroid server update
606 # run these to get their output, but the are not setup, so don't fail
607 $fdroid build || true
608 $fdroid import || true
609 $fdroid install || true
612 #------------------------------------------------------------------------------#
613 echo_header "create a source tarball and use that to build a repo"
616 $python setup.py sdist
618 REPOROOT=`create_test_dir`
620 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
622 ./fdroidserver-*/fdroid init
623 copy_apks_into_repo $REPOROOT
624 ./fdroidserver-*/fdroid update --create-metadata --verbose
627 #------------------------------------------------------------------------------#
628 echo_header "test config checks of local_copy_dir"
630 REPOROOT=`create_test_dir`
633 $fdroid update --create-metadata --verbose
635 $fdroid server update --local-copy-dir=/tmp/fdroid
637 # now test the errors work
639 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
640 if [ $? -eq 0 ]; then
641 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
644 echo "testing absolute path checker passed"
646 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
647 if [ $? -eq 0 ]; then
648 echo "This should have failed because the path does not end with 'fdroid'!"
651 echo "testing dirname exists checker passed"
653 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
654 if [ $? -eq 0 ]; then
655 echo "This should have failed because the dirname path does not exist!"
658 echo "testing dirname exists checker passed"
663 #------------------------------------------------------------------------------#
664 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
666 REPOROOT=`create_test_dir`
669 copy_apks_into_repo $REPOROOT
670 $fdroid update --create-metadata --verbose
672 grep -F '<application id=' repo/index.xml > /dev/null
674 LOCALCOPYDIR=`create_test_dir`/fdroid
675 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
676 NEWREPOROOT=`create_test_dir`
679 echo "sync_from_local_copy_dir = True" >> config.py
680 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
683 #------------------------------------------------------------------------------#
684 # check that --android-home fails when dir does not exist or is not a dir
686 REPOROOT=`create_test_dir`
687 KEYSTORE=$REPOROOT/keystore.jks
690 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
691 if [ $? -eq 0 ]; then
692 echo "This should have failed because /opt/fakeandroidhome does not exist!"
695 echo "testing android-home path checker passed"
697 TESTFILE=`create_test_file`
698 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
699 if [ $? -eq 0 ]; then
700 echo "This should have failed because $TESTFILE is a file not a dir!"
703 echo "testing android-home not-dir checker passed"
708 #------------------------------------------------------------------------------#
709 echo_header "check that fake android home passes 'fdroid init'"
711 REPOROOT=`create_test_dir`
712 FAKE_ANDROID_HOME=`create_test_dir`
713 create_fake_android_home $FAKE_ANDROID_HOME
714 KEYSTORE=$REPOROOT/keystore.jks
716 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
719 #------------------------------------------------------------------------------#
720 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
722 if [ -e /usr/bin/aapt ]; then
723 echo "/usr/bin/aapt exists, not running test"
725 REPOROOT=`create_test_dir`
726 FAKE_ANDROID_HOME=`create_test_dir`
727 create_fake_android_home $FAKE_ANDROID_HOME
728 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
729 KEYSTORE=$REPOROOT/keystore.jks
732 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
733 [ $? -eq 0 ] && exit 1
738 #------------------------------------------------------------------------------#
739 echo_header "check that --android-home overrides ANDROID_HOME"
741 REPOROOT=`create_test_dir`
742 FAKE_ANDROID_HOME=`create_test_dir`
743 create_fake_android_home $FAKE_ANDROID_HOME
744 KEYSTORE=$REPOROOT/keystore.jks
746 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
748 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
749 if [ $? -ne 0 ]; then
750 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
756 #------------------------------------------------------------------------------#
757 # In this case, ANDROID_HOME is set to a fake, non-working version that will
758 # be detected by fdroid as an Android SDK install. It should use the path set
759 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
760 # in ANDROID_HOME, it won't work because it is a fake one. Only
761 # --android-home provides a working one.
762 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
764 REPOROOT=`create_test_dir`
765 KEYSTORE=$REPOROOT/keystore.jks
766 FAKE_ANDROID_HOME=`create_test_dir`
767 create_fake_android_home $FAKE_ANDROID_HOME
768 STORED_ANDROID_HOME=$ANDROID_HOME
770 echo "ANDROID_HOME: $ANDROID_HOME"
772 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
774 copy_apks_into_repo $REPOROOT
775 $fdroid update --create-metadata --verbose
777 grep -F '<application id=' repo/index.xml > /dev/null
778 test -e repo/index.xml
779 test -e repo/index.jar
780 test -e repo/index-v1.jar
782 ! test -z tmp/apkcache
783 export ANDROID_HOME=$STORED_ANDROID_HOME
786 #------------------------------------------------------------------------------#
787 echo_header "check duplicate files are properly handled by fdroid update"
789 REPOROOT=`create_test_dir`
790 KEYSTORE=$WORKSPACE/tests/keystore.jks
792 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
793 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
794 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
795 mkdir $REPOROOT/metadata
796 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
797 echo "accepted_formats = ['txt']" >> config.py
798 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
799 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
800 $fdroid update --pretty
801 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
802 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
803 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
804 # die if there are exact duplicates
805 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
809 #------------------------------------------------------------------------------#
810 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
812 REPOROOT=`create_test_dir`
815 copy_apks_into_repo $REPOROOT
817 $fdroid update --create-metadata --verbose
819 grep -F '<application id=' repo/index.xml > /dev/null
822 #------------------------------------------------------------------------------#
823 echo_header "setup a new repo from scratch and generate a keystore"
825 REPOROOT=`create_test_dir`
826 KEYSTORE=$REPOROOT/keystore.jks
828 $fdroid init --keystore $KEYSTORE
830 copy_apks_into_repo $REPOROOT
831 $fdroid update --create-metadata --verbose
833 test -e repo/index.xml
834 test -e repo/index.jar
835 test -e repo/index-v1.jar
837 ! test -z tmp/apkcache
838 grep -F '<application id=' repo/index.xml > /dev/null
841 #------------------------------------------------------------------------------#
842 echo_header "setup a new repo manually and generate a keystore"
844 REPOROOT=`create_test_dir`
845 KEYSTORE=$REPOROOT/keystore.jks
847 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
851 if [ $? -eq 0 ]; then
852 echo "This should have failed because this repo has no keystore!"
855 echo '`fdroid update` prompted to add keystore'
858 $fdroid update --create-key
860 copy_apks_into_repo $REPOROOT
861 $fdroid update --create-metadata --verbose
863 test -e repo/index.xml
864 test -e repo/index.jar
865 test -e repo/index-v1.jar
867 ! test -z tmp/apkcache
868 grep -F '<application id=' repo/index.xml > /dev/null
871 #------------------------------------------------------------------------------#
872 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
874 REPOROOT=`create_test_dir`
875 KEYSTORE=$REPOROOT/keystore.jks
877 $fdroid init --keystore $KEYSTORE
879 copy_apks_into_repo $REPOROOT
880 $fdroid update --create-metadata --verbose
882 test -e repo/index.xml
883 test -e repo/index.jar
884 test -e repo/index-v1.jar
885 grep -F '<application id=' repo/index.xml > /dev/null
886 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
887 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
888 $fdroid update --create-metadata --verbose
890 test -e repo/index.xml
891 test -e repo/index.jar
892 test -e repo/index-v1.jar
894 ! test -z tmp/apkcache
895 grep -F '<application id=' repo/index.xml > /dev/null
898 #------------------------------------------------------------------------------#
899 echo_header "setup a new repo from scratch with a HSM/smartcard"
900 REPOROOT=`create_test_dir`
902 $fdroid init --keystore NONE
903 test -e opensc-fdroid.cfg
907 #------------------------------------------------------------------------------#
908 echo_header "setup a new repo with no keystore, add APK, and update"
910 REPOROOT=`create_test_dir`
911 KEYSTORE=$REPOROOT/keystore.jks
913 touch fdroid-icon.png
915 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
917 $fdroid update --create-metadata --verbose
918 if [ $? -eq 0 ]; then
919 echo "This should have failed because this repo has no keystore!"
922 echo '`fdroid update` prompted to add keystore'
926 # now set up fake, non-working keystore setup
928 echo "keystore = \"$KEYSTORE\"" >> config.py
929 echo 'repo_keyalias = "foo"' >> config.py
930 echo 'keystorepass = "foo"' >> config.py
931 echo 'keypass = "foo"' >> config.py
933 $fdroid update --create-metadata --verbose
934 if [ $? -eq 0 ]; then
935 echo "This should have failed because this repo has a bad/fake keystore!"
938 echo '`fdroid update` prompted to add keystore'
943 #------------------------------------------------------------------------------#
944 echo_header "copy tests/repo, update with binary transparency log"
946 REPOROOT=`create_test_dir`
947 GIT_REMOTE=`create_test_dir`
948 GNUPGHOME=$REPOROOT/gnupghome
949 KEYSTORE=$WORKSPACE/tests/keystore.jks
951 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
952 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
953 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
954 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
955 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
956 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
957 $fdroid update --verbose
958 if have_git_2_3; then
959 $fdroid server update --verbose
960 test -e repo/index.xml
961 test -e repo/index.jar
962 test -e repo/index-v1.jar
963 grep -F '<application id=' repo/index.xml > /dev/null
964 cd binary_transparency
965 [ `git rev-list --count HEAD` == "2" ]
967 [ `git rev-list --count HEAD` == "2" ]
969 echo "Skipping test, `git --version` older than 2.3"
973 #------------------------------------------------------------------------------#
974 echo_header "setup a new repo with keystore with APK, update, then without key"
976 REPOROOT=`create_test_dir`
977 KEYSTORE=$REPOROOT/keystore.jks
979 $fdroid init --keystore $KEYSTORE
981 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
982 $fdroid update --create-metadata --verbose
984 test -e repo/index.xml
985 test -e repo/index.jar
986 test -e repo/index-v1.jar
988 ! test -z tmp/apkcache
989 grep -F '<application id=' repo/index.xml > /dev/null
991 # now set fake repo_keyalias
992 $sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
995 if [ $? -eq 0 ]; then
996 echo "This should have failed because this repo has a bad repo_keyalias!"
999 echo '`fdroid update` prompted to add keystore'
1003 # try creating a new keystore, but fail because the old one is there
1006 $fdroid update --create-key
1007 if [ $? -eq 0 ]; then
1008 echo "This should have failed because a keystore is already there!"
1011 echo '`fdroid update` complained about existing keystore'
1015 # now actually create the key with the existing settings
1018 $fdroid update --create-key
1022 #------------------------------------------------------------------------------#
1023 echo_header "sign binary repo in offline box, then publishing from online box"
1025 OFFLINE_ROOT=`create_test_dir`
1026 KEYSTORE=$WORKSPACE/tests/keystore.jks
1027 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1028 mkdir $LOCAL_COPY_DIR
1029 ONLINE_ROOT=`create_test_dir`
1030 SERVERWEBROOT=`create_test_dir`
1032 # create offline binary transparency log
1034 mkdir binary_transparency
1035 cd binary_transparency
1038 # fake git remote server for binary transparency log
1039 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1041 # fake git remote server for repo mirror
1042 SERVER_GIT_MIRROR=`create_test_dir`
1043 cd $SERVER_GIT_MIRROR
1045 if have_git_2_3; then
1046 git config receive.denyCurrentBranch updateInstead
1050 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
1051 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1053 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1054 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1055 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
1056 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1057 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1058 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1059 $fdroid update --pretty
1060 grep -F '<application id=' repo/index.xml > /dev/null
1061 grep -F '/fdroid/repo</mirror>' repo/index.xml
1062 grep -F '/fdroid/archive</mirror>' archive/index.xml
1063 test `grep '<mirror>' repo/index.xml | wc -l` -eq 2
1064 test `grep '<mirror>' archive/index.xml | wc -l` -eq 2
1065 cd binary_transparency
1066 [ `git rev-list --count HEAD` == "1" ]
1068 $fdroid server update --verbose
1069 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1071 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1072 echo "sync_from_local_copy_dir = True" >> config.py
1073 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1074 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1075 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1076 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1077 $fdroid server update --verbose
1078 cd $BINARY_TRANSPARENCY_REMOTE
1079 [ `git rev-list --count HEAD` == "1" ]
1080 cd $SERVER_GIT_MIRROR
1081 [ `git rev-list --count HEAD` == "1" ]
1084 #------------------------------------------------------------------------------#
1086 # remove this to prevent git conflicts and complaining
1087 rm -rf $WORKSPACE/fdroidserver.egg-info/