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