Commit | Line | Data |
478358f5 |
1 | use strictures 1; |
2 | use Test::More; |
3 | use FindBin; |
4 | |
5 | use System::Introspector::Sudoers; |
6 | |
7 | my $dir = "$FindBin::Bin/sudoers-data"; |
8 | |
9 | system("mkdir $dir"); |
10 | system("mkdir $dir/bar_host"); |
11 | |
12 | my $start = write_file('sudoers', |
13 | 'foo bar', |
14 | 'baz qux', |
15 | "#include $dir/foo_%h", |
16 | "#includedir $dir/bar_%h", |
17 | ); |
18 | |
19 | my $foo_file = write_file('foo_host', |
20 | 'in foo', |
21 | ); |
22 | my $bar_file = write_file("bar_host/baz", |
23 | 'in bar file', |
24 | ); |
25 | |
26 | my $probe = System::Introspector::Sudoers->new( |
27 | sudoers_file => $start, |
28 | hostname => 'host', |
29 | ); |
30 | |
31 | ok((my $data = $probe->gather), 'received data'); |
32 | |
33 | my $inc = "#include $dir/foo_\%h\n#includedir $dir/bar_\%h\n"; |
34 | is_deeply $data, { |
35 | $start => { body => "foo bar\nbaz qux\n$inc" }, |
36 | $foo_file => { body => "in foo\n" }, |
37 | $bar_file => { body => "in bar file\n" }, |
38 | }, 'found files'; |
39 | |
40 | system("rm $_") for $start, $foo_file, $bar_file; |
41 | system("rmdir $dir/bar_host"); |
42 | system("rmdir $dir"); |
43 | done_testing; |
44 | |
45 | sub write_file { |
46 | my ($file, @lines) = @_; |
47 | my $path = "$FindBin::Bin/sudoers-data/$file"; |
48 | open my $fh, '>', $path or die "Unable to write $path: $!\n"; |
49 | print $fh map "$_\n", @lines; |
50 | return $path; |
51 | } |