mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Run libtests for crypto with all available providers
If QPDF_CRYPTO_PROVIDER is set, just run the tests for the given provider. This is to support cases of running the entire test suite for each provider. If QPDF_CRYPTO_PROVIDER is not set, run the tests that exercise the cyrpto provider for each available provider.
This commit is contained in:
parent
127a957aee
commit
1639d972ea
@ -10,60 +10,81 @@ require TestDriver;
|
||||
|
||||
my $td = new TestDriver('AES');
|
||||
|
||||
cleanup();
|
||||
|
||||
my $key = '000102030405060708090a0b0c0d0e0f';
|
||||
$td->runtest("encrypt test vector",
|
||||
{$td->COMMAND => "aes -cbc -encrypt $key test-vector.clear tmp1"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp1"},
|
||||
{$td->FILE => "test-vector.cipher"});
|
||||
$td->runtest("decrypt test vector",
|
||||
{$td->COMMAND => "aes -cbc -decrypt $key tmp1 tmp2"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp2"},
|
||||
{$td->FILE => "test-vector.clear"});
|
||||
|
||||
$key = '243f6a8885243f6a8885243f6a888524';
|
||||
foreach my $d (['data1', 17072], ['data2', 16032])
|
||||
my @providers = ();
|
||||
if (exists $ENV{'QPDF_CRYPTO_PROVIDER'})
|
||||
{
|
||||
my ($file, $size) = @$d;
|
||||
$td->runtest("encrypt $file",
|
||||
{$td->COMMAND => "aes +cbc -encrypt $key $file tmp1"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
# sleep one second so random number will get a different seed
|
||||
sleep(1);
|
||||
$td->runtest("encrypt $file again",
|
||||
{$td->COMMAND => "aes +cbc -encrypt $key $file tmp2"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
foreach my $f (qw(tmp1 tmp2))
|
||||
push(@providers, $ENV{'QPDF_CRYPTO_PROVIDER'});
|
||||
}
|
||||
else
|
||||
{
|
||||
open(Q, "qpdf --show-crypto|") or die;
|
||||
while (<Q>)
|
||||
{
|
||||
$td->runtest("check size",
|
||||
{$td->STRING => sprintf("%d\n", stat($f)->size)},
|
||||
{$td->STRING => "$size\n"});
|
||||
s/\s+$//s;
|
||||
push(@providers, $_);
|
||||
}
|
||||
$td->runtest("verify files are different",
|
||||
{$td->COMMAND => "cmp tmp1 tmp2"},
|
||||
{$td->REGEXP => '.*', $td->EXIT_STATUS => '!0'});
|
||||
$td->runtest("decrypt $file",
|
||||
{$td->COMMAND => "aes +cbc -decrypt $key tmp1 tmp3"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("decrypt $file again",
|
||||
{$td->COMMAND => "aes +cbc -decrypt $key tmp2 tmp4"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
close(Q);
|
||||
}
|
||||
foreach my $p (@providers)
|
||||
{
|
||||
$ENV{'QPDF_CRYPTO_PROVIDER'} = $p;
|
||||
|
||||
cleanup();
|
||||
|
||||
my $key = '000102030405060708090a0b0c0d0e0f';
|
||||
$td->runtest("encrypt test vector ($p)",
|
||||
{$td->COMMAND =>
|
||||
"aes -cbc -encrypt $key test-vector.clear tmp1"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp3"},
|
||||
{$td->FILE => $file});
|
||||
{$td->FILE => "tmp1"},
|
||||
{$td->FILE => "test-vector.cipher"});
|
||||
$td->runtest("decrypt test vector ($p)",
|
||||
{$td->COMMAND => "aes -cbc -decrypt $key tmp1 tmp2"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp4"},
|
||||
{$td->FILE => $file});
|
||||
{$td->FILE => "tmp2"},
|
||||
{$td->FILE => "test-vector.clear"});
|
||||
|
||||
$key = '243f6a8885243f6a8885243f6a888524';
|
||||
foreach my $d (['data1', 17072], ['data2', 16032])
|
||||
{
|
||||
my ($file, $size) = @$d;
|
||||
$td->runtest("encrypt $file ($p)",
|
||||
{$td->COMMAND => "aes +cbc -encrypt $key $file tmp1"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
# sleep one second so random number will get a different seed
|
||||
sleep(1);
|
||||
$td->runtest("encrypt $file again ($p)",
|
||||
{$td->COMMAND => "aes +cbc -encrypt $key $file tmp2"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
foreach my $f (qw(tmp1 tmp2))
|
||||
{
|
||||
$td->runtest("check size",
|
||||
{$td->STRING => sprintf("%d\n", stat($f)->size)},
|
||||
{$td->STRING => "$size\n"});
|
||||
}
|
||||
$td->runtest("verify files are different",
|
||||
{$td->COMMAND => "cmp tmp1 tmp2"},
|
||||
{$td->REGEXP => '.*', $td->EXIT_STATUS => '!0'});
|
||||
$td->runtest("decrypt $file ($p)",
|
||||
{$td->COMMAND => "aes +cbc -decrypt $key tmp1 tmp3"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("decrypt $file again ($p)",
|
||||
{$td->COMMAND => "aes +cbc -decrypt $key tmp2 tmp4"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp3"},
|
||||
{$td->FILE => $file});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp4"},
|
||||
{$td->FILE => $file});
|
||||
}
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
$td->report(22);
|
||||
$td->report(22 * scalar(@providers));
|
||||
|
||||
sub cleanup
|
||||
{
|
||||
|
@ -9,10 +9,30 @@ require TestDriver;
|
||||
|
||||
my $td = new TestDriver('md5');
|
||||
|
||||
$td->runtest("md5",
|
||||
{$td->COMMAND => "md5"},
|
||||
{$td->FILE => "md5.out",
|
||||
$td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
my @providers = ();
|
||||
if (exists $ENV{'QPDF_CRYPTO_PROVIDER'})
|
||||
{
|
||||
push(@providers, $ENV{'QPDF_CRYPTO_PROVIDER'});
|
||||
}
|
||||
else
|
||||
{
|
||||
open(Q, "qpdf --show-crypto|") or die;
|
||||
while (<Q>)
|
||||
{
|
||||
s/\s+$//s;
|
||||
push(@providers, $_);
|
||||
}
|
||||
close(Q);
|
||||
}
|
||||
foreach my $p (@providers)
|
||||
{
|
||||
$ENV{'QPDF_CRYPTO_PROVIDER'} = $p;
|
||||
|
||||
$td->report(1);
|
||||
$td->runtest("md5 ($p)",
|
||||
{$td->COMMAND => "md5"},
|
||||
{$td->FILE => "md5.out",
|
||||
$td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
}
|
||||
|
||||
$td->report(scalar(@providers));
|
||||
|
@ -9,40 +9,60 @@ require TestDriver;
|
||||
|
||||
my $td = new TestDriver('RC4');
|
||||
|
||||
cleanup();
|
||||
|
||||
my @tests = ('0123456789abcdef',
|
||||
'0123456789abcdef',
|
||||
'0000000000000000',
|
||||
'ef012345',
|
||||
'0123456789abcdef');
|
||||
|
||||
my $n = 0;
|
||||
foreach my $key (@tests)
|
||||
my @providers = ();
|
||||
if (exists $ENV{'QPDF_CRYPTO_PROVIDER'})
|
||||
{
|
||||
++$n;
|
||||
$td->runtest("test $n",
|
||||
{$td->COMMAND => "rc4 $key test$n.in tmp1-$n.out"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp1-$n.out"},
|
||||
{$td->FILE => "test$n.out"});
|
||||
$td->runtest("test $n reverse",
|
||||
{$td->COMMAND => "rc4 $key test$n.out tmp2-$n.out"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp2-$n.out"},
|
||||
{$td->FILE => "test$n.in"});
|
||||
push(@providers, $ENV{'QPDF_CRYPTO_PROVIDER'});
|
||||
}
|
||||
else
|
||||
{
|
||||
open(Q, "qpdf --show-crypto|") or die;
|
||||
while (<Q>)
|
||||
{
|
||||
s/\s+$//s;
|
||||
push(@providers, $_);
|
||||
}
|
||||
close(Q);
|
||||
}
|
||||
my @tests = ('0123456789abcdef',
|
||||
'0123456789abcdef',
|
||||
'0000000000000000',
|
||||
'ef012345',
|
||||
'0123456789abcdef');
|
||||
|
||||
foreach my $p (@providers)
|
||||
{
|
||||
$ENV{'QPDF_CRYPTO_PROVIDER'} = $p;
|
||||
|
||||
cleanup();
|
||||
|
||||
my $n = 0;
|
||||
foreach my $key (@tests)
|
||||
{
|
||||
++$n;
|
||||
$td->runtest("test $n ($p)",
|
||||
{$td->COMMAND => "rc4 $key test$n.in tmp1-$n.out"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp1-$n.out"},
|
||||
{$td->FILE => "test$n.out"});
|
||||
$td->runtest("test $n reverse ($p)",
|
||||
{$td->COMMAND => "rc4 $key test$n.out tmp2-$n.out"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "tmp2-$n.out"},
|
||||
{$td->FILE => "test$n.in"});
|
||||
}
|
||||
|
||||
$td->runtest("other tests ($p)",
|
||||
{$td->COMMAND => "rc4 other"},
|
||||
{$td->STRING => "passed\n", $td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
$td->runtest("other tests",
|
||||
{$td->COMMAND => "rc4 other"},
|
||||
{$td->STRING => "passed\n", $td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
cleanup();
|
||||
|
||||
$td->report(1 + (4 * scalar(@tests)));
|
||||
$td->report((1 + (4 * scalar(@tests))) * scalar(@providers));
|
||||
|
||||
sub cleanup
|
||||
{
|
||||
|
@ -9,10 +9,30 @@ require TestDriver;
|
||||
|
||||
my $td = new TestDriver('sha2');
|
||||
|
||||
$td->runtest("sha2",
|
||||
{$td->COMMAND => "sha2"},
|
||||
{$td->FILE => "sha2.out",
|
||||
$td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
my @providers = ();
|
||||
if (exists $ENV{'QPDF_CRYPTO_PROVIDER'})
|
||||
{
|
||||
push(@providers, $ENV{'QPDF_CRYPTO_PROVIDER'});
|
||||
}
|
||||
else
|
||||
{
|
||||
open(Q, "qpdf --show-crypto|") or die;
|
||||
while (<Q>)
|
||||
{
|
||||
s/\s+$//s;
|
||||
push(@providers, $_);
|
||||
}
|
||||
close(Q);
|
||||
}
|
||||
foreach my $p (@providers)
|
||||
{
|
||||
$ENV{'QPDF_CRYPTO_PROVIDER'} = $p;
|
||||
|
||||
$td->report(1);
|
||||
$td->runtest("sha2 ($p)",
|
||||
{$td->COMMAND => "sha2"},
|
||||
{$td->FILE => "sha2.out",
|
||||
$td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
}
|
||||
|
||||
$td->report(scalar(@providers));
|
||||
|
@ -53,7 +53,8 @@ define run_qtest
|
||||
@echo running qtest-driver for $(1)
|
||||
@(cd $(1)/$(OUTPUT_DIR); \
|
||||
if TC_SRCS="$(foreach T,$(TC_SRCS_$(1)),../../$(T))" \
|
||||
$(QTEST) -bindirs .:.. -datadir ../qtest -covdir .. \
|
||||
$(QTEST) -bindirs .:..:../../qpdf/$(OUTPUT_DIR) \
|
||||
-datadir ../qtest -covdir .. \
|
||||
-junit-suffix `basename $(1)`; then \
|
||||
true; \
|
||||
else \
|
||||
|
Loading…
Reference in New Issue
Block a user