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