Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/Limit/OPTS.pm

raw
1 package ProFTPD::Tests::Config::Limit::OPTS;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Spec;
8 use IO::Handle;
9
10 use ProFTPD::TestSuite::FTP;
11 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
12
13 $| = 1;
14
15 my $order = 0;
16
17 my $TESTS = {
18 opts_limit_utf8_bug3438 => {
19 order => ++$order,
20 test_class => [qw(bug forking mod_lang)],
21 },
22
23 opts_limit_all_bug3438 => {
24 order => ++$order,
25 test_class => [qw(bug forking mod_lang)],
26 },
27
28 };
29
30 sub new {
31 return shift()->SUPER::new(@_);
32 }
33
34 sub list_tests {
35 return testsuite_get_runnable_tests($TESTS);
36 }
37
38 sub opts_limit_utf8_bug3438 {
39 my $self = shift;
40 my $tmpdir = $self->{tmpdir};
41
42 my $config_file = "$tmpdir/limit.conf";
43 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
44 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
45
46 my $log_file = File::Spec->rel2abs('tests.log');
47
48 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
49 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
50
51 my $user = 'proftpd';
52 my $passwd = 'test';
53 my $home_dir = File::Spec->rel2abs($tmpdir);
54 my $uid = 500;
55 my $gid = 500;
56
57 # Make sure that, if we're running as root, that the home directory has
58 # permissions/privs set for the account we create
59 if ($< == 0) {
60 unless (chmod(0755, $home_dir)) {
61 die("Can't set perms on $home_dir to 0755: $!");
62 }
63
64 unless (chown($uid, $gid, $home_dir)) {
65 die("Can't set owner of $home_dir to $uid/$gid: $!");
66 }
67 }
68
69 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
70 '/bin/bash');
71 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
72
73 my $config = {
74 PidFile => $pid_file,
75 ScoreboardFile => $scoreboard_file,
76 SystemLog => $log_file,
77
78 AuthUserFile => $auth_user_file,
79 AuthGroupFile => $auth_group_file,
80 AuthOrder => 'mod_auth_file.c',
81
82 IfModules => {
83 'mod_delay.c' => {
84 DelayEngine => 'off',
85 },
86 },
87
88 Limit => {
89 OPTS_UTF8 => {
90 DenyAll => '',
91 },
92 },
93
94 };
95
96 my ($port, $config_user, $config_group) = config_write($config_file, $config);
97
98 # Open pipes, for use between the parent and child processes. Specifically,
99 # the child will indicate when it's done with its test by writing a message
100 # to the parent.
101 my ($rfh, $wfh);
102 unless (pipe($rfh, $wfh)) {
103 die("Can't open pipe: $!");
104 }
105
106 my $ex;
107
108 # Fork child
109 $self->handle_sigchld();
110 defined(my $pid = fork()) or die("Can't fork: $!");
111 if ($pid) {
112 eval {
113 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
114 $client->login($user, $passwd);
115
116 my ($resp_code, $resp_msg);
117
118 eval { $client->opts('UTF8', 'on') };
119 unless ($@) {
120 die("OPTS UTF8 succeeded unexpectedly");
121
122 } else {
123 $resp_code = $client->response_code();
124 $resp_msg = $client->response_msg();
125 }
126
127 my $expected;
128
129 $expected = 550;
130 $self->assert($expected == $resp_code,
131 test_msg("Expected $expected, got $resp_code"));
132
133 $expected = "OPTS UTF8: Permission denied";
134 $self->assert($expected eq $resp_msg,
135 test_msg("Expected '$expected', got '$resp_msg'"));
136
137 $client->quit();
138 };
139
140 if ($@) {
141 $ex = $@;
142 }
143
144 $wfh->print("done\n");
145 $wfh->flush();
146
147 } else {
148 eval { server_wait($config_file, $rfh) };
149 if ($@) {
150 warn($@);
151 exit 1;
152 }
153
154 exit 0;
155 }
156
157 # Stop server
158 server_stop($pid_file);
159
160 $self->assert_child_ok($pid);
161
162 if ($ex) {
163 die($ex);
164 }
165
166 unlink($log_file);
167 }
168
169 sub opts_limit_all_bug3438 {
170 my $self = shift;
171 my $tmpdir = $self->{tmpdir};
172
173 my $config_file = "$tmpdir/limit.conf";
174 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
175 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
176
177 my $log_file = File::Spec->rel2abs('tests.log');
178
179 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
180 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
181
182 my $user = 'proftpd';
183 my $passwd = 'test';
184 my $home_dir = File::Spec->rel2abs($tmpdir);
185 my $uid = 500;
186 my $gid = 500;
187
188 # Make sure that, if we're running as root, that the home directory has
189 # permissions/privs set for the account we create
190 if ($< == 0) {
191 unless (chmod(0755, $home_dir)) {
192 die("Can't set perms on $home_dir to 0755: $!");
193 }
194
195 unless (chown($uid, $gid, $home_dir)) {
196 die("Can't set owner of $home_dir to $uid/$gid: $!");
197 }
198 }
199
200 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
201 '/bin/bash');
202 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
203
204 my $config = {
205 PidFile => $pid_file,
206 ScoreboardFile => $scoreboard_file,
207 SystemLog => $log_file,
208
209 AuthUserFile => $auth_user_file,
210 AuthGroupFile => $auth_group_file,
211 AuthOrder => 'mod_auth_file.c',
212
213 IfModules => {
214 'mod_delay.c' => {
215 DelayEngine => 'off',
216 },
217 },
218
219 Limit => {
220 ALL => {
221 DenyAll => '',
222 },
223 },
224
225 };
226
227 my ($port, $config_user, $config_group) = config_write($config_file, $config);
228
229 # Open pipes, for use between the parent and child processes. Specifically,
230 # the child will indicate when it's done with its test by writing a message
231 # to the parent.
232 my ($rfh, $wfh);
233 unless (pipe($rfh, $wfh)) {
234 die("Can't open pipe: $!");
235 }
236
237 my $ex;
238
239 # Fork child
240 $self->handle_sigchld();
241 defined(my $pid = fork()) or die("Can't fork: $!");
242 if ($pid) {
243 eval {
244 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
245 $client->login($user, $passwd);
246 $client->opts('UTF8', 'on');
247 $client->quit();
248 };
249
250 if ($@) {
251 $ex = $@;
252 }
253
254 $wfh->print("done\n");
255 $wfh->flush();
256
257 } else {
258 eval { server_wait($config_file, $rfh) };
259 if ($@) {
260 warn($@);
261 exit 1;
262 }
263
264 exit 0;
265 }
266
267 # Stop server
268 server_stop($pid_file);
269
270 $self->assert_child_ok($pid);
271
272 if ($ex) {
273 die($ex);
274 }
275
276 unlink($log_file);
277 }
278
279 1;