From d686ea4c3f3902ba7e52e8078d2d571de33dcbb3 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sat, 25 May 2024 16:52:24 +1200 Subject: [PATCH] Allow tests to dynamically set the DAViCal configuration --- .gitlab-ci.yml | 1 + testing/dav_test | 45 +++++++++++++++++++++++++++-- testing/etc/sudoers | 5 ++++ testing/gitlab_ci_after_script.sh | 5 +++- testing/gitlab_ci_script.sh | 15 ++++++++-- testing/regression-conf.php.example | 6 ---- 6 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 testing/etc/sudoers diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 00513c3a..6ae86d4f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -167,6 +167,7 @@ test_memcache_and_ldap: - testing/report.xml - apache2_log/* - davical_log/* + - davical_conf/* reports: junit: testing/report.xml when: diff --git a/testing/dav_test b/testing/dav_test index abc99899..a53e7d6a 100755 --- a/testing/dav_test +++ b/testing/dav_test @@ -7,10 +7,11 @@ use strict; use warnings; use open qw( :encoding(UTF-8) :std ); use File::Copy; - use DBI; use Getopt::Long qw(:config permute); # allow mixed args. use File::pushd; +use File::Touch; +use Digest::SHA; # Options variables my $debug = 0; @@ -24,9 +25,12 @@ my $testdef; my $suite; my $case; my $helpmeplease = 0; + + my $testmode = 'DAVICAL'; my $save_location = "/var/log/davical"; my $request_id; +my %conf_file_hashes; # Hash for eval'd Perl code to store long lived variables in my %evaled; @@ -94,10 +98,17 @@ open(my $REQUEST_ID_FILE, "> $request_id_file") # manage is empty in case the previous test was aborted. my $dynamic_app_conf_file = 'regression-conf.php.dynamic.per-test'; if (-f $dynamic_app_conf_file) { + $conf_file_hashes{$dynamic_app_conf_file}{'old'} + = Digest::SHA->new->addfile($dynamic_app_conf_file)->hexdigest(); + unlink $dynamic_app_conf_file - || die "Failed to remove $dynamic_app_conf_file\n"; + || die "Failed to remove $dynamic_app_conf_file: $!\n"; +} else { + $conf_file_hashes{$dynamic_app_conf_file}{'old'} = ''; } +touch $dynamic_app_conf_file; + my $datafile = $testdef; $datafile =~ s{\.test$}{}; push @arguments, "--header", 'X-DAViCal-Testcase: '.$datafile; @@ -377,6 +388,8 @@ exit(0); sub run_curl { my $url = shift; + maybe_restart_apache(); + my @args = @arguments; push @args, @auth; @@ -557,12 +570,38 @@ configuration. sub write_app_conf { my $content = shift; - # We may wany to append extra content to a common file. + # We may want to append extra content to a common file. open(my $FILE, ">> $dynamic_app_conf_file") || die "Failed to open $dynamic_app_conf_file for writing"; print $FILE $content; } +=item maybe_restart_apache + +Check to see if the DAViCal config file snippet has changed, if it has, +restart Apache to make sure the new config is picked up. + +=cut + +sub maybe_restart_apache { + my $restarted = 0; + + for my $file (keys %conf_file_hashes) { + my $curr = (-f $file ? Digest::SHA->new->addfile($file)->hexdigest() : ''); + + if (! $restarted && $curr ne $conf_file_hashes{$file}{old}) { + system("sudo /usr/sbin/apache2ctl restart\n"); + $restarted = 1; + } + + # We've restarted Apache, treat the current hashes as old now, in + # case we make multiple queries to the server, or modify the config + # files again within this test file. + $conf_file_hashes{$file}{old} = $curr + if $restarted; + } +} + sub usage { print < /etc/default/locale packages="libdbd-pg-perl libyaml-perl postgresql-client postgresql curl xmlstarlet netcat-openbsd libtest-www-mechanize-perl - libfile-pushd-perl libtemplate-perl libinline-files-perl" + libfile-pushd-perl libtemplate-perl libinline-files-perl + libdigest-sha-perl sudo libfile-touch-perl" if [[ $mode =~ "latestphp" ]]; then # PHP pgsql package is built from source, needs libpq-dev. @@ -165,8 +166,6 @@ if [ -f davical.spec.in ]; then dpkg --ignore-depends=$dpkg_ignore_depends -i *.deb fi -mkdir -p /usr/share/davical/testing/ -cp $davical_repo_path/testing/*.php /usr/share/davical/testing/ mkdir -p /var/log/davical chown www-data /var/log/davical @@ -193,6 +192,9 @@ for site in mycaldav mycaldav_ldap myempty; do ln -s /etc/davical/regression-conf.php /etc/davical/$site-conf.php done +# We need to be able to restart apache as the regression user. +cp $davical_repo_path/testing/etc/sudoers /etc/sudoers.d/davical-tests + ### ### Setup PostgreSQL ### @@ -216,6 +218,7 @@ useradd testrunner # for the memcache tests. adduser testrunner adm +# dav_test may need to write out temporary config files here. chown -R testrunner $davical_repo_path/testing ### @@ -239,6 +242,12 @@ else /etc/apache2/sites-enabled/davical-regression.conf fi +# We need to have some PHP files in a known place. +if [ ! -f php-awl.spec.in ]; then + ln -s $davical_repo_path/testing /usr/share/davical/testing +fi + + a2enmod rewrite a2enmod headers apache2ctl start diff --git a/testing/regression-conf.php.example b/testing/regression-conf.php.example index 162453a6..2e63f639 100644 --- a/testing/regression-conf.php.example +++ b/testing/regression-conf.php.example @@ -25,12 +25,6 @@ // if testing memcache //memcache $c->memcache_servers[] = '127.0.0.1,11211'; - // if testing cached of auth with memcache - //memcache_auth $c->auth_cache = true; - //memcache_auth $c->auth_cache_secret = 'not safe, regression testing only'; - //memcache_auth $c->auth_cache_pass = 15 * 60; - //memcache_auth $c->auth_cache_fail = 15 * 60; - // if testing LDAP //ldap $c->authenticate_hook['call'] = 'LDAP_check'; //ldap $c->authenticate_hook['config'] = array(