~ubuntu-branches/ubuntu/hardy/postgresql-common/hardy-backports

« back to all changes in this revision

Viewing changes to t/130_nonroot_admin.t

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-21 16:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20071021160108-6bp6fxhst130l0do
Tags: 80
* pg_upgradecluster: Fix locale error checking.
* pg_upgradecluster: Use cluster_exists() instead of
  cluster_data_directory().
* PgCommon.pm: Fix cluster_data_directory() to consider the data_directory
  setting in postgresql.conf, which should trump the /pgdata symbolic link.
* debian/init.d-functions: Check for 'postgresql.conf' instead of 'pgdata'
  in the test for a valid cluster configuration directory, since 'pgdata' is
  optional now.
* pg_createcluster: Do not create pgdata symlinks to the data directory in
  /etc any more when configuring a >= 8.0 cluster. Use the data_directory
  configuration option instead. (Part of #444689)
* t/020_create_sql_remove.t: Check that clusters still work when replacing
  the data_directory setting with a pgdata symbolic link, and that
  the data_directory setting trumps the symlink.
* pg_upgradecluster: Set correct data_directory config option after copying
  over the old configuration files.
* t/060_obsolete_confparams.t: Restore data_directory setting after
  scribbling over the configuration file with our template.
* PgCommon.pm, cluster_info(): Only return a value for 'logfile' when it is
  not explicitly configured with log_directory and/or log_filename. The
  previous guessing was wrong anyway, since PostgreSQL always appends a
  pretty unpredictable timestamp.
* pg_ctlcluster: Only do log file checks and pass pg_ctl -l option when the
  log file default is used. Otherwise let PostgreSQL do its logfile handling
  and waive log file checks, since we don't know which file is used.
* pg_ctlcluster: Redirect pg_ctl's stdout and stderr to /dev/null, otherwise
  it will hang forever when using a custom log file (and thus not passing
  -l).
* pg_lsclusters: Print "custom" as log file location if a custom one was set
  in postgresql.conf.
* pg_upgradecluster: Enable 'redirect_stderr' in the 7.4 -> 8.x migration of
  'syslog' -> 'log_destination', so that the log output is actually
  complete.
* t/060_obsolete_confparams.t: Enable 'redirect_stderr' in the template
  postgresql.conf's, so that we actually capture log output.
* t/020_create_sql_remove.t: Check proper handling of logs when configuring
  log file in postgresql.conf, using the log symlink, or having neither.
* PgCommon.pm, cluster_info(): Return default log file in 'logfile' if
  neither postgresql.conf nor a 'log' symlink explicitly specify a log file.
* pg_createcluster: Do not create log symlink if using the default log file
  (i. e. when not using -l). (Closes: #444689)
* t/020_create_sql_remove.t: Verify that log symlink is not created by
  default.
* architecture.html: Update to current reality.
* debian/postgresql-common.config: Do not consider versions as obsolete if
  they are newer than the latest officially supported version. This avoids
  confusion when testing new betas in experimental or using backports.
  (Closes: #446635)
* t/TestLib.pm: Make exec_as() work with user name 'root' (not just uid 0).
* Add t/130_nonroot_admin.t: Check that administrative pg_ tools work as
  non-root, too, if the invoker has sufficient permissions on the
  directories (test case for LP #90036).
* pg_{create,drop,upgrade}cluster: Small tweaks to make the scripts work for
  non-root users with sufficient write permissions to
  /etc/postgresql/<version>, /var/lib/postgresql/<version>, and
  /var/log/postgresql. (LP: #90036)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Check that cluster administration works as non-root if the invoker has
 
2
# sufficient permissions on directories.
 
3
 
 
4
use strict; 
 
5
 
 
6
use lib 't';
 
7
use TestLib;
 
8
 
 
9
my $ownver = $MAJORS[-1];
 
10
my $grpver = $MAJORS[0];
 
11
 
 
12
use Test::More tests => 37;
 
13
 
 
14
use lib '/usr/share/postgresql-common';
 
15
use PgCommon;
 
16
 
 
17
my $testuser = 'postgres';
 
18
my ($uid, $gid) = (getpwnam $testuser)[2,3];
 
19
 
 
20
# fails by default due to access restrictions
 
21
is ((exec_as 'postgres', "pg_createcluster $ownver fail --start"), 1,
 
22
    "pg_createcluster fails as user $testuser by default");
 
23
# and does not leave any garbage behind
 
24
check_clean;
 
25
 
 
26
# prepare directories to that we can access it as owner/group
 
27
die "could not mkdir: $!" if system "mkdir -p /etc/postgresql/$ownver /etc/postgresql/$grpver /var/log/postgresql /var/lib/postgresql/$ownver /var/lib/postgresql/$grpver";
 
28
chown $uid, 0, "/etc/postgresql/$ownver", "/var/lib/postgresql/$ownver";
 
29
chown 0, $gid, "/etc/postgresql/$grpver", "/var/log/postgresql", "/var/lib/postgresql/$grpver";
 
30
chmod 0775, "/etc/postgresql/$grpver", "/var/log/postgresql", "/var/lib/postgresql/$grpver";
 
31
 
 
32
# pg_createcluster and pg_ctlcluster
 
33
is ((exec_as $testuser, "pg_createcluster $ownver own --start"), 0,
 
34
    "pg_createcluster succeeds as user $testuser with appropriate owner permissions");
 
35
is ((exec_as $testuser, "pg_createcluster $grpver grp --start"), 0,
 
36
    "pg_createcluster succeeds as user $testuser with appropriate group permissions");
 
37
 
 
38
like_program_out $testuser, 'pg_lsclusters -h', 0,
 
39
    qr/^$grpver\s+grp.*online.*\n^$ownver\s+own.*online/m;
 
40
like_program_out 'postgres', 'psql -Atl', 0, qr/template1.*UTF8/;
 
41
 
 
42
# pg_maintenance
 
43
like_program_out $testuser, 'pg_maintenance --force', 0,
 
44
    qr/^Doing.*$grpver\/grp.*\n^Doing.*$ownver\/own/m,
 
45
    "pg_maintenance works as user $testuser with appropriate directory permissions";
 
46
 
 
47
# pg_dropcluster
 
48
is ((exec_as $testuser, "pg_dropcluster $ownver own --stop"), 0,
 
49
    "pg_dropcluster succeeds as user $testuser with appropriate directory owner permissions");
 
50
 
 
51
# pg_upgradecluster
 
52
if ($grpver ne $ownver) {
 
53
    my $outref;
 
54
    is ((exec_as $testuser, "pg_upgradecluster $grpver grp", $outref, 0), 0, 
 
55
        "pg_upgradecluster succeeds as user $testuser");
 
56
    like $$outref, qr/Starting target cluster/, 'pg_upgradecluster reported cluster startup';
 
57
    like $$outref, qr/Success. Please check/, 'pg_upgradecluster reported successful operation';
 
58
 
 
59
    like_program_out $testuser, 'pg_lsclusters -h', 0,
 
60
        qr/^$grpver\s+grp.*down.*\n^$ownver\s+grp.*online/m;
 
61
 
 
62
    # clean up
 
63
    is ((exec_as $testuser, "pg_dropcluster $grpver grp"), 0);
 
64
    is ((exec_as $testuser, "pg_dropcluster $ownver grp --stop"), 0);
 
65
} else {
 
66
    pass 'Only one major version installed, skipping pg_upgradecluster tests';
 
67
    for (my $i = 0; $i < 5; ++$i) { pass '...'; }
 
68
 
 
69
    is ((exec_as $testuser, "pg_dropcluster $grpver grp --stop"), 0);
 
70
}
 
71
 
 
72
# we cannot expect full cleanliness of /{etc,var/lib}/postgresql since that
 
73
# requires root permissions; thus help a bit
 
74
rmdir "/etc/postgresql/$ownver";
 
75
rmdir "/etc/postgresql/$grpver";
 
76
rmdir "/var/lib/postgresql/$ownver";
 
77
rmdir "/var/lib/postgresql/$grpver";
 
78
check_clean;
 
79
 
 
80
# vim: filetype=perl