Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::RegexOptions;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Path qw(mkpath);
8 use File::Spec;
9 use IO::Handle;
10
11 use ProFTPD::TestSuite::FTP;
12 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
13
14 $| = 1;
15
16 my $order = 0;
17
18 my $TESTS = {
19 regexoptions_posix_engine_issue1300 => {
20 order => ++$order,
21 test_class => [qw(feature_pcre forking)],
22 },
23
24 };
25
26 sub new {
27 return shift()->SUPER::new(@_);
28 }
29
30 sub list_tests {
31 return testsuite_get_runnable_tests($TESTS);
32 }
33
34 sub regexoptions_posix_engine_issue1300 {
35 my $self = shift;
36 my $tmpdir = $self->{tmpdir};
37 my $setup = test_setup($tmpdir, 'config');
38
39 my $config = {
40 PidFile => $setup->{pid_file},
41 ScoreboardFile => $setup->{scoreboard_file},
42 SystemLog => $setup->{log_file},
43 TraceLog => $setup->{log_file},
44 Trace => 'regexp:20',
45
46 AuthUserFile => $setup->{auth_user_file},
47 AuthGroupFile => $setup->{auth_group_file},
48 AuthOrder => 'mod_auth_file.c',
49
50 DefaultChdir => '~',
51 DenyFilter => '\*.*/',
52 RegexOptions => 'Engine POSIX',
53
54 IfModules => {
55 'mod_delay.c' => {
56 DelayEngine => 'off',
57 },
58 },
59 };
60
61 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
62 $config);
63
64 # Open pipes, for use between the parent and child processes. Specifically,
65 # the child will indicate when it's done with its test by writing a message
66 # to the parent.
67 my ($rfh, $wfh);
68 unless (pipe($rfh, $wfh)) {
69 die("Can't open pipe: $!");
70 }
71
72 my $ex;
73
74 # Fork child
75 $self->handle_sigchld();
76 defined(my $pid = fork()) or die("Can't fork: $!");
77 if ($pid) {
78 eval {
79 # Allow server startup
80 sleep(1);
81
82 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
83 $client->login($setup->{user}, $setup->{passwd});
84 $client->quit();
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 eval {
108 if (open(my $fh, "< $setup->{log_file}")) {
109 my $engine_ok = 0;
110 my $filter_ok = 0;
111
112 while (my $line = <$fh>) {
113 chomp($line);
114
115 if ($ENV{TEST_VERBOSE}) {
116 print STDERR "# $line\n";
117 }
118
119 if ($line =~ /<regexp:\d+>: changed regexp engine from PCRE to POSIX/) {
120 $engine_ok = 1;
121 }
122
123 if ($line =~ /<regexp:\d+>: executing POSIX regex .*? against subject/) {
124 $filter_ok = 1;
125 }
126
127 if ($engine_ok && $filter_ok) {
128 last;
129 }
130 }
131
132 close($fh);
133
134 $self->assert($engine_ok,
135 test_msg("Did not see expected regexp engine TraceLog message"));
136 $self->assert($filter_ok,
137 test_msg("Did not see expected regexp filter TraceLog message"));
138
139 } else {
140 die("Can't read $setup->{log_file}: $!");
141 }
142 };
143 if ($@) {
144 $ex = $@;
145 }
146
147 test_cleanup($setup->{log_file}, $ex);
148 }
149
150 1;