Commit b9c5f2bcd9 for openssl.org
commit b9c5f2bcd93487d737a57bd6ffeeb3aa6528b322
Author: Jakub Zelenka <jakub.zelenka@openssl.foundation>
Date: Sat Aug 29 12:32:20 2026 +0200
apps: cover the dsa error cases in the test recipe
Cover the bad option failures (invalid input and output formats,
extra arguments, unknown cipher and invalid password argument) as
well as the failures when loading an invalid or non-DSA key file
and when requesting an unsupported output format, verifying the
error messages printed to stderr with the shared app_fails helper.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Daniel Kubec <kubec@openssl.foundation>
Merge-date: Wed Sep 16 08:48:56 2026
Merged-from: https://github.com/openssl/openssl/pull/32590
diff --git a/test/recipes/15-test_dsa.t b/test/recipes/15-test_dsa.t
index 9e9aa77052..f8c55fe37e 100644
--- a/test/recipes/15-test_dsa.t
+++ b/test/recipes/15-test_dsa.t
@@ -11,13 +11,13 @@ use strict;
use warnings;
use File::Spec;
-use OpenSSL::Test qw/:DEFAULT srctop_file/;
+use OpenSSL::Test qw/:DEFAULT srctop_file app_fails/;
use OpenSSL::Test::Utils;
setup("test_dsa");
plan skip_all => 'DSA is not supported in this build' if disabled('dsa');
-plan tests => 11;
+plan tests => 12;
require_ok(srctop_file('test','recipes','tconversion.pl'));
@@ -131,6 +131,42 @@ subtest "dsa -text prints the key in text form" => sub {
"-text does not print a private component for a public key");
};
+subtest "dsa error cases" => sub {
+ plan tests => 16;
+
+ my $privkey = srctop_file("test", "testdsa.pem");
+
+ app_fails('dsa', "invalid input format should fail",
+ qr/Invalid format "BAD" for option -inform/,
+ '-inform', 'BAD', '-in', $privkey);
+ app_fails('dsa', "invalid output format should fail",
+ qr/Invalid format "BAD" for option -outform/,
+ '-outform', 'BAD', '-in', $privkey);
+ app_fails('dsa', "extra positional argument should fail",
+ qr/Extra option: "extra"/,
+ '-in', $privkey, 'extra');
+ app_fails('dsa', "unknown cipher option should fail",
+ qr/Unknown option or cipher: badcipher/,
+ '-badcipher', '-in', $privkey);
+ app_fails('dsa', "invalid passin argument should fail",
+ qr/Error getting passwords/,
+ '-passin', 'bad:pass', '-in', $privkey);
+ app_fails('dsa', "unsupported output format should fail",
+ qr/bad output format specified for outfile/,
+ '-in', $privkey, '-outform', 'NSS', '-out', 'dsa-nss.out');
+
+ my $garbage = "garbage.pem";
+ open(my $fh, '>', $garbage) or die "Cannot write $garbage: $!";
+ print $fh "not a valid DSA key file\n";
+ close($fh);
+ app_fails('dsa', "loading garbage key file should fail",
+ qr/unable to load Key/,
+ '-in', $garbage, '-noout');
+ app_fails('dsa', "loading a non-DSA key should fail",
+ qr/Not a DSA key/,
+ '-in', srctop_file("test", "testrsa.pem"), '-noout');
+};
+
subtest "dsa PVK output is rejected for public key input" => sub {
plan tests => 1;