🌐 AI搜索 & 代理 主页
Skip to content

Commit 7d129ba

Browse files
Avoid warnings in tests when openssl binary isn't available
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 c8e4030 made the test use the OPENSSL variable from autoconf/meson instead of a hard- coded value. Author: Daniel Gustafsson <daniel@yesql.se> Reported-by: Christoph Berg <myon@debian.org> Discussion: https://postgr.es/m/aNPSp1-RIAs3skZm@msg.df7cb.de Backpatch-through: 16
1 parent e1a912c commit 7d129ba

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -748,33 +748,29 @@ sub switch_server_cert
748748

749749
# pg_stat_ssl
750750

751-
my $serialno = `$ENV{OPENSSL} x509 -serial -noout -in ssl/client.crt`;
752-
if ($? == 0)
753-
{
754-
# OpenSSL prints serial numbers in hexadecimal and converting the serial
755-
# from hex requires a 64-bit capable Perl as the serialnumber is based on
756-
# the current timestamp. On 32-bit fall back to checking for it being an
757-
# integer like how we do when grabbing the serial fails.
758-
if ($Config{ivsize} == 8)
759-
{
760-
no warnings qw(portable);
751+
# If the openssl program isn't available, or fails to run, fall back to a
752+
# generic integer match rather than skipping the test.
753+
my $serialno = '\d+';
761754

762-
$serialno =~ s/^serial=//;
763-
$serialno =~ s/\s+//g;
764-
$serialno = hex($serialno);
765-
}
766-
else
755+
if ($ENV{OPENSSL} ne '')
756+
{
757+
$serialno = `$ENV{OPENSSL} x509 -serial -noout -in ssl/client.crt`;
758+
if ($? == 0)
767759
{
768-
$serialno = '\d+';
760+
# OpenSSL prints serial numbers in hexadecimal and converting the serial
761+
# from hex requires a 64-bit capable Perl as the serialnumber is based on
762+
# the current timestamp. On 32-bit fall back to checking for it being an
763+
# integer like how we do when grabbing the serial fails.
764+
if ($Config{ivsize} == 8)
765+
{
766+
no warnings qw(portable);
767+
768+
$serialno =~ s/^serial=//;
769+
$serialno =~ s/\s+//g;
770+
$serialno = hex($serialno);
771+
}
769772
}
770773
}
771-
else
772-
{
773-
# OpenSSL isn't functioning on the user's PATH. This probably isn't worth
774-
# skipping the test over, so just fall back to a generic integer match.
775-
warn "couldn't run \"$ENV{OPENSSL} x509\" to get client cert serialno";
776-
$serialno = '\d+';
777-
}
778774

779775
command_like(
780776
[

0 commit comments

Comments
 (0)