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

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

update proftp

File size: 5.8 KB
Line 
1package ProFTPD::Tests::Commands::CDUP;
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  cdup_ok => {
19    order => ++$order,
20    test_class => [qw(forking)],
21  },
22
23  xcup_ok => {
24    order => ++$order,
25    test_class => [qw(forking)],
26  },
27
28};
29
30sub new {
31  return shift()->SUPER::new(@_);
32}
33
34sub list_tests {
35  return testsuite_get_runnable_tests($TESTS);
36}
37
38sub cdup_ok {
39  my $self = shift;
40  my $tmpdir = $self->{tmpdir};
41
42  my $config_file = "$tmpdir/cmds.conf";
43  my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
44  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
45
46  my $log_file = File::Spec->rel2abs('tests.log');
47
48  my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
49  my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.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
81    IfModules => {
82      'mod_delay.c' => {
83        DelayEngine => 'off',
84      },
85    },
86  };
87
88  my ($port, $config_user, $config_group) = config_write($config_file, $config);
89
90  # Open pipes, for use between the parent and child processes.  Specifically,
91  # the child will indicate when it's done with its test by writing a message
92  # to the parent.
93  my ($rfh, $wfh);
94  unless (pipe($rfh, $wfh)) {
95    die("Can't open pipe: $!");
96  }
97
98  my $ex;
99
100  # Fork child
101  $self->handle_sigchld();
102  defined(my $pid = fork()) or die("Can't fork: $!");
103  if ($pid) {
104    eval {
105      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
106
107      $client->login($user, $passwd);
108
109      my ($resp_code, $resp_msg);
110      ($resp_code, $resp_msg) = $client->cdup();
111
112      my $expected;
113
114      $expected = 250;
115      $self->assert($expected == $resp_code,
116        test_msg("Expected $expected, got $resp_code"));
117
118      $expected = "CDUP command successful";
119      $self->assert($expected eq $resp_msg,
120        test_msg("Expected '$expected', got '$resp_msg'"));
121    };
122
123    if ($@) {
124      $ex = $@;
125    }
126
127    $wfh->print("done\n");
128    $wfh->flush();
129
130  } else {
131    eval { server_wait($config_file, $rfh) };
132    if ($@) {
133      warn($@);
134      exit 1;
135    }
136
137    exit 0;
138  }
139
140  # Stop server
141  server_stop($pid_file);
142
143  $self->assert_child_ok($pid);
144
145  if ($ex) {
146    die($ex);
147  }
148
149  unlink($log_file);
150}
151
152sub xcup_ok {
153  my $self = shift;
154  my $tmpdir = $self->{tmpdir};
155
156  my $config_file = "$tmpdir/cmds.conf";
157  my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
158  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
159
160  my $log_file = File::Spec->rel2abs('tests.log');
161
162  my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
163  my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
164
165  my $user = 'proftpd';
166  my $passwd = 'test';
167  my $home_dir = File::Spec->rel2abs($tmpdir);
168  my $uid = 500;
169  my $gid = 500;
170
171  # Make sure that, if we're running as root, that the home directory has
172  # permissions/privs set for the account we create
173  if ($< == 0) {
174    unless (chmod(0755, $home_dir)) {
175      die("Can't set perms on $home_dir to 0755: $!");
176    }
177
178    unless (chown($uid, $gid, $home_dir)) {
179      die("Can't set owner of $home_dir to $uid/$gid: $!");
180    }
181  }
182
183  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
184    '/bin/bash');
185  auth_group_write($auth_group_file, 'ftpd', $gid, $user);
186
187  my $config = {
188    PidFile => $pid_file,
189    ScoreboardFile => $scoreboard_file,
190    SystemLog => $log_file,
191
192    AuthUserFile => $auth_user_file,
193    AuthGroupFile => $auth_group_file,
194
195    IfModules => {
196      'mod_delay.c' => {
197        DelayEngine => 'off',
198      },
199    },
200  };
201
202  my ($port, $config_user, $config_group) = config_write($config_file, $config);
203
204  # Open pipes, for use between the parent and child processes.  Specifically,
205  # the child will indicate when it's done with its test by writing a message
206  # to the parent.
207  my ($rfh, $wfh);
208  unless (pipe($rfh, $wfh)) {
209    die("Can't open pipe: $!");
210  }
211
212  my $ex;
213
214  # Fork child
215  $self->handle_sigchld();
216  defined(my $pid = fork()) or die("Can't fork: $!");
217  if ($pid) {
218    eval {
219      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
220
221      $client->login($user, $passwd);
222
223      my ($resp_code, $resp_msg);
224      ($resp_code, $resp_msg) = $client->xcup();
225
226      my $expected;
227
228      $expected = 250;
229      $self->assert($expected == $resp_code,
230        test_msg("Expected $expected, got $resp_code"));
231
232      $expected = "XCUP command successful";
233      $self->assert($expected eq $resp_msg,
234        test_msg("Expected '$expected', got '$resp_msg'"));
235    };
236
237    if ($@) {
238      $ex = $@;
239    }
240
241    $wfh->print("done\n");
242    $wfh->flush();
243
244  } else {
245    eval { server_wait($config_file, $rfh) };
246    if ($@) {
247      warn($@);
248      exit 1;
249    }
250
251    exit 0;
252  }
253
254  # Stop server
255  server_stop($pid_file);
256
257  $self->assert_child_ok($pid);
258
259  if ($ex) {
260    die($ex);
261  }
262
263  unlink($log_file);
264}
265
2661;
Note: See TracBrowser for help on using the repository browser.