3 set -e # quit script on error
6 { echo -e "==============================================================================\n$1"; } 2>/dev/null
9 copy_apks_into_repo() {
11 for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned -e badsig -e badcert`; do
12 name=$(basename $(dirname `dirname $f`))
13 apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
14 test $f -nt repo/$apk && rm -f repo/$apk # delete existing if $f is newer
15 if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
16 echo "$f --> repo/$apk"
17 ln $f $1/repo/$apk || \
18 rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
24 # keep this as an old version to test the automatic parsing of build-tools
25 # verion numbers in `fdroid init`
26 create_fake_android_home() {
28 mkdir $1/platform-tools
30 mkdir $1/build-tools/19.0.2
31 touch $1/build-tools/19.0.2/aapt
35 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
36 mktemp -d $WORKSPACE/.testfiles/run-tests.XXXX
40 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
41 TMPDIR=$WORKSPACE/.testfiles mktemp
44 # the < is reverse since 0 means success in exit codes
46 python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version`
49 #------------------------------------------------------------------------------#
52 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
54 echo "Usage: $0 '/path/to/folder/with/apks'"
58 if [ -z "$ANDROID_HOME" ]; then
59 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
60 echo " export ANDROID_HOME=/opt/android-sdk"
74 if [ -z $WORKSPACE ]; then
75 WORKSPACE=`dirname $(pwd)`
76 echo "Setting Workspace to $WORKSPACE"
79 # allow the location of the script to be overridden
80 if [ -z $fdroid ]; then
81 fdroid="$WORKSPACE/fdroid"
84 # allow the location of aapt to be overridden
86 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
89 # allow the location of python to be overridden
90 if [ -z $python ]; then
94 set -x # show each command as it is executed
96 #------------------------------------------------------------------------------#
97 echo_header "run commit hooks"
103 #------------------------------------------------------------------------------#
104 echo_header "test python getsig replacement"
106 cd $WORKSPACE/tests/getsig
110 for testcase in $WORKSPACE/tests/*.TestCase; do
115 #------------------------------------------------------------------------------#
116 echo_header "print fdroid version"
121 #------------------------------------------------------------------------------#
122 echo_header 'run process when building and signing are on separate machines'
124 REPOROOT=`create_test_dir`
126 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
127 $fdroid init --keystore keystore.jks --repo-keyalias=sova
128 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
129 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
130 echo "accepted_formats = ['txt', 'yml']" >> config.py
131 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
132 test -d archive || mkdir archive
133 test -d metadata || mkdir metadata
134 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
135 test -d repo || mkdir repo
136 test -d unsigned || mkdir unsigned
137 cp $WORKSPACE/tests/urzip-release-unsigned.apk unsigned/info.guardianproject.urzip_100.apk
138 $fdroid publish --verbose
139 $fdroid update --verbose --nosign
140 $fdroid signindex --verbose
141 test -e repo/index.xml
142 test -e repo/index.jar
143 test -e repo/index-v1.jar
145 grep -F '<application id=' repo/index.xml > /dev/null
148 #------------------------------------------------------------------------------#
149 echo_header "test UTF-8 metadata"
151 REPOROOT=`create_test_dir`
155 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
156 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
158 cp $WORKSPACE/tests/urzip.apk repo/
159 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
165 #------------------------------------------------------------------------------#
166 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
168 cd $WORKSPACE/tests/tmp/importer
171 # stick with known working commit, in case future commits break things for this code
172 git reset --hard cecf00c08aec56ae7a5eba444150c4d1ae868814
173 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
174 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
175 echo "force_build_tools = True" >> config.py
176 $fdroid build --verbose org.fdroid.ci.test.app:300
178 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
181 #------------------------------------------------------------------------------#
182 echo_header 'copy git import and run `fdroid scanner` on it'
184 REPOROOT=`create_test_dir`
187 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
189 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
190 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
191 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
192 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
193 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
194 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
195 echo "" >> metadata/org.fdroid.ci.test.app.txt
196 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
197 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
199 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
200 ls -l build/org.fdroid.ci.test.app
201 $fdroid scanner org.fdroid.ci.test.app --verbose
204 #------------------------------------------------------------------------------#
205 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
207 REPOROOT=`create_test_dir`
208 GNUPGHOME=$REPOROOT/gnupghome
209 KEYSTORE=$WORKSPACE/tests/keystore.jks
211 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
212 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
213 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
214 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
215 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
216 chmod 0700 $GNUPGHOME
217 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
218 echo "install_list = 'org.adaway'" >> config.py
219 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
220 echo "gpghome = '$GNUPGHOME'" >> config.py
221 echo "gpgkey = 'CE71F7FB'" >> config.py
222 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
223 $fdroid update --verbose --pretty
224 test -e repo/index.xml
225 test -e repo/index.jar
226 test -e repo/index-v1.jar
227 grep -F '<application id=' repo/index.xml > /dev/null
228 grep -F '<install packageName=' repo/index.xml > /dev/null
229 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
230 $fdroid gpgsign --verbose
231 $fdroid gpgsign --verbose
232 test -e repo/obb.mainpatch.current_1619.apk.asc
233 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
234 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
235 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
236 ! test -e repo/index.xml.asc
238 # we can't easily reproduce the timestamps for things, so just hardcode them
239 sed -i --expression='s,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
240 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
243 #------------------------------------------------------------------------------#
244 echo_header 'test moving lots of APKs to the archive'
246 REPOROOT=`create_test_dir`
248 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
249 $fdroid init --keystore keystore.jks --repo-keyalias=sova
250 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
251 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
252 echo "accepted_formats = ['txt']" >> config.py
253 sed -i '/allow_disabled_algorithms/d' config.py
254 test -d metadata || mkdir metadata
255 cp $WORKSPACE/tests/metadata/*.txt metadata/
256 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
257 echo 'Summary:good MD5 sig, which is disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
258 sed -i '/Archive Policy:/d' metadata/*.txt
259 test -d repo || mkdir repo
260 cp $WORKSPACE/tests/urzip.apk \
261 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
262 $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
263 $WORKSPACE/tests/repo/obb.main.twoversions_110161[357].apk \
265 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
267 $fdroid update --pretty --nosign
268 test `grep '<package>' archive/index.xml | wc -l` -eq 5
269 test `grep '<package>' repo/index.xml | wc -l` -eq 7
272 #------------------------------------------------------------------------------#
273 echo_header 'test per-app "Archive Policy"'
275 REPOROOT=`create_test_dir`
277 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
278 $fdroid init --keystore keystore.jks --repo-keyalias=sova
279 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
280 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
281 echo "accepted_formats = ['txt']" >> config.py
282 test -d metadata || mkdir metadata
283 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
284 test -d repo || mkdir repo
285 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
286 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
288 $fdroid update --pretty --nosign
289 test `grep '<package>' archive/index.xml | wc -l` -eq 0
290 test `grep '<package>' repo/index.xml | wc -l` -eq 4
291 grep -F com.politedroid_3.apk repo/index.xml
292 grep -F com.politedroid_4.apk repo/index.xml
293 grep -F com.politedroid_5.apk repo/index.xml
294 grep -F com.politedroid_6.apk repo/index.xml
295 test -e repo/com.politedroid_3.apk
296 test -e repo/com.politedroid_4.apk
297 test -e repo/com.politedroid_5.apk
298 test -e repo/com.politedroid_6.apk
300 echo "enable one app in the repo"
301 sed -i 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
302 $fdroid update --pretty --nosign
303 test `grep '<package>' archive/index.xml | wc -l` -eq 3
304 test `grep '<package>' repo/index.xml | wc -l` -eq 1
305 grep -F com.politedroid_3.apk archive/index.xml
306 grep -F com.politedroid_4.apk archive/index.xml
307 grep -F com.politedroid_5.apk archive/index.xml
308 grep -F com.politedroid_6.apk repo/index.xml
309 test -e archive/com.politedroid_3.apk
310 test -e archive/com.politedroid_4.apk
311 test -e archive/com.politedroid_5.apk
312 test -e repo/com.politedroid_6.apk
314 echo "remove all apps from the repo"
315 sed -i 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
316 $fdroid update --pretty --nosign
317 test `grep '<package>' archive/index.xml | wc -l` -eq 4
318 test `grep '<package>' repo/index.xml | wc -l` -eq 0
319 grep -F com.politedroid_3.apk archive/index.xml
320 grep -F com.politedroid_4.apk archive/index.xml
321 grep -F com.politedroid_5.apk archive/index.xml
322 grep -F com.politedroid_6.apk archive/index.xml
323 test -e archive/com.politedroid_3.apk
324 test -e archive/com.politedroid_4.apk
325 test -e archive/com.politedroid_5.apk
326 test -e archive/com.politedroid_6.apk
327 ! test -e repo/com.politedroid_6.apk
329 echo "move back one from archive to the repo"
330 sed -i 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
331 $fdroid update --pretty --nosign
332 test `grep '<package>' archive/index.xml | wc -l` -eq 3
333 test `grep '<package>' repo/index.xml | wc -l` -eq 1
334 grep -F com.politedroid_3.apk archive/index.xml
335 grep -F com.politedroid_4.apk archive/index.xml
336 grep -F com.politedroid_5.apk archive/index.xml
337 grep -F com.politedroid_6.apk repo/index.xml
338 test -e archive/com.politedroid_3.apk
339 test -e archive/com.politedroid_4.apk
340 test -e archive/com.politedroid_5.apk
341 ! test -e archive/com.politedroid_6.apk
342 test -e repo/com.politedroid_6.apk
346 #------------------------------------------------------------------------------#
347 echo_header 'test moving old APKs to and from the archive'
349 REPOROOT=`create_test_dir`
351 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
352 $fdroid init --keystore keystore.jks --repo-keyalias=sova
353 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
354 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
355 echo "accepted_formats = ['txt']" >> config.py
356 test -d metadata || mkdir metadata
357 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
358 sed -i '/Archive Policy:/d' metadata/com.politedroid.txt
359 test -d repo || mkdir repo
360 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
361 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
363 $fdroid update --pretty --nosign
364 test `grep '<package>' archive/index.xml | wc -l` -eq 1
365 test `grep '<package>' repo/index.xml | wc -l` -eq 3
366 grep -F com.politedroid_3.apk archive/index.xml
367 grep -F com.politedroid_4.apk repo/index.xml
368 grep -F com.politedroid_5.apk repo/index.xml
369 grep -F com.politedroid_6.apk repo/index.xml
370 test -e archive/com.politedroid_3.apk
371 test -e repo/com.politedroid_4.apk
372 test -e repo/com.politedroid_5.apk
373 test -e repo/com.politedroid_6.apk
375 sed -i 's,archive_older = 3,archive_older = 1,' config.py
376 $fdroid update --pretty --nosign
377 test `grep '<package>' archive/index.xml | wc -l` -eq 3
378 test `grep '<package>' repo/index.xml | wc -l` -eq 1
379 grep -F com.politedroid_3.apk archive/index.xml
380 grep -F com.politedroid_4.apk archive/index.xml
381 grep -F com.politedroid_5.apk archive/index.xml
382 grep -F com.politedroid_6.apk repo/index.xml
383 test -e archive/com.politedroid_3.apk
384 test -e archive/com.politedroid_4.apk
385 test -e archive/com.politedroid_5.apk
386 test -e repo/com.politedroid_6.apk
388 # disabling deletes from the archive
389 sed -i 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
390 $fdroid update --pretty --nosign
391 test `grep '<package>' archive/index.xml | wc -l` -eq 2
392 test `grep '<package>' repo/index.xml | wc -l` -eq 1
393 grep -F com.politedroid_3.apk archive/index.xml
394 ! grep -F com.politedroid_4.apk archive/index.xml
395 grep -F com.politedroid_5.apk archive/index.xml
396 grep -F com.politedroid_6.apk repo/index.xml
397 test -e archive/com.politedroid_3.apk
398 ! test -e archive/com.politedroid_4.apk
399 test -e archive/com.politedroid_5.apk
400 test -e repo/com.politedroid_6.apk
402 # disabling deletes from the repo, and promotes one from the archive
403 sed -i 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
404 $fdroid update --pretty --nosign
405 test `grep '<package>' archive/index.xml | wc -l` -eq 1
406 test `grep '<package>' repo/index.xml | wc -l` -eq 1
407 grep -F com.politedroid_3.apk archive/index.xml
408 grep -F com.politedroid_5.apk repo/index.xml
409 ! grep -F com.politedroid_6.apk repo/index.xml
410 test -e archive/com.politedroid_3.apk
411 test -e repo/com.politedroid_5.apk
412 ! test -e repo/com.politedroid_6.apk
415 #------------------------------------------------------------------------------#
416 echo_header 'test allowing disabled signatures in repo and archive'
418 REPOROOT=`create_test_dir`
420 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
421 $fdroid init --keystore keystore.jks --repo-keyalias=sova
422 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
423 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
424 echo "accepted_formats = ['txt']" >> config.py
425 echo 'allow_disabled_algorithms = True' >> config.py
426 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
427 test -d metadata || mkdir metadata
428 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
429 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
430 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
431 sed -i '/Archive Policy:/d' metadata/*.txt
432 test -d repo || mkdir repo
433 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
434 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
435 $WORKSPACE/tests/urzip-badsig.apk \
438 $fdroid update --pretty --nosign
439 test `grep '<package>' archive/index.xml | wc -l` -eq 2
440 test `grep '<package>' repo/index.xml | wc -l` -eq 6
441 grep -F com.politedroid_3.apk archive/index.xml
442 grep -F com.politedroid_4.apk repo/index.xml
443 grep -F com.politedroid_5.apk repo/index.xml
444 grep -F com.politedroid_6.apk repo/index.xml
445 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
446 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
447 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
448 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
449 ! grep -F urzip-badsig.apk repo/index.xml
450 ! grep -F urzip-badsig.apk archive/index.xml
451 test -e archive/com.politedroid_3.apk
452 test -e repo/com.politedroid_4.apk
453 test -e repo/com.politedroid_5.apk
454 test -e repo/com.politedroid_6.apk
455 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
456 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
457 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
458 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
459 test -e archive/urzip-badsig.apk
461 sed -i '/allow_disabled_algorithms/d' config.py
462 $fdroid update --pretty --nosign
463 test `grep '<package>' archive/index.xml | wc -l` -eq 5
464 test `grep '<package>' repo/index.xml | wc -l` -eq 3
465 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
466 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
467 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
468 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
469 grep -F com.politedroid_3.apk archive/index.xml
470 grep -F com.politedroid_4.apk repo/index.xml
471 grep -F com.politedroid_5.apk repo/index.xml
472 grep -F com.politedroid_6.apk repo/index.xml
473 ! grep -F urzip-badsig.apk repo/index.xml
474 ! grep -F urzip-badsig.apk archive/index.xml
475 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
476 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
477 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
478 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
479 test -e archive/com.politedroid_3.apk
480 test -e archive/urzip-badsig.apk
481 test -e repo/com.politedroid_4.apk
482 test -e repo/com.politedroid_5.apk
483 test -e repo/com.politedroid_6.apk
486 #------------------------------------------------------------------------------#
487 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
489 REPOROOT=`create_test_dir`
491 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
492 $fdroid init --keystore keystore.jks --repo-keyalias=sova
493 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
494 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
495 echo "accepted_formats = ['txt', 'yml']" >> config.py
496 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
497 test -d metadata || mkdir metadata
498 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
499 test -d repo || mkdir repo
500 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
501 $fdroid update --rename-apks --pretty --nosign
502 test -e repo/info.guardianproject.urzip_100.apk
503 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
504 cp $WORKSPACE/tests/urzip-release.apk repo/
505 $fdroid update --rename-apks --pretty --nosign
506 test -e repo/info.guardianproject.urzip_100.apk
507 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
508 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
509 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
510 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' 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 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
516 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
517 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
518 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
521 #------------------------------------------------------------------------------#
522 echo_header "test metadata checks"
524 REPOROOT=`create_test_dir`
529 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
533 if [ $? -eq 0 ]; then
534 echo "This should have failed because there is no metadata!"
537 echo "testing metadata checks passed"
541 mkdir $REPOROOT/metadata/
542 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
545 # now make a fake duplicate
546 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
550 if [ $? -eq 0 ]; then
551 echo "This should have failed because there is a duplicate metadata file!"
554 echo "testing duplicate metadata checks passed"
559 #------------------------------------------------------------------------------#
560 echo_header "ensure commands that don't need the JDK work without a JDK configed"
562 REPOROOT=`create_test_dir`
566 echo "License:GPL-2.0" >> metadata/fake.txt
567 echo "Summary:Yup still fake" >> metadata/fake.txt
568 echo "Categories:Internet" >> metadata/fake.txt
569 echo "Description:" >> metadata/fake.txt
570 echo "this is fake" >> metadata/fake.txt
571 echo "." >> metadata/fake.txt
573 # fake that no JDKs are available
574 echo 'java_paths = {}' > config.py
576 LOCAL_COPY_DIR=`create_test_dir`/fdroid
577 mkdir -p $LOCAL_COPY_DIR/repo
578 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
584 $fdroid rewritemeta fake
585 $fdroid server update
588 # run these to get their output, but the are not setup, so don't fail
589 $fdroid build || true
590 $fdroid import || true
591 $fdroid install || true
594 #------------------------------------------------------------------------------#
595 echo_header "create a source tarball and use that to build a repo"
598 $python setup.py sdist
600 REPOROOT=`create_test_dir`
602 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
604 ./fdroidserver-*/fdroid init
605 copy_apks_into_repo $REPOROOT
606 ./fdroidserver-*/fdroid update --create-metadata --verbose
609 #------------------------------------------------------------------------------#
610 echo_header "test config checks of local_copy_dir"
612 REPOROOT=`create_test_dir`
615 $fdroid update --create-metadata --verbose
617 $fdroid server update --local-copy-dir=/tmp/fdroid
619 # now test the errors work
621 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
622 if [ $? -eq 0 ]; then
623 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
626 echo "testing absolute path checker passed"
628 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
629 if [ $? -eq 0 ]; then
630 echo "This should have failed because the path does not end with 'fdroid'!"
633 echo "testing dirname exists checker passed"
635 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
636 if [ $? -eq 0 ]; then
637 echo "This should have failed because the dirname path does not exist!"
640 echo "testing dirname exists checker passed"
645 #------------------------------------------------------------------------------#
646 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
648 REPOROOT=`create_test_dir`
651 copy_apks_into_repo $REPOROOT
652 $fdroid update --create-metadata --verbose
654 grep -F '<application id=' repo/index.xml > /dev/null
656 LOCALCOPYDIR=`create_test_dir`/fdroid
657 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
658 NEWREPOROOT=`create_test_dir`
661 echo "sync_from_local_copy_dir = True" >> config.py
662 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
665 #------------------------------------------------------------------------------#
666 # check that --android-home fails when dir does not exist or is not a dir
668 REPOROOT=`create_test_dir`
669 KEYSTORE=$REPOROOT/keystore.jks
672 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
673 if [ $? -eq 0 ]; then
674 echo "This should have failed because /opt/fakeandroidhome does not exist!"
677 echo "testing android-home path checker passed"
679 TESTFILE=`create_test_file`
680 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
681 if [ $? -eq 0 ]; then
682 echo "This should have failed because $TESTFILE is a file not a dir!"
685 echo "testing android-home not-dir checker passed"
690 #------------------------------------------------------------------------------#
691 echo_header "check that fake android home passes 'fdroid init'"
693 REPOROOT=`create_test_dir`
694 FAKE_ANDROID_HOME=`create_test_dir`
695 create_fake_android_home $FAKE_ANDROID_HOME
696 KEYSTORE=$REPOROOT/keystore.jks
698 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
701 #------------------------------------------------------------------------------#
702 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
704 if [ -e /usr/bin/aapt ]; then
705 echo "/usr/bin/aapt exists, not running test"
707 REPOROOT=`create_test_dir`
708 FAKE_ANDROID_HOME=`create_test_dir`
709 create_fake_android_home $FAKE_ANDROID_HOME
710 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
711 KEYSTORE=$REPOROOT/keystore.jks
714 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
715 [ $? -eq 0 ] && exit 1
720 #------------------------------------------------------------------------------#
721 echo_header "check that --android-home overrides ANDROID_HOME"
723 REPOROOT=`create_test_dir`
724 FAKE_ANDROID_HOME=`create_test_dir`
725 create_fake_android_home $FAKE_ANDROID_HOME
726 KEYSTORE=$REPOROOT/keystore.jks
728 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
730 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
731 if [ $? -ne 0 ]; then
732 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
738 #------------------------------------------------------------------------------#
739 # In this case, ANDROID_HOME is set to a fake, non-working version that will
740 # be detected by fdroid as an Android SDK install. It should use the path set
741 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
742 # in ANDROID_HOME, it won't work because it is a fake one. Only
743 # --android-home provides a working one.
744 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
746 REPOROOT=`create_test_dir`
747 KEYSTORE=$REPOROOT/keystore.jks
748 FAKE_ANDROID_HOME=`create_test_dir`
749 create_fake_android_home $FAKE_ANDROID_HOME
750 STORED_ANDROID_HOME=$ANDROID_HOME
752 echo "ANDROID_HOME: $ANDROID_HOME"
754 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
756 copy_apks_into_repo $REPOROOT
757 $fdroid update --create-metadata --verbose
759 grep -F '<application id=' repo/index.xml > /dev/null
760 test -e repo/index.xml
761 test -e repo/index.jar
762 test -e repo/index-v1.jar
763 export ANDROID_HOME=$STORED_ANDROID_HOME
766 #------------------------------------------------------------------------------#
767 echo_header "check duplicate files are properly handled by fdroid update"
769 REPOROOT=`create_test_dir`
770 KEYSTORE=$WORKSPACE/tests/keystore.jks
772 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
773 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
774 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
775 mkdir $REPOROOT/metadata
776 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
777 echo "accepted_formats = ['txt']" >> config.py
778 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
779 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
780 $fdroid update --pretty
781 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
782 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
783 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
784 # die if there are exact duplicates
785 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
789 #------------------------------------------------------------------------------#
790 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
792 REPOROOT=`create_test_dir`
795 copy_apks_into_repo $REPOROOT
797 $fdroid update --create-metadata --verbose
799 grep -F '<application id=' repo/index.xml > /dev/null
802 #------------------------------------------------------------------------------#
803 echo_header "setup a new repo from scratch and generate a keystore"
805 REPOROOT=`create_test_dir`
806 KEYSTORE=$REPOROOT/keystore.jks
808 $fdroid init --keystore $KEYSTORE
810 copy_apks_into_repo $REPOROOT
811 $fdroid update --create-metadata --verbose
813 test -e repo/index.xml
814 test -e repo/index.jar
815 test -e repo/index-v1.jar
816 grep -F '<application id=' repo/index.xml > /dev/null
819 #------------------------------------------------------------------------------#
820 echo_header "setup a new repo manually and generate a keystore"
822 REPOROOT=`create_test_dir`
823 KEYSTORE=$REPOROOT/keystore.jks
826 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
830 if [ $? -eq 0 ]; then
831 echo "This should have failed because this repo has no keystore!"
834 echo '`fdroid update` prompted to add keystore'
837 $fdroid update --create-key
839 copy_apks_into_repo $REPOROOT
840 $fdroid update --create-metadata --verbose
842 test -e repo/index.xml
843 test -e repo/index.jar
844 test -e repo/index-v1.jar
845 grep -F '<application id=' repo/index.xml > /dev/null
848 #------------------------------------------------------------------------------#
849 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
851 REPOROOT=`create_test_dir`
852 KEYSTORE=$REPOROOT/keystore.jks
854 $fdroid init --keystore $KEYSTORE
856 copy_apks_into_repo $REPOROOT
857 $fdroid update --create-metadata --verbose
859 test -e repo/index.xml
860 test -e repo/index.jar
861 test -e repo/index-v1.jar
862 grep -F '<application id=' repo/index.xml > /dev/null
863 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
864 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
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
873 #------------------------------------------------------------------------------#
874 echo_header "setup a new repo from scratch with a HSM/smartcard"
875 REPOROOT=`create_test_dir`
877 $fdroid init --keystore NONE
878 test -e opensc-fdroid.cfg
882 #------------------------------------------------------------------------------#
883 echo_header "setup a new repo with no keystore, add APK, and update"
885 REPOROOT=`create_test_dir`
886 KEYSTORE=$REPOROOT/keystore.jks
889 touch fdroid-icon.png
891 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
893 $fdroid update --create-metadata --verbose
894 if [ $? -eq 0 ]; then
895 echo "This should have failed because this repo has no keystore!"
898 echo '`fdroid update` prompted to add keystore'
902 # now set up fake, non-working keystore setup
904 echo "keystore = \"$KEYSTORE\"" >> config.py
905 echo 'repo_keyalias = "foo"' >> config.py
906 echo 'keystorepass = "foo"' >> config.py
907 echo 'keypass = "foo"' >> config.py
909 $fdroid update --create-metadata --verbose
910 if [ $? -eq 0 ]; then
911 echo "This should have failed because this repo has a bad/fake keystore!"
914 echo '`fdroid update` prompted to add keystore'
919 #------------------------------------------------------------------------------#
920 echo_header "copy tests/repo, update with binary transparency log"
922 REPOROOT=`create_test_dir`
923 GIT_REMOTE=`create_test_dir`
924 GNUPGHOME=$REPOROOT/gnupghome
925 KEYSTORE=$WORKSPACE/tests/keystore.jks
927 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
928 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
929 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
930 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
931 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
932 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
933 $fdroid update --verbose
934 if have_git_2_3; then
935 $fdroid server update --verbose
936 test -e repo/index.xml
937 test -e repo/index.jar
938 test -e repo/index-v1.jar
939 grep -F '<application id=' repo/index.xml > /dev/null
940 cd binary_transparency
941 [ `git rev-list --count HEAD` == "2" ]
943 [ `git rev-list --count HEAD` == "2" ]
945 echo "Skipping test, `git --version` older than 2.3"
949 #------------------------------------------------------------------------------#
950 echo_header "setup a new repo with keystore with APK, update, then without key"
952 REPOROOT=`create_test_dir`
953 KEYSTORE=$REPOROOT/keystore.jks
955 $fdroid init --keystore $KEYSTORE
957 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
958 $fdroid update --create-metadata --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
965 # now set fake repo_keyalias
966 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
969 if [ $? -eq 0 ]; then
970 echo "This should have failed because this repo has a bad repo_keyalias!"
973 echo '`fdroid update` prompted to add keystore'
977 # try creating a new keystore, but fail because the old one is there
980 $fdroid update --create-key
981 if [ $? -eq 0 ]; then
982 echo "This should have failed because a keystore is already there!"
985 echo '`fdroid update` complained about existing keystore'
989 # now actually create the key with the existing settings
992 $fdroid update --create-key
996 #------------------------------------------------------------------------------#
997 echo_header "sign binary repo in offline box, then publishing from online box"
999 OFFLINE_ROOT=`create_test_dir`
1000 KEYSTORE=$WORKSPACE/tests/keystore.jks
1001 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1002 mkdir $LOCAL_COPY_DIR
1003 ONLINE_ROOT=`create_test_dir`
1004 SERVERWEBROOT=`create_test_dir`
1006 # create offline binary transparency log
1008 mkdir binary_transparency
1009 cd binary_transparency
1012 # fake git remote server for binary transparency log
1013 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1015 # fake git remote server for repo mirror
1016 SERVER_GIT_MIRROR=`create_test_dir`
1017 cd $SERVER_GIT_MIRROR
1019 if have_git_2_3; then
1020 git config receive.denyCurrentBranch updateInstead
1024 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
1025 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1027 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1028 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1029 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1030 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1031 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1032 $fdroid update --verbose
1033 grep -F '<application id=' repo/index.xml > /dev/null
1034 cd binary_transparency
1035 [ `git rev-list --count HEAD` == "1" ]
1037 if have_git_2_3; then
1038 $fdroid server update --verbose
1039 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1041 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1042 echo "sync_from_local_copy_dir = True" >> config.py
1043 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1044 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1045 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1046 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1047 $fdroid server update --verbose
1048 cd $BINARY_TRANSPARENCY_REMOTE
1049 [ `git rev-list --count HEAD` == "1" ]
1050 cd $SERVER_GIT_MIRROR
1051 [ `git rev-list --count HEAD` == "1" ]
1053 echo "Skipping test, `git --version` older than 2.3"
1057 #------------------------------------------------------------------------------#
1059 # remove this to prevent git conflicts and complaining
1060 rm -rf $WORKSPACE/fdroidserver.egg-info/