Allow tests to dynamically set the DAViCal configuration

This commit is contained in:
Andrew Ruthven 2024-05-25 16:52:24 +12:00
parent 341707b045
commit d686ea4c3f
6 changed files with 64 additions and 13 deletions

View File

@ -167,6 +167,7 @@ test_memcache_and_ldap:
- testing/report.xml - testing/report.xml
- apache2_log/* - apache2_log/*
- davical_log/* - davical_log/*
- davical_conf/*
reports: reports:
junit: testing/report.xml junit: testing/report.xml
when: when:

View File

@ -7,10 +7,11 @@ use strict;
use warnings; use warnings;
use open qw( :encoding(UTF-8) :std ); use open qw( :encoding(UTF-8) :std );
use File::Copy; use File::Copy;
use DBI; use DBI;
use Getopt::Long qw(:config permute); # allow mixed args. use Getopt::Long qw(:config permute); # allow mixed args.
use File::pushd; use File::pushd;
use File::Touch;
use Digest::SHA;
# Options variables # Options variables
my $debug = 0; my $debug = 0;
@ -24,9 +25,12 @@ my $testdef;
my $suite; my $suite;
my $case; my $case;
my $helpmeplease = 0; my $helpmeplease = 0;
my $testmode = 'DAVICAL'; my $testmode = 'DAVICAL';
my $save_location = "/var/log/davical"; my $save_location = "/var/log/davical";
my $request_id; my $request_id;
my %conf_file_hashes;
# Hash for eval'd Perl code to store long lived variables in # Hash for eval'd Perl code to store long lived variables in
my %evaled; my %evaled;
@ -94,10 +98,17 @@ open(my $REQUEST_ID_FILE, "> $request_id_file")
# manage is empty in case the previous test was aborted. # manage is empty in case the previous test was aborted.
my $dynamic_app_conf_file = 'regression-conf.php.dynamic.per-test'; my $dynamic_app_conf_file = 'regression-conf.php.dynamic.per-test';
if (-f $dynamic_app_conf_file) { 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 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; my $datafile = $testdef;
$datafile =~ s{\.test$}{}; $datafile =~ s{\.test$}{};
push @arguments, "--header", 'X-DAViCal-Testcase: '.$datafile; push @arguments, "--header", 'X-DAViCal-Testcase: '.$datafile;
@ -377,6 +388,8 @@ exit(0);
sub run_curl { sub run_curl {
my $url = shift; my $url = shift;
maybe_restart_apache();
my @args = @arguments; my @args = @arguments;
push @args, @auth; push @args, @auth;
@ -557,12 +570,38 @@ configuration.
sub write_app_conf { sub write_app_conf {
my $content = shift; 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") open(my $FILE, ">> $dynamic_app_conf_file")
|| die "Failed to open $dynamic_app_conf_file for writing"; || die "Failed to open $dynamic_app_conf_file for writing";
print $FILE $content; 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 { sub usage {
print <<EOERROR ; print <<EOERROR ;

5
testing/etc/sudoers Normal file
View File

@ -0,0 +1,5 @@
Cmnd_Alias RESTART_APACHE = /usr/sbin/apache2ctl restart
# If you run the tests with a different user, repeat below line swapping
# "testrunner" for your user account(s).
testrunner ALL = NOPASSWD: RESTART_APACHE

View File

@ -5,7 +5,7 @@ test="${1:-$CI_JOB_NAME}"
test="${test:-unknown}" test="${test:-unknown}"
if [ -d /var/log/apache2 ]; then if [ -d /var/log/apache2 ]; then
mkdir -p apache2_log mkdir apache2_log
cp -r /var/log/apache2 "apache2_log/$test" cp -r /var/log/apache2 "apache2_log/$test"
xz apache2_log/"$test"/* xz apache2_log/"$test"/*
fi fi
@ -14,3 +14,6 @@ if [ -d /var/log/davical ]; then
mkdir -p davical_log mkdir -p davical_log
cp -r /var/log/davical "davical_log/$test" cp -r /var/log/davical "davical_log/$test"
fi fi
mkdir -p davical_conf/$test
cp /etc/davical/* davical_conf/$test

View File

@ -59,7 +59,8 @@ echo "LANG=en_NZ.UTF-8" > /etc/default/locale
packages="libdbd-pg-perl libyaml-perl postgresql-client postgresql packages="libdbd-pg-perl libyaml-perl postgresql-client postgresql
curl xmlstarlet netcat-openbsd libtest-www-mechanize-perl 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 if [[ $mode =~ "latestphp" ]]; then
# PHP pgsql package is built from source, needs libpq-dev. # 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 dpkg --ignore-depends=$dpkg_ignore_depends -i *.deb
fi fi
mkdir -p /usr/share/davical/testing/
cp $davical_repo_path/testing/*.php /usr/share/davical/testing/
mkdir -p /var/log/davical mkdir -p /var/log/davical
chown www-data /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 ln -s /etc/davical/regression-conf.php /etc/davical/$site-conf.php
done 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 ### Setup PostgreSQL
### ###
@ -216,6 +218,7 @@ useradd testrunner
# for the memcache tests. # for the memcache tests.
adduser testrunner adm adduser testrunner adm
# dav_test may need to write out temporary config files here.
chown -R testrunner $davical_repo_path/testing chown -R testrunner $davical_repo_path/testing
### ###
@ -239,6 +242,12 @@ else
/etc/apache2/sites-enabled/davical-regression.conf /etc/apache2/sites-enabled/davical-regression.conf
fi 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 rewrite
a2enmod headers a2enmod headers
apache2ctl start apache2ctl start

View File

@ -25,12 +25,6 @@
// if testing memcache // if testing memcache
//memcache $c->memcache_servers[] = '127.0.0.1,11211'; //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 // if testing LDAP
//ldap $c->authenticate_hook['call'] = 'LDAP_check'; //ldap $c->authenticate_hook['call'] = 'LDAP_check';
//ldap $c->authenticate_hook['config'] = array( //ldap $c->authenticate_hook['config'] = array(