summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-05-22 11:59:44 +0200
committerDr. David von Oheimb <dev@ddvo.net>2021-05-29 07:47:03 +0200
commitd357dd51cbea662792b0816f441718b7fb66bd49 (patch)
treec2db31484ec52e6c5a5282a078c1f25477507c52
parent189c4759ebb7eefe6c8edb0a5493dc4082f45696 (diff)
apps/lib/s_socket.c and 80-test_cmp_http.t: Make ACCEPT port reporting more robust
Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15417)
-rw-r--r--apps/lib/s_socket.c11
-rw-r--r--test/recipes/80-test_cmp_http.t28
-rw-r--r--test/recipes/80-test_cmp_http_data/Mock/server.cnf3
-rw-r--r--test/recipes/80-test_cmp_http_data/Mock/test.cnf1
4 files changed, 24 insertions, 19 deletions
diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c
index f543551bf1..fbe913e37a 100644
--- a/apps/lib/s_socket.c
+++ b/apps/lib/s_socket.c
@@ -195,6 +195,8 @@ int report_server_accept(BIO *out, int asock, int with_address)
{
int success = 0;
+ if (BIO_printf(out, "ACCEPT") <= 0)
+ return 0;
if (with_address) {
union BIO_sock_info_u info;
char *hostname = NULL;
@@ -206,16 +208,17 @@ int report_server_accept(BIO *out, int asock, int with_address)
&& (service = BIO_ADDR_service_string(info.addr, 1)) != NULL
&& BIO_printf(out,
strchr(hostname, ':') == NULL
- ? /* IPv4 */ "ACCEPT %s:%s\n"
- : /* IPv6 */ "ACCEPT [%s]:%s\n",
+ ? /* IPv4 */ " %s:%s\n"
+ : /* IPv6 */ " [%s]:%s\n",
hostname, service) > 0)
success = 1;
+ else
+ (void)BIO_printf(out, "unknown:error\n");
OPENSSL_free(hostname);
OPENSSL_free(service);
BIO_ADDR_free(info.addr);
- } else {
- (void)BIO_printf(out, "ACCEPT\n");
+ } else if (BIO_printf(out, "\n") > 0) {
success = 1;
}
(void)BIO_flush(out);
diff --git a/test/recipes/80-test_cmp_http.t b/test/recipes/80-test_cmp_http.t
index c74a5faf03..106f580636 100644
--- a/test/recipes/80-test_cmp_http.t
+++ b/test/recipes/80-test_cmp_http.t
@@ -187,8 +187,7 @@ indir data_dir() => sub {
if ($server_name eq "Mock") {
indir "Mock" => sub {
$pid = start_mock_server("");
- skip "Cannot start or find the started CMP mock server",
- scalar @all_aspects unless $pid;
+ die "Cannot start or find the started CMP mock server" unless $pid;
}
}
foreach my $aspect (@all_aspects) {
@@ -275,20 +274,23 @@ sub start_mock_server {
my $cmd = bldtop_dir($app) . " -config server.cnf $args";
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";
- # Find out the actual server port
- while (<$server_fh>) {
- print;
- s/\R$//; # Better chomp
- next unless (/^ACCEPT\s.*:(\d+)$/);
- $server_port = $1;
- $server_tls = $1;
- $kur_port = $1;
- $pbm_port = $1;
- last;
+ if ($server_port eq "0") {
+ # Find out the actual server port
+ while (<$server_fh>) {
+ print;
+ s/\R$//; # Better chomp
+ next unless (/^ACCEPT/);
+ $server_port = $server_tls = $kur_port = $pbm_port = $1
+ if m/^ACCEPT\s.*?:(\d+)$/;
+ last;
+ }
}
- return $pid;
+ return $pid if $server_port =~ m/^(\d+)$/;
+ stop_mock_server($pid);
+ return 0;
}
sub stop_mock_server {
diff --git a/test/recipes/80-test_cmp_http_data/Mock/server.cnf b/test/recipes/80-test_cmp_http_data/Mock/server.cnf
index 24a6ebb9f6..633dc9230b 100644
--- a/test/recipes/80-test_cmp_http_data/Mock/server.cnf
+++ b/test/recipes/80-test_cmp_http_data/Mock/server.cnf
@@ -1,7 +1,6 @@
[cmp] # mock server configuration
-# port 0 means that a random available port will be used
-port = 0
+port = 0 # 0 means that the server should choose a random available port
srv_cert = server.crt
srv_key = server.key
srv_secret = pass:test
diff --git a/test/recipes/80-test_cmp_http_data/Mock/test.cnf b/test/recipes/80-test_cmp_http_data/Mock/test.cnf
index 8c8913b3c9..87dd575a8a 100644
--- a/test/recipes/80-test_cmp_http_data/Mock/test.cnf
+++ b/test/recipes/80-test_cmp_http_data/Mock/test.cnf
@@ -17,6 +17,7 @@ policies = certificatePolicies
[Mock] # the built-in OpenSSL CMP mock server
no_check_time = 1
server_host = 127.0.0.1 # localhost
+# server_port = 0 means that the port is determined by the server
server_port = 0
server_tls = $server_port
server_cert = server.crt