chiark / gitweb /
remove support for XML app metadata, its broken
[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 #------------------------------------------------------------------------------#
45 # "main"
46
47 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
48     set +x
49     echo "Usage: $0 '/path/to/folder/with/apks'"
50     exit 1
51 fi
52
53 if [ -z "$ANDROID_HOME" ]; then
54     echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
55     echo "  export ANDROID_HOME=/opt/android-sdk"
56     exit 1
57 fi
58
59 if [ -d tests ]; then
60     cd tests
61 fi
62
63 if [ -z "$1" ]; then
64     APKDIR=`pwd`
65 else
66     APKDIR=$1
67 fi
68
69 if [ -z $WORKSPACE ]; then
70     WORKSPACE=`dirname $(pwd)`
71     echo "Setting Workspace to $WORKSPACE"
72 fi
73
74 # allow the location of the script to be overridden
75 if [ -z $fdroid ]; then
76     fdroid="$WORKSPACE/fdroid"
77 fi
78
79 # allow the location of aapt to be overridden
80 if [ -z $aapt ]; then
81     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
82 fi
83
84 # allow the location of python to be overridden
85 if [ -z $python ]; then
86     python=python3
87 fi
88
89 set -x # show each command as it is executed
90
91 #------------------------------------------------------------------------------#
92 echo_header "run commit hooks"
93
94 cd $WORKSPACE
95 ./hooks/pre-commit
96
97
98 #------------------------------------------------------------------------------#
99 echo_header "test python getsig replacement"
100
101 cd $WORKSPACE/tests/getsig
102 ./make.sh
103
104 cd $WORKSPACE/tests
105 for testcase in $WORKSPACE/tests/*.TestCase; do
106     $testcase
107 done
108
109
110 #------------------------------------------------------------------------------#
111 echo_header "print fdroid version"
112
113 $fdroid --version
114
115
116 #------------------------------------------------------------------------------#
117 echo_header "build the TeX manual"
118
119 cd $WORKSPACE/docs
120 # this is only ever generated officially on GNU/Linux
121 if [ `uname -s` == "Linux" ]; then
122     ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
123 fi
124
125
126 #------------------------------------------------------------------------------#
127 echo_header "test UTF-8 metadata"
128
129 REPOROOT=`create_test_dir`
130 cd $REPOROOT
131
132 $fdroid init
133 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
134 echo "mirrors = {'https://foo.bar/fdroid', 'http://secret.onion/fdroid'}" >> config.py
135 mkdir metadata
136 cp $WORKSPACE/tests/urzip.apk repo/
137 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.txt metadata/
138
139 $fdroid readmeta
140 $fdroid update
141
142
143 #------------------------------------------------------------------------------#
144 echo_header 'run `fdroid build` in fresh git checkout from import.TestCase'
145
146 cd $WORKSPACE/tests/tmp/importer
147 if [ -d $ANDROID_HOME/platforms/android-23 ]; then
148     echo "build_tools = '`ls -1 $ANDROID_HOME/build-tools/ | sort -n | tail -1`'" > config.py
149     echo "force_build_tools = True" >> config.py
150     $fdroid build --verbose org.fdroid.ci.test.app:300
151 else
152     echo 'WARNING: Skipping `fdroid build` test since android-23 is missing!'
153 fi
154
155
156 #------------------------------------------------------------------------------#
157 echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
158
159 REPOROOT=`create_test_dir`
160 GNUPGHOME=$REPOROOT/gnupghome
161 cd $REPOROOT
162 $fdroid init
163 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $REPOROOT/
164 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
165 chmod 0700 $GNUPGHOME
166 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
167 echo "install_list = 'org.adaway'" >> config.py
168 echo "uninstall_list = {'com.android.vending', 'com.facebook.orca',}" >> config.py
169 echo "gpghome = '$GNUPGHOME'" >> config.py
170 echo "gpgkey = 'CE71F7FB'" >> config.py
171 $fdroid update --verbose
172 test -e repo/index.xml
173 test -e repo/index.jar
174 grep -F '<application id=' repo/index.xml > /dev/null
175 grep -F '<install packageName=' repo/index.xml > /dev/null
176 grep -F '<uninstall packageName=' repo/index.xml > /dev/null
177 $fdroid gpgsign --verbose
178 $fdroid gpgsign --verbose
179 test -e repo/obb.mainpatch.current_1619.apk.asc
180 test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc
181 ! test -e repo/obb.mainpatch.current_1619.apk.asc.asc
182 ! test -e repo/obb.main.twoversions_1101617_src.tar.gz.asc.asc
183 ! test -e repo/index.xml.asc
184
185
186 #------------------------------------------------------------------------------#
187 echo_header "test metadata checks"
188
189 REPOROOT=`create_test_dir`
190 cd $REPOROOT
191
192 touch config.py
193 mkdir repo
194 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
195
196 set +e
197 $fdroid build
198 if [ $? -eq 0 ]; then
199     echo "This should have failed because there is no metadata!"
200     exit 1
201 else
202     echo "testing metadata checks passed"
203 fi
204 set -e
205
206 mkdir $REPOROOT/metadata/
207 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
208 $fdroid readmeta
209
210 # now make a fake duplicate
211 touch $REPOROOT/metadata/org.smssecure.smssecure.yml
212
213 set +e
214 $fdroid readmeta
215 if [ $? -eq 0 ]; then
216     echo "This should have failed because there is a duplicate metadata file!"
217     exit 1
218 else
219     echo "testing duplicate metadata checks passed"
220 fi
221 set -e
222
223
224 #------------------------------------------------------------------------------#
225 echo_header "ensure commands that don't need the JDK work without a JDK configed"
226
227 REPOROOT=`create_test_dir`
228 cd $REPOROOT
229 mkdir repo
230 mkdir metadata
231 echo "License:GPL" >> metadata/fake.txt
232 echo "Summary:Yup still fake" >> metadata/fake.txt
233 echo "Categories:Internet" >> metadata/fake.txt
234 echo "Description:" >> metadata/fake.txt
235 echo "this is fake" >> metadata/fake.txt
236 echo "." >> metadata/fake.txt
237
238 # fake that no JDKs are available
239 echo 'java_paths = {}' > config.py
240
241 LOCAL_COPY_DIR=`create_test_dir`/fdroid
242 mkdir -p $LOCAL_COPY_DIR/repo
243 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
244
245 $fdroid checkupdates
246 $fdroid gpgsign
247 $fdroid lint
248 $fdroid readmeta
249 $fdroid rewritemeta fake
250 $fdroid server update
251 $fdroid scanner
252
253 # run these to get their output, but the are not setup, so don't fail
254 $fdroid build || true
255 $fdroid import || true
256 $fdroid install || true
257
258
259 #------------------------------------------------------------------------------#
260 echo_header "create a source tarball and use that to build a repo"
261
262 cd $WORKSPACE
263 $python setup.py sdist
264
265 REPOROOT=`create_test_dir`
266 cd $REPOROOT
267 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
268 cd $REPOROOT
269 ./fdroidserver-*/fdroid init
270 copy_apks_into_repo $REPOROOT
271 ./fdroidserver-*/fdroid update --create-metadata --verbose
272
273
274 #------------------------------------------------------------------------------#
275 echo_header "test config checks of local_copy_dir"
276
277 REPOROOT=`create_test_dir`
278 cd $REPOROOT
279 $fdroid init
280 $fdroid update --create-metadata --verbose
281 $fdroid readmeta
282 $fdroid server update --local-copy-dir=/tmp/fdroid
283
284 # now test the errors work
285 set +e
286 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
287 if [ $? -eq 0 ]; then
288     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
289     exit 1
290 else
291     echo "testing absolute path checker passed"
292 fi
293 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
294 if [ $? -eq 0 ]; then
295     echo "This should have failed because the path does not end with 'fdroid'!"
296     exit 1
297 else
298     echo "testing dirname exists checker passed"
299 fi
300 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
301 if [ $? -eq 0 ]; then
302     echo "This should have failed because the dirname path does not exist!"
303     exit 1
304 else
305     echo "testing dirname exists checker passed"
306 fi
307 set -e
308
309
310 #------------------------------------------------------------------------------#
311 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
312
313 REPOROOT=`create_test_dir`
314 cd $REPOROOT
315 $fdroid init
316 copy_apks_into_repo $REPOROOT
317 $fdroid update --create-metadata --verbose
318 $fdroid readmeta
319 grep -F '<application id=' repo/index.xml > /dev/null
320
321 LOCALCOPYDIR=`create_test_dir`/fdroid
322 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
323 NEWREPOROOT=`create_test_dir`
324 cd $NEWREPOROOT
325 $fdroid init
326 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
327
328
329 #------------------------------------------------------------------------------#
330 # check that --android-home fails when dir does not exist or is not a dir
331
332 REPOROOT=`create_test_dir`
333 KEYSTORE=$REPOROOT/keystore.jks
334 cd $REPOROOT
335 set +e
336 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
337 if [ $? -eq 0 ]; then
338     echo "This should have failed because /opt/fakeandroidhome does not exist!"
339     exit 1
340 else
341     echo "testing android-home path checker passed"
342 fi
343 TESTFILE=`create_test_file`
344 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
345 if [ $? -eq 0 ]; then
346     echo "This should have failed because $TESTFILE is a file not a dir!"
347     exit 1
348 else
349     echo "testing android-home not-dir checker passed"
350 fi
351 set -e
352
353
354 #------------------------------------------------------------------------------#
355 echo_header "check that fake android home passes 'fdroid init'"
356
357 REPOROOT=`create_test_dir`
358 FAKE_ANDROID_HOME=`create_test_dir`
359 create_fake_android_home $FAKE_ANDROID_HOME
360 KEYSTORE=$REPOROOT/keystore.jks
361 cd $REPOROOT
362 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
363
364
365 #------------------------------------------------------------------------------#
366 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
367
368 if [ -e /usr/bin/aapt ]; then
369     echo "/usr/bin/aapt exists, not running test"
370 else
371     REPOROOT=`create_test_dir`
372     FAKE_ANDROID_HOME=`create_test_dir`
373     create_fake_android_home $FAKE_ANDROID_HOME
374     rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
375     KEYSTORE=$REPOROOT/keystore.jks
376     cd $REPOROOT
377     set +e
378     $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
379     [ $? -eq 0 ] && exit 1
380     set -e
381 fi
382
383
384 #------------------------------------------------------------------------------#
385 echo_header "check that --android-home overrides ANDROID_HOME"
386
387 REPOROOT=`create_test_dir`
388 FAKE_ANDROID_HOME=`create_test_dir`
389 create_fake_android_home $FAKE_ANDROID_HOME
390 KEYSTORE=$REPOROOT/keystore.jks
391 cd $REPOROOT
392 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
393 set +e
394 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
395 if [ $? -ne 0 ]; then
396     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
397     exit 1
398 fi
399 set -e
400
401
402 #------------------------------------------------------------------------------#
403 # In this case, ANDROID_HOME is set to a fake, non-working version that will
404 # be detected by fdroid as an Android SDK install.  It should use the path set
405 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
406 # in ANDROID_HOME, it won't work because it is a fake one.  Only
407 # --android-home provides a working one.
408 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
409
410 REPOROOT=`create_test_dir`
411 KEYSTORE=$REPOROOT/keystore.jks
412 FAKE_ANDROID_HOME=`create_test_dir`
413 create_fake_android_home $FAKE_ANDROID_HOME
414 STORED_ANDROID_HOME=$ANDROID_HOME
415 unset ANDROID_HOME
416 echo "ANDROID_HOME: $ANDROID_HOME"
417 cd $REPOROOT
418 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
419 test -e $KEYSTORE
420 copy_apks_into_repo $REPOROOT
421 $fdroid update --create-metadata --verbose
422 $fdroid readmeta
423 grep -F '<application id=' repo/index.xml > /dev/null
424 test -e repo/index.xml
425 test -e repo/index.jar
426 export ANDROID_HOME=$STORED_ANDROID_HOME
427
428
429 #------------------------------------------------------------------------------#
430 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
431
432 REPOROOT=`create_test_dir`
433 cd $REPOROOT
434 mkdir repo
435 copy_apks_into_repo $REPOROOT
436 $fdroid init
437 $fdroid update --create-metadata --verbose
438 $fdroid readmeta
439 grep -F '<application id=' repo/index.xml > /dev/null
440
441
442 #------------------------------------------------------------------------------#
443 echo_header "setup a new repo from scratch and generate a keystore"
444
445 REPOROOT=`create_test_dir`
446 KEYSTORE=$REPOROOT/keystore.jks
447 cd $REPOROOT
448 $fdroid init --keystore $KEYSTORE
449 test -e $KEYSTORE
450 copy_apks_into_repo $REPOROOT
451 $fdroid update --create-metadata --verbose
452 $fdroid readmeta
453 test -e repo/index.xml
454 test -e repo/index.jar
455 grep -F '<application id=' repo/index.xml > /dev/null
456
457
458 #------------------------------------------------------------------------------#
459 echo_header "setup a new repo manually and generate a keystore"
460
461 REPOROOT=`create_test_dir`
462 KEYSTORE=$REPOROOT/keystore.jks
463 cd $REPOROOT
464 touch config.py
465 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
466 ! test -e $KEYSTORE
467 set +e
468 $fdroid update
469 if [ $? -eq 0 ]; then
470     echo "This should have failed because this repo has no keystore!"
471     exit 1
472 else
473     echo '`fdroid update` prompted to add keystore'
474 fi
475 set -e
476 $fdroid update --create-key
477 test -e $KEYSTORE
478 copy_apks_into_repo $REPOROOT
479 $fdroid update --create-metadata --verbose
480 $fdroid readmeta
481 test -e repo/index.xml
482 test -e repo/index.jar
483 grep -F '<application id=' repo/index.xml > /dev/null
484
485
486 #------------------------------------------------------------------------------#
487 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
488
489 REPOROOT=`create_test_dir`
490 KEYSTORE=$REPOROOT/keystore.jks
491 cd $REPOROOT
492 $fdroid init --keystore $KEYSTORE
493 test -e $KEYSTORE
494 copy_apks_into_repo $REPOROOT
495 $fdroid update --create-metadata --verbose
496 $fdroid readmeta
497 test -e repo/index.xml
498 test -e repo/index.jar
499 grep -F '<application id=' repo/index.xml > /dev/null
500 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
501     cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
502 $fdroid update --create-metadata --verbose
503 $fdroid readmeta
504 test -e repo/index.xml
505 test -e repo/index.jar
506 grep -F '<application id=' repo/index.xml > /dev/null
507
508
509 #------------------------------------------------------------------------------#
510 echo_header "setup a new repo from scratch with a HSM/smartcard"
511 REPOROOT=`create_test_dir`
512 cd $REPOROOT
513 $fdroid init --keystore NONE
514 test -e opensc-fdroid.cfg
515 test ! -e NONE
516
517
518 #------------------------------------------------------------------------------#
519 echo_header "setup a new repo with no keystore, add APK, and update"
520
521 REPOROOT=`create_test_dir`
522 KEYSTORE=$REPOROOT/keystore.jks
523 cd $REPOROOT
524 touch config.py
525 touch fdroid-icon.png
526 mkdir repo
527 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
528 set +e
529 $fdroid update --create-metadata --verbose
530 if [ $? -eq 0 ]; then
531     echo "This should have failed because this repo has no keystore!"
532     exit 1
533 else
534     echo '`fdroid update` prompted to add keystore'
535 fi
536 set -e
537
538 # now set up fake, non-working keystore setup
539 touch $KEYSTORE
540 echo "keystore = \"$KEYSTORE\"" >> config.py
541 echo 'repo_keyalias = "foo"' >> config.py
542 echo 'keystorepass = "foo"' >> config.py
543 echo 'keypass = "foo"' >> config.py
544 set +e
545 $fdroid update --create-metadata --verbose
546 if [ $? -eq 0 ]; then
547     echo "This should have failed because this repo has a bad/fake keystore!"
548     exit 1
549 else
550     echo '`fdroid update` prompted to add keystore'
551 fi
552 set -e
553
554
555 #------------------------------------------------------------------------------#
556 echo_header "setup a new repo with keystore with APK, update, then without key"
557
558 REPOROOT=`create_test_dir`
559 KEYSTORE=$REPOROOT/keystore.jks
560 cd $REPOROOT
561 $fdroid init --keystore $KEYSTORE
562 test -e $KEYSTORE
563 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
564 $fdroid update --create-metadata --verbose
565 $fdroid readmeta
566 test -e repo/index.xml
567 test -e repo/index.jar
568 grep -F '<application id=' repo/index.xml > /dev/null
569
570 # now set fake repo_keyalias
571 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
572 set +e
573 $fdroid update
574 if [ $? -eq 0 ]; then
575     echo "This should have failed because this repo has a bad repo_keyalias!"
576     exit 1
577 else
578     echo '`fdroid update` prompted to add keystore'
579 fi
580 set -e
581
582 # try creating a new keystore, but fail because the old one is there
583 test -e $KEYSTORE
584 set +e
585 $fdroid update --create-key
586 if [ $? -eq 0 ]; then
587     echo "This should have failed because a keystore is already there!"
588     exit 1
589 else
590     echo '`fdroid update` complained about existing keystore'
591 fi
592 set -e
593
594 # now actually create the key with the existing settings
595 rm -f $KEYSTORE
596 ! test -e $KEYSTORE
597 $fdroid update --create-key
598 test -e $KEYSTORE
599
600
601 #------------------------------------------------------------------------------#
602
603 # remove this to prevent git conflicts and complaining
604 rm -rf $WORKSPACE/fdroidserver.egg-info/
605
606 echo SUCCESS