From 4fa1f2973cdd4dbeff7bd2f43dc02e4afba54762 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 18 Jan 2005 01:33:48 +0000 Subject: [PATCH] Add tests for the exit status of pgpverify in various situations. --- tests/messages/bad-corrupt | 23 ++++++++++++++ tests/messages/bad-syntax | 25 +++++++++++++++ tests/messages/gnu | 30 ++++++++++++++++++ tests/run-tests | 62 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 tests/messages/bad-corrupt create mode 100644 tests/messages/bad-syntax create mode 100644 tests/messages/gnu diff --git a/tests/messages/bad-corrupt b/tests/messages/bad-corrupt new file mode 100644 index 0000000..925f0f6 --- /dev/null +++ b/tests/messages/bad-corrupt @@ -0,0 +1,23 @@ +Path: bounce-back +From: group-admin@isc.org (David C Lawrence) +Newsgroups: news.announce.newusers +Subject: cmsg newgroup news.announce.newusers moderated +Control: newgroup news.announce.newusers moderated +Approved: newgroups-request@isc.org +Message-ID: <868485430.2655@isc.org> +Date: Wed, 09 Jul 1997 21:57:10 GMT +Lines: 8 +X-Info: ftp://ftp.isc.org/pub/pgpcontrol/README.html + ftp://ftp.isc.org/pub/pgpcontrol/README +X-PGP-Sig: 2.6.2 Subject,Control,Message-ID,Date,From,Sender + iQCVAwUBM8QJNsJdOtO4janBAQGkUAP6AlzO065jDQFrG20/b3/SaOm4WGQBly5D + pXlVJdYBqPAG3HvxVqAdKM7y6ixM7Mml4OdfK0JeVCH03nqeGuBc51sTDIZ6kyAx + +YHlNSnp/JJnpDuJCfXZjwNl4kWImucGgwI5BxrQco8re949Cg5m5TFXiwYMiR/+ + AjKZCTtmV1Y= + =uSbd + +news.announce.newusers is a moderated newsgroup which has existed +since the mid-1980s. + +For your newsgroups file: +news.announce.newusers Explanatory postings for new users. (Moderated) diff --git a/tests/messages/bad-syntax b/tests/messages/bad-syntax new file mode 100644 index 0000000..372c5a3 --- /dev/null +++ b/tests/messages/bad-syntax @@ -0,0 +1,25 @@ +Path: bounce-back +From: group-admin@isc.org (David C Lawrence) +Newsgroups: news.announce.newusers +Subject: cmsg newgroup news.announce.newusers moderated +Control: newgroup news.announce.newusers moderated +Approved: newgroups-request@isc.org +Message-ID: <868485430.2655@isc.org> +Date: Wed, 09 Jul 1997 21:57:10 GMT +Lines: 8 +X-Info: ftp://ftp.isc.org/pub/pgpcontrol/README.html + ftp://ftp.isc.org/pub/pgpcontrol/README +X-PGP-Sig: 2.6.2 Subject,Control,Message-ID,Date,From,Sender + iQCVAwUBM8QJNsJdOtO4janBAQGkUAP6AlzO065jDQFrG20/b3/SaOm4WGQBly5D + pXlVJdYBqPAG3HvxVqAdKM7y6ixM7Mml4OdfK0JeVCH03nqeGuBc51sTDIZ6kyAx + +YHlNSnp/JJnpDuJCfXZjwNl4kWImucGgwI5BxrQco8re949Cg5m5TFXiwYMiR/+ + =uSbd + +news.announce.newusers is a moderated newsgroup which has existed +since the mid-1980s. + +Group submission address: netannounce@deshaw.com +Moderator contact address: netannounce@deshaw.com (Mark Moraes) + +For your newsgroups file: +news.announce.newusers Explanatory postings for new users. (Moderated) diff --git a/tests/messages/gnu b/tests/messages/gnu new file mode 100644 index 0000000..22cdf96 --- /dev/null +++ b/tests/messages/gnu @@ -0,0 +1,30 @@ +Path: usenet.gnu.org!not-for-mail +From: usenet@gnu.org +Newsgroups: gnu.cvs.bug +Subject: cmsg newgroup gnu.cvs.bug +Control: newgroup gnu.cvs.bug +Date: Mon, 17 Jan 2005 17:17:07 -0800 +Message-ID: +X-PGP-Sig: GnuPG_v1.2.4_(GNU/Linux) Subject,Control,Message-ID,Date,From,Sender + iQCVAwUBQexjk/IyWVItWelFAQEV+AP/TQa8myc0/OS+SVlRD10JK5tEF8+uYBC+ + Y7PKfFaWEC2srD4jutLFEPSdqEWCEvydh4odirmI3gkJECNL8HZ1qn/ov7daXS51 + yyg5H0/OidwRswNILSRw7QNd9tKoMX2b5D+B9E4Lem//a09c1z5dSmruo/S7jIFC + 01x8svEwA1M= + =XpKe + +gnu.cvs.bug is a unmoderated newsgroup in the gnu.* hierarchy. Please +create it at all sites carrying gnu.* newsgroups. + +Please send any queries about this action to usenet@gnu.org. + +For your newsgroups file: +gnu.cvs.bug Concurrent Versions System (CVS) bug reports and fixes. + + +This newsgroup was initially created on 1999-02-25. The corresponding +mailing list is bug-cvs@gnu.org. + +Charter: + +This list distributes bug reports, fixes, and suggestions for improvements +to the maintainers of CVS. diff --git a/tests/run-tests b/tests/run-tests index 7e8d6b5..4a01593 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -89,6 +89,22 @@ sub pgpverify { } } +# Run pgpverify on a given file, expecting failure with the provided status +# code. Warn if we succeed and return true on success of the test and false +# on failure. +sub pgpverify_fail { + my ($file, $status) = @_; + my $signer = `./pgpverify < $file 2> /dev/null`; + chomp $signer; + if (($? >> 8) == $status && !$signer) { + return 1; + } else { + print "pgpverify exited with status ", ($? >> 8), "\n"; + print "pgpverify said the signer was $signer\n" if $signer; + return 0; + } +} + ############################################################################## # Test suite ############################################################################## @@ -245,6 +261,52 @@ if (pgpverify ('./signed.pgp', 'testing')) { } $tests++; +# Check the return status for a truncated signature. +if (pgpverify_fail ('./messages/bad-syntax', 255)) { + print "PASS: pgpverify-pgp-syntax\n"; +} else { + print "FAIL: pgpverify-pgp-syntax\n"; + $failed++; +} +$tests++; + +# Check the return status for a bad signature. +if (pgpverify_fail ('./messages/bad-corrupt', 3)) { + print "PASS: pgpverify-pgp-bad\n"; +} else { + print "FAIL: pgpverify-pgp-bad\n"; + $failed++; +} +$tests++; + +# Switch to GnuPG and check the return status for a truncated signature. +fix_pgpverify ($gpgv); +if (pgpverify_fail ('./messages/bad-syntax', 255)) { + print "PASS: pgpverify-gpg-syntax\n"; +} else { + print "FAIL: pgpverify-gpg-syntax\n"; + $failed++; +} +$tests++; + +# Check the return status for a bad signature. +if (pgpverify_fail ('./messages/bad-corrupt', 3)) { + print "PASS: pgpverify-gpg-bad\n"; +} else { + print "FAIL: pgpverify-gpg-bad\n"; + $failed++; +} +$tests++; + +# Check the return status for an unknown signer. +if (pgpverify_fail ('./messages/gnu', 2)) { + print "PASS: pgpverify-gpg-unknown\n"; +} else { + print "FAIL: pgpverify-gpg-unknown\n"; + $failed++; +} +$tests++; + # Print out a summary of the tests. unlink ('pgpverify', 'signcontrol', 'signed', 'signed.pgp', 'signed.gpg') unless $failed > 0;