[openssl] master update
dev at ddvo.net
dev at ddvo.net
Wed Jun 9 12:03:53 UTC 2021
The branch master has been updated
via d63053bbdfa226c85e9cec06c35283296e254a84 (commit)
via ee1d1db824a68f80c4cbdcbffbd7b4026f57a4f2 (commit)
from f8ab78f6c2b5faee74c3056d237d418e2f53d6a8 (commit)
- Log -----------------------------------------------------------------
commit d63053bbdfa226c85e9cec06c35283296e254a84
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date: Mon Jun 7 11:50:43 2021 +0200
80-test_cmp_http.t: Improve the way the test server is launched and killed
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15642)
commit ee1d1db824a68f80c4cbdcbffbd7b4026f57a4f2
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date: Mon Jun 7 11:44:23 2021 +0200
80-test_cmp_http.t: Simplify and prevent hangs on server not launching/behaving correctly
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15642)
-----------------------------------------------------------------------
Summary of changes:
apps/include/s_apps.h | 2 +-
apps/lib/http_server.c | 2 +-
apps/lib/s_socket.c | 29 +++++++++++++++--------------
test/recipes/79-test_http.t | 5 +++--
test/recipes/80-test_cmp_http.t | 35 ++++++++++++-----------------------
5 files changed, 32 insertions(+), 41 deletions(-)
diff --git a/apps/include/s_apps.h b/apps/include/s_apps.h
index 18dbd50d31..d610df40be 100644
--- a/apps/include/s_apps.h
+++ b/apps/include/s_apps.h
@@ -16,7 +16,7 @@
#define PROTOCOL "tcp"
typedef int (*do_server_cb)(int s, int stype, int prot, unsigned char *context);
-int report_server_accept(BIO *out, int asock, int with_address);
+int report_server_accept(BIO *out, int asock, int with_address, int with_pid);
int do_server(int *accept_sock, const char *host, const char *port,
int family, int type, int protocol, do_server_cb cb,
unsigned char *context, int naccept, BIO *bio_s_out);
diff --git a/apps/lib/http_server.c b/apps/lib/http_server.c
index 1858d04ccb..03faac7707 100644
--- a/apps/lib/http_server.c
+++ b/apps/lib/http_server.c
@@ -241,7 +241,7 @@ BIO *http_server_init_bio(const char *prog, const char *port)
/* Report back what address and port are used */
BIO_get_fd(acbio, &asock);
- if (!report_server_accept(bio_out, asock, 1)) {
+ if (!report_server_accept(bio_out, asock, 1, 1)) {
log_message(prog, LOG_ERR, "Error printing ACCEPT string");
goto err;
}
diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c
index fbe913e37a..36dbe615d2 100644
--- a/apps/lib/s_socket.c
+++ b/apps/lib/s_socket.c
@@ -191,9 +191,9 @@ out:
return ret;
}
-int report_server_accept(BIO *out, int asock, int with_address)
+int report_server_accept(BIO *out, int asock, int with_address, int with_pid)
{
- int success = 0;
+ int success = 1;
if (BIO_printf(out, "ACCEPT") <= 0)
return 0;
@@ -205,22 +205,23 @@ int report_server_accept(BIO *out, int asock, int with_address)
if ((info.addr = BIO_ADDR_new()) != NULL
&& BIO_sock_info(asock, BIO_SOCK_INFO_ADDRESS, &info)
&& (hostname = BIO_ADDR_hostname_string(info.addr, 1)) != NULL
- && (service = BIO_ADDR_service_string(info.addr, 1)) != NULL
- && BIO_printf(out,
- strchr(hostname, ':') == NULL
- ? /* IPv4 */ " %s:%s\n"
- : /* IPv6 */ " [%s]:%s\n",
- hostname, service) > 0)
- success = 1;
- else
+ && (service = BIO_ADDR_service_string(info.addr, 1)) != NULL) {
+ success = BIO_printf(out,
+ strchr(hostname, ':') == NULL
+ ? /* IPv4 */ " %s:%s"
+ : /* IPv6 */ " [%s]:%s",
+ hostname, service) > 0;
+ } else {
(void)BIO_printf(out, "unknown:error\n");
-
+ success = 0;
+ }
OPENSSL_free(hostname);
OPENSSL_free(service);
BIO_ADDR_free(info.addr);
- } else if (BIO_printf(out, "\n") > 0) {
- success = 1;
}
+ if (with_pid)
+ success = success && BIO_printf(out, " PID=%d", getpid()) > 0;
+ success = success && BIO_printf(out, "\n") > 0;
(void)BIO_flush(out);
return success;
@@ -331,7 +332,7 @@ int do_server(int *accept_sock, const char *host, const char *port,
BIO_ADDRINFO_free(res);
res = NULL;
- if (!report_server_accept(bio_s_out, asock, sock_port == 0)) {
+ if (!report_server_accept(bio_s_out, asock, sock_port == 0, 0)) {
BIO_closesocket(asock);
ERR_print_errors(bio_err);
goto end;
diff --git a/test/recipes/79-test_http.t b/test/recipes/79-test_http.t
index b5bb74393a..939e7fc099 100644
--- a/test/recipes/79-test_http.t
+++ b/test/recipes/79-test_http.t
@@ -19,8 +19,9 @@ SKIP: {
skip "OCSP disabled", 1 if disabled("ocsp");
my $cmd = [qw{openssl ocsp -index any -port 0}];
my @output = run(app($cmd), capture => 1);
- ok($output[0] =~ /^ACCEPT (0.0.0.0|\[::\]):(\d+?)$/ && $2 >= 1024,
- "HTTP server auto-selects and reports local port >= 1024");
+ ok($output[0] =~ /^ACCEPT (0.0.0.0|\[::\]):(\d+?) PID=(\d+)$/
+ && $2 >= 1024 && $3 > 0,
+ "HTTP server auto-selects and reports local port >= 1024 and pid > 0");
}
ok(run(test(["http_test", srctop_file("test", "certs", "ca-cert.pem")])));
diff --git a/test/recipes/80-test_cmp_http.t b/test/recipes/80-test_cmp_http.t
index 9c99226721..10f2b84c68 100644
--- a/test/recipes/80-test_cmp_http.t
+++ b/test/recipes/80-test_cmp_http.t
@@ -12,7 +12,7 @@ use strict;
use warnings;
use POSIX;
-use OpenSSL::Test qw/:DEFAULT data_file data_dir srctop_dir bldtop_dir result_dir/;
+use OpenSSL::Test qw/:DEFAULT cmdstr data_file data_dir srctop_dir bldtop_dir result_dir/;
use OpenSSL::Test::Utils;
BEGIN {
@@ -266,38 +266,27 @@ sub load_tests {
sub start_mock_server {
my $args = $_[0]; # optional further CLI arguments
- my $dir = bldtop_dir("");
- local $ENV{LD_LIBRARY_PATH} = $dir;
- local $ENV{DYLD_LIBRARY_PATH} = $dir;
- my $cmd = bldtop_dir($app) . " -config server.cnf $args";
+ my $cmd = cmdstr(app(['openssl', 'cmp', '-config', 'server.cnf',
+ $args ? $args : ()]), display => 1);
print "Current directory is ".getcwd()."\n";
print "Launching mock server: $cmd\n";
die "Invalid port: $server_port" unless $server_port =~ m/^\d+$/;
my $pid = open($server_fh, "$cmd|") or die "Trying to $cmd";
print "Pid is: $pid\n";
if ($server_port == 0) {
- # Clear it first
- $server_port = undef;
-
# Find out the actual server port
while (<$server_fh>) {
- print;
+ print "Server output: $_";
+ next if m/using section/;
s/\R$//; # Better chomp
- next unless (/^ACCEPT/);
-
- # $1 may be undefined, which is OK to assign to $server_port,
- # as that gets detected further down.
- /^ACCEPT\s.*:(\d+)$/;
- $server_port = $1;
-
- last;
- }
-
- unless (defined $server_port) {
- stop_mock_server($pid);
- return 0;
+ ($server_port, $pid) = ($1, $2) if /^ACCEPT\s.*:(\d+) PID=(\d+)$/;
+ last; # Do not loop further to prevent hangs on server misbehavior
}
}
+ unless ($server_port > 0) {
+ stop_mock_server($pid);
+ return 0;
+ }
$server_tls = $kur_port = $pbm_port = $server_port;
return $pid;
}
@@ -305,5 +294,5 @@ sub start_mock_server {
sub stop_mock_server {
my $pid = $_[0];
print "Killing mock server with pid=$pid\n";
- kill('QUIT', $pid) if $pid;
+ kill('QUIT', $pid);
}
More information about the openssl-commits
mailing list