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}, {
48 list => [qw( testfoo_group_A testfoo_group_B testfoo_group_C )],
51 my $tab = $user->{crontab};
52 ok $tab, 'got crontab results';
53 like $tab->{body}, qr{-u\s*testfoo}, 'crontab called with user option';
54 like $tab->{body}, qr{-l}, 'crontab asked for list';
58 my $user = $data->{users}{testbar};
59 ok $user, 'found second user';
61 my $keys = $user->{ssh}{keys};
62 ok $keys, 'found ssh keys structure';
67 file_name => "$nohome/.ssh/authorized_keys",
73 #ok((my $user = $data->{users}{ +getlogin }), 'found own user');
74 #ok(defined($user->{ $_ }), "$_ is defined")
75 # for qw( comment crontab gid groups home shell ssh uid username );
76 #ok(not(exists $user->{crontab}{error}), 'no crontab error');
77 #is($user->{ssh}{keys}{error}, undef, 'no ssh keys error');