mirror of
https://github.com/duncs/clusterssh.git
synced 2025-04-22 09:22:24 +00:00
Fix test when run as root
Root user cannot easily be prevented from accessing a no-access file so don't run the test if run as root
This commit is contained in:
parent
c8e66fbcdd
commit
5edca936ed
2 changed files with 28 additions and 20 deletions
1
Changes
1
Changes
|
@ -11,6 +11,7 @@
|
|||
* Remove doc references to 'always_tile' as renamed 'window_tiling' (Debian bug ID #697371)
|
||||
* Updated manpage whatis entries (patch by Tony Mancill)
|
||||
* Fix watch line expression to catch 4.x series tarballs (Debian patch LP ID #1076897)
|
||||
* Allow tests to pass successfully when run as root
|
||||
|
||||
2012-12-09 Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.01_02
|
||||
* Fix logic when using 'autoclose' on the command line or config file
|
||||
|
|
|
@ -8,6 +8,7 @@ use Test::More;
|
|||
use Test::Trap;
|
||||
use File::Which qw(which);
|
||||
use File::Temp qw(tempdir);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use Readonly;
|
||||
|
||||
|
@ -27,24 +28,33 @@ $cluster1->register_tag( 'people', @expected );
|
|||
|
||||
my @got = $cluster2->get_tag('people');
|
||||
|
||||
is_deeply( \@got, \@expected,
|
||||
'Shared cluster object' );
|
||||
is_deeply( \@got, \@expected, 'Shared cluster object' );
|
||||
|
||||
# should pass without issue
|
||||
trap {
|
||||
$cluster1->read_cluster_file( $Bin . '/30cluster.doesnt exist' );
|
||||
};
|
||||
is( ! $trap, '', 'coped with missing file ok' );
|
||||
is( !$trap, '', 'coped with missing file ok' );
|
||||
isa_ok( $cluster1, 'App::ClusterSSH::Cluster' );
|
||||
|
||||
my $no_read=$Bin . '/30cluster.cannot_read';
|
||||
chmod 0000, $no_read;
|
||||
trap {
|
||||
$cluster1->read_cluster_file( $no_read );
|
||||
};
|
||||
chmod 0644, $no_read;
|
||||
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Cluster' );
|
||||
is( $trap->die, "Unable to read file $no_read: Permission denied", 'Error on reading an existing file ok');
|
||||
# no point running this test as root since root cannot be blocked
|
||||
# from accessing the file
|
||||
if ( $EUID != 0 ) {
|
||||
my $no_read = $Bin . '/30cluster.cannot_read';
|
||||
chmod 0000, $no_read;
|
||||
trap {
|
||||
$cluster1->read_cluster_file($no_read);
|
||||
};
|
||||
chmod 0644, $no_read;
|
||||
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Cluster' );
|
||||
is( $trap->die,
|
||||
"Unable to read file $no_read: Permission denied",
|
||||
'Error on reading an existing file ok'
|
||||
);
|
||||
}
|
||||
else {
|
||||
pass('Cannot test for lack of read access when run as root');
|
||||
}
|
||||
|
||||
@expected = ('host1');
|
||||
$cluster1->read_cluster_file( $Bin . '/30cluster.file1' );
|
||||
|
@ -53,18 +63,15 @@ is_deeply( \@got, \@expected, 'read simple file OK' );
|
|||
|
||||
@expected = ('host1');
|
||||
$cluster1->read_cluster_file( $Bin . '/30cluster.file2' );
|
||||
@got=$cluster1->get_tag('tag1');
|
||||
is_deeply( \@got,
|
||||
\@expected, 'read more complex file OK' );
|
||||
@got = $cluster1->get_tag('tag1');
|
||||
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
||||
|
||||
@expected = ('host2');
|
||||
@got=$cluster1->get_tag('tag2');
|
||||
is_deeply( \@got,
|
||||
\@expected, 'read more complex file OK' );
|
||||
@got = $cluster1->get_tag('tag2');
|
||||
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
||||
|
||||
@expected = ( 'host3', 'host4' );
|
||||
@got=$cluster1->get_tag('tag3');
|
||||
is_deeply( \@got,
|
||||
\@expected, 'read more complex file OK' );
|
||||
@got = $cluster1->get_tag('tag3');
|
||||
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
||||
|
||||
done_testing();
|
||||
|
|
Loading…
Add table
Reference in a new issue