Skip to content

Commit

Permalink
root_t now work on MacOSX; new credentials tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyacheslav Matyukhin committed Jun 15, 2012
1 parent f9f28fb commit 14080e1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
56 changes: 56 additions & 0 deletions root_t/credentials.t
@@ -0,0 +1,56 @@
#!/usr/bin/perl

use strict;
use warnings;

use lib 'lib';

use Test::More;
use parent qw(Test::Class);

use Ubic::Credentials;
use t::Utils;

sub setup :Test(setup) {
rebuild_tfiles();
xsystem('chmod -R 777 tfiles');
}

sub current :Tests {
my $c = Ubic::Credentials->new;

is($c->user, 'root');

my @pwnam = getpwnam 'root';
my $root_group = (getgrgid( (getpwnam 'root')[3] ))[0];
my ($group) = $c->group;
is($group, $root_group, "main group is $root_group");
}

sub set :Tests {
my $file = 'tfiles/blah';
my $user = 'nobody';
my $group = 'daemon';

my $c = Ubic::Credentials->new(user => $user, group => $group);

my $pid = fork;
die "fork failed" unless defined $pid;
unless ($pid) {
eval {
$c->set;
die "Tainted" if ${^TAINT};
xsystem("touch $file");
};
warn "subprocess failed: $@" if $@;
exit;
}

waitpid($pid, 0);
ok(-f $file);
my @stat = stat($file);
is($stat[4], scalar(getpwnam($user)), "$file belongs to $user");
is($stat[5], scalar(getgrnam($group)), "$file group is $group") unless $^O eq 'darwin';
}

__PACKAGE__->new->runtests;
4 changes: 4 additions & 0 deletions root_t/groups.t
Expand Up @@ -7,6 +7,10 @@ use parent qw(Test::Class);
use Test::More;
use Time::HiRes qw(sleep);

if ($^O eq 'darwin') {
plan skip_all => 'Group tests are broken on MacOSX';
}

use lib 'lib';
use lib '.';

Expand Down
4 changes: 2 additions & 2 deletions root_t/root.t
Expand Up @@ -30,7 +30,7 @@ sub setup :Test(setup) {
xsystem('chmod -R 777 tfiles');
}

sub test_grants :Tests(8) {
sub test_grants :Tests {
my $self = shift;
my $name = $self->{name};
my $user = $self->{user};
Expand All @@ -46,7 +46,7 @@ sub test_grants :Tests(8) {
my ($file, $user, $group) = @_;
my @stat = stat($file);
is($stat[4], scalar(getpwnam($user)), "$file belongs to $user");
is($stat[5], scalar(getgrnam($group)), "$file group is $group");
is($stat[5], scalar(getgrnam($group)), "$file group is $group") unless $^O eq 'darwin';
};
$check_file->("tfiles/$name.result", $result_user, $result_group);
$check_file->("tfiles/$name.ubic.log", $user, $group);
Expand Down
2 changes: 1 addition & 1 deletion root_t/watchdog.t
Expand Up @@ -34,7 +34,7 @@ sub watchdog :Tests(2) {
my @stat = stat("tfiles/ubic/status/daemongroup-daemon");

is($stat[4], scalar(getpwnam('nobody')), 'status file owner is correct after watchdog');
is($stat[5], scalar(getgrnam('daemon')), 'status file group is correct after watchdog');
is($stat[5], scalar(getgrnam('daemon')), 'status file group is correct after watchdog') unless $^O eq 'darwin';
}

__PACKAGE__->new->runtests;

0 comments on commit 14080e1

Please sign in to comment.