chiark / gitweb /
allow APKs with same packageName/versionCode but different signer
[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 echo_header 'copy git import and run `fdroid scanner` on it'
183
184 REPOROOT=`create_test_dir`
185 cd $REPOROOT
186 touch config.py
187 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
188 mkdir metadata
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
198 mkdir build
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
202
203
204 #------------------------------------------------------------------------------#
205 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
206
207 REPOROOT=`create_test_dir`
208 GNUPGHOME=$REPOROOT/gnupghome
209 KEYSTORE=$WORKSPACE/tests/keystore.jks
210 cd $REPOROOT
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
237
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 $WORKSPACE/tests/repo/index.xml repo/index.xml
241
242 #------------------------------------------------------------------------------#
243 echo_header "test metadata checks"
244
245 REPOROOT=`create_test_dir`
246 cd $REPOROOT
247
248 touch config.py
249 mkdir repo
250 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
251
252 set +e
253 $fdroid build
254 if [ $? -eq 0 ]; then
255     echo "This should have failed because there is no metadata!"
256     exit 1
257 else
258     echo "testing metadata checks passed"
259 fi
260 set -e
261
262 mkdir $REPOROOT/metadata/
263 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
264 $fdroid readmeta
265
266 # now make a fake duplicate
267 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
268
269 set +e
270 $fdroid readmeta
271 if [ $? -eq 0 ]; then
272     echo "This should have failed because there is a duplicate metadata file!"
273     exit 1
274 else
275     echo "testing duplicate metadata checks passed"
276 fi
277 set -e
278
279
280 #------------------------------------------------------------------------------#
281 echo_header "ensure commands that don't need the JDK work without a JDK configed"
282
283 REPOROOT=`create_test_dir`
284 cd $REPOROOT
285 mkdir repo
286 mkdir metadata
287 echo "License:GPL-2.0" >> metadata/fake.txt
288 echo "Summary:Yup still fake" >> metadata/fake.txt
289 echo "Categories:Internet" >> metadata/fake.txt
290 echo "Description:" >> metadata/fake.txt
291 echo "this is fake" >> metadata/fake.txt
292 echo "." >> metadata/fake.txt
293
294 # fake that no JDKs are available
295 echo 'java_paths = {}' > config.py
296
297 LOCAL_COPY_DIR=`create_test_dir`/fdroid
298 mkdir -p $LOCAL_COPY_DIR/repo
299 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
300
301 $fdroid checkupdates
302 $fdroid gpgsign
303 $fdroid lint
304 $fdroid readmeta
305 $fdroid rewritemeta fake
306 $fdroid server update
307 $fdroid scanner
308
309 # run these to get their output, but the are not setup, so don't fail
310 $fdroid build || true
311 $fdroid import || true
312 $fdroid install || true
313
314
315 #------------------------------------------------------------------------------#
316 echo_header "create a source tarball and use that to build a repo"
317
318 cd $WORKSPACE
319 $python setup.py sdist
320
321 REPOROOT=`create_test_dir`
322 cd $REPOROOT
323 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
324 cd $REPOROOT
325 ./fdroidserver-*/fdroid init
326 copy_apks_into_repo $REPOROOT
327 ./fdroidserver-*/fdroid update --create-metadata --verbose
328
329
330 #------------------------------------------------------------------------------#
331 echo_header "test config checks of local_copy_dir"
332
333 REPOROOT=`create_test_dir`
334 cd $REPOROOT
335 $fdroid init
336 $fdroid update --create-metadata --verbose
337 $fdroid readmeta
338 $fdroid server update --local-copy-dir=/tmp/fdroid
339
340 # now test the errors work
341 set +e
342 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
343 if [ $? -eq 0 ]; then
344     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
345     exit 1
346 else
347     echo "testing absolute path checker passed"
348 fi
349 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
350 if [ $? -eq 0 ]; then
351     echo "This should have failed because the path does not end with 'fdroid'!"
352     exit 1
353 else
354     echo "testing dirname exists checker passed"
355 fi
356 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
357 if [ $? -eq 0 ]; then
358     echo "This should have failed because the dirname path does not exist!"
359     exit 1
360 else
361     echo "testing dirname exists checker passed"
362 fi
363 set -e
364
365
366 #------------------------------------------------------------------------------#
367 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
368
369 REPOROOT=`create_test_dir`
370 cd $REPOROOT
371 $fdroid init
372 copy_apks_into_repo $REPOROOT
373 $fdroid update --create-metadata --verbose
374 $fdroid readmeta
375 grep -F '<application id=' repo/index.xml > /dev/null
376
377 LOCALCOPYDIR=`create_test_dir`/fdroid
378 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
379 NEWREPOROOT=`create_test_dir`
380 cd $NEWREPOROOT
381 $fdroid init
382 echo "sync_from_local_copy_dir = True" >> config.py
383 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
384
385
386 #------------------------------------------------------------------------------#
387 # check that --android-home fails when dir does not exist or is not a dir
388
389 REPOROOT=`create_test_dir`
390 KEYSTORE=$REPOROOT/keystore.jks
391 cd $REPOROOT
392 set +e
393 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
394 if [ $? -eq 0 ]; then
395     echo "This should have failed because /opt/fakeandroidhome does not exist!"
396     exit 1
397 else
398     echo "testing android-home path checker passed"
399 fi
400 TESTFILE=`create_test_file`
401 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
402 if [ $? -eq 0 ]; then
403     echo "This should have failed because $TESTFILE is a file not a dir!"
404     exit 1
405 else
406     echo "testing android-home not-dir checker passed"
407 fi
408 set -e
409
410
411 #------------------------------------------------------------------------------#
412 echo_header "check that fake android home passes 'fdroid init'"
413
414 REPOROOT=`create_test_dir`
415 FAKE_ANDROID_HOME=`create_test_dir`
416 create_fake_android_home $FAKE_ANDROID_HOME
417 KEYSTORE=$REPOROOT/keystore.jks
418 cd $REPOROOT
419 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
420
421
422 #------------------------------------------------------------------------------#
423 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
424
425 if [ -e /usr/bin/aapt ]; then
426     echo "/usr/bin/aapt exists, not running test"
427 else
428     REPOROOT=`create_test_dir`
429     FAKE_ANDROID_HOME=`create_test_dir`
430     create_fake_android_home $FAKE_ANDROID_HOME
431     rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
432     KEYSTORE=$REPOROOT/keystore.jks
433     cd $REPOROOT
434     set +e
435     $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
436     [ $? -eq 0 ] && exit 1
437     set -e
438 fi
439
440
441 #------------------------------------------------------------------------------#
442 echo_header "check that --android-home overrides ANDROID_HOME"
443
444 REPOROOT=`create_test_dir`
445 FAKE_ANDROID_HOME=`create_test_dir`
446 create_fake_android_home $FAKE_ANDROID_HOME
447 KEYSTORE=$REPOROOT/keystore.jks
448 cd $REPOROOT
449 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
450 set +e
451 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
452 if [ $? -ne 0 ]; then
453     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
454     exit 1
455 fi
456 set -e
457
458
459 #------------------------------------------------------------------------------#
460 # In this case, ANDROID_HOME is set to a fake, non-working version that will
461 # be detected by fdroid as an Android SDK install.  It should use the path set
462 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
463 # in ANDROID_HOME, it won't work because it is a fake one.  Only
464 # --android-home provides a working one.
465 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
466
467 REPOROOT=`create_test_dir`
468 KEYSTORE=$REPOROOT/keystore.jks
469 FAKE_ANDROID_HOME=`create_test_dir`
470 create_fake_android_home $FAKE_ANDROID_HOME
471 STORED_ANDROID_HOME=$ANDROID_HOME
472 unset ANDROID_HOME
473 echo "ANDROID_HOME: $ANDROID_HOME"
474 cd $REPOROOT
475 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
476 test -e $KEYSTORE
477 copy_apks_into_repo $REPOROOT
478 $fdroid update --create-metadata --verbose
479 $fdroid readmeta
480 grep -F '<application id=' repo/index.xml > /dev/null
481 test -e repo/index.xml
482 test -e repo/index.jar
483 test -e repo/index-v1.jar
484 export ANDROID_HOME=$STORED_ANDROID_HOME
485
486
487 #------------------------------------------------------------------------------#
488 echo_header "check duplicate files are properly handled by fdroid update"
489
490 REPOROOT=`create_test_dir`
491 KEYSTORE=$WORKSPACE/tests/keystore.jks
492 cd $REPOROOT
493 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
494 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
495 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
496 mkdir $REPOROOT/metadata
497 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
498 echo "accepted_formats = ['txt']" >> config.py
499 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/
500 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619_another-release-key.apk $REPOROOT/repo/
501 $fdroid update --pretty
502 grep -F 'obb.mainpatch.current_1619.apk' repo/index.xml
503 grep -F 'obb.mainpatch.current_1619_another-release-key.apk' repo/index.xml
504 # die if there are exact duplicates
505 cp $WORKSPACE/tests/repo/obb.mainpatch.current_1619.apk $REPOROOT/repo/duplicate.apk
506 ! $fdroid update
507
508
509 #------------------------------------------------------------------------------#
510 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
511
512 REPOROOT=`create_test_dir`
513 cd $REPOROOT
514 mkdir repo
515 copy_apks_into_repo $REPOROOT
516 $fdroid init
517 $fdroid update --create-metadata --verbose
518 $fdroid readmeta
519 grep -F '<application id=' repo/index.xml > /dev/null
520
521
522 #------------------------------------------------------------------------------#
523 echo_header "setup a new repo from scratch and generate a keystore"
524
525 REPOROOT=`create_test_dir`
526 KEYSTORE=$REPOROOT/keystore.jks
527 cd $REPOROOT
528 $fdroid init --keystore $KEYSTORE
529 test -e $KEYSTORE
530 copy_apks_into_repo $REPOROOT
531 $fdroid update --create-metadata --verbose
532 $fdroid readmeta
533 test -e repo/index.xml
534 test -e repo/index.jar
535 test -e repo/index-v1.jar
536 grep -F '<application id=' repo/index.xml > /dev/null
537
538
539 #------------------------------------------------------------------------------#
540 echo_header "setup a new repo manually and generate a keystore"
541
542 REPOROOT=`create_test_dir`
543 KEYSTORE=$REPOROOT/keystore.jks
544 cd $REPOROOT
545 touch config.py
546 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
547 ! test -e $KEYSTORE
548 set +e
549 $fdroid update
550 if [ $? -eq 0 ]; then
551     echo "This should have failed because this repo has no keystore!"
552     exit 1
553 else
554     echo '`fdroid update` prompted to add keystore'
555 fi
556 set -e
557 $fdroid update --create-key
558 test -e $KEYSTORE
559 copy_apks_into_repo $REPOROOT
560 $fdroid update --create-metadata --verbose
561 $fdroid readmeta
562 test -e repo/index.xml
563 test -e repo/index.jar
564 test -e repo/index-v1.jar
565 grep -F '<application id=' repo/index.xml > /dev/null
566
567
568 #------------------------------------------------------------------------------#
569 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
570
571 REPOROOT=`create_test_dir`
572 KEYSTORE=$REPOROOT/keystore.jks
573 cd $REPOROOT
574 $fdroid init --keystore $KEYSTORE
575 test -e $KEYSTORE
576 copy_apks_into_repo $REPOROOT
577 $fdroid update --create-metadata --verbose
578 $fdroid readmeta
579 test -e repo/index.xml
580 test -e repo/index.jar
581 test -e repo/index-v1.jar
582 grep -F '<application id=' repo/index.xml > /dev/null
583 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
584     cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
585 $fdroid update --create-metadata --verbose
586 $fdroid readmeta
587 test -e repo/index.xml
588 test -e repo/index.jar
589 test -e repo/index-v1.jar
590 grep -F '<application id=' repo/index.xml > /dev/null
591
592
593 #------------------------------------------------------------------------------#
594 echo_header "setup a new repo from scratch with a HSM/smartcard"
595 REPOROOT=`create_test_dir`
596 cd $REPOROOT
597 $fdroid init --keystore NONE
598 test -e opensc-fdroid.cfg
599 test ! -e NONE
600
601
602 #------------------------------------------------------------------------------#
603 echo_header "setup a new repo with no keystore, add APK, and update"
604
605 REPOROOT=`create_test_dir`
606 KEYSTORE=$REPOROOT/keystore.jks
607 cd $REPOROOT
608 touch config.py
609 touch fdroid-icon.png
610 mkdir repo
611 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
612 set +e
613 $fdroid update --create-metadata --verbose
614 if [ $? -eq 0 ]; then
615     echo "This should have failed because this repo has no keystore!"
616     exit 1
617 else
618     echo '`fdroid update` prompted to add keystore'
619 fi
620 set -e
621
622 # now set up fake, non-working keystore setup
623 touch $KEYSTORE
624 echo "keystore = \"$KEYSTORE\"" >> config.py
625 echo 'repo_keyalias = "foo"' >> config.py
626 echo 'keystorepass = "foo"' >> config.py
627 echo 'keypass = "foo"' >> config.py
628 set +e
629 $fdroid update --create-metadata --verbose
630 if [ $? -eq 0 ]; then
631     echo "This should have failed because this repo has a bad/fake keystore!"
632     exit 1
633 else
634     echo '`fdroid update` prompted to add keystore'
635 fi
636 set -e
637
638
639 #------------------------------------------------------------------------------#
640 echo_header "copy tests/repo, update with binary transparency log"
641
642 REPOROOT=`create_test_dir`
643 GIT_REMOTE=`create_test_dir`
644 GNUPGHOME=$REPOROOT/gnupghome
645 KEYSTORE=$WORKSPACE/tests/keystore.jks
646 cd $REPOROOT
647 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
648 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
649 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
650 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
651 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
652 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
653 $fdroid update --verbose
654 if have_git_2_3; then
655     $fdroid server update --verbose
656     test -e repo/index.xml
657     test -e repo/index.jar
658     test -e repo/index-v1.jar
659     grep -F '<application id=' repo/index.xml > /dev/null
660     cd binary_transparency
661     [ `git rev-list --count HEAD` == "2" ]
662     cd $GIT_REMOTE
663     [ `git rev-list --count HEAD` == "2" ]
664 else
665     echo "Skipping test, `git --version` older than 2.3"
666 fi
667
668
669 #------------------------------------------------------------------------------#
670 echo_header "setup a new repo with keystore with APK, update, then without key"
671
672 REPOROOT=`create_test_dir`
673 KEYSTORE=$REPOROOT/keystore.jks
674 cd $REPOROOT
675 $fdroid init --keystore $KEYSTORE
676 test -e $KEYSTORE
677 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
678 $fdroid update --create-metadata --verbose
679 $fdroid readmeta
680 test -e repo/index.xml
681 test -e repo/index.jar
682 test -e repo/index-v1.jar
683 grep -F '<application id=' repo/index.xml > /dev/null
684
685 # now set fake repo_keyalias
686 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
687 set +e
688 $fdroid update
689 if [ $? -eq 0 ]; then
690     echo "This should have failed because this repo has a bad repo_keyalias!"
691     exit 1
692 else
693     echo '`fdroid update` prompted to add keystore'
694 fi
695 set -e
696
697 # try creating a new keystore, but fail because the old one is there
698 test -e $KEYSTORE
699 set +e
700 $fdroid update --create-key
701 if [ $? -eq 0 ]; then
702     echo "This should have failed because a keystore is already there!"
703     exit 1
704 else
705     echo '`fdroid update` complained about existing keystore'
706 fi
707 set -e
708
709 # now actually create the key with the existing settings
710 rm -f $KEYSTORE
711 ! test -e $KEYSTORE
712 $fdroid update --create-key
713 test -e $KEYSTORE
714
715
716 #------------------------------------------------------------------------------#
717 echo_header "sign binary repo in offline box, then publishing from online box"
718
719 OFFLINE_ROOT=`create_test_dir`
720 KEYSTORE=$WORKSPACE/tests/keystore.jks
721 LOCAL_COPY_DIR=`create_test_dir`/fdroid
722 mkdir $LOCAL_COPY_DIR
723 ONLINE_ROOT=`create_test_dir`
724 SERVERWEBROOT=`create_test_dir`
725
726 # create offline binary transparency log
727 cd $OFFLINE_ROOT
728 mkdir binary_transparency
729 cd binary_transparency
730 git init
731
732 # fake git remote server for binary transparency log
733 BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
734
735 # fake git remote server for repo mirror
736 SERVER_GIT_MIRROR=`create_test_dir`
737 cd $SERVER_GIT_MIRROR
738 git init
739 if have_git_2_3; then
740     git config receive.denyCurrentBranch updateInstead
741 fi
742
743 cd $OFFLINE_ROOT
744 $fdroid init --keystore $KEYSTORE --repo-keyalias=sova
745 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
746
747 echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
748 echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
749 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
750 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
751 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
752 $fdroid update --verbose
753 grep -F '<application id=' repo/index.xml > /dev/null
754 cd binary_transparency
755 [ `git rev-list --count HEAD` == "1" ]
756 cd ..
757 if have_git_2_3; then
758     $fdroid server update --verbose
759     grep -F '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
760     cd $ONLINE_ROOT
761     echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
762     echo "sync_from_local_copy_dir = True" >> config.py
763     echo "serverwebroots = '$SERVERWEBROOT'" >> config.py
764     echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
765     echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
766     echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py
767     $fdroid server update --verbose
768     cd $BINARY_TRANSPARENCY_REMOTE
769     [ `git rev-list --count HEAD` == "1" ]
770     cd $SERVER_GIT_MIRROR
771     [ `git rev-list --count HEAD` == "1" ]
772 else
773     echo "Skipping test, `git --version` older than 2.3"
774 fi
775
776
777 #------------------------------------------------------------------------------#
778
779 # remove this to prevent git conflicts and complaining
780 rm -rf $WORKSPACE/fdroidserver.egg-info/
781
782 echo SUCCESS