Avoid warnings in tests when openssl binary isn't available
authorDaniel Gustafsson <[email protected]>
Fri, 17 Oct 2025 12:21:26 +0000 (14:21 +0200)
committerDaniel Gustafsson <[email protected]>
Fri, 17 Oct 2025 12:21:26 +0000 (14:21 +0200)
The SSL tests for pg_stat_ssl tries to exactly match the serial
from the certificate by extracting it with the openssl binary.
If that fails due to the binary not being available, a fallback
match is used, but the attempt to execute a missing binary adds
a warning to the output which can confuse readers for a failure
in the test.  Fix by only attempting if the openssl binary was
found by autoconf/meson.

Backpatch down to v16 where commit c8e4030d1bdd made the test
use the OPENSSL variable from autoconf/meson instead of a hard-
coded value.

Author: Daniel Gustafsson <[email protected]>
Reported-by: Christoph Berg <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 16

src/test/ssl/t/001_ssltests.pl

index b2eb18d3e815ed7748f95ae05417afbdb57b6d08..eaee88d027e833710dcefe1bf7c9708d97a6c2f4 100644 (file)
@@ -748,33 +748,29 @@ TODO:
 
 # pg_stat_ssl
 
-my $serialno = `$ENV{OPENSSL} x509 -serial -noout -in ssl/client.crt`;
-if ($? == 0)
-{
-   # OpenSSL prints serial numbers in hexadecimal and converting the serial
-   # from hex requires a 64-bit capable Perl as the serialnumber is based on
-   # the current timestamp. On 32-bit fall back to checking for it being an
-   # integer like how we do when grabbing the serial fails.
-   if ($Config{ivsize} == 8)
-   {
-       no warnings qw(portable);
+# If the openssl program isn't available, or fails to run, fall back to a
+# generic integer match rather than skipping the test.
+my $serialno = '\d+';
 
-       $serialno =~ s/^serial=//;
-       $serialno =~ s/\s+//g;
-       $serialno = hex($serialno);
-   }
-   else
+if ($ENV{OPENSSL} ne '')
+{
+   $serialno = `$ENV{OPENSSL} x509 -serial -noout -in ssl/client.crt`;
+   if ($? == 0)
    {
-       $serialno = '\d+';
+       # OpenSSL prints serial numbers in hexadecimal and converting the serial
+       # from hex requires a 64-bit capable Perl as the serialnumber is based on
+       # the current timestamp. On 32-bit fall back to checking for it being an
+       # integer like how we do when grabbing the serial fails.
+       if ($Config{ivsize} == 8)
+       {
+           no warnings qw(portable);
+
+           $serialno =~ s/^serial=//;
+           $serialno =~ s/\s+//g;
+           $serialno = hex($serialno);
+       }
    }
 }
-else
-{
-   # OpenSSL isn't functioning on the user's PATH. This probably isn't worth
-   # skipping the test over, so just fall back to a generic integer match.
-   warn "couldn't run \"$ENV{OPENSSL} x509\" to get client cert serialno";
-   $serialno = '\d+';
-}
 
 command_like(
    [