From: Moritz Bunkus Date: Tue, 10 Oct 2017 09:46:54 +0000 (+0200) Subject: Tests: Eigene Verbindungsdaten für DB-Upgrades mit Super-User-Rechten X-Git-Tag: release-3.5.4~720 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=39a77adbb6f19f35d25f5e26dd274f46a626e505;p=kivitendo-erp.git Tests: Eigene Verbindungsdaten für DB-Upgrades mit Super-User-Rechten Wenn der Benutzer, der in der Konfiguration mit `user` & `password` angegeben ist, keine Super-User-Rechte hat, so kann ein weiterer Account dafür mit `superuser_user` & `superuser_password` angegeben werden. Nur diejenigen Datenbankuprade-Scripte, die über den Tag `@superuser_privileges` signalisieren, dass sie Super-User-Rechte benötigen, werden auch wirklich mit Super-User-Rechten ausgeführt. --- diff --git a/config/kivitendo.conf.default b/config/kivitendo.conf.default index 60be4b326..108ce6b95 100644 --- a/config/kivitendo.conf.default +++ b/config/kivitendo.conf.default @@ -256,12 +256,14 @@ log_file = /tmp/kivitendo_console_debug.log # database will be dropped & created before any other test is run. The # following parameters must be given: [testing/database] -host = localhost -port = 5432 -db = -user = postgres -password = -template = template1 +host = localhost +port = 5432 +db = +user = postgres +password = +template = template1 +superuser_user = postgres +superuser_password = [devel] # Several settings related to the development of kivitendo. diff --git a/t/000setup_database.t b/t/000setup_database.t index f61c8a3c1..a927503b5 100755 --- a/t/000setup_database.t +++ b/t/000setup_database.t @@ -16,7 +16,7 @@ use SL::Layout::None; use SL::LxOfficeConf; use Support::TestSetup; -our ($db_cfg, $dbh); +our ($db_cfg, $dbh, $superuser_dbh); sub dbg { # diag(@_); @@ -85,6 +85,7 @@ sub drop_and_create_database { sub report_success { $dbh->disconnect; + $superuser_dbh->disconnect if $superuser_dbh; ok(1, "Database has been setup sucessfully."); done_testing(); } @@ -97,7 +98,8 @@ sub apply_dbupgrade { dbg("Applying $file"); - my $error = $dbupdater->process_file($dbh, $file, $control); + my $script_dbh = $control && $control->{superuser_privileges} ? ($superuser_dbh // $dbh) : $dbh; + my $error = $dbupdater->process_file($script_dbh, $file, $control); BAIL_OUT("Error applying $file: $error") if $error; } @@ -117,6 +119,17 @@ sub create_initial_schema { my $dbupdater = SL::DBUpgrade2->new(form => $::form, return_on_error => 1, silent => 1); my $coa = 'Germany-DATEV-SKR03EU'; + if ($db_cfg->{superuser_user} && ($db_cfg->{superuser_user} ne $db_cfg->{user})) { + @dbi_options = ( + 'dbi:Pg:dbname=' . $db_cfg->{db} . ';host=' . $db_cfg->{host} . ';port=' . $db_cfg->{port}, + $db_cfg->{superuser_user}, + $db_cfg->{superuser_password}, + SL::DBConnect->get_options(PrintError => 0, PrintWarn => 0), + ); + + $superuser_dbh = SL::DBConnect->connect(@dbi_options) || BAIL_OUT("Database superuser connection failed: " . $DBI::errstr); + } + apply_dbupgrade($dbupdater, "sql/lx-office.sql"); apply_dbupgrade($dbupdater, "sql/${coa}-chart.sql");