chiark / gitweb /
tests: fix --android-home test to actually work
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e
4 set -x
5
6 echo_header() {
7     echo "=============================================================================="
8     echo $1
9 }
10
11 copy_apks_into_repo() {
12     for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned`; do
13         name=$(basename $(dirname `dirname $f`))
14         apk=`aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
15         test $f -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
16         if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
17             echo "$f --> repo/$apk"
18             ln $f $1/repo/$apk || \
19                 rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
20         fi
21     done
22 }
23
24 create_fake_android_home() {
25     mkdir $1/build-tools
26     mkdir $1/build-tools/19.0.1
27     touch $1/build-tools/19.0.1/aapt
28 }
29
30 create_test_dir() {
31     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
32     mktemp --directory --tmpdir=$WORKSPACE/.testfiles
33 }
34
35 create_test_file() {
36     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
37     mktemp --tmpdir=$WORKSPACE/.testfiles
38 }
39
40 #------------------------------------------------------------------------------#
41 # "main"
42
43 if [ $# -ne 1 ]; then
44     echo "Usage: $0 '/path/to/folder/with/apks'"
45     exit 1
46 fi
47
48 APKDIR=$1
49
50 if [ -z $WORKSPACE ]; then
51     WORKSPACE=`dirname $(pwd)`
52     echo "Setting Workspace to $WORKSPACE"
53 fi
54
55 # allow the location of the script to be overridden
56 if [ -z $fdroid ]; then
57     fdroid="$WORKSPACE/fdroid"
58 fi
59
60 #------------------------------------------------------------------------------#
61 echo_header "setup a new repo from scratch using ANDROID_HOME"
62
63 REPOROOT=`create_test_dir`
64 cd $REPOROOT
65 $fdroid init
66 copy_apks_into_repo $REPOROOT
67 $fdroid update --create-metadata
68 grep -F '<application id=' repo/index.xml
69
70
71 #------------------------------------------------------------------------------#
72 # check that --android-home fails when dir does not exist or is not a dir
73
74 REPOROOT=`create_test_dir`
75 KEYSTORE=$REPOROOT/keystore.jks
76 cd $REPOROOT
77 set +e
78 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
79 if [ $? -eq 0 ]; then
80     echo "This should have failed because /opt/fakeandroidhome does not exist!"
81     exit 1
82 else
83     echo "testing android-home path checker passed"
84 fi
85 TESTFILE=`create_test_file`
86 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
87 if [ $? -eq 0 ]; then
88     echo "This should have failed because $TESTFILE is a file not a dir!"
89     exit 1
90 else
91     echo "testing android-home not-dir checker passed"
92 fi
93 set -e
94
95
96 #------------------------------------------------------------------------------#
97 echo_header "check that fake android home passes `fdroid init`"
98
99 REPOROOT=`create_test_dir`
100 FAKE_ANDROID_HOME=`create_test_dir`
101 create_fake_android_home $FAKE_ANDROID_HOME
102 KEYSTORE=$REPOROOT/keystore.jks
103 cd $REPOROOT
104 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
105
106
107 #------------------------------------------------------------------------------#
108 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
109
110 REPOROOT=`create_test_dir`
111 FAKE_ANDROID_HOME=`create_test_dir`
112 create_fake_android_home $FAKE_ANDROID_HOME
113 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
114 KEYSTORE=$REPOROOT/keystore.jks
115 cd $REPOROOT
116 set +e
117 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
118 [ $? -eq 0 ] && exit 1
119 set -e
120
121
122 #------------------------------------------------------------------------------#
123 echo_header "check that --android-home overrides ANDROID_HOME"
124
125 REPOROOT=`create_test_dir`
126 FAKE_ANDROID_HOME=`create_test_dir`
127 create_fake_android_home $FAKE_ANDROID_HOME
128 KEYSTORE=$REPOROOT/keystore.jks
129 cd $REPOROOT
130 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
131 set +e
132 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
133 if [ $? -ne 0 ]; then
134     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
135     exit 1
136 fi
137 set -e
138
139
140 #------------------------------------------------------------------------------#
141 # In this case, ANDROID_HOME is set to a fake, non-working version that will
142 # be detected by fdroid as an Android SDK install.  It should use the path set
143 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
144 # in ANDROID_HOME, it won't work because it is a fake one.  Only
145 # --android-home provides a working one.
146 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
147
148 REPOROOT=`create_test_dir`
149 KEYSTORE=$REPOROOT/keystore.jks
150 FAKE_ANDROID_HOME=`create_test_dir`
151 create_fake_android_home $FAKE_ANDROID_HOME
152 STORED_ANDROID_HOME=$ANDROID_HOME
153 unset ANDROID_HOME
154 echo "ANDROID_HOME: $ANDROID_HOME"
155 cd $REPOROOT
156 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
157 test -e $KEYSTORE
158 copy_apks_into_repo $REPOROOT
159 $fdroid update --create-metadata
160 grep -F '<application id=' repo/index.xml
161 test -e repo/index.xml
162 test -e repo/index.jar
163 export ANDROID_HOME=$STORED_ANDROID_HOME
164
165
166 #------------------------------------------------------------------------------#
167 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
168
169 REPOROOT=`create_test_dir`
170 cd $REPOROOT
171 mkdir repo
172 copy_apks_into_repo $REPOROOT
173 $fdroid init
174 $fdroid update --create-metadata
175 grep -F '<application id=' repo/index.xml
176
177
178 #------------------------------------------------------------------------------#
179 echo_header "setup a new repo from scratch and generate a keystore"
180
181 REPOROOT=`create_test_dir`
182 KEYSTORE=$REPOROOT/keystore.jks
183 cd $REPOROOT
184 $fdroid init --keystore $KEYSTORE
185 test -e $KEYSTORE
186 copy_apks_into_repo $REPOROOT
187 $fdroid update --create-metadata
188 test -e repo/index.xml
189 test -e repo/index.jar
190 grep -F '<application id=' repo/index.xml
191
192
193 #------------------------------------------------------------------------------#
194 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
195
196 REPOROOT=`create_test_dir`
197 KEYSTORE=$REPOROOT/keystore.jks
198 cd $REPOROOT
199 $fdroid init --keystore $KEYSTORE
200 test -e $KEYSTORE
201 copy_apks_into_repo $REPOROOT
202 $fdroid update --create-metadata
203 test -e repo/index.xml
204 test -e repo/index.jar
205 grep -F '<application id=' repo/index.xml
206 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
207 $fdroid update --create-metadata
208 test -e repo/index.xml
209 test -e repo/index.jar
210 grep -F '<application id=' repo/index.xml
211
212
213 #------------------------------------------------------------------------------#
214 echo_header "setup a new repo from scratch with a HSM/smartcard"
215
216 REPOROOT=`create_test_dir`
217 cd $REPOROOT
218 $fdroid init --keystore NONE
219 test -e opensc-fdroid.cfg
220 test ! -e NONE
221
222
223 echo SUCCESS