From: Hans-Christoph Steiner Date: Wed, 20 Dec 2017 23:16:03 +0000 (+0000) Subject: Merge branch 'nail-down-tests' into 'master' X-Git-Tag: 1.0.0~19 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5f9bfe48ffd2bacb0aa7dc770669475a8bb6a715;hp=22aaa3dcbbb960982ff58e0549cb579c5690f360;p=fdroidserver.git Merge branch 'nail-down-tests' into 'master' Nail down tests Closes #432 See merge request fdroid/fdroidserver!418 --- diff --git a/.travis.yml b/.travis.yml index 8af32606..edfd9079 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,11 +67,13 @@ install: mkdir -p "$ANDROID_HOME/licenses"; echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"; + echo -e "\nd56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"; echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"; - echo y | $ANDROID_HOME/tools/bin/sdkmanager "platform-tools" > /dev/null 2&>1; - echo y | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;25.0.2" > /dev/null 2&>1; - echo y | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-23" > /dev/null 2&>1; + echo y | $ANDROID_HOME/tools/bin/sdkmanager "platform-tools"; + echo y | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;25.0.2"; + echo y | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-23"; + sudo pip3 install babel; sudo pip3 install --quiet --editable . ; sudo rm -rf fdroidserver.egg-info; diff --git a/README.md b/README.md index a28b4844..8ebbeb61 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,39 @@ https://f-droid.org/docs/Installing_the_Server_and_Repo_Tools All sorts of other documentation lives there as well. +### Tests + +There are many components to all of the tests for the components in +this git repo. The most commonly used parts of well tested, while +some parts still lack tests. This test suite has built over time a +bit haphazardly, so it is not as clean, organized, or complete as it +could be. We welcome contributions. Before rearchitecting any parts +of it, be sure to [contact us](https://f-droid.org/about) to discuss +the changes beforehand. + + +#### `fdroid` commands + +The test suite for all of the `fdroid` commands is in the _tests/_ +subdir. _.gitlab-ci.yml_ and _.travis.yml_ run this test suite on +various configurations. + +* _tests/complete-ci-tests_ runs _pylint_ and all tests on two + different pyvenvs +* _tests/run-tests_ runs the whole test suite +* _tests/*.TestCase_ are individual unit tests for all of the `fdroid` + commands, which can be run separately, e.g. `./update.TestCase`. + + +#### buildserver + +The tests for the whole build server setup are entirely separate +because they require at least 200GB of disk space, and 8GB of +RAM. These test scripts are in the root of the project, all starting +with _jenkins-_ since they are run on https://jenkins.debian.net. + + + ### Drozer Scanner There is a new feature under development that can scan any APK in a diff --git a/fdroidserver/build.py b/fdroidserver/build.py index d4f50005..3f428af7 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -419,7 +419,7 @@ def build_local(app, build, vcs, build_dir, output_dir, log_dir, srclib_dir, ext raise BuildException("Error locking root account for %s:%s" % (app.id, build.versionName), p.output) - p = FDroidPopen(['sudo', 'SUDO_FORCE_REMOVE=yes', 'apt-get', '-y', 'purge', 'sudo']) + p = FDroidPopen(['sudo', 'SUDO_FORCE_REMOVE=yes', 'dpkg', '--purge', 'sudo']) if p.returncode != 0: raise BuildException("Error removing sudo for %s:%s" % (app.id, build.versionName), p.output) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 624e9353..8248a944 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -128,6 +128,13 @@ default_config = { def setup_global_opts(parser): + try: # the buildserver VM might not have PIL installed + from PIL import PngImagePlugin + logger = logging.getLogger(PngImagePlugin.__name__) + logger.setLevel(logging.INFO) # tame the "STREAM" debug messages + except ImportError: + pass + parser.add_argument("-v", "--verbose", action="store_true", default=False, help=_("Spew out even more information than normal")) parser.add_argument("-q", "--quiet", action="store_true", default=False, diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 3015e337..c1079489 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1492,7 +1492,7 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir): logging.warning(_("Failed reading {path}: {error}") .format(path=icon_path, error=e)) finally: - if im: + if im and hasattr(im, 'close'): im.close() if apk['icons']: diff --git a/tests/complete-ci-tests b/tests/complete-ci-tests index 4573fcd5..6201eb2c 100755 --- a/tests/complete-ci-tests +++ b/tests/complete-ci-tests @@ -92,11 +92,6 @@ test -e $WORKSPACE/env/share/locale/de/LC_MESSAGES/fdroidserver.mo fdroid=$WORKSPACE/env/bin/fdroid $WORKSPACE/tests/run-tests $apksource -#------------------------------------------------------------------------------# -# run git pre-commit hook for pep8, pyflakes, etc -sh hooks/pre-commit - - #------------------------------------------------------------------------------# # run pylint diff --git a/tests/run-tests b/tests/run-tests index af29f471..13a96a37 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -41,6 +41,17 @@ create_test_file() { TMPDIR=$WORKSPACE/.testfiles mktemp } +fdroid_init_with_prebuilt_keystore() { + if [ -z "$1" ]; then + keystore=$WORKSPACE/tests/keystore.jks + else + keystore="$1" + fi + $fdroid init --keystore $keystore --repo-keyalias=sova + echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py + echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +} + # the < is reverse since 0 means success in exit codes have_git_2_3() { python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version` @@ -91,11 +102,6 @@ if [ -z $aapt ]; then aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1` fi -# allow the location of python to be overridden -if [ -z $python ]; then - python=python3 -fi - # try to use GNU sed on OSX/BSD cuz BSD sed sucks if which gsed; then sed=gsed @@ -165,7 +171,7 @@ echo_header "test UTF-8 metadata" REPOROOT=`create_test_dir` cd $REPOROOT -$fdroid init +fdroid_init_with_prebuilt_keystore $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py mkdir metadata @@ -219,11 +225,8 @@ echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign" REPOROOT=`create_test_dir` GNUPGHOME=$REPOROOT/gnupghome -KEYSTORE=$WORKSPACE/tests/keystore.jks cd $REPOROOT -$fdroid init --keystore $KEYSTORE --repo-keyalias=sova -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +fdroid_init_with_prebuilt_keystore cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/ cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME chmod 0700 $GNUPGHOME @@ -263,10 +266,7 @@ echo_header 'test moving lots of APKs to the archive' REPOROOT=`create_test_dir` cd $REPOROOT -cp $WORKSPACE/tests/keystore.jks $REPOROOT/ -$fdroid init --keystore keystore.jks --repo-keyalias=sova -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +fdroid_init_with_prebuilt_keystore echo "accepted_formats = ['txt']" >> config.py $sed -i.tmp '/allow_disabled_algorithms/d' config.py test -d metadata || mkdir metadata @@ -293,10 +293,7 @@ echo_header 'test per-app "Archive Policy"' REPOROOT=`create_test_dir` cd $REPOROOT -cp $WORKSPACE/tests/keystore.jks $REPOROOT/ -$fdroid init --keystore keystore.jks --repo-keyalias=sova -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +fdroid_init_with_prebuilt_keystore echo "accepted_formats = ['txt']" >> config.py test -d metadata || mkdir metadata cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/ @@ -367,10 +364,7 @@ echo_header 'test moving old APKs to and from the archive' REPOROOT=`create_test_dir` cd $REPOROOT -cp $WORKSPACE/tests/keystore.jks $REPOROOT/ -$fdroid init --keystore keystore.jks --repo-keyalias=sova -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +fdroid_init_with_prebuilt_keystore echo "accepted_formats = ['txt']" >> config.py test -d metadata || mkdir metadata cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/ @@ -436,10 +430,7 @@ echo_header 'test allowing disabled signatures in repo and archive' REPOROOT=`create_test_dir` cd $REPOROOT -cp $WORKSPACE/tests/keystore.jks $REPOROOT/ -$fdroid init --keystore keystore.jks --repo-keyalias=sova -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +fdroid_init_with_prebuilt_keystore echo "accepted_formats = ['txt']" >> config.py echo 'allow_disabled_algorithms = True' >> config.py $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py @@ -507,10 +498,7 @@ echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed' REPOROOT=`create_test_dir` cd $REPOROOT -cp $WORKSPACE/tests/keystore.jks $REPOROOT/ -$fdroid init --keystore keystore.jks --repo-keyalias=sova -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +fdroid_init_with_prebuilt_keystore echo "accepted_formats = ['txt', 'yml']" >> config.py echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py test -d metadata || mkdir metadata @@ -610,10 +598,10 @@ $fdroid install || true #------------------------------------------------------------------------------# -echo_header "create a source tarball and use that to build a repo" +echo_header "create a source tarball" cd $WORKSPACE -$python setup.py sdist +./setup.py compile_catalog sdist REPOROOT=`create_test_dir` cd $REPOROOT @@ -665,7 +653,7 @@ echo_header "setup a new repo from scratch using ANDROID_HOME and do a local syn REPOROOT=`create_test_dir` cd $REPOROOT -$fdroid init +fdroid_init_with_prebuilt_keystore copy_apks_into_repo $REPOROOT $fdroid update --create-metadata --verbose $fdroid readmeta @@ -675,7 +663,7 @@ LOCALCOPYDIR=`create_test_dir`/fdroid $fdroid server update --local-copy-dir=$LOCALCOPYDIR NEWREPOROOT=`create_test_dir` cd $NEWREPOROOT -$fdroid init +fdroid_init_with_prebuilt_keystore echo "sync_from_local_copy_dir = True" >> config.py $fdroid server update --local-copy-dir=$LOCALCOPYDIR @@ -787,11 +775,8 @@ export ANDROID_HOME=$STORED_ANDROID_HOME echo_header "check duplicate files are properly handled by fdroid update" REPOROOT=`create_test_dir` -KEYSTORE=$WORKSPACE/tests/keystore.jks cd $REPOROOT -$fdroid init --keystore $KEYSTORE --repo-keyalias=sova -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py +fdroid_init_with_prebuilt_keystore mkdir $REPOROOT/metadata cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata echo "accepted_formats = ['txt']" >> config.py @@ -813,7 +798,7 @@ REPOROOT=`create_test_dir` cd $REPOROOT mkdir repo copy_apks_into_repo $REPOROOT -$fdroid init +fdroid_init_with_prebuilt_keystore $fdroid update --create-metadata --verbose $fdroid readmeta grep -F '> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py $fdroid update --verbose @@ -976,7 +958,8 @@ 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 +cp $WORKSPACE/tests/keystore.jks $KEYSTORE +fdroid_init_with_prebuilt_keystore $KEYSTORE test -e $KEYSTORE cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/ $fdroid update --create-metadata --verbose @@ -1047,11 +1030,9 @@ if have_git_2_3; then fi cd $OFFLINE_ROOT -$fdroid init --keystore $KEYSTORE --repo-keyalias=sova +fdroid_init_with_prebuilt_keystore cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/ -echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py -echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py