Commit | Line | Data |
a2598396 |
1 | use strictures 1; |
2 | use Test::More; |
970fe8fe |
3 | use FindBin; |
a2598396 |
4 | |
afd7c030 |
5 | use System::Introspector::Probe::Users; |
a2598396 |
6 | |
970fe8fe |
7 | my $passwd_file = "$FindBin::Bin/test-passwd"; |
8 | my $home = "$FindBin::Bin/data/home-testfoo"; |
9 | my $nohome = "$FindBin::Bin/data/home-doesnotexist"; |
a2598396 |
10 | |
970fe8fe |
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']; |
16 | close $passwd_fh; |
a2598396 |
17 | |
970fe8fe |
18 | local $ENV{PATH} = join ':', |
19 | "$FindBin::Bin/bin", |
20 | $ENV{PATH}; |
21 | |
22 | my $probe = System::Introspector::Probe::Users->new( |
23 | passwd_file => $passwd_file, |
24 | ); |
25 | my $data = $probe->gather; |
26 | |
27 | do { |
28 | my $user = $data->{users}{testfoo}; |
29 | ok $user, 'found first user'; |
30 | |
31 | my $keys = $user->{ssh}{keys}; |
32 | ok $keys, 'found ssh keys structure'; |
33 | |
34 | is_deeply $keys, { |
35 | files => { |
36 | 'first.pub' => { |
37 | file_name => "$home/.ssh/first.pub", |
38 | body => "pubkey\n", |
39 | }, |
40 | }, |
41 | authorized => { |
42 | file_name => "$home/.ssh/authorized_keys", |
43 | body => "keyA\nkeyB\n", |
44 | }, |
45 | }, 'ssh key data'; |
46 | |
1b608727 |
47 | is_deeply $user->{groups}, [qw( |
48 | testfoo_group_A |
49 | testfoo_group_B |
50 | testfoo_group_C |
51 | )], 'groups list'; |
970fe8fe |
52 | |
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'; |
57 | }; |
58 | |
59 | do { |
60 | my $user = $data->{users}{testbar}; |
61 | ok $user, 'found second user'; |
62 | |
63 | my $keys = $user->{ssh}{keys}; |
64 | ok $keys, 'found ssh keys structure'; |
65 | |
66 | is_deeply $keys, { |
67 | files => {}, |
68 | authorized => { |
69 | file_name => "$nohome/.ssh/authorized_keys", |
70 | body => '', |
71 | }, |
72 | }, 'ssh key data'; |
73 | }; |
74 | |
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'); |
80 | |
81 | |
82 | unlink $passwd_file; |
a2598396 |
83 | done_testing; |