diff --git a/.gitignore b/.gitignore index 1cd52769..f922e895 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ random_crap testing/tests/x-* testing/tests/local testing/timing.stats* +testing/report.xml .sync-cache .buildpath .cvsignore diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..9dfdd560 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,71 @@ +image: php:apache-stretch + +build: + stage: build + script: + - apt-get -y update + - bash -c 'mkdir -p /usr/share/man/man{0..10}' + - apt-get -y install build-essential devscripts fakeroot dh-exec jdupes rst2pdf doxygen # todo build-dep instead, change this task's image to plain debian + - mv debian/changelog debian/changelog.old + - > + cat + <(echo "davical ($(cat VERSION)~git$(date +"%Y%m%d")-$(git rev-parse --short $CI_COMMIT_SHA)) unstable; urgency=medium") + <(echo "") + <(echo " * Build on CI") + <(echo "") + <(echo " -- ${GITLAB_USER_NAME} <${GITLAB_USER_EMAIL}> $(date -R)") + <(echo "") + debian/changelog.old + >debian/changelog + - rm debian/changelog.old + - debuild -us -uc -b -d + - 'mv ../davical_*_all.deb ./davical.deb' + artifacts: + paths: + - '*.deb' + +test: + stage: test + artifacts: + paths: + - testing/report.xml + reports: + junit: testing/report.xml + when: + always + script: + - apt-get -y update + - bash -c 'mkdir -p /usr/share/man/man{0..10}' + - apt-get -y install locales + - echo "en_NZ.UTF-8 UTF-8" >> /etc/locale.gen + - locale-gen + - echo "LANG=en_NZ.UTF-8" > /etc/default/locale + - apt-get -y install libdbd-pg-perl libyaml-perl perl postgresql postgresql-client libpq-dev xmlstarlet + - curl 'https://gitlab.com/davical-project/awl/-/archive/master/awl-master.tar.gz' | tar zxf - + - mv awl-master /usr/share/awl/ + - chown -R www-data /usr/share/awl/ + - dpkg --ignore-depends=php,php-pgsql,php-xml,libawl-php,php-cli -i *.deb + - docker-php-ext-install -j$(nproc) pgsql + - docker-php-ext-install -j$(nproc) pdo_pgsql + - docker-php-ext-install -j$(nproc) calendar + - echo '127.0.1.1 regression mycaldav myempty' >> /etc/hosts + - cp testing/apache-site.conf.example /etc/apache2/sites-enabled/davical-regression.conf + - sed -i 's/\/path\/to/\/usr\/share/g' /etc/apache2/sites-enabled/davical-regression.conf + - mkdir /usr/share/davical/testing/ + - cp testing/*.php /usr/share/davical/testing/ + - rm /etc/davical/config.php + - cp testing/regression-conf.php.example /etc/davical/regression-conf.php + - ln -s /etc/davical/regression-conf.php /etc/davical/mycaldav-conf.php + - ln -s /etc/davical/regression-conf.php /etc/davical/myempty-conf.php + - sed -i '/peer/d' /etc/postgresql/9.6/main/pg_hba.conf + - echo 'local all all trust' >> /etc/postgresql/9.6/main/pg_hba.conf + - pg_ctlcluster 9.6 main start + - su postgres -c 'createuser davical_dba --createdb --createrole --superuser' + - su postgres -c 'createuser davical_app --superuser' + - su postgres -c 'createuser testrunner --superuser' + - pg_ctlcluster 9.6 main restart + - a2enmod rewrite + - apache2ctl start + - useradd testrunner + - cd testing && su testrunner -c 'IS_CI=yes ALLSUITES="regression-suite binding carddav" ./run_regressions.sh all x' + diff --git a/inc/DAVResource.php b/inc/DAVResource.php index 4b34cee1..65311ebf 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -1534,7 +1534,7 @@ EOQRY; */ function DAV_AllProperties() { if ( !isset($this->dead_properties) ) $this->FetchDeadProperties(); - $allprop = array_merge( (isset($this->dead_properties)?$this->dead_properties:array()), + $allprop = array_merge( (isset($this->dead_properties)?array_keys($this->dead_properties):array()), (isset($include_properties)?$include_properties:array()), array( 'DAV::getcontenttype', 'DAV::resourcetype', 'DAV::getcontentlength', 'DAV::displayname', 'DAV::getlastmodified', diff --git a/testing/apache-site.conf.example b/testing/apache-site.conf.example new file mode 100644 index 00000000..f97c4032 --- /dev/null +++ b/testing/apache-site.conf.example @@ -0,0 +1,28 @@ +Listen 127.0.1.1:80 + + ServerName regression + ServerAlias myempty mycaldav + DocumentRoot /path/to/davical/htdocs + CustomLog ${APACHE_LOG_DIR}/regression-access.log combined + ErrorLog ${APACHE_LOG_DIR}/regression-error.log + + Alias /davical /path/to/davical/htdocs + + Require all granted + DirectoryIndex index.php index.html + php_value include_path /path/to/awl/inc:/path/to/davical/testing + + + RewriteEngine On + # Redirect /.well-known URLs + RewriteRule ^/\.well-known/(.*)$ /caldav.php/.well-known/$1 [NC,L] + # and other special URLs + RewriteRule ^/principals/users/(.*)$ /caldav.php/$1 [NC,L] + RewriteRule ^/principals/resources/(.*)$ /caldav.php/$1 [NC,L] + RewriteRule ^/calendars/__uids__/(.*)$ /caldav.php/$1 [NC,L] + RewriteRule ^/addressbooks/__uids__/(.*)$ /caldav.php/$1 [NC,L] + # let caldav.php handle "anything else" + RewriteCond %{REQUEST_URI} !^/$ + RewriteCond %{REQUEST_URI} !\.(php|css|png|gif|js|jpg|ico) + RewriteRule ^(.*)$ /caldav.php$1 [NC,L] + \ No newline at end of file diff --git a/testing/regression-conf.php.example b/testing/regression-conf.php.example new file mode 100644 index 00000000..9687a216 --- /dev/null +++ b/testing/regression-conf.php.example @@ -0,0 +1,22 @@ +pg_connect[] = 'dbname=regression user=davical_app'; + + // use strict result ordering for regression testing only + $c->strict_result_ordering = true; + // PUT: 405 Method Not Allowed + $c->readonly_webdav_collections = false; + // fix ETag differences (CRLF) in 0218-Moz-REPORT and later + $c->hide_alarm = true; + // some freebusy queries will be 404 otherwise + $c->public_freebusy_url = true; + // helps with 1035-GET-mashup + $c->get_includes_subcollections = true; + // helps with 1036-REPORT-sync-initial-bound + $c->hide_TODO = false; + + // for ischedule suite; also needs DKIM set up? + $c->enable_scheduling = true; + + // enable for debugging, as needed + //$c->dbg['ALL'] = 1; +?> \ No newline at end of file diff --git a/testing/regression_reporting.sh b/testing/regression_reporting.sh new file mode 100644 index 00000000..976c2b9e --- /dev/null +++ b/testing/regression_reporting.sh @@ -0,0 +1,75 @@ +setup_report() { + if [ ! -z "$IS_CI" ]; then + cat > "$REPORTFILE" < + + +EOHEADER + fi +} + +report_test_success() { + if [ ! -z "$IS_CI" ]; then + SUITEPATH="/testsuites/testsuite[@name=\"$SUITE\"]" + xmlstarlet ed -L \ + -s "$SUITEPATH" -t elem -n testcase \ + -i "$SUITEPATH/testcase[not(@name)]" -t attr -n wip -v "1" \ + -i "$SUITEPATH/testcase[@wip]" -t attr -n name -v "$TEST" \ + -i "$SUITEPATH/testcase[@wip]" -t attr -n classname -v "$TEST" \ + -i "$SUITEPATH/testcase[@wip]" -t attr -n timestamp -v "0" \ + -d "$SUITEPATH/testcase[@wip]/@wip" \ + "$REPORTFILE" + fi +} + +report_test_failure() { + if [ ! -z "$IS_CI" ]; then + SUITEPATH="/testsuites/testsuite[@name=\"$SUITE\"]" + xmlstarlet ed -L \ + -s "$SUITEPATH" -t elem -n testcase \ + -i "$SUITEPATH/testcase[not(@name)]" -t attr -n wip -v "1" \ + -i "$SUITEPATH/testcase[@wip]" -t attr -n name -v "$SUITE: $TEST" \ + -i "$SUITEPATH/testcase[@wip]" -t attr -n classname -v "$TEST" \ + -i "$SUITEPATH/testcase[@wip]" -t attr -n timestamp -v "0" \ + -s "$SUITEPATH/testcase[@wip]" -t elem -n failure -v "xxxPERL_REPLACE_THIS_WITH_THE_ESCAPED_DIFFxxx" \ + -i "$SUITEPATH/testcase[@wip]/failure" -t attr -n message -v "test failure" \ + -d "$SUITEPATH/testcase[@wip]/@wip" \ + "$REPORTFILE" + + # I encountered a bug in xmlstarlet where small sections of large files are not properly escaped if inserted directly :/ + perl -pi -e 'BEGIN {$diff = `xmlstarlet esc < "'"${REGRESSION}/diffs/${TEST}"'"`} s/xxxPERL_REPLACE_THIS_WITH_THE_ESCAPED_DIFFxxx/$diff/g' "$REPORTFILE" + fi +} + +report_suite_setup() { + if [ ! -z "$IS_CI" ]; then + xmlstarlet ed -L \ + -s '/testsuites' -t elem -n testsuite \ + -i '/testsuites/testsuite[not(@name)]' -t attr -n name -v "$SUITE" \ + -i '/testsuites/testsuite[not(@time)]' -t attr -n time -v "0" \ + -i '/testsuites/testsuite[not(@errors)]' -t attr -n errors -v "0" \ + -i '/testsuites/testsuite[not(@timestamp)]' -t attr -n timestamp -v "$(date -u +'%FT%TZ')" \ + "$REPORTFILE" + fi +} + +report_suite_counts() { + if [ ! -z "$IS_CI" ]; then + xmlstarlet ed -L \ + -i "/testsuites/testsuite[@name=\"$SUITE\"]" -t attr -n tests -v "$(xmlstarlet sel -t -v "count(/testsuites/testsuite[@name=\"$SUITE\"]/testcase)" "$REPORTFILE")" \ + -i "/testsuites/testsuite[@name=\"$SUITE\"]" -t attr -n failures -v "$(xmlstarlet sel -t -v "count(/testsuites/testsuite[@name=\"$SUITE\"]/testcase/failure)" "$REPORTFILE")" \ + "$REPORTFILE" + fi +} + +exit_based_on_reported_failures() { + if [ ! -z "$IS_CI" ]; then + FAILCOUNT="$(xmlstarlet sel -t -v "count(//failure)" "$REPORTFILE")" + if [ "$FAILCOUNT" -gt 0 ]; then + exit 2 + else + exit 0 + fi + fi + exit 0 +} diff --git a/testing/run_regressions.sh b/testing/run_regressions.sh index b2d1b1ef..f2cd1bdb 100755 --- a/testing/run_regressions.sh +++ b/testing/run_regressions.sh @@ -12,6 +12,7 @@ DBNAME=regression PGPOOL=inactive HOSTNAME=mycaldav +REPORTFILE=report.xml # We need to run the regression tests in the timezone they were written for. export PGTZ=Pacific/Auckland @@ -49,6 +50,7 @@ ACCEPT_ALL=${2:-""} # psql ${PSQLOPTS} -l +. ./regression_reporting.sh check_result() { TEST="$1" @@ -59,6 +61,7 @@ check_result() { diff --text -u "${REGRESSION}/${TEST}.result" "${RESULTS}/${TEST}" >"${REGRESSION}/diffs/${TEST}" if [ -s "${REGRESSION}/diffs/${TEST}" ] ; then + report_test_failure if [ -z "$SKIPDIFF" ]; then echo "=======================================" echo "Displaying diff for test ${TEST}" @@ -75,7 +78,7 @@ check_result() { cp "${RESULTS}/${TEST}" "${REGRESSION}/${TEST}.result" elif [ "${ACCEPT}" = "x" ]; then echo "./dav_test --dsn '${DSN}' ${WEBHOST} ${ALTHOST} --suite '${SUITE}' --case '${TEST}' --debug" - exit + if [ -z "$IS_CI" ]; then exit 2; fi elif [ "${ACCEPT}" = "v" ]; then echo "Showing test $REGRESSION/${TEST}.test" cat "$REGRESSION/${TEST}.test" @@ -107,6 +110,7 @@ check_result() { return 1 fi else + report_test_success echo "Test ${TEST} passed OK!" fi return 0 @@ -184,6 +188,8 @@ run_regression_suite() { mkdir -p "${RESULTS}" mkdir -p "${REGRESSION}/diffs" + report_suite_setup + if [ -f "${REGRESSION}/initial.dbdump" ]; then restore_database else @@ -217,6 +223,8 @@ run_regression_suite() { TCOUNT="$(( ${TCOUNT} + 1 ))" done + + report_suite_counts } @@ -224,6 +232,8 @@ run_regression_suite() { TSTART="`date +%s`" TCOUNT=0 +setup_report + if [ "${SUITE}" = "all" ]; then for SUITE in ${ALLSUITES} ; do echo "Running $SUITE" @@ -241,3 +251,5 @@ fi TFINISH="`date +%s`" echo "Regression test run took $(( ${TFINISH} - ${TSTART} )) seconds for ${TCOUNT} tests." + +exit_based_on_reported_failures diff --git a/testing/tests/regression-suite/0824-Spec-PROPFIND-5.result b/testing/tests/regression-suite/0824-Spec-PROPFIND-5.result index 0cd11d44..05d94318 100644 --- a/testing/tests/regression-suite/0824-Spec-PROPFIND-5.result +++ b/testing/tests/regression-suite/0824-Spec-PROPFIND-5.result @@ -1,9 +1,20 @@ - + /caldav.php/user1/home/ + #0252D4FF + 1 + + /caldav.php/user1/home/ + + + + inside + inside2 + + httpd/unix-directory diff --git a/testing/tests/regression-suite/0828-Spec-PROPFIND-5.result b/testing/tests/regression-suite/0828-Spec-PROPFIND-5.result index 0cd11d44..05d94318 100644 --- a/testing/tests/regression-suite/0828-Spec-PROPFIND-5.result +++ b/testing/tests/regression-suite/0828-Spec-PROPFIND-5.result @@ -1,9 +1,20 @@ - + /caldav.php/user1/home/ + #0252D4FF + 1 + + /caldav.php/user1/home/ + + + + inside + inside2 + + httpd/unix-directory