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 ! test -z tmp/apkcache
147 grep -F '<application id=' repo/index.xml > /dev/null
150 #------------------------------------------------------------------------------#
151 echo_header "test UTF-8 metadata"
153 REPOROOT=`create_test_dir`
157 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
158 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
160 cp $WORKSPACE/tests/urzip.apk repo/
161 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
167 #------------------------------------------------------------------------------#
168 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
170 cd $WORKSPACE/tests/tmp/importer
173 # stick with known working commit, in case future commits break things for this code
174 git reset --hard cecf00c08aec56ae7a5eba444150c4d1ae868814
175 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
176 echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
177 echo "force_build_tools = True" >> config.py
178 $fdroid build --verbose org.fdroid.ci.test.app:300
180 echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
183 #------------------------------------------------------------------------------#
184 echo_header 'copy git import and run `fdroid scanner` on it'
186 REPOROOT=`create_test_dir`
188 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
190 echo "Auto Name:Just A Test" > metadata/org.fdroid.ci.test.app.txt
191 echo "Web Site:" >> metadata/org.fdroid.ci.test.app.txt
192 echo "Build:0.3,300" >> metadata/org.fdroid.ci.test.app.txt
193 echo " commit=0.3" >> metadata/org.fdroid.ci.test.app.txt
194 echo " subdir=app" >> metadata/org.fdroid.ci.test.app.txt
195 echo " gradle=yes" >> metadata/org.fdroid.ci.test.app.txt
196 echo "" >> metadata/org.fdroid.ci.test.app.txt
197 echo "Repo:https://gitlab.com/fdroid/ci-test-app.git" >> metadata/org.fdroid.ci.test.app.txt
198 echo "Repo Type:git" >> metadata/org.fdroid.ci.test.app.txt
200 cp -a $WORKSPACE/tests/tmp/importer build/org.fdroid.ci.test.app
201 ls -l build/org.fdroid.ci.test.app
202 $fdroid scanner org.fdroid.ci.test.app --verbose
205 #------------------------------------------------------------------------------#
206 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
208 REPOROOT=`create_test_dir`
209 GNUPGHOME=$REPOROOT/gnupghome
210 KEYSTORE=$WORKSPACE/tests/keystore.jks
212 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
213 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
214 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
215 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
216 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
217 chmod 0700 $GNUPGHOME
218 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
219 echo "install_list = 'org.adaway'" >> config.py
220 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
221 echo "gpghome = '$GNUPGHOME'" >> config.py
222 echo "gpgkey = 'CE71F7FB'" >> config.py
223 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
224 $fdroid update --verbose --pretty
225 test -e repo/index.xml
226 test -e repo/index.jar
227 test -e repo/index-v1.jar
228 grep -F '<application id=' repo/index.xml > /dev/null
229 grep -F '<install packageName=' repo/index.xml > /dev/null
230 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
231 $fdroid gpgsign --verbose
232 $fdroid gpgsign --verbose
233 test -e repo/obb.mainpatch.current_1619.apk.asc
234 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
235 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
236 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
237 ! test -e repo/index.xml.asc
239 # we can't easily reproduce the timestamps for things, so just hardcode them
240 sed -i --expression='s,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
241 diff -uw $WORKSPACE/tests/repo/index.xml repo/index.xml
244 #------------------------------------------------------------------------------#
245 echo_header 'test moving lots of APKs to the archive'
247 REPOROOT=`create_test_dir`
249 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
250 $fdroid init --keystore keystore.jks --repo-keyalias=sova
251 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
252 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
253 echo "accepted_formats = ['txt']" >> config.py
254 sed -i '/allow_disabled_algorithms/d' config.py
255 test -d metadata || mkdir metadata
256 cp $WORKSPACE/tests/metadata/*.txt metadata/
257 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
258 echo 'Summary:good MD5 sig, which is disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
259 sed -i '/Archive Policy:/d' metadata/*.txt
260 test -d repo || mkdir repo
261 cp $WORKSPACE/tests/urzip.apk \
262 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
263 $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
264 $WORKSPACE/tests/repo/obb.main.twoversions_110161[357].apk \
266 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
268 $fdroid update --pretty --nosign
269 test `grep '<package>' archive/index.xml | wc -l` -eq 5
270 test `grep '<package>' repo/index.xml | wc -l` -eq 7
273 #------------------------------------------------------------------------------#
274 echo_header 'test per-app "Archive Policy"'
276 REPOROOT=`create_test_dir`
278 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
279 $fdroid init --keystore keystore.jks --repo-keyalias=sova
280 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
281 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
282 echo "accepted_formats = ['txt']" >> config.py
283 test -d metadata || mkdir metadata
284 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
285 test -d repo || mkdir repo
286 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
287 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
289 $fdroid update --pretty --nosign
290 test `grep '<package>' archive/index.xml | wc -l` -eq 0
291 test `grep '<package>' repo/index.xml | wc -l` -eq 4
292 grep -F com.politedroid_3.apk repo/index.xml
293 grep -F com.politedroid_4.apk repo/index.xml
294 grep -F com.politedroid_5.apk repo/index.xml
295 grep -F com.politedroid_6.apk repo/index.xml
296 test -e repo/com.politedroid_3.apk
297 test -e repo/com.politedroid_4.apk
298 test -e repo/com.politedroid_5.apk
299 test -e repo/com.politedroid_6.apk
301 echo "enable one app in the repo"
302 sed -i 's,^Archive Policy:4,Archive Policy:1,' metadata/com.politedroid.txt
303 $fdroid update --pretty --nosign
304 test `grep '<package>' archive/index.xml | wc -l` -eq 3
305 test `grep '<package>' repo/index.xml | wc -l` -eq 1
306 grep -F com.politedroid_3.apk archive/index.xml
307 grep -F com.politedroid_4.apk archive/index.xml
308 grep -F com.politedroid_5.apk archive/index.xml
309 grep -F com.politedroid_6.apk repo/index.xml
310 test -e archive/com.politedroid_3.apk
311 test -e archive/com.politedroid_4.apk
312 test -e archive/com.politedroid_5.apk
313 test -e repo/com.politedroid_6.apk
315 echo "remove all apps from the repo"
316 sed -i 's,^Archive Policy:1,Archive Policy:0,' metadata/com.politedroid.txt
317 $fdroid update --pretty --nosign
318 test `grep '<package>' archive/index.xml | wc -l` -eq 4
319 test `grep '<package>' repo/index.xml | wc -l` -eq 0
320 grep -F com.politedroid_3.apk archive/index.xml
321 grep -F com.politedroid_4.apk archive/index.xml
322 grep -F com.politedroid_5.apk archive/index.xml
323 grep -F com.politedroid_6.apk archive/index.xml
324 test -e archive/com.politedroid_3.apk
325 test -e archive/com.politedroid_4.apk
326 test -e archive/com.politedroid_5.apk
327 test -e archive/com.politedroid_6.apk
328 ! test -e repo/com.politedroid_6.apk
330 echo "move back one from archive to the repo"
331 sed -i 's,^Archive Policy:0,Archive Policy:1,' metadata/com.politedroid.txt
332 $fdroid update --pretty --nosign
333 test `grep '<package>' archive/index.xml | wc -l` -eq 3
334 test `grep '<package>' repo/index.xml | wc -l` -eq 1
335 grep -F com.politedroid_3.apk archive/index.xml
336 grep -F com.politedroid_4.apk archive/index.xml
337 grep -F com.politedroid_5.apk archive/index.xml
338 grep -F com.politedroid_6.apk repo/index.xml
339 test -e archive/com.politedroid_3.apk
340 test -e archive/com.politedroid_4.apk
341 test -e archive/com.politedroid_5.apk
342 ! test -e archive/com.politedroid_6.apk
343 test -e repo/com.politedroid_6.apk
347 #------------------------------------------------------------------------------#
348 echo_header 'test moving old APKs to and from the archive'
350 REPOROOT=`create_test_dir`
352 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
353 $fdroid init --keystore keystore.jks --repo-keyalias=sova
354 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
355 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
356 echo "accepted_formats = ['txt']" >> config.py
357 test -d metadata || mkdir metadata
358 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
359 sed -i '/Archive Policy:/d' metadata/com.politedroid.txt
360 test -d repo || mkdir repo
361 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk repo/
362 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
364 $fdroid update --pretty --nosign
365 test `grep '<package>' archive/index.xml | wc -l` -eq 1
366 test `grep '<package>' repo/index.xml | wc -l` -eq 3
367 grep -F com.politedroid_3.apk archive/index.xml
368 grep -F com.politedroid_4.apk repo/index.xml
369 grep -F com.politedroid_5.apk repo/index.xml
370 grep -F com.politedroid_6.apk repo/index.xml
371 test -e archive/com.politedroid_3.apk
372 test -e repo/com.politedroid_4.apk
373 test -e repo/com.politedroid_5.apk
374 test -e repo/com.politedroid_6.apk
376 sed -i 's,archive_older = 3,archive_older = 1,' config.py
377 $fdroid update --pretty --nosign
378 test `grep '<package>' archive/index.xml | wc -l` -eq 3
379 test `grep '<package>' repo/index.xml | wc -l` -eq 1
380 grep -F com.politedroid_3.apk archive/index.xml
381 grep -F com.politedroid_4.apk archive/index.xml
382 grep -F com.politedroid_5.apk archive/index.xml
383 grep -F com.politedroid_6.apk repo/index.xml
384 test -e archive/com.politedroid_3.apk
385 test -e archive/com.politedroid_4.apk
386 test -e archive/com.politedroid_5.apk
387 test -e repo/com.politedroid_6.apk
389 # disabling deletes from the archive
390 sed -i 's/Build:1.3,4/Build:1.3,4\n disable=testing deletion/' metadata/com.politedroid.txt
391 $fdroid update --pretty --nosign
392 test `grep '<package>' archive/index.xml | wc -l` -eq 2
393 test `grep '<package>' repo/index.xml | wc -l` -eq 1
394 grep -F com.politedroid_3.apk archive/index.xml
395 ! grep -F com.politedroid_4.apk archive/index.xml
396 grep -F com.politedroid_5.apk archive/index.xml
397 grep -F com.politedroid_6.apk repo/index.xml
398 test -e archive/com.politedroid_3.apk
399 ! test -e archive/com.politedroid_4.apk
400 test -e archive/com.politedroid_5.apk
401 test -e repo/com.politedroid_6.apk
403 # disabling deletes from the repo, and promotes one from the archive
404 sed -i 's/Build:1.5,6/Build:1.5,6\n disable=testing deletion/' metadata/com.politedroid.txt
405 $fdroid update --pretty --nosign
406 test `grep '<package>' archive/index.xml | wc -l` -eq 1
407 test `grep '<package>' repo/index.xml | wc -l` -eq 1
408 grep -F com.politedroid_3.apk archive/index.xml
409 grep -F com.politedroid_5.apk repo/index.xml
410 ! grep -F com.politedroid_6.apk repo/index.xml
411 test -e archive/com.politedroid_3.apk
412 test -e repo/com.politedroid_5.apk
413 ! test -e repo/com.politedroid_6.apk
416 #------------------------------------------------------------------------------#
417 echo_header 'test allowing disabled signatures in repo and archive'
419 REPOROOT=`create_test_dir`
421 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
422 $fdroid init --keystore keystore.jks --repo-keyalias=sova
423 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
424 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
425 echo "accepted_formats = ['txt']" >> config.py
426 echo 'allow_disabled_algorithms = True' >> config.py
427 sed -i 's,archive_older = [0-9],archive_older = 3,' config.py
428 test -d metadata || mkdir metadata
429 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
430 echo 'Summary:good test version of urzip' > metadata/info.guardianproject.urzip.txt
431 echo 'Summary:good MD5 sig, disabled algorithm' > metadata/org.bitbucket.tickytacky.mirrormirror.txt
432 sed -i '/Archive Policy:/d' metadata/*.txt
433 test -d repo || mkdir repo
434 cp $WORKSPACE/tests/repo/com.politedroid_[0-9].apk \
435 $WORKSPACE/tests/org.bitbucket.tickytacky.mirrormirror_[0-9].apk \
436 $WORKSPACE/tests/urzip-badsig.apk \
439 $fdroid update --pretty --nosign
440 test `grep '<package>' archive/index.xml | wc -l` -eq 2
441 test `grep '<package>' repo/index.xml | wc -l` -eq 6
442 grep -F com.politedroid_3.apk archive/index.xml
443 grep -F com.politedroid_4.apk repo/index.xml
444 grep -F com.politedroid_5.apk repo/index.xml
445 grep -F com.politedroid_6.apk repo/index.xml
446 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
447 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk repo/index.xml
448 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk repo/index.xml
449 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk repo/index.xml
450 ! grep -F urzip-badsig.apk repo/index.xml
451 ! grep -F urzip-badsig.apk archive/index.xml
452 test -e archive/com.politedroid_3.apk
453 test -e repo/com.politedroid_4.apk
454 test -e repo/com.politedroid_5.apk
455 test -e repo/com.politedroid_6.apk
456 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
457 test -e repo/org.bitbucket.tickytacky.mirrormirror_2.apk
458 test -e repo/org.bitbucket.tickytacky.mirrormirror_3.apk
459 test -e repo/org.bitbucket.tickytacky.mirrormirror_4.apk
460 test -e archive/urzip-badsig.apk
462 sed -i '/allow_disabled_algorithms/d' config.py
463 $fdroid update --pretty --nosign
464 test `grep '<package>' archive/index.xml | wc -l` -eq 5
465 test `grep '<package>' repo/index.xml | wc -l` -eq 3
466 grep -F org.bitbucket.tickytacky.mirrormirror_1.apk archive/index.xml
467 grep -F org.bitbucket.tickytacky.mirrormirror_2.apk archive/index.xml
468 grep -F org.bitbucket.tickytacky.mirrormirror_3.apk archive/index.xml
469 grep -F org.bitbucket.tickytacky.mirrormirror_4.apk archive/index.xml
470 grep -F com.politedroid_3.apk archive/index.xml
471 grep -F com.politedroid_4.apk repo/index.xml
472 grep -F com.politedroid_5.apk repo/index.xml
473 grep -F com.politedroid_6.apk repo/index.xml
474 ! grep -F urzip-badsig.apk repo/index.xml
475 ! grep -F urzip-badsig.apk archive/index.xml
476 test -e archive/org.bitbucket.tickytacky.mirrormirror_1.apk
477 test -e archive/org.bitbucket.tickytacky.mirrormirror_2.apk
478 test -e archive/org.bitbucket.tickytacky.mirrormirror_3.apk
479 test -e archive/org.bitbucket.tickytacky.mirrormirror_4.apk
480 test -e archive/com.politedroid_3.apk
481 test -e archive/urzip-badsig.apk
482 test -e repo/com.politedroid_4.apk
483 test -e repo/com.politedroid_5.apk
484 test -e repo/com.politedroid_6.apk
487 #------------------------------------------------------------------------------#
488 echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
490 REPOROOT=`create_test_dir`
492 cp $WORKSPACE/tests/keystore.jks $REPOROOT/
493 $fdroid init --keystore keystore.jks --repo-keyalias=sova
494 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
495 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
496 echo "accepted_formats = ['txt', 'yml']" >> config.py
497 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
498 test -d metadata || mkdir metadata
499 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
500 test -d repo || mkdir repo
501 cp $WORKSPACE/tests/urzip.apk "repo/asdfiuhk urzip-πÇÇπÇÇ现代汉语通用字-български-عربي1234 ö.apk"
502 $fdroid update --rename-apks --pretty --nosign
503 test -e repo/info.guardianproject.urzip_100.apk
504 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
505 cp $WORKSPACE/tests/urzip-release.apk repo/
506 $fdroid update --rename-apks --pretty --nosign
507 test -e repo/info.guardianproject.urzip_100.apk
508 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
509 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
510 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
511 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
512 cp $WORKSPACE/tests/urzip-release.apk repo/
513 $fdroid update --rename-apks --pretty --nosign
514 test -e repo/info.guardianproject.urzip_100.apk
515 test -e repo/info.guardianproject.urzip_100_b4964fd.apk
516 test -e duplicates/repo/info.guardianproject.urzip_100_b4964fd.apk
517 grep -F 'info.guardianproject.urzip_100.apk' repo/index-v1.json repo/index.xml
518 grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index-v1.json
519 ! grep -F 'info.guardianproject.urzip_100_b4964fd.apk' repo/index.xml
522 #------------------------------------------------------------------------------#
523 echo_header "test metadata checks"
525 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
764 ! test -z tmp/apkcache
765 export ANDROID_HOME=$STORED_ANDROID_HOME
768 #------------------------------------------------------------------------------#
769 echo_header "check duplicate files are properly handled by fdroid update"
771 REPOROOT=`create_test_dir`
772 KEYSTORE=$WORKSPACE/tests/keystore.jks
774 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
775 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
776 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
777 mkdir $REPOROOT/metadata
778 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
779 echo "accepted_formats = ['txt']" >> config.py
780 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
781 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
782 $fdroid update --pretty
783 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml repo/index-v1.json
784 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index-v1.json
785 ! grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
786 # die if there are exact duplicates
787 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
791 #------------------------------------------------------------------------------#
792 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
794 REPOROOT=`create_test_dir`
797 copy_apks_into_repo $REPOROOT
799 $fdroid update --create-metadata --verbose
801 grep -F '<application id=' repo/index.xml > /dev/null
804 #------------------------------------------------------------------------------#
805 echo_header "setup a new repo from scratch and generate a keystore"
807 REPOROOT=`create_test_dir`
808 KEYSTORE=$REPOROOT/keystore.jks
810 $fdroid init --keystore $KEYSTORE
812 copy_apks_into_repo $REPOROOT
813 $fdroid update --create-metadata --verbose
815 test -e repo/index.xml
816 test -e repo/index.jar
817 test -e repo/index-v1.jar
819 ! test -z tmp/apkcache
820 grep -F '<application id=' repo/index.xml > /dev/null
823 #------------------------------------------------------------------------------#
824 echo_header "setup a new repo manually and generate a keystore"
826 REPOROOT=`create_test_dir`
827 KEYSTORE=$REPOROOT/keystore.jks
829 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
833 if [ $? -eq 0 ]; then
834 echo "This should have failed because this repo has no keystore!"
837 echo '`fdroid update` prompted to add keystore'
840 $fdroid update --create-key
842 copy_apks_into_repo $REPOROOT
843 $fdroid update --create-metadata --verbose
845 test -e repo/index.xml
846 test -e repo/index.jar
847 test -e repo/index-v1.jar
849 ! test -z tmp/apkcache
850 grep -F '<application id=' repo/index.xml > /dev/null
853 #------------------------------------------------------------------------------#
854 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
856 REPOROOT=`create_test_dir`
857 KEYSTORE=$REPOROOT/keystore.jks
859 $fdroid init --keystore $KEYSTORE
861 copy_apks_into_repo $REPOROOT
862 $fdroid update --create-metadata --verbose
864 test -e repo/index.xml
865 test -e repo/index.jar
866 test -e repo/index-v1.jar
867 grep -F '<application id=' repo/index.xml > /dev/null
868 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
869 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
870 $fdroid update --create-metadata --verbose
872 test -e repo/index.xml
873 test -e repo/index.jar
874 test -e repo/index-v1.jar
876 ! test -z tmp/apkcache
877 grep -F '<application id=' repo/index.xml > /dev/null
880 #------------------------------------------------------------------------------#
881 echo_header "setup a new repo from scratch with a HSM/smartcard"
882 REPOROOT=`create_test_dir`
884 $fdroid init --keystore NONE
885 test -e opensc-fdroid.cfg
889 #------------------------------------------------------------------------------#
890 echo_header "setup a new repo with no keystore, add APK, and update"
892 REPOROOT=`create_test_dir`
893 KEYSTORE=$REPOROOT/keystore.jks
895 touch fdroid-icon.png
897 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
899 $fdroid update --create-metadata --verbose
900 if [ $? -eq 0 ]; then
901 echo "This should have failed because this repo has no keystore!"
904 echo '`fdroid update` prompted to add keystore'
908 # now set up fake, non-working keystore setup
910 echo "keystore = \"$KEYSTORE\"" >> config.py
911 echo 'repo_keyalias = "foo"' >> config.py
912 echo 'keystorepass = "foo"' >> config.py
913 echo 'keypass = "foo"' >> config.py
915 $fdroid update --create-metadata --verbose
916 if [ $? -eq 0 ]; then
917 echo "This should have failed because this repo has a bad/fake keystore!"
920 echo '`fdroid update` prompted to add keystore'
925 #------------------------------------------------------------------------------#
926 echo_header "copy tests/repo, update with binary transparency log"
928 REPOROOT=`create_test_dir`
929 GIT_REMOTE=`create_test_dir`
930 GNUPGHOME=$REPOROOT/gnupghome
931 KEYSTORE=$WORKSPACE/tests/keystore.jks
933 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
934 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
935 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
936 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
937 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
938 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
939 $fdroid update --verbose
940 if have_git_2_3; then
941 $fdroid server update --verbose
942 test -e repo/index.xml
943 test -e repo/index.jar
944 test -e repo/index-v1.jar
945 grep -F '<application id=' repo/index.xml > /dev/null
946 cd binary_transparency
947 [ `git rev-list --count HEAD` == "2" ]
949 [ `git rev-list --count HEAD` == "2" ]
951 echo "Skipping test, `git --version` older than 2.3"
955 #------------------------------------------------------------------------------#
956 echo_header "setup a new repo with keystore with APK, update, then without key"
958 REPOROOT=`create_test_dir`
959 KEYSTORE=$REPOROOT/keystore.jks
961 $fdroid init --keystore $KEYSTORE
963 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
964 $fdroid update --create-metadata --verbose
966 test -e repo/index.xml
967 test -e repo/index.jar
968 test -e repo/index-v1.jar
970 ! test -z tmp/apkcache
971 grep -F '<application id=' repo/index.xml > /dev/null
973 # now set fake repo_keyalias
974 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
977 if [ $? -eq 0 ]; then
978 echo "This should have failed because this repo has a bad repo_keyalias!"
981 echo '`fdroid update` prompted to add keystore'
985 # try creating a new keystore, but fail because the old one is there
988 $fdroid update --create-key
989 if [ $? -eq 0 ]; then
990 echo "This should have failed because a keystore is already there!"
993 echo '`fdroid update` complained about existing keystore'
997 # now actually create the key with the existing settings
1000 $fdroid update --create-key
1004 #------------------------------------------------------------------------------#
1005 echo_header "sign binary repo in offline box, then publishing from online box"
1007 OFFLINE_ROOT=`create_test_dir`
1008 KEYSTORE=$WORKSPACE/tests/keystore.jks
1009 LOCAL_COPY_DIR=`create_test_dir`/fdroid
1010 mkdir $LOCAL_COPY_DIR
1011 ONLINE_ROOT=`create_test_dir`
1012 SERVERWEBROOT=`create_test_dir`
1014 # create offline binary transparency log
1016 mkdir binary_transparency
1017 cd binary_transparency
1020 # fake git remote server for binary transparency log
1021 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
1023 # fake git remote server for repo mirror
1024 SERVER_GIT_MIRROR=`create_test_dir`
1025 cd $SERVER_GIT_MIRROR
1027 if have_git_2_3; then
1028 git config receive.denyCurrentBranch updateInstead
1032 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
1033 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
1035 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1036 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
1037 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
1038 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1039 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1040 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
1041 $fdroid update --pretty
1042 grep -F '<application id=' repo/index.xml > /dev/null
1043 grep -F '/fdroid/repo</mirror>' repo/index.xml
1044 grep -F '/fdroid/archive</mirror>' archive/index.xml
1045 test `grep '<mirror>' repo/index.xml | wc -l` -eq 2
1046 test `grep '<mirror>' archive/index.xml | wc -l` -eq 2
1047 cd binary_transparency
1048 [ `git rev-list --count HEAD` == "1" ]
1050 $fdroid server update --verbose
1051 grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
1053 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1054 echo "sync_from_local_copy_dir = True" >> config.py
1055 echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
1056 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
1057 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
1058 echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
1059 $fdroid server update --verbose
1060 cd $BINARY_TRANSPARENCY_REMOTE
1061 [ `git rev-list --count HEAD` == "1" ]
1062 cd $SERVER_GIT_MIRROR
1063 [ `git rev-list --count HEAD` == "1" ]
1066 #------------------------------------------------------------------------------#
1068 # remove this to prevent git conflicts and complaining
1069 rm -rf $WORKSPACE/fdroidserver.egg-info/