[network-manager-openvpn/th/ovpn-import-bgo761285: 8/10] properties: don't store imported certifacates in home directory during tests



commit 4bdce47971caf60833a9438df8aadc962ae6032e
Author: Thomas Haller <thaller redhat com>
Date:   Thu Jan 28 23:49:36 2016 +0100

    properties: don't store imported certifacates in home directory during tests
    
    When testing importing, we should not store the certificate in the users
    home directory, instead hack it up to place it in the test directory.

 properties/import-export.c            |   32 ++++++++++++++++++++------------
 properties/import-export.h            |    2 ++
 properties/tests/test-import-export.c |    4 ++++
 3 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index 8dafe37..c8f0b9d 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -88,6 +88,8 @@
 #define TAG_TUN_MTU                     "tun-mtu"
 
 
+const char *_nmovpn_test_temp_path = NULL;
+
 static void
 __attribute__((__format__ (__printf__, 3, 4)))
 setting_vpn_add_data_item_v (NMSettingVpn *setting,
@@ -1079,7 +1081,6 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
                        gsize end_token_len;
                        gsize my_contents_cur_line = contents_cur_line;
                        gs_free char *f_filename = NULL;
-                       gs_free char *f_dirname = NULL;
                        gs_free char *f_path = NULL;
                        const char *key;
                        gboolean can_have_direction = FALSE;
@@ -1132,19 +1133,26 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
 
                        /* Construct file name to write the data in */
                        f_filename = g_strdup_printf ("%s-%s.pem", basename, token);
-                       f_dirname = g_build_filename (g_get_home_dir (), ".cert", NULL);
-                       f_path = g_build_filename (f_dirname, f_filename, NULL);
-
-                       /* Check that dirname exists and is a directory, otherwise create it */
-                       if (!g_file_test (f_dirname, G_FILE_TEST_IS_DIR)) {
-                               if (!g_file_test (f_dirname, G_FILE_TEST_EXISTS)) {
-                                       if (mkdir (f_dirname, 0755) < 0) {
-                                               line_error = g_strdup_printf (_("cannot create .cert 
directory for %s blob"), token);
+
+                       if (_nmovpn_test_temp_path) {
+                               f_path = g_build_filename (_nmovpn_test_temp_path, f_filename, NULL);
+                       } else {
+                               gs_free char *f_dirname = NULL;
+
+                               f_dirname = g_build_filename (g_get_home_dir (), ".cert", NULL);
+                               f_path = g_build_filename (f_dirname, f_filename, NULL);
+
+                               /* Check that dirname exists and is a directory, otherwise create it */
+                               if (!g_file_test (f_dirname, G_FILE_TEST_IS_DIR)) {
+                                       if (!g_file_test (f_dirname, G_FILE_TEST_EXISTS)) {
+                                               if (mkdir (f_dirname, 0755) < 0) {
+                                                       line_error = g_strdup_printf (_("cannot create .cert 
directory for %s blob"), token);
+                                                       goto handle_line_error;
+                                               }
+                                       } else {
+                                               line_error = g_strdup_printf (_(".cert directory is not 
usable for %s blob"), token);
                                                goto handle_line_error;
                                        }
-                               } else {
-                                       line_error = g_strdup_printf (_(".cert directory is not usable for %s 
blob"), token);
-                                       goto handle_line_error;
                                }
                        }
 
diff --git a/properties/import-export.h b/properties/import-export.h
index da46c97..91e079f 100644
--- a/properties/import-export.h
+++ b/properties/import-export.h
@@ -30,6 +30,8 @@
 #include <NetworkManager.h>
 #endif
 
+extern const char *_nmovpn_test_temp_path;
+
 gboolean _nmovpn_test_args_parse_line (const char *line,
                                        gsize line_len,
                                        const char ***out_p,
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 8b629bf..1c93a98 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -398,6 +398,8 @@ test_tls_inline_import (NMVpnEditorPlugin *plugin, const char *dir)
        test_secret ("tls-import-secrets", s_vpn, NM_OPENVPN_KEY_PASSWORD, NULL);
        test_secret ("tls-import-secrets", s_vpn, NM_OPENVPN_KEY_CERTPASS, NULL);
 
+       g_assert (unlink (TEST_BUILDDIR_CONF"/tls-inline-tls-auth.pem") == 0);
+
        g_object_unref (connection);
 }
 
@@ -1454,6 +1456,8 @@ int main (int argc, char **argv)
        g_type_init ();
 #endif
 
+       _nmovpn_test_temp_path = TEST_BUILDDIR_CONF;
+
        plugin = nm_vpn_editor_plugin_factory (&error);
        if (error)
                FAIL ("plugin-init", "failed to initialize UI plugin: %s", error->message);


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