TEST: Add TODO segments in test/recipes/15-test_genec.t

There currently do not support 'ec_param_enc:explicit' with provider
side key generation.  Reflect that by encoding the expected failure
with a Test::More TODO section for those particular tests.

Because the tests in this recipe are data driven, we implement this
mechanism with two functions, one for stuff that's supported and one
for stuff that isn't.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/12080)
This commit is contained in:
Richard Levitte 2020-06-09 12:29:27 +02:00 committed by Nicola Tuveri
parent 0c2bddb76a
commit c65b1d0252
1 changed files with 47 additions and 17 deletions

View File

@ -14,6 +14,31 @@ use File::Spec;
use OpenSSL::Test qw/:DEFAULT srctop_file/;
use OpenSSL::Test::Utils;
# 'supported' and 'unsupported' reflect the current state of things. In
# Test::More terms, 'supported' works exactly like ok(run(whatever)), while
# 'unsupported' wraps that in a TODO: { } block.
#
# The first argument is the test name (this becomes the last argument to
# 'ok')
# The remaining argument are passed unchecked to 'run'.
# 1: the result of app() or similar, i.e. something you can pass to
sub supported {
my $str = shift;
ok(run(@_), $str);
}
sub unsupported {
my $str = shift;
TODO: {
local $TODO = "Currently not supported";
ok(run(@_), $str);
}
}
setup("test_genec");
plan skip_all => "This test is unsupported in a no-ec build"
@ -137,35 +162,40 @@ push(@curve_list, @binary_curves)
push(@curve_list, @other_curves);
push(@curve_list, @curve_aliases);
my @params_encodings = ('named_curve', 'explicit');
my %params_encodings =
(
'named_curve' => \&supported,
'explicit' => \&unsupported
);
my @output_formats = ('PEM', 'DER');
plan tests => scalar(@curve_list) * scalar(@params_encodings)
plan tests => scalar(@curve_list) * scalar(keys %params_encodings)
* (1 + scalar(@output_formats)) # Try listed @output_formats and text output
+ 1 # Checking that with no curve it fails
+ 1 # Checking that with unknown curve it fails
;
foreach my $curvename (@curve_list) {
foreach my $paramenc (@params_encodings) {
ok(run(app([ 'openssl', 'genpkey',
'-algorithm', 'EC',
'-pkeyopt', 'ec_paramgen_curve:'.$curvename,
'-pkeyopt', 'ec_param_enc:'.$paramenc,
'-text'])),
"genpkey EC params ${curvename} with ec_param_enc:'${paramenc}' (text)");
foreach my $paramenc (sort keys %params_encodings) {
my $fn = $params_encodings{$paramenc};
$fn->("genpkey EC params ${curvename} with ec_param_enc:'${paramenc}' (text)",
app([ 'openssl', 'genpkey',
'-algorithm', 'EC',
'-pkeyopt', 'ec_paramgen_curve:'.$curvename,
'-pkeyopt', 'ec_param_enc:'.$paramenc,
'-text']));
foreach my $outform (@output_formats) {
my $outfile = "ecgen.${curvename}.${paramenc}." . lc $outform;
ok(run(app([ 'openssl', 'genpkey', '-genparam',
'-algorithm', 'EC',
'-pkeyopt', 'ec_paramgen_curve:'.$curvename,
'-pkeyopt', 'ec_param_enc:'.$paramenc,
'-outform', $outform,
'-out', $outfile])),
"genpkey EC params ${curvename} with ec_param_enc:'${paramenc}' (${outform})");
}
$fn->("genpkey EC params ${curvename} with ec_param_enc:'${paramenc}' (${outform})",
app([ 'openssl', 'genpkey', '-genparam',
'-algorithm', 'EC',
'-pkeyopt', 'ec_paramgen_curve:'.$curvename,
'-pkeyopt', 'ec_param_enc:'.$paramenc,
'-outform', $outform,
'-out', $outfile]));
}
}
}