5 use System::Introspector::Probe::Users;
7 my $passwd_file = "$FindBin::Bin/test-passwd";
8 my $home = "$FindBin::Bin/data/home-testfoo";
9 my $nohome = "$FindBin::Bin/data/home-doesnotexist";
11 open my $passwd_fh, '>', $passwd_file
12 or die "Unable to write $passwd_file: $!\n";
13 printf $passwd_fh "%s\n", join ':', @$_
14 for [qw( testfoo x 23 42 comment ), $home, '/bin/false'],
15 [qw( testbar x 24 43 comment ), $nohome, '/bin/false'];
18 local $ENV{PATH} = join ':',
22 my $probe = System::Introspector::Probe::Users->new(
23 passwd_file => $passwd_file,
25 my $data = $probe->gather;
28 my $user = $data->{users}{testfoo};
29 ok $user, 'found first user';
31 my $keys = $user->{ssh}{keys};
32 ok $keys, 'found ssh keys structure';
37 file_name => "$home/.ssh/first.pub",
42 file_name => "$home/.ssh/authorized_keys",
43 body => "keyA\nkeyB\n",
47 is_deeply $user->{groups}, [qw(
53 my $tab = $user->{crontab};
54 ok $tab, 'got crontab results';
55 like $tab->{body}, qr{-u\s*testfoo}, 'crontab called with user option';
56 like $tab->{body}, qr{-l}, 'crontab asked for list';
60 my $user = $data->{users}{testbar};
61 ok $user, 'found second user';
63 my $keys = $user->{ssh}{keys};
64 ok $keys, 'found ssh keys structure';
69 file_name => "$nohome/.ssh/authorized_keys",
75 #ok((my $user = $data->{users}{ +getlogin }), 'found own user');
76 #ok(defined($user->{ $_ }), "$_ is defined")
77 # for qw( comment crontab gid groups home shell ssh uid username );
78 #ok(not(exists $user->{crontab}{error}), 'no crontab error');
79 #is($user->{ssh}{keys}{error}, undef, 'no ssh keys error');