chiark / gitweb /
Merge branch 'lint-for-newness' into 'master'
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e # quit script on error
4
5 echo_header() {
6     { echo -e "==============================================================================\n$1"; } 2>/dev/null
7 }
8
9 copy_apks_into_repo() {
10     set +x
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
19         fi
20     done
21     set -x
22 }
23
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() {
27     mkdir $1/tools
28     mkdir $1/platform-tools
29     mkdir $1/build-tools
30     mkdir $1/build-tools/19.0.2
31     touch $1/build-tools/19.0.2/aapt
32 }
33
34 create_test_dir() {
35     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
36     mktemp -d $WORKSPACE/.testfiles/run-tests.XXXX
37 }
38
39 create_test_file() {
40     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
41     TMPDIR=$WORKSPACE/.testfiles  mktemp
42 }
43
44 # the < is reverse since 0 means success in exit codes
45 have_git_2_3() {
46     python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version`
47 }
48
49 #------------------------------------------------------------------------------#
50 # "main"
51
52 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
53     set +x
54     echo "Usage: $0 '/path/to/folder/with/apks'"
55     exit 1
56 fi
57
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"
61     exit 1
62 fi
63
64 if [ -d tests ]; then
65     cd tests
66 fi
67
68 if [ -z "$1" ]; then
69     APKDIR=`pwd`
70 else
71     APKDIR=$1
72 fi
73
74 if [ -z $WORKSPACE ]; then
75     WORKSPACE=`dirname $(pwd)`
76     echo "Setting Workspace to $WORKSPACE"
77 fi
78
79 # allow the location of the script to be overridden
80 if [ -z $fdroid ]; then
81     fdroid="$WORKSPACE/fdroid"
82 fi
83
84 # allow the location of aapt to be overridden
85 if [ -z $aapt ]; then
86     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
87 fi
88
89 # allow the location of python to be overridden
90 if [ -z $python ]; then
91     python=python3
92 fi
93
94 set -x # show each command as it is executed
95
96 #------------------------------------------------------------------------------#
97 echo_header "run commit hooks"
98
99 cd $WORKSPACE
100 ./hooks/pre-commit
101
102
103 #------------------------------------------------------------------------------#
104 echo_header "test python getsig replacement"
105
106 cd $WORKSPACE/tests/getsig
107 ./make.sh
108
109 cd $WORKSPACE/tests
110 for testcase in $WORKSPACE/tests/*.TestCase; do
111     $testcase
112 done
113
114
115 #------------------------------------------------------------------------------#
116 echo_header "print fdroid version"
117
118 $fdroid --version
119
120
121 #------------------------------------------------------------------------------#
122 echo_header 'run process when building and signing are on separate machines'
123
124 REPOROOT=`create_test_dir`
125 cd $REPOROOT
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
144 test -L urzip.apk
145 grep -F '<application id=' repo/index.xml > /dev/null
146
147
148 #------------------------------------------------------------------------------#
149 echo_header "test UTF-8 metadata"
150
151 REPOROOT=`create_test_dir`
152 cd $REPOROOT
153
154 $fdroid init
155 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
156 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
157 mkdir metadata
158 cp $WORKSPACE/tests/urzip.apk repo/
159 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.yml metadata/
160
161 $fdroid readmeta
162 $fdroid update
163
164
165 #------------------------------------------------------------------------------#
166 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
167
168 cd $WORKSPACE/tests/tmp/importer
169 git remote update -p
170 git clean -fdx
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
177 else
178     echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
179 fi
180
181
182 #------------------------------------------------------------------------------#
183 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
184
185 REPOROOT=`create_test_dir`
186 GNUPGHOME=$REPOROOT/gnupghome
187 KEYSTORE=$WORKSPACE/tests/keystore.jks
188 cd $REPOROOT
189 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
190 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
191 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
192 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
193 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
194 chmod 0700 $GNUPGHOME
195 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
196 echo "install_list = 'org.adaway'" >> config.py
197 echo "uninstall_list = ('com.android.vending', 'com.facebook.orca',)" >> config.py
198 echo "gpghome = '$GNUPGHOME'" >> config.py
199 echo "gpgkey = 'CE71F7FB'" >> config.py
200 echo "mirrors = ('http://foobarfoobarfoobar.onion/fdroid','https://foo.bar/fdroid',)" >> config.py
201 $fdroid update --verbose --pretty
202 test -e repo/index.xml
203 test -e repo/index.jar
204 test -e repo/index-v1.jar
205 grep -F '<application id=' repo/index.xml > /dev/null
206 grep -F '<install packageName=' repo/index.xml > /dev/null
207 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
208 $fdroid gpgsign --verbose
209 $fdroid gpgsign --verbose
210 test -e repo/obb.mainpatch.current_1619.apk.asc
211 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
212 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
213 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
214 ! test -e repo/index.xml.asc
215
216 # we can't easily reproduce the timestamps for things, so just hardcode them
217 sed -i --expression='s,timestamp="[0-9]*",timestamp="1480431575",' repo/index.xml
218 diff $WORKSPACE/tests/repo/index.xml repo/index.xml
219
220 #------------------------------------------------------------------------------#
221 echo_header "test metadata checks"
222
223 REPOROOT=`create_test_dir`
224 cd $REPOROOT
225
226 touch config.py
227 mkdir repo
228 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
229
230 set +e
231 $fdroid build
232 if [ $? -eq 0 ]; then
233     echo "This should have failed because there is no metadata!"
234     exit 1
235 else
236     echo "testing metadata checks passed"
237 fi
238 set -e
239
240 mkdir $REPOROOT/metadata/
241 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
242 $fdroid readmeta
243
244 # now make a fake duplicate
245 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
246
247 set +e
248 $fdroid readmeta
249 if [ $? -eq 0 ]; then
250     echo "This should have failed because there is a duplicate metadata file!"
251     exit 1
252 else
253     echo "testing duplicate metadata checks passed"
254 fi
255 set -e
256
257
258 #------------------------------------------------------------------------------#
259 echo_header "ensure commands that don't need the JDK work without a JDK configed"
260
261 REPOROOT=`create_test_dir`
262 cd $REPOROOT
263 mkdir repo
264 mkdir metadata
265 echo "License:GPL-2.0" >> metadata/fake.txt
266 echo "Summary:Yup still fake" >> metadata/fake.txt
267 echo "Categories:Internet" >> metadata/fake.txt
268 echo "Description:" >> metadata/fake.txt
269 echo "this is fake" >> metadata/fake.txt
270 echo "." >> metadata/fake.txt
271
272 # fake that no JDKs are available
273 echo 'java_paths = {}' > config.py
274
275 LOCAL_COPY_DIR=`create_test_dir`/fdroid
276 mkdir -p $LOCAL_COPY_DIR/repo
277 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
278
279 $fdroid checkupdates
280 $fdroid gpgsign
281 $fdroid lint
282 $fdroid readmeta
283 $fdroid rewritemeta fake
284 $fdroid server update
285 $fdroid scanner
286
287 # run these to get their output, but the are not setup, so don't fail
288 $fdroid build || true
289 $fdroid import || true
290 $fdroid install || true
291
292
293 #------------------------------------------------------------------------------#
294 echo_header "create a source tarball and use that to build a repo"
295
296 cd $WORKSPACE
297 $python setup.py sdist
298
299 REPOROOT=`create_test_dir`
300 cd $REPOROOT
301 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
302 cd $REPOROOT
303 ./fdroidserver-*/fdroid init
304 copy_apks_into_repo $REPOROOT
305 ./fdroidserver-*/fdroid update --create-metadata --verbose
306
307
308 #------------------------------------------------------------------------------#
309 echo_header "test config checks of local_copy_dir"
310
311 REPOROOT=`create_test_dir`
312 cd $REPOROOT
313 $fdroid init
314 $fdroid update --create-metadata --verbose
315 $fdroid readmeta
316 $fdroid server update --local-copy-dir=/tmp/fdroid
317
318 # now test the errors work
319 set +e
320 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
321 if [ $? -eq 0 ]; then
322     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
323     exit 1
324 else
325     echo "testing absolute path checker passed"
326 fi
327 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
328 if [ $? -eq 0 ]; then
329     echo "This should have failed because the path does not end with 'fdroid'!"
330     exit 1
331 else
332     echo "testing dirname exists checker passed"
333 fi
334 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
335 if [ $? -eq 0 ]; then
336     echo "This should have failed because the dirname path does not exist!"
337     exit 1
338 else
339     echo "testing dirname exists checker passed"
340 fi
341 set -e
342
343
344 #------------------------------------------------------------------------------#
345 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
346
347 REPOROOT=`create_test_dir`
348 cd $REPOROOT
349 $fdroid init
350 copy_apks_into_repo $REPOROOT
351 $fdroid update --create-metadata --verbose
352 $fdroid readmeta
353 grep -F '<application id=' repo/index.xml > /dev/null
354
355 LOCALCOPYDIR=`create_test_dir`/fdroid
356 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
357 NEWREPOROOT=`create_test_dir`
358 cd $NEWREPOROOT
359 $fdroid init
360 echo "sync_from_local_copy_dir = True" >> config.py
361 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
362
363
364 #------------------------------------------------------------------------------#
365 # check that --android-home fails when dir does not exist or is not a dir
366
367 REPOROOT=`create_test_dir`
368 KEYSTORE=$REPOROOT/keystore.jks
369 cd $REPOROOT
370 set +e
371 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
372 if [ $? -eq 0 ]; then
373     echo "This should have failed because /opt/fakeandroidhome does not exist!"
374     exit 1
375 else
376     echo "testing android-home path checker passed"
377 fi
378 TESTFILE=`create_test_file`
379 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
380 if [ $? -eq 0 ]; then
381     echo "This should have failed because $TESTFILE is a file not a dir!"
382     exit 1
383 else
384     echo "testing android-home not-dir checker passed"
385 fi
386 set -e
387
388
389 #------------------------------------------------------------------------------#
390 echo_header "check that fake android home passes 'fdroid init'"
391
392 REPOROOT=`create_test_dir`
393 FAKE_ANDROID_HOME=`create_test_dir`
394 create_fake_android_home $FAKE_ANDROID_HOME
395 KEYSTORE=$REPOROOT/keystore.jks
396 cd $REPOROOT
397 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
398
399
400 #------------------------------------------------------------------------------#
401 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
402
403 if [ -e /usr/bin/aapt ]; then
404     echo "/usr/bin/aapt exists, not running test"
405 else
406     REPOROOT=`create_test_dir`
407     FAKE_ANDROID_HOME=`create_test_dir`
408     create_fake_android_home $FAKE_ANDROID_HOME
409     rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
410     KEYSTORE=$REPOROOT/keystore.jks
411     cd $REPOROOT
412     set +e
413     $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
414     [ $? -eq 0 ] && exit 1
415     set -e
416 fi
417
418
419 #------------------------------------------------------------------------------#
420 echo_header "check that --android-home overrides ANDROID_HOME"
421
422 REPOROOT=`create_test_dir`
423 FAKE_ANDROID_HOME=`create_test_dir`
424 create_fake_android_home $FAKE_ANDROID_HOME
425 KEYSTORE=$REPOROOT/keystore.jks
426 cd $REPOROOT
427 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
428 set +e
429 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
430 if [ $? -ne 0 ]; then
431     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
432     exit 1
433 fi
434 set -e
435
436
437 #------------------------------------------------------------------------------#
438 # In this case, ANDROID_HOME is set to a fake, non-working version that will
439 # be detected by fdroid as an Android SDK install.  It should use the path set
440 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
441 # in ANDROID_HOME, it won't work because it is a fake one.  Only
442 # --android-home provides a working one.
443 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
444
445 REPOROOT=`create_test_dir`
446 KEYSTORE=$REPOROOT/keystore.jks
447 FAKE_ANDROID_HOME=`create_test_dir`
448 create_fake_android_home $FAKE_ANDROID_HOME
449 STORED_ANDROID_HOME=$ANDROID_HOME
450 unset ANDROID_HOME
451 echo "ANDROID_HOME: $ANDROID_HOME"
452 cd $REPOROOT
453 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
454 test -e $KEYSTORE
455 copy_apks_into_repo $REPOROOT
456 $fdroid update --create-metadata --verbose
457 $fdroid readmeta
458 grep -F '<application id=' repo/index.xml > /dev/null
459 test -e repo/index.xml
460 test -e repo/index.jar
461 test -e repo/index-v1.jar
462 export ANDROID_HOME=$STORED_ANDROID_HOME
463
464
465 #------------------------------------------------------------------------------#
466 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
467
468 REPOROOT=`create_test_dir`
469 cd $REPOROOT
470 mkdir repo
471 copy_apks_into_repo $REPOROOT
472 $fdroid init
473 $fdroid update --create-metadata --verbose
474 $fdroid readmeta
475 grep -F '<application id=' repo/index.xml > /dev/null
476
477
478 #------------------------------------------------------------------------------#
479 echo_header "setup a new repo from scratch and generate a keystore"
480
481 REPOROOT=`create_test_dir`
482 KEYSTORE=$REPOROOT/keystore.jks
483 cd $REPOROOT
484 $fdroid init --keystore $KEYSTORE
485 test -e $KEYSTORE
486 copy_apks_into_repo $REPOROOT
487 $fdroid update --create-metadata --verbose
488 $fdroid readmeta
489 test -e repo/index.xml
490 test -e repo/index.jar
491 test -e repo/index-v1.jar
492 grep -F '<application id=' repo/index.xml > /dev/null
493
494
495 #------------------------------------------------------------------------------#
496 echo_header "setup a new repo manually and generate a keystore"
497
498 REPOROOT=`create_test_dir`
499 KEYSTORE=$REPOROOT/keystore.jks
500 cd $REPOROOT
501 touch config.py
502 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
503 ! test -e $KEYSTORE
504 set +e
505 $fdroid update
506 if [ $? -eq 0 ]; then
507     echo "This should have failed because this repo has no keystore!"
508     exit 1
509 else
510     echo '`fdroid update` prompted to add keystore'
511 fi
512 set -e
513 $fdroid update --create-key
514 test -e $KEYSTORE
515 copy_apks_into_repo $REPOROOT
516 $fdroid update --create-metadata --verbose
517 $fdroid readmeta
518 test -e repo/index.xml
519 test -e repo/index.jar
520 test -e repo/index-v1.jar
521 grep -F '<application id=' repo/index.xml > /dev/null
522
523
524 #------------------------------------------------------------------------------#
525 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
526
527 REPOROOT=`create_test_dir`
528 KEYSTORE=$REPOROOT/keystore.jks
529 cd $REPOROOT
530 $fdroid init --keystore $KEYSTORE
531 test -e $KEYSTORE
532 copy_apks_into_repo $REPOROOT
533 $fdroid update --create-metadata --verbose
534 $fdroid readmeta
535 test -e repo/index.xml
536 test -e repo/index.jar
537 test -e repo/index-v1.jar
538 grep -F '<application id=' repo/index.xml > /dev/null
539 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
540     cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
541 $fdroid update --create-metadata --verbose
542 $fdroid readmeta
543 test -e repo/index.xml
544 test -e repo/index.jar
545 test -e repo/index-v1.jar
546 grep -F '<application id=' repo/index.xml > /dev/null
547
548
549 #------------------------------------------------------------------------------#
550 echo_header "setup a new repo from scratch with a HSM/smartcard"
551 REPOROOT=`create_test_dir`
552 cd $REPOROOT
553 $fdroid init --keystore NONE
554 test -e opensc-fdroid.cfg
555 test ! -e NONE
556
557
558 #------------------------------------------------------------------------------#
559 echo_header "setup a new repo with no keystore, add APK, and update"
560
561 REPOROOT=`create_test_dir`
562 KEYSTORE=$REPOROOT/keystore.jks
563 cd $REPOROOT
564 touch config.py
565 touch fdroid-icon.png
566 mkdir repo
567 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
568 set +e
569 $fdroid update --create-metadata --verbose
570 if [ $? -eq 0 ]; then
571     echo "This should have failed because this repo has no keystore!"
572     exit 1
573 else
574     echo '`fdroid update` prompted to add keystore'
575 fi
576 set -e
577
578 # now set up fake, non-working keystore setup
579 touch $KEYSTORE
580 echo "keystore = \"$KEYSTORE\"" >> config.py
581 echo 'repo_keyalias = "foo"' >> config.py
582 echo 'keystorepass = "foo"' >> config.py
583 echo 'keypass = "foo"' >> config.py
584 set +e
585 $fdroid update --create-metadata --verbose
586 if [ $? -eq 0 ]; then
587     echo "This should have failed because this repo has a bad/fake keystore!"
588     exit 1
589 else
590     echo '`fdroid update` prompted to add keystore'
591 fi
592 set -e
593
594
595 #------------------------------------------------------------------------------#
596 echo_header "copy tests/repo, update with binary transparency log"
597
598 REPOROOT=`create_test_dir`
599 GIT_REMOTE=`create_test_dir`
600 GNUPGHOME=$REPOROOT/gnupghome
601 KEYSTORE=$WORKSPACE/tests/keystore.jks
602 cd $REPOROOT
603 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
604 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
605 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
606 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
607 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
608 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
609 $fdroid update --verbose
610 if have_git_2_3; then
611     $fdroid server update --verbose
612     test -e repo/index.xml
613     test -e repo/index.jar
614     test -e repo/index-v1.jar
615     grep -F '<application id=' repo/index.xml > /dev/null
616     cd binary_transparency
617     [ `git rev-list --count HEAD` == "2" ]
618     cd $GIT_REMOTE
619     [ `git rev-list --count HEAD` == "2" ]
620 else
621     echo "Skipping test, `git --version` older than 2.3"
622 fi
623
624
625 #------------------------------------------------------------------------------#
626 echo_header "setup a new repo with keystore with APK, update, then without key"
627
628 REPOROOT=`create_test_dir`
629 KEYSTORE=$REPOROOT/keystore.jks
630 cd $REPOROOT
631 $fdroid init --keystore $KEYSTORE
632 test -e $KEYSTORE
633 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
634 $fdroid update --create-metadata --verbose
635 $fdroid readmeta
636 test -e repo/index.xml
637 test -e repo/index.jar
638 test -e repo/index-v1.jar
639 grep -F '<application id=' repo/index.xml > /dev/null
640
641 # now set fake repo_keyalias
642 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
643 set +e
644 $fdroid update
645 if [ $? -eq 0 ]; then
646     echo "This should have failed because this repo has a bad repo_keyalias!"
647     exit 1
648 else
649     echo '`fdroid update` prompted to add keystore'
650 fi
651 set -e
652
653 # try creating a new keystore, but fail because the old one is there
654 test -e $KEYSTORE
655 set +e
656 $fdroid update --create-key
657 if [ $? -eq 0 ]; then
658     echo "This should have failed because a keystore is already there!"
659     exit 1
660 else
661     echo '`fdroid update` complained about existing keystore'
662 fi
663 set -e
664
665 # now actually create the key with the existing settings
666 rm -f $KEYSTORE
667 ! test -e $KEYSTORE
668 $fdroid update --create-key
669 test -e $KEYSTORE
670
671
672 #------------------------------------------------------------------------------#
673 echo_header "sign binary repo in offline box, then publishing from online box"
674
675 OFFLINE_ROOT=`create_test_dir`
676 KEYSTORE=$WORKSPACE/tests/keystore.jks
677 LOCAL_COPY_DIR=`create_test_dir`/fdroid
678 mkdir $LOCAL_COPY_DIR
679 ONLINE_ROOT=`create_test_dir`
680 SERVERWEBROOT=`create_test_dir`
681
682 # create offline binary transparency log
683 cd $OFFLINE_ROOT
684 mkdir binary_transparency
685 cd binary_transparency
686 git init
687
688 # fake git remote server for binary transparency log
689 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
690
691 # fake git remote server for repo mirror
692 SERVER_GIT_MIRROR=`create_test_dir`
693 cd $SERVER_GIT_MIRROR
694 git init
695 if have_git_2_3; then
696     git config receive.denyCurrentBranch updateInstead
697 fi
698
699 cd $OFFLINE_ROOT
700 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
701 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
702
703 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
704 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
705 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
706 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
707 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
708 $fdroid update --verbose
709 grep -F '<application id=' repo/index.xml > /dev/null
710 cd binary_transparency
711 [ `git rev-list --count HEAD` == "1" ]
712 cd ..
713 if have_git_2_3; then
714     $fdroid server update --verbose
715     grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
716     cd $ONLINE_ROOT
717     echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
718     echo "sync_from_local_copy_dir = True" >> config.py
719     echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
720     echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
721     echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
722     echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
723     $fdroid server update --verbose
724     cd $BINARY_TRANSPARENCY_REMOTE
725     [ `git rev-list --count HEAD` == "1" ]
726     cd $SERVER_GIT_MIRROR
727     [ `git rev-list --count HEAD` == "1" ]
728 else
729     echo "Skipping test, `git --version` older than 2.3"
730 fi
731
732
733 #------------------------------------------------------------------------------#
734
735 # remove this to prevent git conflicts and complaining
736 rm -rf $WORKSPACE/fdroidserver.egg-info/
737
738 echo SUCCESS