chiark / gitweb /
run-tests: verbose output for `fdroid update` to aid debugging
[fdroidserver.git] / tests / run-tests
index ae566b74ef53646fd9b5b23f6d4665f652acb345..c770091f2339583932a3702d550c5727fa250d34 100755 (executable)
@@ -1,11 +1,9 @@
 #!/bin/bash
 
 set -e # quit script on error
-set -x # show each command as it is executed
 
 echo_header() {
-    echo "=============================================================================="
-    echo $1
+    { echo -e "==============================================================================\n$1"; } 2>/dev/null
 }
 
 copy_apks_into_repo() {
@@ -35,12 +33,12 @@ create_fake_android_home() {
 
 create_test_dir() {
     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
-    mktemp --directory --tmpdir=$WORKSPACE/.testfiles
+    TMPDIR=$WORKSPACE/.testfiles  mktemp -d
 }
 
 create_test_file() {
     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
-    mktemp --tmpdir=$WORKSPACE/.testfiles
+    TMPDIR=$WORKSPACE/.testfiles  mktemp
 }
 
 #------------------------------------------------------------------------------#
@@ -58,6 +56,10 @@ if [ -z "$ANDROID_HOME" ]; then
     exit 1
 fi
 
+if [ -d tests ]; then
+    cd tests
+fi
+
 if [ -z "$1" ]; then
     APKDIR=`pwd`
 else
@@ -84,6 +86,7 @@ if [ -z $python ]; then
     python=python2
 fi
 
+set -x # show each command as it is executed
 
 #------------------------------------------------------------------------------#
 echo_header "run commit hooks"
@@ -97,8 +100,60 @@ echo_header "test python getsig replacement"
 
 cd $WORKSPACE/tests/getsig
 ./make.sh
-cd $WORKSPACE/tests
-./update.TestCase
+for testcase in $WORKSPACE/tests/*.TestCase; do
+    $testcase
+done
+
+
+#------------------------------------------------------------------------------#
+echo_header "print fdroid version"
+
+$fdroid --version
+
+
+#------------------------------------------------------------------------------#
+echo_header "build the TeX manual"
+
+cd $WORKSPACE/docs
+./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
+
+
+#------------------------------------------------------------------------------#
+echo_header "test metadata checks"
+
+REPOROOT=`create_test_dir`
+cd $REPOROOT
+
+touch config.py
+mkdir repo
+cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
+
+set +e
+$fdroid build
+if [ $? -eq 0 ]; then
+    echo "This should have failed because there is no metadata!"
+    exit 1
+else
+    echo "testing metadata checks passed"
+fi
+set -e
+
+mkdir $REPOROOT/metadata/
+cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
+$fdroid readmeta
+
+# now make a fake duplicate
+touch $REPOROOT/metadata/org.smssecure.smssecure.yaml
+
+set +e
+$fdroid readmeta
+if [ $? -eq 0 ]; then
+    echo "This should have failed because there is a duplicate metadata file!"
+    exit 1
+else
+    echo "testing duplicate metadata checks passed"
+fi
+set -e
 
 
 #------------------------------------------------------------------------------#
@@ -113,7 +168,7 @@ tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
 cd $REPOROOT
 ./fdroidserver-*/fdroid init
 copy_apks_into_repo $REPOROOT
-./fdroidserver-*/fdroid update --create-metadata
+./fdroidserver-*/fdroid update --create-metadata --verbose
 
 
 #------------------------------------------------------------------------------#
@@ -122,7 +177,8 @@ echo_header "test config checks of local_copy_dir"
 REPOROOT=`create_test_dir`
 cd $REPOROOT
 $fdroid init
-$fdroid update --create-metadata
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
 $fdroid server update --local-copy-dir=/tmp/fdroid
 
 # now test the errors work
@@ -158,8 +214,9 @@ REPOROOT=`create_test_dir`
 cd $REPOROOT
 $fdroid init
 copy_apks_into_repo $REPOROOT
-$fdroid update --create-metadata
-grep -F '<application id=' repo/index.xml
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
+grep -F '<application id=' repo/index.xml > /dev/null
 
 LOCALCOPYDIR=`create_test_dir`/fdroid
 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
@@ -208,16 +265,20 @@ $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
 #------------------------------------------------------------------------------#
 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
 
-REPOROOT=`create_test_dir`
-FAKE_ANDROID_HOME=`create_test_dir`
-create_fake_android_home $FAKE_ANDROID_HOME
-rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
-KEYSTORE=$REPOROOT/keystore.jks
-cd $REPOROOT
-set +e
-$fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
-[ $? -eq 0 ] && exit 1
-set -e
+if [ -e /usr/bin/aapt ]; then
+    echo "/usr/bin/aapt exists, not running test"
+else
+    REPOROOT=`create_test_dir`
+    FAKE_ANDROID_HOME=`create_test_dir`
+    create_fake_android_home $FAKE_ANDROID_HOME
+    rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
+    KEYSTORE=$REPOROOT/keystore.jks
+    cd $REPOROOT
+    set +e
+    $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
+    [ $? -eq 0 ] && exit 1
+    set -e
+fi
 
 
 #------------------------------------------------------------------------------#
@@ -257,8 +318,9 @@ cd $REPOROOT
 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
 test -e $KEYSTORE
 copy_apks_into_repo $REPOROOT
-$fdroid update --create-metadata
-grep -F '<application id=' repo/index.xml
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
+grep -F '<application id=' repo/index.xml > /dev/null
 test -e repo/index.xml
 test -e repo/index.jar
 export ANDROID_HOME=$STORED_ANDROID_HOME
@@ -272,8 +334,9 @@ cd $REPOROOT
 mkdir repo
 copy_apks_into_repo $REPOROOT
 $fdroid init
-$fdroid update --create-metadata
-grep -F '<application id=' repo/index.xml
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
+grep -F '<application id=' repo/index.xml > /dev/null
 
 
 #------------------------------------------------------------------------------#
@@ -285,10 +348,39 @@ cd $REPOROOT
 $fdroid init --keystore $KEYSTORE
 test -e $KEYSTORE
 copy_apks_into_repo $REPOROOT
-$fdroid update --create-metadata
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
+test -e repo/index.xml
+test -e repo/index.jar
+grep -F '<application id=' repo/index.xml > /dev/null
+
+
+#------------------------------------------------------------------------------#
+echo_header "setup a new repo manually and generate a keystore"
+
+REPOROOT=`create_test_dir`
+KEYSTORE=$REPOROOT/keystore.jks
+cd $REPOROOT
+touch config.py
+cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
+! test -e $KEYSTORE
+set +e
+$fdroid update
+if [ $? -eq 0 ]; then
+    echo "This should have failed because this repo has no keystore!"
+    exit 1
+else
+    echo '`fdroid update` prompted to add keystore'
+fi
+set -e
+$fdroid update --create-key
+test -e $KEYSTORE
+copy_apks_into_repo $REPOROOT
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
 test -e repo/index.xml
 test -e repo/index.jar
-grep -F '<application id=' repo/index.xml
+grep -F '<application id=' repo/index.xml > /dev/null
 
 
 #------------------------------------------------------------------------------#
@@ -300,26 +392,115 @@ cd $REPOROOT
 $fdroid init --keystore $KEYSTORE
 test -e $KEYSTORE
 copy_apks_into_repo $REPOROOT
-$fdroid update --create-metadata
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
 test -e repo/index.xml
 test -e repo/index.jar
-grep -F '<application id=' repo/index.xml
-cp $WORKSPACE/tests/urzip.apk $REPOROOT/
-$fdroid update --create-metadata
+grep -F '<application id=' repo/index.xml > /dev/null
+test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
+    cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
 test -e repo/index.xml
 test -e repo/index.jar
-grep -F '<application id=' repo/index.xml
+grep -F '<application id=' repo/index.xml > /dev/null
 
 
 #------------------------------------------------------------------------------#
 echo_header "setup a new repo from scratch with a HSM/smartcard"
-
 REPOROOT=`create_test_dir`
 cd $REPOROOT
 $fdroid init --keystore NONE
 test -e opensc-fdroid.cfg
 test ! -e NONE
 
+
+#------------------------------------------------------------------------------#
+echo_header "setup a new repo with no keystore, add APK, and update"
+
+REPOROOT=`create_test_dir`
+KEYSTORE=$REPOROOT/keystore.jks
+cd $REPOROOT
+touch config.py
+touch fdroid-icon.png
+mkdir repo
+cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
+set +e
+$fdroid update --create-metadata --verbose
+if [ $? -eq 0 ]; then
+    echo "This should have failed because this repo has no keystore!"
+    exit 1
+else
+    echo '`fdroid update` prompted to add keystore'
+fi
+set -e
+
+# now set up fake, non-working keystore setup
+touch $KEYSTORE
+echo "keystore = \"$KEYSTORE\"" >> config.py
+echo 'repo_keyalias = "foo"' >> config.py
+echo 'keystorepass = "foo"' >> config.py
+echo 'keypass = "foo"' >> config.py
+set +e
+$fdroid update --create-metadata --verbose
+if [ $? -eq 0 ]; then
+    echo "This should have failed because this repo has a bad/fake keystore!"
+    exit 1
+else
+    echo '`fdroid update` prompted to add keystore'
+fi
+set -e
+
+
+#------------------------------------------------------------------------------#
+echo_header "setup a new repo with keystore with APK, update, then without key"
+
+REPOROOT=`create_test_dir`
+KEYSTORE=$REPOROOT/keystore.jks
+cd $REPOROOT
+$fdroid init --keystore $KEYSTORE
+test -e $KEYSTORE
+cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
+$fdroid update --create-metadata --verbose
+$fdroid readmeta
+test -e repo/index.xml
+test -e repo/index.jar
+grep -F '<application id=' repo/index.xml > /dev/null
+
+# now set fake repo_keyalias
+sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
+set +e
+$fdroid update
+if [ $? -eq 0 ]; then
+    echo "This should have failed because this repo has a bad repo_keyalias!"
+    exit 1
+else
+    echo '`fdroid update` prompted to add keystore'
+fi
+set -e
+
+# try creating a new keystore, but fail because the old one is there
+test -e $KEYSTORE
+set +e
+$fdroid update --create-key
+if [ $? -eq 0 ]; then
+    echo "This should have failed because a keystore is already there!"
+    exit 1
+else
+    echo '`fdroid update` complained about existing keystore'
+fi
+set -e
+
+# now actually create the key with the existing settings
+rm -f $KEYSTORE
+! test -e $KEYSTORE
+$fdroid update --create-key
+test -e $KEYSTORE
+
+
+#------------------------------------------------------------------------------#
+
+# remove this to prevent git conflicts and complaining
 rm -rf $WORKSPACE/fdroidserver.egg-info/
 
 echo SUCCESS