* crypto: add automated test for 'verify'

This commit is contained in:
djcb 2012-07-18 11:35:57 +03:00
parent 807c9de625
commit 39fe3f417c
4 changed files with 112 additions and 1 deletions

View File

@ -5,7 +5,6 @@ Received: from localhost.roma.net([127.0.0.1] helo=borealis)
by borealis with esmtp (Exim 4.77)
id 1SSpnB-00038a-55
for djcb@localhost; Fri, 11 May 2012 16:21:57 +0300
Delivered-To: diggler@gmail.com
From: Skipio <skipio@roma.net>
To: Hannibal <hanni@carthago.net>
Subject: signed

View File

@ -0,0 +1,35 @@
Return-path: <>
Envelope-to: skipio@localhost
Delivery-date: Fri, 11 May 2012 16:21:57 +0300
Received: from localhost.roma.net([127.0.0.1] helo=borealis)
by borealis with esmtp (Exim 4.77)
id 1SSpnB-00038a-55
for djcb@localhost; Fri, 11 May 2012 16:21:57 +0300
From: Skipio <skipio@roma.net>
To: Hannibal <hanni@carthago.net>
Subject: signed
User-agent: mu4e 0.9.8.5-dev1; emacs 24.1.50.8
Date: Fri, 11 May 2012 16:20:45 +0300
Message-ID: <878vgy97ma.fsf@roma.net>
MIME-Version: 1.0
Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1;
protocol="application/pgp-signature"
--=-=-=
Content-Type: text/plain
I am signed! But it's not good because I added this later
--=-=-=
Content-Type: application/pgp-signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAk+tEi0ACgkQ6WrHoQF92jxTzACeKd/XxY+P7bpymWL3JBRHaW9p
DpwAoKw7PDW4z/lNTkWjndVTjoO9jGhs
=blXz
-----END PGP SIGNATURE-----
--=-=-=--

View File

@ -25,6 +25,7 @@ INCLUDES=$(XAPIAN_CXXFLAGS) \
-DMU_TESTMAILDIR=\"${top_srcdir}/lib/tests/testdir\" \
-DMU_TESTMAILDIR2=\"${top_srcdir}/lib/tests/testdir2\" \
-DMU_TESTMAILDIR3=\"${top_srcdir}/lib/tests/testdir3\" \
-DMU_TESTMAILDIR4=\"${top_srcdir}/lib/tests/testdir4\" \
-DMU_PROGRAM=\"${abs_top_builddir}/mu/mu\" \
-DABS_CURDIR=\"${abs_builddir}\" \
-DABS_SRCDIR=\"${abs_srcdir}\"

View File

@ -734,6 +734,79 @@ test_mu_mkdir_01 (void)
g_free (cmdline);
}
/* we can only test 'verify' if gpg is installed, and has
* djcb@djcbsoftware's key in the keyring */
static gboolean
verify_is_testable (void)
{
gchar *gpg, *cmdline;
gchar *output, *erroutput;
int retval;
gboolean rv;
/* find GPG or return FALSE */
if ((gpg = (char*)g_getenv ("MU_GPG_PATH"))) {
if (access (gpg, X_OK) != 0)
return FALSE;
else
gpg = g_strdup (gpg);
} else if (!(gpg = g_find_program_in_path ("gpg")))
return FALSE;
cmdline = g_strdup_printf ("%s --list-keys 017DDA3C", gpg);
g_free (gpg);
output = erroutput = NULL;
rv = g_spawn_command_line_sync (cmdline, &output, &erroutput,
&retval, NULL);
g_free (output);
g_free (erroutput);
g_free (cmdline);
return (rv && retval == 0) ? TRUE:FALSE;
}
static void
test_mu_verify_good (void)
{
gchar *cmdline;
int retval;
if (!verify_is_testable ())
return;
cmdline = g_strdup_printf ("%s verify %s/signed!2,S",
MU_PROGRAM,
MU_TESTMAILDIR4);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
&retval, NULL));
g_assert_cmpuint (retval, ==, 0);
g_free (cmdline);
}
static void
test_mu_verify_bad (void)
{
gchar *cmdline;
int retval;
if (!verify_is_testable ())
return;
cmdline = g_strdup_printf ("%s verify %s/signed-bad!2,S",
MU_PROGRAM,
MU_TESTMAILDIR4);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
&retval, NULL));
g_assert_cmpuint (retval, !=, 0);
g_free (cmdline);
}
int
@ -781,6 +854,9 @@ main (int argc, char *argv[])
g_test_add_func ("/mu-cmd/test-mu-view-attach", test_mu_view_attach);
g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01);
g_test_add_func ("/mu-cmd/test-mu-verify-good", test_mu_verify_good);
g_test_add_func ("/mu-cmd/test-mu-verify-bad", test_mu_verify_bad);
g_log_set_handler (NULL,
G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING|
G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,