summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-01-01 13:44:00 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2021-01-05 12:52:11 -0500
commit5b1b9f78247e122804490b17112e94df32851464 (patch)
treee8b7580206627e5cd84e9fa4c01dcd0296344da6 /tests
parent048af4c5063485b65d9919f6a7a5d28c1db02d66 (diff)
downloadlighttpd-git-5b1b9f78247e122804490b17112e94df32851464.tar.gz
[tests] use ephemeral ports in tests
avoid spurious test failures due to conflicts with ports in use by other processes, which might occur when tests use hard-coded ports
Diffstat (limited to 'tests')
-rw-r--r--tests/404-handler.conf8
-rw-r--r--tests/LightyTest.pm65
-rw-r--r--tests/condition.conf9
-rw-r--r--tests/fastcgi-responder.conf21
-rw-r--r--tests/lighttpd.conf8
-rw-r--r--tests/lowercase.conf7
-rw-r--r--tests/mod-auth.conf7
-rw-r--r--tests/mod-deflate.conf7
-rw-r--r--tests/mod-extforward.conf7
-rwxr-xr-xtests/mod-fastcgi.t5
-rwxr-xr-xtests/mod-proxy.t4
-rwxr-xr-xtests/mod-scgi.t6
-rw-r--r--tests/mod-secdownload.conf7
-rw-r--r--tests/proxy.conf9
-rw-r--r--tests/scgi-responder.conf14
-rw-r--r--tests/var-include.conf9
16 files changed, 83 insertions, 110 deletions
diff --git a/tests/404-handler.conf b/tests/404-handler.conf
index 8eff0d1c..415adb6b 100644
--- a/tests/404-handler.conf
+++ b/tests/404-handler.conf
@@ -2,19 +2,13 @@ debug.log-request-handling = "enable"
debug.log-response-header = "enable"
debug.log-request-header = "enable"
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
server.tag = "Apache 1.3.29"
-
server.compat-module-load = "disable"
server.modules = (
"mod_cgi",
diff --git a/tests/LightyTest.pm b/tests/LightyTest.pm
index 04496f66..2392e6e8 100644
--- a/tests/LightyTest.pm
+++ b/tests/LightyTest.pm
@@ -1,12 +1,10 @@
package LightyTest;
use strict;
-use IO::Socket;
-use Test::More;
+use IO::Socket ();
+use Test::More; # diag()
use Socket;
use Cwd 'abs_path';
-use POSIX qw(:sys_wait_h dup2);
-use Errno qw(EADDRINUSE);
sub find_program {
my @DEFAULT_PATHS = ('/usr/bin/', '/usr/local/bin/');
@@ -80,7 +78,6 @@ sub new {
if (exists $ENV{LIGHTTPD_EXE_PATH}) {
$self->{LIGHTTPD_PATH} = $ENV{LIGHTTPD_EXE_PATH};
}
- $self->{PORT} = 2048;
my ($name, $aliases, $addrtype, $net) = gethostbyaddr(inet_aton("127.0.0.1"), AF_INET);
@@ -131,7 +128,8 @@ sub wait_for_port_with_proc {
$timeout--;
# the process is gone, we failed
- if (0 != waitpid($child, WNOHANG)) {
+ require POSIX;
+ if (0 != waitpid($child, POSIX::WNOHANG)) {
return -1;
}
if (0 >= $timeout) {
@@ -144,15 +142,32 @@ sub wait_for_port_with_proc {
return 0;
}
+sub bind_ephemeral_tcp_socket {
+ my $SOCK;
+ socket($SOCK, PF_INET, SOCK_STREAM, 0) || die "socket: $!";
+ setsockopt($SOCK, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!";
+ bind($SOCK, sockaddr_in(0, INADDR_LOOPBACK)) || die "bind: $!";
+ my($port) = sockaddr_in(getsockname($SOCK));
+ return ($SOCK, $port);
+}
+
+sub get_ephemeral_tcp_port {
+ # bind to an ephemeral port, close() it, and return port that was used
+ # (While there is a race condition before caller may reuse the port,
+ # the port is likely to remain available for the serialized tests)
+ my $port;
+ (undef, $port) = bind_ephemeral_tcp_socket();
+ return $port;
+}
+
sub start_proc {
my $self = shift;
# kill old proc if necessary
#$self->stop_proc;
- if ($self->listening_on($self->{PORT})) {
- diag("\nPort ".$self->{PORT}." already in use");
- return -1;
- }
+ # listen on localhost and kernel-assigned ephemeral port
+ my $SOCK;
+ ($SOCK, $self->{PORT}) = bind_ephemeral_tcp_socket();
# pre-process configfile if necessary
#
@@ -175,11 +190,26 @@ sub start_proc {
my $child = fork();
if (not defined $child) {
diag("\nFork failed");
+ close($SOCK);
return -1;
}
if ($child == 0) {
+ # set up systemd socket activation env vars
+ $ENV{LISTEN_FDS} = "1";
+ $ENV{LISTEN_PID} = $$;
+ listen($SOCK, 1024) || die "listen: $!";
+ if (fileno($SOCK) != 3) { # SD_LISTEN_FDS_START 3
+ require POSIX;
+ POSIX::dup2(fileno($SOCK), 3) || die "dup2: $!";
+ close($SOCK);
+ }
+ else {
+ require Fcntl;
+ fcntl($SOCK, Fcntl::F_SETFD, 0); # clr FD_CLOEXEC
+ }
exec @cmdline or die($?);
}
+ close($SOCK);
if (0 != $self->wait_for_port_with_proc($self->{PORT}, $child)) {
diag(sprintf('\nThe process %i is not up', $child));
@@ -237,15 +267,15 @@ sub handle_http {
print $remote $_;
diag("<< ".$_."\n") if $is_debug;
- select(undef, undef, undef, 0.001);
+ select(undef, undef, undef, 0.0001);
print $remote "\015";
- select(undef, undef, undef, 0.001);
+ select(undef, undef, undef, 0.0001);
print $remote "\012";
- select(undef, undef, undef, 0.001);
+ select(undef, undef, undef, 0.0001);
print $remote "\015";
- select(undef, undef, undef, 0.001);
+ select(undef, undef, undef, 0.0001);
print $remote "\012";
- select(undef, undef, undef, 0.001);
+ select(undef, undef, undef, 0.0001);
}
}
@@ -428,7 +458,8 @@ sub spawnfcgi {
setsockopt(SOCK, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!";
bind(SOCK, sockaddr_in($port, $iaddr)) || die "bind: $!";
listen(SOCK, 1024) || die "listen: $!";
- dup2(fileno(SOCK), 0) || die "dup2: $!";
+ require POSIX;
+ POSIX::dup2(fileno(SOCK), 0) || die "dup2: $!";
exec { $binary } ($binary) or die($?);
} else {
if (0 != $self->wait_for_port_with_proc($port, $child)) {
@@ -467,7 +498,7 @@ sub has_crypto {
my $FH;
open($FH, "-|",$self->{LIGHTTPD_PATH}, "-V") || return 0;
while (<$FH>) {
- return 1 if (/[+] (?i:OpenSSL|mbedTLS|GnuTLS|WolfSSL|Nettle) support/);
+ return 1 if (/[+] (?i:OpenSSL|mbedTLS|GnuTLS|WolfSSL|Nettle|NSS crypto) support/);
}
close $FH;
return 0;
diff --git a/tests/condition.conf b/tests/condition.conf
index f02e7ec4..b28be7b8 100644
--- a/tests/condition.conf
+++ b/tests/condition.conf
@@ -1,20 +1,13 @@
-
debug.log-request-handling = "enable"
debug.log-condition-handling = "enable"
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
server.tag = "Apache 1.3.29"
-
server.compat-module-load = "disable"
server.modules = (
"mod_redirect",
diff --git a/tests/fastcgi-responder.conf b/tests/fastcgi-responder.conf
index 0ea22b62..f2394b66 100644
--- a/tests/fastcgi-responder.conf
+++ b/tests/fastcgi-responder.conf
@@ -1,14 +1,9 @@
-server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
debug.log-request-header = "enable"
debug.log-response-header = "enable"
debug.log-request-handling = "enable"
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
+server.systemd-socket-activation = "enable"
+server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
@@ -45,7 +40,7 @@ $HTTP["host"] == "auth.example.org" {
"/" => (
"grisu-auth" => (
"host" => "127.0.0.1",
- "port" => 10000,
+ "port" => env.EPHEMERAL_PORT,
"bin-path" => env.SRCDIR + "/fcgi-responder",
"bin-copy-environment" => ( "PATH", "SHELL", "USER", ),
"check-local" => "disable",
@@ -54,7 +49,7 @@ $HTTP["host"] == "auth.example.org" {
),
"grisu-resp" => (
"host" => "127.0.0.1",
- "port" => 10000,
+ "port" => env.EPHEMERAL_PORT,
"bin-path" => env.SRCDIR + "/fcgi-responder",
"bin-copy-environment" => ( "PATH", "SHELL", "USER", ),
"check-local" => "disable",
@@ -70,7 +65,7 @@ else {
fastcgi.server = (
".php" => ( (
"host" => "127.0.0.1",
- "port" => 10000,
+ "port" => env.EPHEMERAL_PORT,
"bin-path" => env.SRCDIR + "/fcgi-responder",
"bin-copy-environment" => ( "PATH", "SHELL", "USER", ),
"check-local" => "disable",
@@ -78,14 +73,14 @@ else {
) ),
"/prefix.fcgi" => ( (
"host" => "127.0.0.1",
- "port" => 10000,
+ "port" => env.EPHEMERAL_PORT,
"bin-path" => env.SRCDIR + "/fcgi-responder",
"max-procs" => 1,
) ),
".fcgi" => (
"grisu" => (
"host" => "127.0.0.1",
- "port" => 10000,
+ "port" => env.EPHEMERAL_PORT,
"bin-path" => env.SRCDIR + "/fcgi-responder",
"bin-copy-environment" => ( "PATH", "SHELL", "USER", ),
"check-local" => "disable",
@@ -100,7 +95,7 @@ $HTTP["host"] == "wsgi.example.org" {
fastcgi.server = (
"/" => ( (
"host" => "127.0.0.1",
- "port" => 10000,
+ "port" => env.EPHEMERAL_PORT,
"bin-path" => env.SRCDIR + "/fcgi-responder",
"bin-copy-environment" => ( "PATH", "SHELL", "USER", ),
"check-local" => "disable",
diff --git a/tests/lighttpd.conf b/tests/lighttpd.conf
index 7b57d42e..2c8d4729 100644
--- a/tests/lighttpd.conf
+++ b/tests/lighttpd.conf
@@ -2,16 +2,12 @@ debug.log-request-handling = "enable"
debug.log-request-header = "enable"
debug.log-response-header = "enable"
#debug.log-condition-handling = "enable"
-server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
## 64 Mbyte ... nice limit
server.max-request-size = 65000
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
+server.systemd-socket-activation = "enable"
+server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
diff --git a/tests/lowercase.conf b/tests/lowercase.conf
index f29e8a54..4d13b69a 100644
--- a/tests/lowercase.conf
+++ b/tests/lowercase.conf
@@ -1,10 +1,5 @@
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
diff --git a/tests/mod-auth.conf b/tests/mod-auth.conf
index 8e14bbd6..a5742246 100644
--- a/tests/mod-auth.conf
+++ b/tests/mod-auth.conf
@@ -2,13 +2,8 @@ debug.log-request-handling = "enable"
debug.log-request-header = "enable"
debug.log-response-header = "enable"
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
diff --git a/tests/mod-deflate.conf b/tests/mod-deflate.conf
index 870b03ed..be197714 100644
--- a/tests/mod-deflate.conf
+++ b/tests/mod-deflate.conf
@@ -2,14 +2,9 @@ debug.log-request-handling = "enable"
debug.log-response-header = "disable"
debug.log-request-header = "disable"
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
diff --git a/tests/mod-extforward.conf b/tests/mod-extforward.conf
index 0b9362c4..e67867aa 100644
--- a/tests/mod-extforward.conf
+++ b/tests/mod-extforward.conf
@@ -2,13 +2,8 @@ debug.log-request-handling = "enable"
debug.log-response-header = "disable"
debug.log-request-header = "disable"
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
diff --git a/tests/mod-fastcgi.t b/tests/mod-fastcgi.t
index 8bf846be..f90ed852 100755
--- a/tests/mod-fastcgi.t
+++ b/tests/mod-fastcgi.t
@@ -19,6 +19,9 @@ SKIP: {
unless ( -x $tf->{BASEDIR}."/tests/fcgi-responder"
|| -x $tf->{BASEDIR}."/tests/fcgi-responder.exe");
+ my $ephemeral_port = LightyTest->get_ephemeral_tcp_port();
+ $ENV{EPHEMERAL_PORT} = $ephemeral_port;
+
$tf->{CONFIGFILE} = 'fastcgi-responder.conf';
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
@@ -196,7 +199,7 @@ EOF
# (might take lighttpd 1 sec to detect backend exit)
select(undef, undef, undef, .5);
- for (my $c = 2*20; $c && 0 == $tf->listening_on(10000); --$c) {
+ for (my $c = 2*20; $c && 0 == $tf->listening_on($ephemeral_port); --$c) {
select(undef, undef, undef, 0.05);
}
$t->{REQUEST} = ( <<EOF
diff --git a/tests/mod-proxy.t b/tests/mod-proxy.t
index 50cd1424..809fd1a0 100755
--- a/tests/mod-proxy.t
+++ b/tests/mod-proxy.t
@@ -20,14 +20,12 @@ my $t;
## 1. the real webserver
## 2. the proxy server
-$tf_real->{PORT} = 2048;
$tf_real->{CONFIGFILE} = 'lighttpd.conf';
-
-$tf_proxy->{PORT} = 2050;
$tf_proxy->{CONFIGFILE} = 'proxy.conf';
ok($tf_real->start_proc == 0, "Starting lighttpd") or goto cleanup;
+$ENV{EPHEMERAL_PORT} = $tf_real->{PORT};
ok($tf_proxy->start_proc == 0, "Starting lighttpd as proxy") or goto cleanup;
$t->{REQUEST} = ( <<EOF
diff --git a/tests/mod-scgi.t b/tests/mod-scgi.t
index 3b30249c..2cf3e605 100755
--- a/tests/mod-scgi.t
+++ b/tests/mod-scgi.t
@@ -16,8 +16,12 @@ my $t;
SKIP: {
skip "no scgi-responder found", 10 unless -x $tf->{BASEDIR}."/tests/scgi-responder" || -x $tf->{BASEDIR}."/tests/scgi-responder.exe";
+ my $ephemeral_port = LightyTest->get_ephemeral_tcp_port();
+ $ENV{EPHEMERAL_PORT} = $ephemeral_port;
+
$tf->{CONFIGFILE} = 'scgi-responder.conf';
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
+
$t->{REQUEST} = ( <<EOF
GET /index.scgi?lf HTTP/1.0
Host: www.example.org
@@ -77,7 +81,7 @@ EOF
# (might take lighttpd 1 sec to detect backend exit)
select(undef, undef, undef, .5);
- for (my $c = 2*20; $c && 0 == $tf->listening_on(10000); --$c) {
+ for (my $c = 2*20; $c && 0 == $tf->listening_on($ephemeral_port); --$c) {
select(undef, undef, undef, 0.05);
}
$t->{REQUEST} = ( <<EOF
diff --git a/tests/mod-secdownload.conf b/tests/mod-secdownload.conf
index 486f3f7a..63407df9 100644
--- a/tests/mod-secdownload.conf
+++ b/tests/mod-secdownload.conf
@@ -2,13 +2,8 @@ debug.log-request-handling = "enable"
debug.log-request-header = "enable"
debug.log-response-header = "enable"
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
diff --git a/tests/proxy.conf b/tests/proxy.conf
index ba2f49dd..23a5173f 100644
--- a/tests/proxy.conf
+++ b/tests/proxy.conf
@@ -1,10 +1,5 @@
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2050
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
@@ -23,7 +18,7 @@ proxy.debug = 1
proxy.server = ( "" => (
"grisu" => (
"host" => "127.0.0.1",
- "port" => 2048,
+ "port" => env.EPHEMERAL_PORT,
),
))
diff --git a/tests/scgi-responder.conf b/tests/scgi-responder.conf
index 4ccaf1eb..0fe5181d 100644
--- a/tests/scgi-responder.conf
+++ b/tests/scgi-responder.conf
@@ -1,14 +1,9 @@
-server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
#debug.log-request-header = "enable"
#debug.log-response-header = "enable"
#debug.log-request-handling = "enable"
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
+server.systemd-socket-activation = "enable"
+server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
@@ -27,7 +22,7 @@ scgi.server = (
".scgi" => (
"grisu" => (
"host" => "127.0.0.1",
- "port" => 10000,
+ "port" => env.EPHEMERAL_PORT,
"bin-path" => env.SRCDIR + "/scgi-responder",
"check-local" => "disable",
"max-procs" => 1,
@@ -39,7 +34,8 @@ scgi.server = (
$HTTP["host"] == "wsgi.example.org" {
scgi.server = (
"/" => ( (
- "host" => "127.0.0.1", "port" => 10000,
+ "host" => "127.0.0.1",
+ "port" => env.EPHEMERAL_PORT,
"fix-root-scriptname" => "enable",
"check-local" => "disable",
"bin-path" => env.SRCDIR + "/scgi-responder",
diff --git a/tests/var-include.conf b/tests/var-include.conf
index 06812d35..da23167f 100644
--- a/tests/var-include.conf
+++ b/tests/var-include.conf
@@ -1,20 +1,13 @@
-
debug.log-request-handling = "enable"
#debug.log-condition-handling = "enable"
+server.systemd-socket-activation = "enable"
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
-
-## bind to port (default: 80)
-server.port = 2048
-
-## bind to localhost (default: all interfaces)
-server.bind = "localhost"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
server.name = "www.example.org"
server.tag = "Apache 1.3.29"
-
server.compat-module-load = "disable"
server.modules = (
"mod_redirect",