]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Adapt 80-test_cmp_http.t and its data for random accept ports
authorRichard Levitte <levitte@openssl.org>
Fri, 14 May 2021 10:26:21 +0000 (12:26 +0200)
committerRichard Levitte <levitte@openssl.org>
Sun, 16 May 2021 10:07:14 +0000 (12:07 +0200)
Fixes #14694

Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/15281)

test/recipes/80-test_cmp_http.t
test/recipes/80-test_cmp_http_data/Mock/server.cnf
test/recipes/80-test_cmp_http_data/Mock/test.cnf
test/recipes/80-test_cmp_http_data/test_connection.csv

index 7bb720a823667ef41b1cae99e87faf6a4c37b863..8bd9eacde9d272b444e02da9971cf12524640874 100644 (file)
@@ -28,15 +28,13 @@ plan skip_all => "These tests are not supported in a no-cmp build"
     if disabled("cmp");
 plan skip_all => "These tests are not supported in a no-ec build"
     if disabled("ec");
+plan skip_all => "These tests are not supported in a no-sock build"
+    if disabled("sock");
 
 plan skip_all => "Tests involving local HTTP server not available on Windows, AIX or VMS"
     if $^O =~ /^(VMS|MSWin32|AIX)$/;
 plan skip_all => "Tests involving local HTTP server not available in cross-compile builds"
     if defined $ENV{EXE_SHELL};
-plan skip_all => "Tests involving local HTTP server require 'kill' command"
-    if system("which kill >/dev/null");
-plan skip_all => "Tests involving local HTTP server require 'lsof' command"
-    if system("which lsof >/dev/null"); # this typically excludes Solaris
 
 sub chop_dblquot { # chop any leading and trailing '"' (needed for Windows)
     my $str = shift;
@@ -65,6 +63,7 @@ my $pbm_ref;    # The reference for PBM
 my $pbm_secret; # The secret for PBM
 my $column;     # The column number of the expected result
 my $sleep = 0;  # The time to sleep between two requests
+my $server_fh;  # Server file handle
 
 # The local $server_name variables below are among others taken as the name of a
 # sub-directory with server-specific certs etc. and CA-specific config section.
@@ -131,6 +130,9 @@ sub test_cmp_http {
     my $params = shift;
     my $expected_exit = shift;
     my $path_app = bldtop_dir($app);
+    $params = [ '-server', "127.0.0.1:$server_port", @$params ]
+        unless grep { $_ eq '-server' } @$params;
+
     with({ exit_checker => sub {
         my $actual_exit = shift;
         my $OK = $actual_exit == $expected_exit;
@@ -265,28 +267,32 @@ sub load_tests {
     return \@result;
 }
 
-sub mock_server_pid {
-    return `lsof -iTCP:$server_port` =~ m/\n\S+\s+(\d+)\s+[^\n]+LISTEN/s ? $1 : 0;
-}
-
 sub start_mock_server {
     my $args = $_[0]; # optional further CLI arguments
     my $dir = bldtop_dir("");
-    my $cmd = "LD_LIBRARY_PATH=$dir DYLD_LIBRARY_PATH=$dir " .
-        bldtop_dir($app) . " -config server.cnf $args";
-    my $pid = mock_server_pid();
-    if ($pid) {
-        print "Mock server already running with pid=$pid\n";
-        return $pid;
-    }
+    local $ENV{LD_LIBRARY_PATH} = $dir;
+    local $ENV{DYLD_LIBRARY_PATH} = $dir;
+    my $cmd = bldtop_dir($app) . " -config server.cnf $args";
     print "Current directory is ".getcwd()."\n";
-    print "Launching mock server listening on port $server_port: $cmd\n";
-    return system("$cmd &") == 0 # start in background, check for success
-        ? (sleep 1, mock_server_pid()) : 0;
+    print "Launching mock server: $cmd\n";
+    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;
+    }
+    return $pid;
 }
 
 sub stop_mock_server {
     my $pid = $_[0];
     print "Killing mock server with pid=$pid\n";
-    system("kill $pid") if $pid;
+    kill('QUIT', $pid) if $pid;
 }
index c8fe8edcc6c2fcfdb652c76899af8c70af1e8adf..24a6ebb9f62fb29264e22fcbe19d5ef13f38fd30 100644 (file)
@@ -1,6 +1,7 @@
 [cmp] # mock server configuration
 
-port = 1700
+# port 0 means that a random available port will be used
+port = 0
 srv_cert = server.crt
 srv_key = server.key
 srv_secret = pass:test
index 22ca0f23622635d82560009c62c78a40462833b5..503ded18e384edeb57e88a0499d8b525ba8914f4 100644 (file)
@@ -17,8 +17,8 @@ policies = certificatePolicies
 [Mock] # the built-in OpenSSL CMP mock server
 no_check_time = 1
 server_host = 127.0.0.1 # localhost
-server_port = 1700
-server_tls = 0
+server_port = 0
+server_tls = $server_port
 server_cert = server.crt
 server = $server_host:$server_port
 server_path = pkix/
@@ -30,8 +30,8 @@ expect_sender = $server_dn
 subject = "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=leaf"
 newkey = signer.key
 out_trusted = signer_root.crt
-kur_port = 1700
-pbm_port = 1700
+kur_port = $server_port
+pbm_port = $server_port
 pbm_ref =
 pbm_secret = pass:test
 cert = signer.crt
index 3276eb5fb35b150105f3b0f08213a881ee85588b..b3290e0e730e038834061b0295fb676cbc83bc0b 100644 (file)
@@ -14,7 +14,7 @@ TBD,IP address, -section,, -server,_SERVER_IP:_SERVER_PORT,,,,,,,,,,,,,,
 1,server with default port, -section,, -server,_SERVER_HOST,,,,,BLANK,,,,BLANK,,BLANK,,BLANK,
 1,server port bad syntax: leading garbage, -section,, -server,_SERVER_HOST:x/+80,,,,,BLANK,,,,BLANK,,BLANK,,BLANK,
 1,server port bad synatx: trailing garbage, -section,, -server,_SERVER_HOST:_SERVER_PORT+/x.,,,,,BLANK,,,,BLANK,,BLANK,,BLANK,
-1,server with TLS port, -section,, -server,_SERVER_HOST:_SERVER_TLS,,,,,BLANK,,,,BLANK,,BLANK,,BLANK,
+1,server with wrong port, -section,, -server,_SERVER_HOST:999,,,,,BLANK,,,,-msg_timeout,1,BLANK,,BLANK,
 TBD,server IP address with TLS port, -section,, -server,_SERVER_IP:_SERVER_TLS,,,,,BLANK,,,,BLANK,,BLANK,,BLANK,
 ,,,,,,,,,,,,,,,,,,,
 1,proxy port bad syntax: leading garbage, -section,, -server,_SERVER_HOST:_SERVER_PORT, -proxy,127.0.0.1:x*/8888, -no_proxy,nonmatch.com,BLANK,,,,-msg_timeout,1,BLANK,,BLANK,