| 1 |
package ProFTPD::Tests::Config::VirtualHost; |
| 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 |
vhost_namebased_different_ports => { |
| 21 |
test_class => [qw(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 vhost_namebased_different_ports { |
| 35 |
my $self = shift; |
| 36 |
my $tmpdir = $self->{tmpdir}; |
| 37 |
my $setup = test_setup($tmpdir, 'config'); |
| 38 |
|
| 39 |
my $host = hostname(); |
| 40 |
|
| 41 |
my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key'); |
| 42 |
my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key'); |
| 43 |
|
| 44 |
my $config = { |
| 45 |
PidFile => $setup->{pid_file}, |
| 46 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 47 |
SystemLog => $setup->{log_file}, |
| 48 |
|
| 49 |
AuthUserFile => $setup->{auth_user_file}, |
| 50 |
AuthGroupFile => $setup->{auth_group_file}, |
| 51 |
AuthOrder => 'mod_auth_file.c', |
| 52 |
|
| 53 |
ServerName => 'Real Server', |
| 54 |
SocketBindTight => 'off', |
| 55 |
DefaultServer => 'off', |
| 56 |
|
| 57 |
IfModules => { |
| 58 |
'mod_delay.c' => { |
| 59 |
DelayEngine => 'off', |
| 60 |
}, |
| 61 |
}, |
| 62 |
}; |
| 63 |
|
| 64 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 65 |
$config); |
| 66 |
|
| 67 |
my $vhost_port = $port + 3; |
| 68 |
my $vhost_name = 'Virtual Server'; |
| 69 |
|
| 70 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 71 |
print $fh <<EOC; |
| 72 |
<VirtualHost $host> |
| 73 |
Port $vhost_port |
| 74 |
ServerName "$vhost_name" |
| 75 |
|
| 76 |
WtmpLog off |
| 77 |
TransferLog none |
| 78 |
|
| 79 |
AuthUserFile $setup->{auth_user_file} |
| 80 |
AuthGroupFile $setup->{auth_group_file} |
| 81 |
AuthOrder mod_auth_file.c |
| 82 |
</VirtualHost> |
| 83 |
EOC |
| 84 |
unless (close($fh)) { |
| 85 |
die("Can't write $setup->{config_file}: $!"); |
| 86 |
} |
| 87 |
|
| 88 |
} else { |
| 89 |
die("Can't open $setup->{config_file}: $!"); |
| 90 |
} |
| 91 |
|
| 92 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 93 |
# the child will indicate when it's done with its test by writing a message |
| 94 |
# to the parent. |
| 95 |
my ($rfh, $wfh); |
| 96 |
unless (pipe($rfh, $wfh)) { |
| 97 |
die("Can't open pipe: $!"); |
| 98 |
} |
| 99 |
|
| 100 |
my $ex; |
| 101 |
|
| 102 |
# Fork child |
| 103 |
$self->handle_sigchld(); |
| 104 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 105 |
if ($pid) { |
| 106 |
eval { |
| 107 |
my $client = ProFTPD::TestSuite::FTP->new($host, $vhost_port, 0); |
| 108 |
my $resp_code = $client->response_code(); |
| 109 |
my $resp_msg = $client->response_msg(); |
| 110 |
$client->login($setup->{user}, $setup->{passwd}); |
| 111 |
$client->quit(); |
| 112 |
|
| 113 |
$self->assert(qr/$vhost_name/, $resp_msg, |
| 114 |
"Expected '$vhost_name', got '$resp_msg'"); |
| 115 |
}; |
| 116 |
|
| 117 |
if ($@) { |
| 118 |
$ex = $@; |
| 119 |
} |
| 120 |
|
| 121 |
$wfh->print("done\n"); |
| 122 |
$wfh->flush(); |
| 123 |
|
| 124 |
} else { |
| 125 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 126 |
if ($@) { |
| 127 |
warn($@); |
| 128 |
exit 1; |
| 129 |
} |
| 130 |
|
| 131 |
exit 0; |
| 132 |
} |
| 133 |
|
| 134 |
# Stop server |
| 135 |
server_stop($setup->{pid_file}); |
| 136 |
$self->assert_child_ok($pid); |
| 137 |
|
| 138 |
test_cleanup($setup->{log_file}, $ex); |
| 139 |
} |
| 140 |
|
| 141 |
1; |