| 1 |
package ProFTPD::Tests::Config::ServerAlias; |
| 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 |
use IO::Socket::INET; |
| 10 |
use Sys::Hostname; |
| 11 |
|
| 12 |
use ProFTPD::TestSuite::FTP; |
| 13 |
use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite); |
| 14 |
|
| 15 |
$| = 1; |
| 16 |
|
| 17 |
my $order = 0; |
| 18 |
|
| 19 |
my $TESTS = { |
| 20 |
serveralias_same_ports_issue1369 => { |
| 21 |
test_class => [qw(bug forking)], |
| 22 |
}, |
| 23 |
|
| 24 |
# Wildcard, with first-match-wins |
| 25 |
}; |
| 26 |
|
| 27 |
sub new { |
| 28 |
return shift()->SUPER::new(@_); |
| 29 |
} |
| 30 |
|
| 31 |
sub list_tests { |
| 32 |
return testsuite_get_runnable_tests($TESTS); |
| 33 |
} |
| 34 |
|
| 35 |
sub serveralias_same_ports_issue1369 { |
| 36 |
my $self = shift; |
| 37 |
my $tmpdir = $self->{tmpdir}; |
| 38 |
my $setup = test_setup($tmpdir, 'config'); |
| 39 |
|
| 40 |
my $config = { |
| 41 |
PidFile => $setup->{pid_file}, |
| 42 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 43 |
SystemLog => $setup->{log_file}, |
| 44 |
TraceLog => $setup->{log_file}, |
| 45 |
Trace => 'binding:30', |
| 46 |
|
| 47 |
AuthUserFile => $setup->{auth_user_file}, |
| 48 |
AuthGroupFile => $setup->{auth_group_file}, |
| 49 |
AuthOrder => 'mod_auth_file.c', |
| 50 |
|
| 51 |
Port => '0', |
| 52 |
ServerName => 'zero.castaglia.org', |
| 53 |
SocketBindTight => 'on', |
| 54 |
|
| 55 |
IfModules => { |
| 56 |
'mod_delay.c' => { |
| 57 |
DelayEngine => 'off', |
| 58 |
}, |
| 59 |
}, |
| 60 |
}; |
| 61 |
|
| 62 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 63 |
$config); |
| 64 |
|
| 65 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 66 |
print $fh <<EOC; |
| 67 |
<VirtualHost 127.0.0.1> |
| 68 |
Port $port |
| 69 |
ServerAlias first.castaglia.org |
| 70 |
ServerName first.castaglia.org |
| 71 |
|
| 72 |
AuthUserFile $setup->{auth_user_file} |
| 73 |
AuthGroupFile $setup->{auth_group_file} |
| 74 |
AuthOrder mod_auth_file.c |
| 75 |
TransferLog none |
| 76 |
WtmpLog off |
| 77 |
</VirtualHost> |
| 78 |
|
| 79 |
<VirtualHost 127.0.0.1> |
| 80 |
Port $port |
| 81 |
ServerAlias second.castaglia.org |
| 82 |
ServerName second.castaglia.org |
| 83 |
|
| 84 |
AuthUserFile $setup->{auth_user_file} |
| 85 |
AuthGroupFile $setup->{auth_group_file} |
| 86 |
AuthOrder mod_auth_file.c |
| 87 |
TransferLog none |
| 88 |
WtmpLog off |
| 89 |
</VirtualHost> |
| 90 |
|
| 91 |
<VirtualHost 127.0.0.1> |
| 92 |
Port $port |
| 93 |
ServerAlias *.castaglia.org |
| 94 |
ServerName match.castaglia.org |
| 95 |
|
| 96 |
AuthUserFile $setup->{auth_user_file} |
| 97 |
AuthGroupFile $setup->{auth_group_file} |
| 98 |
AuthOrder mod_auth_file.c |
| 99 |
TransferLog none |
| 100 |
WtmpLog off |
| 101 |
</VirtualHost> |
| 102 |
|
| 103 |
<VirtualHost 127.0.0.1> |
| 104 |
Port $port |
| 105 |
ServerAlias * |
| 106 |
ServerName wildcard |
| 107 |
|
| 108 |
AuthUserFile $setup->{auth_user_file} |
| 109 |
AuthGroupFile $setup->{auth_group_file} |
| 110 |
AuthOrder mod_auth_file.c |
| 111 |
TransferLog none |
| 112 |
WtmpLog off |
| 113 |
</VirtualHost> |
| 114 |
EOC |
| 115 |
unless (close($fh)) { |
| 116 |
die("Can't write $setup->{config_file}: $!"); |
| 117 |
} |
| 118 |
|
| 119 |
} else { |
| 120 |
die("Can't open $setup->{config_file}: $!"); |
| 121 |
} |
| 122 |
|
| 123 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 124 |
# the child will indicate when it's done with its test by writing a message |
| 125 |
# to the parent. |
| 126 |
my ($rfh, $wfh); |
| 127 |
unless (pipe($rfh, $wfh)) { |
| 128 |
die("Can't open pipe: $!"); |
| 129 |
} |
| 130 |
|
| 131 |
my $ex; |
| 132 |
|
| 133 |
# Fork child |
| 134 |
$self->handle_sigchld(); |
| 135 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 136 |
if ($pid) { |
| 137 |
eval { |
| 138 |
# first.castaglia.org (default) |
| 139 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0); |
| 140 |
my $resp_code = $client->response_code(); |
| 141 |
my $resp_msg = $client->response_msg(); |
| 142 |
$client->login($setup->{user}, $setup->{passwd}); |
| 143 |
$client->quit(); |
| 144 |
|
| 145 |
my $expected = 'first.castaglia.org'; |
| 146 |
$self->assert(qr/$expected/, $resp_msg, |
| 147 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 148 |
|
| 149 |
# second.castaglia.org (explicit HOST) |
| 150 |
$client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0); |
| 151 |
$client->host('second.castaglia.org'); |
| 152 |
$resp_code = $client->response_code(); |
| 153 |
$resp_msg = $client->response_msg(); |
| 154 |
$client->login($setup->{user}, $setup->{passwd}); |
| 155 |
$client->quit(); |
| 156 |
|
| 157 |
$expected = 'second.castaglia.org'; |
| 158 |
$self->assert(qr/$expected/, $resp_msg, |
| 159 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 160 |
|
| 161 |
# match.castaglia.org (matched HOST) |
| 162 |
$client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0); |
| 163 |
$client->host('third.castaglia.org'); |
| 164 |
$resp_code = $client->response_code(); |
| 165 |
$resp_msg = $client->response_msg(); |
| 166 |
$client->login($setup->{user}, $setup->{passwd}); |
| 167 |
$client->quit(); |
| 168 |
|
| 169 |
$expected = 'match.castaglia.org'; |
| 170 |
$self->assert(qr/$expected/, $resp_msg, |
| 171 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 172 |
|
| 173 |
# wildcard (catchall) |
| 174 |
$client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0); |
| 175 |
$client->host('example.com'); |
| 176 |
$resp_code = $client->response_code(); |
| 177 |
$resp_msg = $client->response_msg(); |
| 178 |
$client->login($setup->{user}, $setup->{passwd}); |
| 179 |
$client->quit(); |
| 180 |
|
| 181 |
$expected = 'wildcard'; |
| 182 |
$self->assert(qr/$expected/, $resp_msg, |
| 183 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 184 |
}; |
| 185 |
if ($@) { |
| 186 |
$ex = $@; |
| 187 |
} |
| 188 |
|
| 189 |
$wfh->print("done\n"); |
| 190 |
$wfh->flush(); |
| 191 |
|
| 192 |
} else { |
| 193 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 194 |
if ($@) { |
| 195 |
warn($@); |
| 196 |
exit 1; |
| 197 |
} |
| 198 |
|
| 199 |
exit 0; |
| 200 |
} |
| 201 |
|
| 202 |
# Stop server |
| 203 |
server_stop($setup->{pid_file}); |
| 204 |
$self->assert_child_ok($pid); |
| 205 |
|
| 206 |
test_cleanup($setup->{log_file}, $ex); |
| 207 |
} |
| 208 |
|
| 209 |
1; |