chiark / gitweb /
Merge branch 'master' of https://gitlab.com/eighthave/fdroidserver
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e
4 set -x
5
6 copy_apks_into_repo() {
7     for f in `ls -1 ../../*/bin/*.apk`; do
8         name=$(basename $(dirname `dirname $f`))
9         echo "name $name"
10         apk=`aapt d badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
11         echo "apk $apk"
12         cp -f $f $1/repo/$apk
13     done
14 }
15
16 create_fake_android_home() {
17     mkdir $1/build-tools
18     mkdir $1/build-tools/19.0.1
19     touch $1/build-tools/19.0.1/aapt
20 }
21
22 create_test_dir() {
23     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
24     mktemp --directory --tmpdir=$WORKSPACE/.testfiles
25 }
26
27 create_test_file() {
28     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
29     mktemp --tmpdir=$WORKSPACE/.testfiles
30 }
31
32 if [ -z $WORKSPACE ]; then
33     WORKSPACE=`dirname $(pwd)`
34     echo "Setting Workspace to $WORKSPACE"
35 fi
36
37 # allow the location of the script to be overridden
38 if [ -z $fdroid ]; then
39     fdroid="$WORKSPACE/fdroid"
40 fi
41
42 #------------------------------------------------------------------------------#
43 echo "setup a new repo from scratch using ANDROID_HOME"
44
45 REPOROOT=`create_test_dir`
46 cd $REPOROOT
47 $fdroid init
48 copy_apks_into_repo $REPOROOT
49 $fdroid update -c
50 $fdroid update
51
52
53 #------------------------------------------------------------------------------#
54 # check that --android-home fails when dir does not exist or is not a dir
55
56 REPOROOT=`create_test_dir`
57 KEYSTORE=$REPOROOT/keystore.jks
58 cd $REPOROOT
59 set +e
60 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
61 if [ $? -eq 0 ]; then
62     echo "This should have failed because /opt/fakeandroidhome does not exist!"
63     exit 1
64 else
65     echo "testing android-home path checker passed"
66 fi
67 TESTFILE=`create_test_file`
68 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
69 if [ $? -eq 0 ]; then
70     echo "This should have failed because $TESTFILE is a file not a dir!"
71     exit 1
72 else
73     echo "testing android-home not-dir checker passed"
74 fi
75 set -e
76
77
78 #------------------------------------------------------------------------------#
79 echo "check that --android-home overrides ANDROID_HOME"
80
81 REPOROOT=`create_test_dir`
82 FAKE_ANDROID_HOME=`create_test_dir`
83 create_fake_android_home $FAKE_ANDROID_HOME
84 KEYSTORE=$REPOROOT/keystore.jks
85 cd $REPOROOT
86 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
87 set +e
88 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
89 if [ $? -ne 0 ]; then
90     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
91     exit 1
92 fi
93 set -e
94
95
96 #------------------------------------------------------------------------------#
97 echo "setup a new repo from scratch with keystore and android-home set on cmd line"
98
99 REPOROOT=`create_test_dir`
100 KEYSTORE=$REPOROOT/keystore.jks
101 FAKE_ANDROID_HOME=`create_test_dir`
102 create_fake_android_home $FAKE_ANDROID_HOME
103 STORED_ANDROID_HOME=$ANDROID_HOME
104 unset ANDROID_HOME
105 echo "ANDROID_HOME: $ANDROID_HOME"
106 cd $REPOROOT
107 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME --no-prompt
108 test -e $KEYSTORE
109 copy_apks_into_repo $REPOROOT
110 $fdroid update -c
111 $fdroid update
112 test -e repo/index.xml
113 test -e repo/index.jar
114 export ANDROID_HOME=$STORED_ANDROID_HOME
115
116
117 #------------------------------------------------------------------------------#
118 echo "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
119
120 REPOROOT=`create_test_dir`
121 cd $REPOROOT
122 mkdir repo
123 copy_apks_into_repo $REPOROOT
124 $fdroid init
125 $fdroid update -c
126 $fdroid update
127
128
129 #------------------------------------------------------------------------------#
130 echo "setup a new repo from scratch and generate a keystore"
131
132 REPOROOT=`create_test_dir`
133 KEYSTORE=$REPOROOT/keystore.jks
134 cd $REPOROOT
135 $fdroid init --keystore $KEYSTORE
136 test -e $KEYSTORE
137 copy_apks_into_repo $REPOROOT
138 $fdroid update -c
139 $fdroid update
140 test -e repo/index.xml
141 test -e repo/index.jar
142
143
144 #------------------------------------------------------------------------------#
145 echo "setup a new repo from scratch with a HSM/smartcard"
146
147 REPOROOT=`create_test_dir`
148 cd $REPOROOT
149 $fdroid init --keystore NONE
150 test -e opensc-fdroid.cfg
151 test ! -e NONE
152
153
154 echo SUCCESS