X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fusers.t;h=ccd6826afc0588c6e4b90990760e9f0768371e39;hb=f25e8c9fc4232f051b3b96c52004c0086f6eca70;hp=2e9d653d0733e7b746cf40538b8f51e96bbd5032;hpb=b535ee84aa3a8fa959e0ee278faada175f5d69a0;p=scpubgit%2FSystem-Introspector.git diff --git a/t/users.t b/t/users.t index 2e9d653..ccd6826 100644 --- a/t/users.t +++ b/t/users.t @@ -1,15 +1,81 @@ use strictures 1; use Test::More; +use FindBin; -use System::Introspector::Users; +use System::Introspector::Probe::Users; -my $probe = System::Introspector::Users->new; -my $data = $probe->gather; +my $passwd_file = "$FindBin::Bin/test-passwd"; +my $home = "$FindBin::Bin/data/home-testfoo"; +my $nohome = "$FindBin::Bin/data/home-doesnotexist"; -ok((my $user = $data->{users}{ $> }), 'found own user'); -ok(defined($user->{ $_ }), "$_ is defined") - for qw( comment crontab gid groups home shell ssh uid username ); -ok(not(exists $user->{crontab}{error}), 'no crontab error'); -is($user->{ssh}{keys}{error}, undef, 'no ssh keys error'); +open my $passwd_fh, '>', $passwd_file + or die "Unable to write $passwd_file: $!\n"; +printf $passwd_fh "%s\n", join ':', @$_ + for [qw( testfoo x 23 42 comment ), $home, '/bin/false'], + [qw( testbar x 24 43 comment ), $nohome, '/bin/false']; +close $passwd_fh; +local $ENV{PATH} = join ':', + "$FindBin::Bin/bin", + $ENV{PATH}; + +my $probe = System::Introspector::Probe::Users->new( + passwd_file => $passwd_file, +); +my $data = $probe->gather; + +do { + my $user = $data->{users}{testfoo}; + ok $user, 'found first user'; + + my $keys = $user->{ssh}{keys}; + ok $keys, 'found ssh keys structure'; + + is_deeply $keys, { + files => { + 'first.pub' => { + file_name => "$home/.ssh/first.pub", + body => "pubkey\n", + }, + }, + authorized => { + file_name => "$home/.ssh/authorized_keys", + body => "keyA\nkeyB\n", + }, + }, 'ssh key data'; + + is_deeply $user->{groups}, { + list => [qw( testfoo_group_A testfoo_group_B testfoo_group_C )], + }, 'groups list'; + + my $tab = $user->{crontab}; + ok $tab, 'got crontab results'; + like $tab->{body}, qr{-u\s*testfoo}, 'crontab called with user option'; + like $tab->{body}, qr{-l}, 'crontab asked for list'; +}; + +do { + my $user = $data->{users}{testbar}; + ok $user, 'found second user'; + + my $keys = $user->{ssh}{keys}; + ok $keys, 'found ssh keys structure'; + + is_deeply $keys, { + files => {}, + authorized => { + file_name => "$nohome/.ssh/authorized_keys", + body => '', + }, + }, 'ssh key data'; +}; + +#ok((my $user = $data->{users}{ +getlogin }), 'found own user'); +#ok(defined($user->{ $_ }), "$_ is defined") +# for qw( comment crontab gid groups home shell ssh uid username ); +#ok(not(exists $user->{crontab}{error}), 'no crontab error'); +#is($user->{ssh}{keys}{error}, undef, 'no ssh keys error'); + + +unlink $passwd_file; done_testing;