summaryrefslogtreecommitdiffstats
path: root/scripts/t/Dpkg_OpenPGP.t
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/t/Dpkg_OpenPGP.t')
-rw-r--r--scripts/t/Dpkg_OpenPGP.t84
1 files changed, 41 insertions, 43 deletions
diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t
index d409082..2902cf6 100644
--- a/scripts/t/Dpkg_OpenPGP.t
+++ b/scripts/t/Dpkg_OpenPGP.t
@@ -17,7 +17,7 @@ use strict;
use warnings;
use Test::More;
-use Test::Dpkg qw(:paths :needs);
+use Test::Dpkg qw(:paths :needs test_get_openpgp_backend);
use File::Compare;
@@ -25,14 +25,6 @@ use Dpkg::ErrorHandling;
use Dpkg::Path qw(find_command);
use Dpkg::OpenPGP::KeyHandle;
-my %backend_cmd = (
- auto => 'auto',
- 'gpg-sq' => 'gpg',
- gpg => 'gpg',
- sq => 'sq',
- sqop => 'sop',
- 'pgpainless-cli' => 'sop',
-);
my @cmds = test_needs_openpgp_backend();
unshift @cmds, 'auto';
@@ -58,48 +50,54 @@ foreach my $cmd (@cmds) {
my $datadir = test_get_data_path();
my $tempdir = test_get_temp_path();
- my $backend = $backend_cmd{$cmd};
+ my $backend = test_get_openpgp_backend($cmd);
my $openpgp = Dpkg::OpenPGP->new(
backend => $backend,
cmd => $cmd,
);
- ok($openpgp->dearmor('PUBLIC KEY BLOCK', "$datadir/dpkg-test-pub.asc", "$tempdir/dpkg-test-pub.pgp") == OPENPGP_OK(),
- "($backend:$cmd) dearmoring OpenPGP ASCII Armored certificate");
- ok($openpgp->armor('PUBLIC KEY BLOCK', "$tempdir/dpkg-test-pub.pgp", "$tempdir/dpkg-test-pub.asc") == OPENPGP_OK(),
- "($backend:$cmd) armoring OpenPGP binary certificate");
- test_diff("$datadir/dpkg-test-pub.asc", "$tempdir/dpkg-test-pub.asc",
- "($backend:$cmd) OpenPGP certificate dearmor/armor round-trip correctly");
-
- ok($openpgp->armor('SIGNATURE', "$datadir/sign-file.sig", "$tempdir/sign-file.asc") == OPENPGP_OK(),
- "($backend:$cmd) armoring OpenPGP binary signature succeeded");
- ok(compare("$datadir/sign-file.sig", "$tempdir/sign-file.asc") != 0,
- "($backend:$cmd) armoring OpenPGP ASCII Armor changed the file");
- ok($openpgp->armor('SIGNATURE', "$datadir/sign-file.asc", "$tempdir/sign-file-rearmor.asc") == OPENPGP_OK(),
- "($backend:$cmd) armoring OpenPGP armored signature succeeded");
- test_diff("$datadir/sign-file.asc", "$tempdir/sign-file-rearmor.asc",
- "($backend:$cmd) rearmoring OpenPGP ASCII Armor changed the file");
-
- ok($openpgp->dearmor('SIGNATURE', "$tempdir/sign-file.asc", "$tempdir/sign-file.sig") == OPENPGP_OK(),
- "($backend:$cmd) dearmoring OpenPGP armored signature succeeded");
- test_diff("$datadir/sign-file.sig", "$tempdir/sign-file.sig",
- "($backend:$cmd) dearmored OpenPGP ASCII Armor signature matches");
-
- my $cert = "$datadir/dpkg-test-pub.asc";
-
- ok($openpgp->inline_verify("$datadir/sign-file-inline.asc", undef, $cert) == OPENPGP_OK(),
- "($backend:$cmd) verify OpenPGP ASCII Armor inline signature");
- ok($openpgp->inline_verify("$datadir/sign-file-inline.sig", undef, $cert) == OPENPGP_OK(),
- "($backend:$cmd) verify OpenPGP binary inline signature");
-
- ok($openpgp->verify("$datadir/sign-file", "$datadir/sign-file.asc", $cert) == OPENPGP_OK(),
+ my $certfile = "$datadir/dpkg-test-pub.asc";
+ my $keyfile = "$datadir/dpkg-test-sec.asc";
+
+ SKIP: {
+ skip 'missing backend command', 13
+ unless $openpgp->{backend}->has_verify_cmd();
+
+ ok($openpgp->dearmor('PUBLIC KEY BLOCK', $certfile, "$tempdir/dpkg-test-pub.pgp") == OPENPGP_OK(),
+ "($backend:$cmd) dearmoring OpenPGP ASCII Armored certificate");
+ ok($openpgp->armor('PUBLIC KEY BLOCK', "$tempdir/dpkg-test-pub.pgp", "$tempdir/dpkg-test-pub.asc") == OPENPGP_OK(),
+ "($backend:$cmd) armoring OpenPGP binary certificate");
+ test_diff($certfile, "$tempdir/dpkg-test-pub.asc",
+ "($backend:$cmd) OpenPGP certificate dearmor/armor round-trip correctly");
+
+ ok($openpgp->armor('SIGNATURE', "$datadir/sign-file.sig", "$tempdir/sign-file.asc") == OPENPGP_OK(),
+ "($backend:$cmd) armoring OpenPGP binary signature succeeded");
+ ok(compare("$datadir/sign-file.sig", "$tempdir/sign-file.asc") != 0,
+ "($backend:$cmd) armoring OpenPGP ASCII Armor changed the file");
+ ok($openpgp->armor('SIGNATURE', "$datadir/sign-file.asc", "$tempdir/sign-file-rearmor.asc") == OPENPGP_OK(),
+ "($backend:$cmd) armoring OpenPGP armored signature succeeded");
+ test_diff("$datadir/sign-file.asc", "$tempdir/sign-file-rearmor.asc",
+ "($backend:$cmd) rearmoring OpenPGP ASCII Armor changed the file");
+
+ ok($openpgp->dearmor('SIGNATURE', "$tempdir/sign-file.asc", "$tempdir/sign-file.sig") == OPENPGP_OK(),
+ "($backend:$cmd) dearmoring OpenPGP armored signature succeeded");
+ test_diff("$datadir/sign-file.sig", "$tempdir/sign-file.sig",
+ "($backend:$cmd) dearmored OpenPGP ASCII Armor signature matches");
+
+ ok($openpgp->inline_verify("$datadir/sign-file-inline.asc", undef, $certfile) == OPENPGP_OK(),
+ "($backend:$cmd) verify OpenPGP ASCII Armor inline signature");
+ ok($openpgp->inline_verify("$datadir/sign-file-inline.sig", undef, $certfile) == OPENPGP_OK(),
+ "($backend:$cmd) verify OpenPGP binary inline signature");
+
+ ok($openpgp->verify("$datadir/sign-file", "$datadir/sign-file.asc", $certfile) == OPENPGP_OK(),
"($backend:$cmd) verify OpenPGP ASCII Armor detached signature");
- ok($openpgp->verify("$datadir/sign-file", "$datadir/sign-file.sig", $cert) == OPENPGP_OK(),
- "($backend:$cmd) verify OpenPGP binary detached signature");
+ ok($openpgp->verify("$datadir/sign-file", "$datadir/sign-file.sig", $certfile) == OPENPGP_OK(),
+ "($backend:$cmd) verify OpenPGP binary detached signature");
+ };
my $key = Dpkg::OpenPGP::KeyHandle->new(
type => 'keyfile',
- handle => "$datadir/dpkg-test-sec.asc",
+ handle => $keyfile,
);
SKIP: {
@@ -107,7 +105,7 @@ foreach my $cmd (@cmds) {
ok($openpgp->inline_sign("$datadir/sign-file", "$tempdir/sign-file-inline.asc", $key) == OPENPGP_OK(),
"($backend:$cmd) inline OpenPGP sign");
- ok($openpgp->inline_verify("$tempdir/sign-file-inline.asc", undef, $cert) == OPENPGP_OK(),
+ ok($openpgp->inline_verify("$tempdir/sign-file-inline.asc", undef, $certfile) == OPENPGP_OK(),
"($backend:$cmd) verify generated inline OpenPGP signature");
};