chiark / gitweb /
tests: create_fake_android_home should create old build-tools version
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e # quit script on error
4 set -x # show each command as it is executed
5
6 echo_header() {
7     echo "=============================================================================="
8     echo $1
9 }
10
11 copy_apks_into_repo() {
12     set +x
13     for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned`; do
14         name=$(basename $(dirname `dirname $f`))
15         apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
16         test $f -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
17         if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
18             echo "$f --> repo/$apk"
19             ln $f $1/repo/$apk || \
20                 rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
21         fi
22     done
23     set -x
24 }
25
26 # keep this as an old version to test the automatic parsing of build-tools
27 # verion numbers in `fdroid init`
28 create_fake_android_home() {
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 --directory --tmpdir=$WORKSPACE/.testfiles
37 }
38
39 create_test_file() {
40     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
41     mktemp --tmpdir=$WORKSPACE/.testfiles
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 [ -z $1 ]; then
60     APKDIR=`pwd`
61 else
62     APKDIR=$1
63 fi
64
65 if [ -z $WORKSPACE ]; then
66     WORKSPACE=`dirname $(pwd)`
67     echo "Setting Workspace to $WORKSPACE"
68 fi
69
70 # allow the location of the script to be overridden
71 if [ -z $fdroid ]; then
72     fdroid="$WORKSPACE/fdroid"
73 fi
74
75 # allow the location of aapt to be overridden
76 if [ -z $aapt ]; then
77     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
78 fi
79
80
81 #------------------------------------------------------------------------------#
82 echo_header "create a source tarball and use that to build a repo"
83
84 cd $WORKSPACE
85 python setup.py sdist
86
87 REPOROOT=`create_test_dir`
88 cd $REPOROOT
89 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
90 cd $REPOROOT/fdroidserver-*/fdroidserver/getsig
91 ./make.sh
92 cd $REPOROOT
93 ./fdroidserver-*/fdroid init
94 copy_apks_into_repo $REPOROOT
95 ./fdroidserver-*/fdroid update --create-metadata
96
97
98 #------------------------------------------------------------------------------#
99 echo_header "test config checks of local_copy_dir"
100
101 REPOROOT=`create_test_dir`
102 cd $REPOROOT
103 $fdroid init
104 $fdroid update --create-metadata
105 $fdroid server update --local-copy-dir=/tmp/fdroid
106
107 # now test the errors work
108 set +e
109 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
110 if [ $? -eq 0 ]; then
111     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
112     exit 1
113 else
114     echo "testing absolute path checker passed"
115 fi
116 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
117 if [ $? -eq 0 ]; then
118     echo "This should have failed because the path does not end with 'fdroid'!"
119     exit 1
120 else
121     echo "testing dirname exists checker passed"
122 fi
123 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
124 if [ $? -eq 0 ]; then
125     echo "This should have failed because the dirname path does not exist!"
126     exit 1
127 else
128     echo "testing dirname exists checker passed"
129 fi
130 set -e
131
132
133 #------------------------------------------------------------------------------#
134 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
135
136 REPOROOT=`create_test_dir`
137 cd $REPOROOT
138 $fdroid init
139 copy_apks_into_repo $REPOROOT
140 $fdroid update --create-metadata
141 grep -F '<application id=' repo/index.xml
142
143 LOCALCOPYDIR=`create_test_dir`/fdroid
144 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
145 NEWREPOROOT=`create_test_dir`
146 cd $NEWREPOROOT
147 $fdroid init
148 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
149
150
151 #------------------------------------------------------------------------------#
152 # check that --android-home fails when dir does not exist or is not a dir
153
154 REPOROOT=`create_test_dir`
155 KEYSTORE=$REPOROOT/keystore.jks
156 cd $REPOROOT
157 set +e
158 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
159 if [ $? -eq 0 ]; then
160     echo "This should have failed because /opt/fakeandroidhome does not exist!"
161     exit 1
162 else
163     echo "testing android-home path checker passed"
164 fi
165 TESTFILE=`create_test_file`
166 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
167 if [ $? -eq 0 ]; then
168     echo "This should have failed because $TESTFILE is a file not a dir!"
169     exit 1
170 else
171     echo "testing android-home not-dir checker passed"
172 fi
173 set -e
174
175
176 #------------------------------------------------------------------------------#
177 echo_header "check that fake android home passes `fdroid init`"
178
179 REPOROOT=`create_test_dir`
180 FAKE_ANDROID_HOME=`create_test_dir`
181 create_fake_android_home $FAKE_ANDROID_HOME
182 KEYSTORE=$REPOROOT/keystore.jks
183 cd $REPOROOT
184 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
185
186
187 #------------------------------------------------------------------------------#
188 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
189
190 REPOROOT=`create_test_dir`
191 FAKE_ANDROID_HOME=`create_test_dir`
192 create_fake_android_home $FAKE_ANDROID_HOME
193 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
194 KEYSTORE=$REPOROOT/keystore.jks
195 cd $REPOROOT
196 set +e
197 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
198 [ $? -eq 0 ] && exit 1
199 set -e
200
201
202 #------------------------------------------------------------------------------#
203 echo_header "check that --android-home overrides ANDROID_HOME"
204
205 REPOROOT=`create_test_dir`
206 FAKE_ANDROID_HOME=`create_test_dir`
207 create_fake_android_home $FAKE_ANDROID_HOME
208 KEYSTORE=$REPOROOT/keystore.jks
209 cd $REPOROOT
210 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
211 set +e
212 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
213 if [ $? -ne 0 ]; then
214     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
215     exit 1
216 fi
217 set -e
218
219
220 #------------------------------------------------------------------------------#
221 # In this case, ANDROID_HOME is set to a fake, non-working version that will
222 # be detected by fdroid as an Android SDK install.  It should use the path set
223 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
224 # in ANDROID_HOME, it won't work because it is a fake one.  Only
225 # --android-home provides a working one.
226 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
227
228 REPOROOT=`create_test_dir`
229 KEYSTORE=$REPOROOT/keystore.jks
230 FAKE_ANDROID_HOME=`create_test_dir`
231 create_fake_android_home $FAKE_ANDROID_HOME
232 STORED_ANDROID_HOME=$ANDROID_HOME
233 unset ANDROID_HOME
234 echo "ANDROID_HOME: $ANDROID_HOME"
235 cd $REPOROOT
236 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
237 test -e $KEYSTORE
238 copy_apks_into_repo $REPOROOT
239 $fdroid update --create-metadata
240 grep -F '<application id=' repo/index.xml
241 test -e repo/index.xml
242 test -e repo/index.jar
243 export ANDROID_HOME=$STORED_ANDROID_HOME
244
245
246 #------------------------------------------------------------------------------#
247 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
248
249 REPOROOT=`create_test_dir`
250 cd $REPOROOT
251 mkdir repo
252 copy_apks_into_repo $REPOROOT
253 $fdroid init
254 $fdroid update --create-metadata
255 grep -F '<application id=' repo/index.xml
256
257
258 #------------------------------------------------------------------------------#
259 echo_header "setup a new repo from scratch and generate a keystore"
260
261 REPOROOT=`create_test_dir`
262 KEYSTORE=$REPOROOT/keystore.jks
263 cd $REPOROOT
264 $fdroid init --keystore $KEYSTORE
265 test -e $KEYSTORE
266 copy_apks_into_repo $REPOROOT
267 $fdroid update --create-metadata
268 test -e repo/index.xml
269 test -e repo/index.jar
270 grep -F '<application id=' repo/index.xml
271
272
273 #------------------------------------------------------------------------------#
274 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
275
276 REPOROOT=`create_test_dir`
277 KEYSTORE=$REPOROOT/keystore.jks
278 cd $REPOROOT
279 $fdroid init --keystore $KEYSTORE
280 test -e $KEYSTORE
281 copy_apks_into_repo $REPOROOT
282 $fdroid update --create-metadata
283 test -e repo/index.xml
284 test -e repo/index.jar
285 grep -F '<application id=' repo/index.xml
286 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
287 $fdroid update --create-metadata
288 test -e repo/index.xml
289 test -e repo/index.jar
290 grep -F '<application id=' repo/index.xml
291
292
293 #------------------------------------------------------------------------------#
294 echo_header "setup a new repo from scratch with a HSM/smartcard"
295
296 REPOROOT=`create_test_dir`
297 cd $REPOROOT
298 $fdroid init --keystore NONE
299 test -e opensc-fdroid.cfg
300 test ! -e NONE
301
302
303 echo SUCCESS