Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_facl.pm

raw
1 package ProFTPD::Tests::Modules::mod_facl;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Copy;
8 use File::Path qw(mkpath);
9 use File::Spec;
10 use IO::Handle;
11
12 use ProFTPD::TestSuite::FTP;
13 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
14
15 $| = 1;
16
17 my $order = 0;
18
19 my $TESTS = {
20 facl_bug4303 => {
21 order => ++$order,
22 test_class => [qw(forking os_linux)],
23 },
24
25 };
26
27 sub new {
28 return shift()->SUPER::new(@_);
29 }
30
31 sub list_tests {
32 return testsuite_get_runnable_tests($TESTS);
33 }
34
35 sub facl_bug4303 {
36 my $self = shift;
37 my $tmpdir = $self->{tmpdir};
38 my $setup = test_setup($tmpdir, 'facl');
39
40 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
41 mkpath($sub_dir);
42
43 # Follow the reproduction recipe in Bug#4303.
44 my $cmd = "setfacl -m u:`tail -n1 /etc/passwd | cut -d: -f1`:rwx $sub_dir";
45 `$cmd`;
46
47 $cmd = "setfacl -m g::rx $sub_dir";
48 `$cmd`;
49
50 $cmd = "setfacl -m g:`tail -n1 /etc/passwd | cut -d: -f1`:rwx $sub_dir";
51 `$cmd`;
52
53 $cmd = "setfacl -m m::rwx $sub_dir";
54 `$cmd`;
55
56 $cmd = "getfacl --access $sub_dir | setfacl -d -M- $sub_dir";
57 `$cmd`;
58
59 $cmd = "getfacl $sub_dir";
60 my $results = [`$cmd`];
61 if ($ENV{TEST_VERBOSE}) {
62 print STDERR "# Results for command: $cmd:\n";
63 print STDERR join('', @$results), "\n";
64 }
65
66 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d/test.d");
67
68 my $config = {
69 PidFile => $setup->{pid_file},
70 ScoreboardFile => $setup->{scoreboard_file},
71 SystemLog => $setup->{log_file},
72 TraceLog => $setup->{log_file},
73 Trace => 'fsio:20 facl:20',
74
75 AuthUserFile => $setup->{auth_user_file},
76 AuthGroupFile => $setup->{auth_group_file},
77 AuthOrder => 'mod_auth_file.c',
78
79 IfModules => {
80 'mod_delay.c' => {
81 DelayEngine => 'off',
82 },
83 },
84 };
85
86 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
87 $config);
88
89 # Open pipes, for use between the parent and child processes. Specifically,
90 # the child will indicate when it's done with its test by writing a message
91 # to the parent.
92 my ($rfh, $wfh);
93 unless (pipe($rfh, $wfh)) {
94 die("Can't open pipe: $!");
95 }
96
97 my $ex;
98
99 # Fork child
100 $self->handle_sigchld();
101 defined(my $pid = fork()) or die("Can't fork: $!");
102 if ($pid) {
103 eval {
104 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
105 $client->login($setup->{user}, $setup->{passwd});
106 $client->mkd('sub.d/test.d');
107 $client->quit();
108 };
109 if ($@) {
110 $ex = $@;
111 }
112
113 $wfh->print("done\n");
114 $wfh->flush();
115
116 } else {
117 eval { server_wait($setup->{config_file}, $rfh) };
118 if ($@) {
119 warn($@);
120 exit 1;
121 }
122
123 exit 0;
124 }
125
126 # Stop server
127 server_stop($setup->{pid_file});
128 $self->assert_child_ok($pid);
129
130 $cmd = "getfacl $test_dir";
131 $results = [`$cmd`];
132 if ($ENV{TEST_VERBOSE}) {
133 print STDERR "# Results for command: $cmd:\n";
134 print STDERR join('', @$results), "\n";
135 }
136
137 my $seen = grep(/^mask::rwx$/, @$results);
138 $self->assert($seen == 1,
139 "Expected 'mask::rwx' not appearing in getfacl results");
140 test_cleanup($setup->{log_file}, $ex);
141 }
142
143 1;