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