source: src/router/proftpd/tests/t/lib/ProFTPD/Tests/Commands/MFF.pm @ 17876

Last change on this file since 17876 was 17876, checked in by BrainSlayer, 19 months ago

update proftp

File size: 9.1 KB
Line 
1package ProFTPD::Tests::Commands::MFF;
2
3use lib qw(t/lib);
4use base qw(ProFTPD::TestSuite::Child);
5use strict;
6
7use File::Spec;
8use IO::Handle;
9
10use ProFTPD::TestSuite::FTP;
11use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
12
13$| = 1;
14
15my $order = 0;
16
17my $TESTS = {
18  mff_ok => {
19    order => ++$order,
20    test_class => [qw(forking)],
21  },
22
23  mff_chrooted_ok => {
24    order => ++$order,
25    test_class => [qw(forking rootprivs)],
26  },
27
28  mff_bug3142 => {
29    order => ++$order,
30    test_class => [qw(bug forking)],
31  },
32
33};
34
35sub new {
36  return shift()->SUPER::new(@_);
37}
38
39sub list_tests {
40  return testsuite_get_runnable_tests($TESTS);
41}
42
43sub mff_ok {
44  my $self = shift;
45  my $tmpdir = $self->{tmpdir};
46
47  my $config_file = "$tmpdir/cmds.conf";
48  my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
49  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
50
51  my $log_file = File::Spec->rel2abs('tests.log');
52
53  my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
54  my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
55
56  my $user = 'proftpd';
57  my $passwd = 'test';
58  my $home_dir = File::Spec->rel2abs($tmpdir);
59  my $uid = 500;
60  my $gid = 500;
61
62  my $test_file = File::Spec->rel2abs("$tmpdir/foo");
63  if (open(my $fh, "> $test_file")) {
64    close($fh);
65
66  } else {
67    die("Can't open $test_file: $!");
68  }
69
70  # Make sure that, if we're running as root, that the home directory has
71  # permissions/privs set for the account we create
72  if ($< == 0) {
73    unless (chmod(0755, $home_dir)) {
74      die("Can't set perms on $home_dir to 0755: $!");
75    }
76
77    unless (chown($uid, $gid, $home_dir, $test_file)) {
78      die("Can't set owner of $home_dir, $test_file to $uid/$gid: $!");
79    }
80  }
81
82  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
83    '/bin/bash');
84  auth_group_write($auth_group_file, 'ftpd', $gid, $user);
85
86  my $config = {
87    PidFile => $pid_file,
88    ScoreboardFile => $scoreboard_file,
89    SystemLog => $log_file,
90
91    AuthUserFile => $auth_user_file,
92    AuthGroupFile => $auth_group_file,
93
94    IfModules => {
95      'mod_delay.c' => {
96        DelayEngine => 'off',
97      },
98    },
99  };
100
101  my ($port, $config_user, $config_group) = config_write($config_file, $config);
102
103  # Open pipes, for use between the parent and child processes.  Specifically,
104  # the child will indicate when it's done with its test by writing a message
105  # to the parent.
106  my ($rfh, $wfh);
107  unless (pipe($rfh, $wfh)) {
108    die("Can't open pipe: $!");
109  }
110
111  my $ex;
112
113  # Fork child
114  $self->handle_sigchld();
115  defined(my $pid = fork()) or die("Can't fork: $!");
116  if ($pid) {
117    eval {
118      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
119
120      $client->login($user, $passwd);
121
122      my ($resp_code, $resp_msg);
123      ($resp_code, $resp_msg) = $client->mff('modify=20020717210715;', 'foo');
124
125      my $expected;
126
127      $expected = 213;
128      $self->assert($expected == $resp_code,
129        test_msg("Expected $expected, got $resp_code"));
130
131      $expected = 'modify=20020717210715; foo';
132      $self->assert($expected eq $resp_msg,
133        test_msg("Expected '$expected', got '$resp_msg'"));
134    };
135
136    if ($@) {
137      $ex = $@;
138    }
139
140    $wfh->print("done\n");
141    $wfh->flush();
142
143  } else {
144    eval { server_wait($config_file, $rfh) };
145    if ($@) {
146      warn($@);
147      exit 1;
148    }
149
150    exit 0;
151  }
152
153  # Stop server
154  server_stop($pid_file);
155
156  $self->assert_child_ok($pid);
157
158  if ($ex) {
159    die($ex);
160  }
161
162  unlink($log_file);
163}
164
165sub mff_chrooted_ok {
166  my $self = shift;
167  my $tmpdir = $self->{tmpdir};
168
169  my $config_file = "$tmpdir/cmds.conf";
170  my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
171  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
172
173  my $log_file = File::Spec->rel2abs('tests.log');
174
175  my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
176  my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
177
178  my $user = 'proftpd';
179  my $passwd = 'test';
180  my $home_dir = File::Spec->rel2abs($tmpdir);
181  my $uid = 500;
182  my $gid = 500;
183
184  my $test_file = File::Spec->rel2abs("$tmpdir/foo");
185  if (open(my $fh, "> $test_file")) {
186    close($fh);
187
188  } else {
189    die("Can't open $test_file: $!");
190  }
191
192  # Make sure that, if we're running as root, that the home directory has
193  # permissions/privs set for the account we create
194  if ($< == 0) {
195    unless (chmod(0755, $home_dir)) {
196      die("Can't set perms on $home_dir to 0755: $!");
197    }
198
199    unless (chown($uid, $gid, $home_dir, $test_file)) {
200      die("Can't set owner of $home_dir, $test_file to $uid/$gid: $!");
201    }
202  }
203
204  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
205    '/bin/bash');
206  auth_group_write($auth_group_file, 'ftpd', $gid, $user);
207
208  my $config = {
209    PidFile => $pid_file,
210    ScoreboardFile => $scoreboard_file,
211    SystemLog => $log_file,
212
213    AuthUserFile => $auth_user_file,
214    AuthGroupFile => $auth_group_file,
215
216    DefaultRoot => '~',
217
218    IfModules => {
219      'mod_delay.c' => {
220        DelayEngine => 'off',
221      },
222    },
223  };
224
225  my ($port, $config_user, $config_group) = config_write($config_file, $config);
226
227  # Open pipes, for use between the parent and child processes.  Specifically,
228  # the child will indicate when it's done with its test by writing a message
229  # to the parent.
230  my ($rfh, $wfh);
231  unless (pipe($rfh, $wfh)) {
232    die("Can't open pipe: $!");
233  }
234
235  my $ex;
236
237  # Fork child
238  $self->handle_sigchld();
239  defined(my $pid = fork()) or die("Can't fork: $!");
240  if ($pid) {
241    eval {
242      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
243
244      $client->login($user, $passwd);
245
246      my ($resp_code, $resp_msg);
247      ($resp_code, $resp_msg) = $client->mff('modify=20020717210715;', 'foo');
248
249      my $expected;
250
251      $expected = 213;
252      $self->assert($expected == $resp_code,
253        test_msg("Expected $expected, got $resp_code"));
254
255      $expected = 'modify=20020717210715; foo';
256      $self->assert($expected eq $resp_msg,
257        test_msg("Expected '$expected', got '$resp_msg'"));
258    };
259
260    if ($@) {
261      $ex = $@;
262    }
263
264    $wfh->print("done\n");
265    $wfh->flush();
266
267  } else {
268    eval { server_wait($config_file, $rfh) };
269    if ($@) {
270      warn($@);
271      exit 1;
272    }
273
274    exit 0;
275  }
276
277  # Stop server
278  server_stop($pid_file);
279
280  $self->assert_child_ok($pid);
281
282  if ($ex) {
283    die($ex);
284  }
285
286  unlink($log_file);
287}
288
289sub mff_bug3142 {
290  my $self = shift;
291  my $tmpdir = $self->{tmpdir};
292
293  my $config_file = "$tmpdir/cmds.conf";
294  my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
295  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
296
297  my $log_file = File::Spec->rel2abs('tests.log');
298
299  my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
300  my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
301
302  my $user = 'proftpd';
303  my $passwd = 'test';
304  my $home_dir = File::Spec->rel2abs($tmpdir);
305  my $uid = 500;
306  my $gid = 500;
307
308  my $test_file = File::Spec->rel2abs("$tmpdir/foo bar");
309  if (open(my $fh, "> $test_file")) {
310    close($fh);
311
312  } else {
313    die("Can't open $test_file: $!");
314  }
315
316  # Make sure that, if we're running as root, that the home directory has
317  # permissions/privs set for the account we create
318  if ($< == 0) {
319    unless (chmod(0755, $home_dir)) {
320      die("Can't set perms on $home_dir to 0755: $!");
321    }
322
323    unless (chown($uid, $gid, $home_dir, $test_file)) {
324      die("Can't set owner of $home_dir, $test_file to $uid/$gid: $!");
325    }
326  }
327
328  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
329    '/bin/bash');
330  auth_group_write($auth_group_file, 'ftpd', $gid, $user);
331
332  my $config = {
333    PidFile => $pid_file,
334    ScoreboardFile => $scoreboard_file,
335    SystemLog => $log_file,
336
337    AuthUserFile => $auth_user_file,
338    AuthGroupFile => $auth_group_file,
339
340    IfModules => {
341      'mod_delay.c' => {
342        DelayEngine => 'off',
343      },
344    },
345  };
346
347  my ($port, $config_user, $config_group) = config_write($config_file, $config);
348
349  # Open pipes, for use between the parent and child processes.  Specifically,
350  # the child will indicate when it's done with its test by writing a message
351  # to the parent.
352  my ($rfh, $wfh);
353  unless (pipe($rfh, $wfh)) {
354    die("Can't open pipe: $!");
355  }
356
357  my $ex;
358
359  # Fork child
360  $self->handle_sigchld();
361  defined(my $pid = fork()) or die("Can't fork: $!");
362  if ($pid) {
363    eval {
364      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
365
366      $client->login($user, $passwd);
367
368      my ($resp_code, $resp_msg);
369      ($resp_code, $resp_msg) = $client->mff('modify=20020717210715;', 'foo bar');
370
371      my $expected;
372
373      $expected = 213;
374      $self->assert($expected == $resp_code,
375        test_msg("Expected $expected, got $resp_code"));
376
377      $expected = 'modify=20020717210715; foo bar';
378      $self->assert($expected eq $resp_msg,
379        test_msg("Expected '$expected', got '$resp_msg'"));
380    };
381
382    if ($@) {
383      $ex = $@;
384    }
385
386    $wfh->print("done\n");
387    $wfh->flush();
388
389  } else {
390    eval { server_wait($config_file, $rfh) };
391    if ($@) {
392      warn($@);
393      exit 1;
394    }
395
396    exit 0;
397  }
398
399  # Stop server
400  server_stop($pid_file);
401
402  $self->assert_child_ok($pid);
403
404  if ($ex) {
405    die($ex);
406  }
407
408  unlink($log_file);
409}
410
4111;
Note: See TracBrowser for help on using the repository browser.