[gmime] Cleaned up gpg testing



commit cccb9f12e85c3d1867f1a7c83619b4e603148fda
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Tue Mar 7 18:01:13 2017 -0500

    Cleaned up gpg testing

 tests/test-pgp.c     |   12 ++++++++----
 tests/test-pgpmime.c |   15 +++++++++------
 tests/test-pkcs7.c   |    8 ++------
 tests/testsuite.c    |   13 ++++++-------
 tests/testsuite.h    |    2 +-
 5 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/tests/test-pgp.c b/tests/test-pgp.c
index 3bba38d..030c101 100644
--- a/tests/test-pgp.c
+++ b/tests/test-pgp.c
@@ -34,8 +34,6 @@
 
 #include "testsuite.h"
 
-#define GPG_PATH "gpg"
-
 extern int verbose;
 
 #define v(x) if (verbose > 3) x
@@ -287,17 +285,23 @@ int main (int argc, char **argv)
        GMimeStream *istream, *ostream;
        GMimeCryptoContext *ctx;
        const char *what;
+       char *gpg, *key;
        struct stat st;
-       char *key;
        int i;
        
        g_mime_init ();
        
        testsuite_init (argc, argv);
        
-       if (testsuite_setup_gpghome (GPG_PATH) != 0)
+       if (!(gpg = g_find_program_in_path ("gpg2")))
+               if (!(gpg = g_find_program_in_path ("gpg")))
+                       return EXIT_FAILURE;
+       
+       if (testsuite_setup_gpghome (gpg) != 0)
                return EXIT_FAILURE;
        
+       g_free (gpg);
+       
        for (i = 1; i < argc; i++) {
                if (argv[i][0] != '-') {
                        datadir = argv[i];
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index 5772fde..b8c236c 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -35,8 +35,6 @@
 
 #include "testsuite.h"
 
-#define GPG_PATH "gpg"
-
 extern int verbose;
 
 #define v(x) if (verbose > 3) x
@@ -459,15 +457,19 @@ int main (int argc, char *argv[])
        char *session_key = NULL;
        GMimeCryptoContext *ctx;
        GError *err = NULL;
+       char *gpg, *key;
        struct stat st;
-       char *key;
        int i;
        
        g_mime_init ();
        
        testsuite_init (argc, argv);
        
-       if (testsuite_setup_gpghome (GPG_PATH) != 0)
+       if (!(gpg = g_find_program_in_path ("gpg2")))
+               if (!(gpg = g_find_program_in_path ("gpg")))
+                       return EXIT_FAILURE;
+       
+       if (testsuite_setup_gpghome (gpg) != 0)
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -513,7 +515,7 @@ int main (int argc, char *argv[])
        try {
                create_encrypted_message (ctx, FALSE, &cleartext, &stream);
                session_key = test_multipart_encrypted (ctx, FALSE, cleartext, stream, NULL);
-               if (testsuite_can_safely_override_session_key (GPG_PATH))
+               if (testsuite_can_safely_override_session_key (gpg))
                        g_free (test_multipart_encrypted (ctx, FALSE, cleartext, stream, session_key));
                testsuite_check_passed ();
        } catch (ex) {
@@ -534,7 +536,7 @@ int main (int argc, char *argv[])
        try {
                create_encrypted_message (ctx, TRUE, &cleartext, &stream);
                session_key = test_multipart_encrypted (ctx, TRUE, cleartext, stream, NULL);
-               if (testsuite_can_safely_override_session_key (GPG_PATH))
+               if (testsuite_can_safely_override_session_key (gpg))
                        g_free (test_multipart_encrypted (ctx, TRUE, cleartext, stream, session_key));
                testsuite_check_passed ();
        } catch (ex) {
@@ -552,6 +554,7 @@ int main (int argc, char *argv[])
        }
        
        g_object_unref (ctx);
+       g_free (gpg);
        
        testsuite_end ();
        
diff --git a/tests/test-pkcs7.c b/tests/test-pkcs7.c
index 34b5ad4..4d655e1 100644
--- a/tests/test-pkcs7.c
+++ b/tests/test-pkcs7.c
@@ -332,12 +332,8 @@ int main (int argc, char **argv)
        
        testsuite_init (argc, argv);
        
-       /* reset .gnupg config directory */
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_setup_gpghome ("gpgsm") != 0)
                return EXIT_FAILURE;
-       if (system ("/bin/mkdir ./tmp") != 0)
-               return EXIT_FAILURE;
-       g_setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
        
        for (i = 1; i < argc; i++) {
                if (argv[i][0] != '-') {
@@ -453,7 +449,7 @@ int main (int argc, char **argv)
        
        g_mime_shutdown ();
        
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_destroy_gpghome () != 0)
                return EXIT_FAILURE;
        
        return testsuite_exit ();
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 4544004..374ec61 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -363,7 +363,7 @@ g_throw (Exception *ex)
 static int
 get_gpg_version (const char *path)
 {
-       const char vheader[] = "gpg (GnuPG) ";
+       const char vheader[] = " (GnuPG) ";
        int v, n = 0, version = 0;
        const char *inptr;
        char buffer[128];
@@ -381,8 +381,8 @@ get_gpg_version (const char *path)
        
        inptr = fgets (buffer, 128, gpg);
        pclose (gpg);
-       
-       if (strncmp (inptr, vheader, sizeof (vheader) - 1) != 0)
+
+       if (!(inptr = strstr (inptr, vheader)))
                return -1;
        
        inptr += sizeof (vheader) - 1;
@@ -412,7 +412,7 @@ get_gpg_version (const char *path)
        return version;
 }
 
-int
+gboolean
 testsuite_can_safely_override_session_key (const char *gpg)
 {
        return get_gpg_version (gpg) >= v2_1_16;
@@ -423,6 +423,7 @@ testsuite_setup_gpghome (const char *gpg)
 {
        const char directive[] = "pinentry-mode loopback\n";
        char *command;
+       FILE *fp;
        
        /* reset .gnupg config directory */
        if (system ("/bin/rm -rf ./tmp") != 0)
@@ -446,9 +447,7 @@ testsuite_setup_gpghome (const char *gpg)
        g_free (command);
        
        if (get_gpg_version (gpg) >= ((2 << 24) | (1 << 16))) {
-               FILE *fp;
-               
-               if ((fp = fopen ("./tmp/.gnupg/gpg.conf", "w")) == NULL)
+               if (!(fp = fopen ("./tmp/.gnupg/gpg.conf", "a")))
                        return EXIT_FAILURE;
                
                if (fwrite (directive, sizeof (directive) - 1, 1, fp) != 1) {
diff --git a/tests/testsuite.h b/tests/testsuite.h
index 70e6486..4a885e9 100644
--- a/tests/testsuite.h
+++ b/tests/testsuite.h
@@ -48,7 +48,7 @@ int testsuite_total_errors (void);
 /* GnuPG test suite utility functions */
 int testsuite_setup_gpghome (const char *gpg);
 int testsuite_destroy_gpghome (void);
-int testsuite_can_safely_override_session_key (const char *gpg);
+gboolean testsuite_can_safely_override_session_key (const char *gpg);
 
 /*#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 #define G_GNUC_NORETURN __attribute__((noreturn))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]