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