Browse Source

TEST: modify tconversion.pl for forensics

In the interest of finding out what went wrong with a test by looking
at its output, tconversion.pl is modified to take arguments in option
form, and gets an additional -prefix option that callers can use to
ensure output files are uniquely named.

Test recipes are modified to use these new options.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13147)
master
Richard Levitte 2 years ago
parent
commit
b40498c6e7
9 changed files with 88 additions and 47 deletions
  1. +11
    -6
      test/recipes/15-test_dsa.t
  2. +32
    -16
      test/recipes/15-test_ec.t
  3. +8
    -4
      test/recipes/15-test_rsa.t
  4. +1
    -1
      test/recipes/25-test_crl.t
  5. +4
    -2
      test/recipes/25-test_pkcs7.t
  6. +2
    -1
      test/recipes/25-test_req.t
  7. +2
    -1
      test/recipes/25-test_sid.t
  8. +6
    -3
      test/recipes/25-test_x509.t
  9. +22
    -13
      test/recipes/tconversion.pl

+ 11
- 6
test/recipes/15-test_dsa.t View File

@ -26,17 +26,22 @@ ok(run(test(["dsa_no_digest_size_test"])),
"running dsa_no_digest_size_test");
subtest "dsa conversions using 'openssl dsa' -- private key" => sub {
tconversion("dsa", srctop_file("test","testdsa.pem"));
tconversion( -type => 'dsa', -prefix => 'dsa-priv',
-in => srctop_file("test","testdsa.pem") );
};
subtest "dsa conversions using 'openssl dsa' -- public key" => sub {
tconversion("msb", srctop_file("test","testdsapub.pem"), "dsa",
"-pubin", "-pubout");
tconversion( -type => 'msb', -prefix => 'dsa-msb-pub',
-in => srctop_file("test","testdsapub.pem"),
-args => ["dsa", "-pubin", "-pubout"] );
};
subtest "dsa conversions using 'openssl pkey' -- private key PKCS#8" => sub {
tconversion("dsa", srctop_file("test","testdsa.pem"), "pkey");
tconversion( -type => 'dsa', -prefix => 'dsa-pkcs8',
-in => srctop_file("test","testdsa.pem"),
-args => ["pkey"] );
};
subtest "dsa conversions using 'openssl pkey' -- public key" => sub {
tconversion("dsa", srctop_file("test","testdsapub.pem"), "pkey",
"-pubin", "-pubout");
tconversion( -type => 'dsa', -prefix => 'dsa-pkey-pub',
-in => srctop_file("test","testdsapub.pem"),
-args => ["pkey", "-pubin", "-pubout"] );
};

+ 32
- 16
test/recipes/15-test_ec.t View File

@ -30,14 +30,18 @@ SKIP: {
if disabled("ec");
subtest 'EC conversions -- private key' => sub {
tconversion("ec", srctop_file("test","testec-p256.pem"));
tconversion( -type => 'ec', -prefix => 'ec-priv',
-in => srctop_file("test","testec-p256.pem") );
};
subtest 'EC conversions -- private key PKCS#8' => sub {
tconversion("ec", srctop_file("test","testec-p256.pem"), "pkey");
tconversion( -type => 'ec', -prefix => 'ec-pkcs8',
-in => srctop_file("test","testec-p256.pem"),
-args => "pkey" );
};
subtest 'EC conversions -- public key' => sub {
tconversion("ec", srctop_file("test","testecpub-p256.pem"),
"ec", "-pubin", "-pubout");
tconversion( -type => 'ec', -prefix => 'ec-pub',
-in => srctop_file("test","testecpub-p256.pem"),
-args => [ "ec", "-pubin", "-pubout" ] );
};
}
@ -46,14 +50,18 @@ SKIP: {
if disabled("ec");
subtest 'PKEY conversions -- private key' => sub {
tconversion("pkey", srctop_file("test","testec-p256.pem"));
tconversion( -type => 'pkey', -prefix => 'ec-pkey-priv',
-in => srctop_file("test","testec-p256.pem") );
};
subtest 'PKEY conversions -- private key PKCS#8' => sub {
tconversion("pkey", srctop_file("test","testec-p256.pem"), "pkey");
tconversion( -type => 'pkey', -prefix => 'ec-pkey-pkcs8',
-in => srctop_file("test","testec-p256.pem"),
-args => "pkey" );
};
subtest 'PKEY conversions -- public key' => sub {
tconversion("pkey", srctop_file("test","testecpub-p256.pem"),
"pkey", "-pubin", "-pubout");
tconversion( -type => 'pkey', -prefix => 'ec-pkey-pub',
-in => srctop_file("test","testecpub-p256.pem"),
-args => [ "pkey", "-pubin", "-pubout" ] );
};
}
@ -62,24 +70,32 @@ SKIP: {
if disabled("ec");
subtest 'Ed25519 conversions -- private key' => sub {
tconversion("pkey", srctop_file("test", "tested25519.pem"));
tconversion( -type => "pkey", -prefix => "ed25519-pkey-priv",
-in => srctop_file("test", "tested25519.pem") );
};
subtest 'Ed25519 conversions -- private key PKCS#8' => sub {
tconversion("pkey", srctop_file("test", "tested25519.pem"), "pkey");
tconversion( -type => "pkey", -prefix => "ed25519-pkey-pkcs8",
-in => srctop_file("test", "tested25519.pem"),
-args => ["pkey"] );
};
subtest 'Ed25519 conversions -- public key' => sub {
tconversion("pkey", srctop_file("test", "tested25519pub.pem"),
"pkey", "-pubin", "-pubout");
tconversion( -type => "pkey", -prefix => "ed25519-pkey-pub",
-in => srctop_file("test", "tested25519pub.pem"),
-args => ["pkey", "-pubin", "-pubout"] );
};
subtest 'Ed448 conversions -- private key' => sub {
tconversion("pkey", srctop_file("test", "tested448.pem"));
tconversion( -type => "pkey", -prefix => "ed448-pkey-priv",
-in => srctop_file("test", "tested448.pem") );
};
subtest 'Ed448 conversions -- private key PKCS#8' => sub {
tconversion("pkey", srctop_file("test", "tested448.pem"), "pkey");
tconversion( -type => "pkey", -prefix => "ed448-pkey-pkcs8",
-in => srctop_file("test", "tested448.pem"),
-args => ["pkey"] );
};
subtest 'Ed448 conversions -- public key' => sub {
tconversion("pkey", srctop_file("test", "tested448pub.pem"),
"pkey", "-pubin", "-pubout");
tconversion( -type => "pkey", -prefix => "ed448-pkey-pub",
-in => srctop_file("test", "tested448pub.pem"),
-args => ["pkey", "-pubin", "-pubout"] );
};
}

+ 8
- 4
test/recipes/15-test_rsa.t View File

@ -37,10 +37,13 @@ sub run_rsa_tests {
if disabled("rsa");
subtest "$cmd conversions -- private key" => sub {
tconversion($cmd, srctop_file("test", "testrsa.pem"));
tconversion( -type => $cmd, -prefix => "$cmd-priv",
-in => srctop_file("test", "testrsa.pem") );
};
subtest "$cmd conversions -- private key PKCS#8" => sub {
tconversion($cmd, srctop_file("test", "testrsa.pem"), "pkey");
tconversion( -type => $cmd, -prefix => "$cmd-pkcs8",
-in => srctop_file("test", "testrsa.pem"),
-args => ["pkey"] );
};
}
@ -49,8 +52,9 @@ sub run_rsa_tests {
if disabled($cmd) || disabled("dsa") || $cmd == 'pkey';
subtest "$cmd conversions -- public key" => sub {
tconversion("msb", srctop_file("test", "testrsapub.pem"), "rsa",
"-pubin", "-pubout");
tconversion( -type => 'msb', -prefix => "$cmd-msb-pub",
-in => srctop_file("test", "testrsapub.pem"),
-args => ["rsa", "-pubin", "-pubout"] );
};
}
}

+ 1
- 1
test/recipes/25-test_crl.t View File

@ -24,7 +24,7 @@ my $out = "cyrillic_crl.out";
my $utf = srctop_file("test/certs", "cyrillic_crl.utf8");
subtest 'crl conversions' => sub {
tconversion("crl", srctop_file("test","testcrl.pem"));
tconversion( -type => "crl", -in => srctop_file("test","testcrl.pem") );
};
ok(run(test(['crltest'])));


+ 4
- 2
test/recipes/25-test_pkcs7.t View File

@ -20,8 +20,10 @@ plan tests => 3;
require_ok(srctop_file('test','recipes','tconversion.pl'));
subtest 'pkcs7 conversions -- pkcs7' => sub {
tconversion("p7", srctop_file("test", "testp7.pem"), "pkcs7");
tconversion( -type => 'p7', -in => srctop_file("test", "testp7.pem"),
-args => ["pkcs7"] );
};
subtest 'pkcs7 conversions -- pkcs7d' => sub {
tconversion("p7d", srctop_file("test", "pkcs7-1.pem"), "pkcs7");
tconversion( -type => 'p7d', -in => srctop_file("test", "pkcs7-1.pem"),
-args => ["pkcs7"] );
};

+ 2
- 1
test/recipes/25-test_req.t View File

@ -237,7 +237,8 @@ sub run_conversion {
plan skip_all => "skipping req conversion test for $reqfile"
if grep /Unknown Public Key/, map { s/\R//; } <DATA>;
tconversion("req", $reqfile, @openssl_args);
tconversion( -type => 'req', -in => $reqfile,
-args => [ @openssl_args ] );
}
close DATA;
unlink "req-check.err";


+ 2
- 1
test/recipes/25-test_sid.t View File

@ -24,5 +24,6 @@ plan tests => 2;
require_ok(srctop_file('test','recipes','tconversion.pl'));
subtest 'sid conversions' => sub {
tconversion("sid", srctop_file("test","testsid.pem"), "sess_id");
tconversion( -type => 'sid', -in => srctop_file("test","testsid.pem"),
-args => ["sess_id"] );
};

+ 6
- 3
test/recipes/25-test_x509.t View File

@ -72,13 +72,16 @@ SKIP: {
}
subtest 'x509 -- x.509 v1 certificate' => sub {
tconversion("x509", srctop_file("test","testx509.pem"));
tconversion( -type => 'x509', -prefix => 'x509v1',
-in => srctop_file("test","testx509.pem") );
};
subtest 'x509 -- first x.509 v3 certificate' => sub {
tconversion("x509", srctop_file("test","v3-cert1.pem"));
tconversion( -type => 'x509', -prefix => 'x509v3-1',
-in => srctop_file("test","v3-cert1.pem") );
};
subtest 'x509 -- second x.509 v3 certificate' => sub {
tconversion("x509", srctop_file("test","v3-cert2.pem"));
tconversion( -type => 'x509', -prefix => 'x509v3-2',
-in => srctop_file("test","v3-cert2.pem") );
};
subtest 'x509 -- pathlen' => sub {


+ 22
- 13
test/recipes/tconversion.pl View File

@ -21,14 +21,23 @@ my %conversionforms = (
"msb" => [ "d", "p", "msblob" ],
);
sub tconversion {
my $testtype = shift;
my $t = shift;
my %opts = @_;
die "Missing option -type" unless $opts{-type};
die "Missing option -in" unless $opts{-in};
my $testtype = $opts{-type};
my $t = $opts{-in};
my $prefix = $opts{-prefix} // $testtype;
my @conversionforms =
defined($conversionforms{$testtype}) ?
@{$conversionforms{$testtype}} :
@{$conversionforms{"*"}};
my @openssl_args = @_;
if (!@openssl_args) { @openssl_args = ($testtype); }
my @openssl_args;
if (defined $opts{-args}) {
@openssl_args = @{$opts{-args}} if ref $opts{-args} eq 'ARRAY';
@openssl_args = ($opts{-args}) if ref $opts{-args} eq '';
}
@openssl_args = ($testtype) unless @openssl_args;
my $n = scalar @conversionforms;
my $totaltests =
@ -44,13 +53,13 @@ sub tconversion {
my $init;
if (scalar @openssl_args > 0 && $openssl_args[0] eq "pkey") {
$init = ok(run(app([@cmd, "-in", $t, "-out", "$testtype-fff.p"])),
$init = ok(run(app([@cmd, "-in", $t, "-out", "$prefix-fff.p"])),
'initializing');
} else {
$init = ok(copy($t, "$testtype-fff.p"), 'initializing');
$init = ok(copy($t, "$prefix-fff.p"), 'initializing');
}
if (!$init) {
diag("Trying to copy $t to $testtype-fff.p : $!");
diag("Trying to copy $t to $prefix-fff.p : $!");
}
SKIP: {
@ -58,9 +67,9 @@ sub tconversion {
foreach my $to (@conversionforms) {
ok(run(app([@cmd,
"-in", "$testtype-fff.p",
"-in", "$prefix-fff.p",
"-inform", "p",
"-out", "$testtype-f.$to",
"-out", "$prefix-f.$to",
"-outform", $to])),
"p -> $to");
}
@ -68,23 +77,23 @@ sub tconversion {
foreach my $to (@conversionforms) {
foreach my $from (@conversionforms) {
ok(run(app([@cmd,
"-in", "$testtype-f.$from",
"-in", "$prefix-f.$from",
"-inform", $from,
"-out", "$testtype-ff.$from$to",
"-out", "$prefix-ff.$from$to",
"-outform", $to])),
"$from -> $to");
}
}
if ($testtype ne "p7d") {
is(cmp_text("$testtype-fff.p", "$testtype-f.p"), 0,
is(cmp_text("$prefix-fff.p", "$prefix-f.p"), 0,
'comparing orig to p');
}
foreach my $to (@conversionforms) {
next if $to eq "d";
foreach my $from (@conversionforms) {
is(cmp_text("$testtype-f.$to", "$testtype-ff.$from$to"), 0,
is(cmp_text("$prefix-f.$to", "$prefix-ff.$from$to"), 0,
"comparing $to to $from$to");
}
}


Loading…
Cancel
Save