summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2015-04-17 20:10:24 +0200
committerRichard Levitte <levitte@openssl.org>2015-09-07 16:10:57 +0200
commit904ae3342600fe1dae3e0835a784c73b7c237106 (patch)
tree476505dad5223600c75a763b50c595216a0175b3 /test
parent13350a0c0eb8937c299c394a88d6cb51d3356d1f (diff)
Add a helper script for key file format conversion tests
As tests are done until now, there are a few scripts that look almost, but not quite the same. tkey, tx509, tcrl, tpkcs7, treq, tsid and probably a few more. recipes/tconversions.pl is a helper script that generalises the function of each of those, and can then be used in a general manner from test recipes. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'test')
-rw-r--r--test/recipes/tconversion.pl88
1 files changed, 88 insertions, 0 deletions
diff --git a/test/recipes/tconversion.pl b/test/recipes/tconversion.pl
new file mode 100644
index 0000000000..94039e932b
--- /dev/null
+++ b/test/recipes/tconversion.pl
@@ -0,0 +1,88 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use File::Compare qw/compare_text/;
+use File::Copy;
+use Test::More;
+use lib 'testlib';
+use OpenSSL::Test qw/:DEFAULT top_file/;
+
+my %conversionforms = (
+ "*" => [ "d", "p" ],
+ x509 => [ "d", "n", "p" ],
+ );
+sub tconversion {
+ my $testtype = shift;
+ my $t = shift;
+ my @conversionforms =
+ defined($conversionforms{$testtype}) ?
+ @{$conversionforms{$testtype}} :
+ @{$conversionforms{"*"}};
+ my @openssl_args = @_;
+ if (!@openssl_args) { @openssl_args = ($testtype); }
+
+ my $n = scalar @conversionforms;
+ my $totaltests =
+ 1 # for initializing
+ + $n # initial conversions from p to all forms (A)
+ + $n*$n # conversion from result of A to all forms (B)
+ + 1 # comparing original test file to p form of A
+ + $n*($n-1); # comparing first conversion to each fom in A with B
+ $totaltests-- if ($testtype eq "p7d"); # no comparison of original test file
+ plan tests => $totaltests;
+
+ my @cmd = ("openssl", @openssl_args);
+
+ my $init;
+ if (scalar @openssl_args > 0 && $openssl_args[0] eq "pkey") {
+ $init = ok(run(app([@cmd, "-in", $t, "-out", "$testtype-fff.p"])),
+ 'initializing');
+ } else {
+ $init = ok(copy($t, "$testtype-fff.p"), 'initializing');
+ }
+ if (!$init) {
+ diag("Trying to copy $t to $testtype-fff.p : $!");
+ }
+
+ SKIP: {
+ skip "Not initialized, skipping...", 22 unless $init;
+
+ foreach my $to (@conversionforms) {
+ ok(run(app([@cmd,
+ "-in", "$testtype-fff.p",
+ "-inform", "p",
+ "-outform", $to],
+ stdout => "$testtype-f.$to")), "p -> $to");
+ }
+
+ foreach my $to (@conversionforms) {
+ foreach my $from (@conversionforms) {
+ ok(run(app([@cmd,
+ "-in", "$testtype-f.$from",
+ "-inform", $from,
+ "-outform", $to],
+ stdout => "$testtype-ff.$from$to")), "$from -> $to");
+ }
+ }
+
+ if ($testtype ne "p7d") {
+ is(compare_text("$testtype-fff.p", "$testtype-f.p"), 0,
+ 'comparing orig to p');
+ }
+
+ foreach my $to (@conversionforms) {
+ next if $to eq "d";
+ foreach my $from (@conversionforms) {
+ is(compare_text("$testtype-f.$to", "$testtype-ff.$from$to"), 0,
+ "comparing $to to $from$to");
+ }
+ }
+ }
+ unlink glob "$testtype-f.*";
+ unlink glob "$testtype-ff.*";
+ unlink glob "$testtype-fff.*";
+}
+
+1;