Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/MaxPasswordSize.pm

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