Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Commands/NOOP.pm

raw
1 package ProFTPD::Tests::Commands::NOOP;
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 noop_ok => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 noop_limit_deny_issue684 => {
24 order => ++$order,
25 test_class => [qw(bug forking)],
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 noop_ok {
39 my $self = shift;
40 my $tmpdir = $self->{tmpdir};
41 my $setup = test_setup($tmpdir, 'cmds');
42
43 my $config = {
44 PidFile => $setup->{pid_file},
45 ScoreboardFile => $setup->{scoreboard_file},
46 SystemLog => $setup->{log_file},
47
48 IfModules => {
49 'mod_delay.c' => {
50 DelayEngine => 'off',
51 },
52 },
53 };
54
55 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
56 $config);
57
58 # Open pipes, for use between the parent and child processes. Specifically,
59 # the child will indicate when it's done with its test by writing a message
60 # to the parent.
61 my ($rfh, $wfh);
62 unless (pipe($rfh, $wfh)) {
63 die("Can't open pipe: $!");
64 }
65
66 my $ex;
67
68 # Fork child
69 $self->handle_sigchld();
70 defined(my $pid = fork()) or die("Can't fork: $!");
71 if ($pid) {
72 eval {
73 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
74 my ($resp_code, $resp_msg) = $client->noop();
75
76 my $expected = 200;
77 $self->assert($expected == $resp_code,
78 "Expected response code $expected, got $resp_code");
79
80 $expected = "NOOP command successful";
81 $self->assert($expected eq $resp_msg,
82 "Expected response message '$expected', got '$resp_msg'");
83 };
84
85 if ($@) {
86 $ex = $@;
87 }
88
89 $wfh->print("done\n");
90 $wfh->flush();
91
92 } else {
93 eval { server_wait($setup->{config_file}, $rfh) };
94 if ($@) {
95 warn($@);
96 exit 1;
97 }
98
99 exit 0;
100 }
101
102 # Stop server
103 server_stop($setup->{pid_file});
104 $self->assert_child_ok($pid);
105
106 test_cleanup($setup->{log_file}, $ex);
107 }
108
109 sub noop_limit_deny_issue684 {
110 my $self = shift;
111 my $tmpdir = $self->{tmpdir};
112 my $setup = test_setup($tmpdir, 'cmds');
113
114 my $config = {
115 PidFile => $setup->{pid_file},
116 ScoreboardFile => $setup->{scoreboard_file},
117 SystemLog => $setup->{log_file},
118
119 IfModules => {
120 'mod_delay.c' => {
121 DelayEngine => 'off',
122 },
123 },
124
125 Limit => {
126 NOOP => {
127 DenyAll => '',
128 }
129 },
130 };
131
132 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
133 $config);
134
135 # Open pipes, for use between the parent and child processes. Specifically,
136 # the child will indicate when it's done with its test by writing a message
137 # to the parent.
138 my ($rfh, $wfh);
139 unless (pipe($rfh, $wfh)) {
140 die("Can't open pipe: $!");
141 }
142
143 my $ex;
144
145 # Fork child
146 $self->handle_sigchld();
147 defined(my $pid = fork()) or die("Can't fork: $!");
148 if ($pid) {
149 eval {
150 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
151
152 eval { $client->noop() };
153 unless ($@) {
154 die("NOOP succeeded unexpectedly");
155 }
156
157 my $resp_code = $client->response_code();
158 my $resp_msg = $client->response_msg();
159
160 my $expected = 550;
161 $self->assert($expected == $resp_code,
162 "Expected response code $expected, got $resp_code");
163
164 $expected = 'Operation not permitted';
165 $self->assert($expected eq $resp_msg,
166 "Expected response message '$expected', got '$resp_msg'");
167 };
168
169 if ($@) {
170 $ex = $@;
171 }
172
173 $wfh->print("done\n");
174 $wfh->flush();
175
176 } else {
177 eval { server_wait($setup->{config_file}, $rfh) };
178 if ($@) {
179 warn($@);
180 exit 1;
181 }
182
183 exit 0;
184 }
185
186 # Stop server
187 server_stop($setup->{pid_file});
188 $self->assert_child_ok($pid);
189
190 test_cleanup($setup->{log_file}, $ex);
191 }
192
193 1;