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