Blame SOURCES/0115-testsuite-add-unittests-for-uReport-API.patch

562801
From 0dbe0fdaf11ed8948fc947831c3c421b1d113f05 Mon Sep 17 00:00:00 2001
562801
From: Matej Habrnal <mhabrnal@redhat.com>
562801
Date: Wed, 22 Oct 2014 00:14:55 +0200
562801
Subject: [LIBREPORT PATCH 115/118] testsuite: add unittests for uReport API
562801
562801
Fixes #294
562801
Related #1140224
562801
562801
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
562801
Signed-off-by: Jakub Filak <jfilak@redhat.com>
562801
---
562801
 tests/Makefile.am                                  |    3 +-
562801
 tests/testsuite.at                                 |    1 +
562801
 tests/ureport.at                                   | 1101 ++++++++++++++++++++
562801
 tests/ureport/certs/correct/cert-key.pem           |    5 +
562801
 tests/ureport/certs/correct/cert.pem               |   13 +
562801
 tests/ureport/certs/incorrect_content/cert-key.pem |    5 +
562801
 tests/ureport/certs/incorrect_content/cert.pem     |    0
562801
 tests/ureport/rhsm/__init__.py                     |    0
562801
 tests/ureport/rhsm/config.py                       |    8 +
562801
 9 files changed, 1135 insertions(+), 1 deletion(-)
562801
 create mode 100644 tests/ureport.at
562801
 create mode 100644 tests/ureport/certs/correct/cert-key.pem
562801
 create mode 100644 tests/ureport/certs/correct/cert.pem
562801
 create mode 100644 tests/ureport/certs/incorrect_content/cert-key.pem
562801
 create mode 100644 tests/ureport/certs/incorrect_content/cert.pem
562801
 create mode 100644 tests/ureport/rhsm/__init__.py
562801
 create mode 100644 tests/ureport/rhsm/config.py
562801
562801
diff --git a/tests/Makefile.am b/tests/Makefile.am
562801
index 4731bad..cda9375 100644
562801
--- a/tests/Makefile.am
562801
+++ b/tests/Makefile.am
562801
@@ -41,7 +41,8 @@ TESTSUITE_AT = \
562801
   xml_definition.at \
562801
   report_python.at \
562801
   xfuncs.at \
562801
-  string_list.at
562801
+  string_list.at \
562801
+  ureport.at
562801
 
562801
 EXTRA_DIST += $(TESTSUITE_AT)
562801
 TESTSUITE = $(srcdir)/testsuite
562801
diff --git a/tests/testsuite.at b/tests/testsuite.at
562801
index 60b2e94..abad32b 100644
562801
--- a/tests/testsuite.at
562801
+++ b/tests/testsuite.at
562801
@@ -16,3 +16,4 @@ m4_include([libreport_types.at])
562801
 m4_include([xml_definition.at])
562801
 m4_include([report_python.at])
562801
 m4_include([string_list.at])
562801
+m4_include([ureport.at])
562801
diff --git a/tests/ureport.at b/tests/ureport.at
562801
new file mode 100644
562801
index 0000000..22d34e9
562801
--- /dev/null
562801
+++ b/tests/ureport.at
562801
@@ -0,0 +1,1101 @@
562801
+# -*- Autotest -*-
562801
+
562801
+AT_BANNER([ureport])
562801
+
562801
+## ---------------------------- ##
562801
+##  ureport_server_config_init  ##
562801
+## ---------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_config_init],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+
562801
+#define DESTROYED_POINTER (void *)0xdeadbeef
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    assert(config.ur_url == NULL);
562801
+    assert(config.ur_ssl_verify == true);
562801
+    assert(config.ur_client_cert == NULL);
562801
+    assert(config.ur_client_key == NULL);
562801
+    assert(config.ur_username == NULL);
562801
+    assert(config.ur_password == NULL);
562801
+    assert(config.ur_http_headers != NULL);
562801
+    assert(config.ur_prefs.urp_auth_items == NULL);
562801
+
562801
+    config.ur_url = (char *)"url";
562801
+    config.ur_ssl_verify = false;
562801
+    config.ur_client_cert = (char *)"cert";
562801
+    config.ur_client_key = (char *)"key";
562801
+    config.ur_username = (char *)"username";
562801
+    config.ur_password = (char *)"password";
562801
+    free_map_string(config.ur_http_headers);
562801
+    config.ur_prefs.urp_auth_items = DESTROYED_POINTER;
562801
+
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    assert(config.ur_url == NULL);
562801
+    assert(config.ur_ssl_verify == true);
562801
+    assert(config.ur_client_cert == NULL);
562801
+    assert(config.ur_client_key == NULL);
562801
+    assert(config.ur_username == NULL);
562801
+    assert(config.ur_password == NULL);
562801
+    assert(config.ur_http_headers != NULL);
562801
+    assert(config.ur_prefs.urp_auth_items == NULL);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## ------------------------------- ##
562801
+##  ureport_server_config_destroy  ##
562801
+## ------------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_config_destroy],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+
562801
+#define DESTROYED_POINTER (void *)0xdeadbeef
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    config.ur_url = strdup("url");
562801
+    config.ur_client_cert = strdup("cert");
562801
+    config.ur_client_key = strdup("key");
562801
+    config.ur_username = strdup("username");
562801
+    config.ur_password = strdup("password");
562801
+
562801
+    assert(strcmp(config.ur_url, "url") == 0);
562801
+    assert(strcmp(config.ur_client_cert, "cert") == 0);
562801
+    assert(strcmp(config.ur_client_key, "key") == 0);
562801
+    assert(strcmp(config.ur_username, "username") == 0);
562801
+    assert(strcmp(config.ur_password , "password") == 0);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    assert(config.ur_url == DESTROYED_POINTER);
562801
+    assert(config.ur_client_cert == DESTROYED_POINTER);
562801
+    assert(config.ur_client_key == DESTROYED_POINTER);
562801
+    assert(config.ur_username == DESTROYED_POINTER);
562801
+    assert(config.ur_password == DESTROYED_POINTER);
562801
+    assert(config.ur_prefs.urp_auth_items == DESTROYED_POINTER);
562801
+    assert(config.ur_http_headers == DESTROYED_POINTER);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## ---------------------------- ##
562801
+##  ureport_server_config_load  ##
562801
+## ---------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_config_load],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    /* value from env */
562801
+    /* IncludeAuthData set to 'no' */
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    setenv("uReport_URL", "env_url", 1);
562801
+    setenv("uReport_SSLVerify", "yes", 1);
562801
+    setenv("SSLClientAuth", "", 1);
562801
+    setenv("uReport_IncludeAuthData", "no", 1);
562801
+    setenv("uReport_AuthDataItems", "hostname", 1);
562801
+
562801
+    map_string_t *settings = new_map_string();
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    assert(strcmp(config.ur_url, "env_url") == 0);
562801
+    assert(config.ur_ssl_verify == true);
562801
+
562801
+    GList *l = config.ur_prefs.urp_auth_items;
562801
+    assert(l == NULL);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* value from env */
562801
+    /* IncludeAuthData set to 'yes' but AuthDataItems is empty. */
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    setenv("uReport_URL", "env_url", 1);
562801
+    setenv("uReport_SSLVerify", "yes", 1);
562801
+    setenv("SSLClientAuth", "", 1);
562801
+    setenv("uReport_IncludeAuthData", "yes", 1);
562801
+    setenv("uReport_AuthDataItems", "", 1);
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    assert(strcmp(config.ur_url, "env_url") == 0);
562801
+    assert(config.ur_ssl_verify == true);
562801
+
562801
+    l = config.ur_prefs.urp_auth_items;
562801
+    assert(l == NULL);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* value from env */
562801
+    /* IncludeAuthData set to 'yes' */
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    setenv("uReport_URL", "env_url", 1);
562801
+    setenv("uReport_SSLVerify", "no", 1);
562801
+    setenv("SSLClientAuth", "", 1);
562801
+    setenv("uReport_IncludeAuthData", "yes", 1);
562801
+    setenv("uReport_AuthDataItems", "hostname, time", 1);
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    assert(strcmp(config.ur_url, "env_url") == 0);
562801
+    assert(config.ur_ssl_verify == false);
562801
+
562801
+    l = config.ur_prefs.urp_auth_items;
562801
+    assert(strcmp(l->data, "hostname") == 0);
562801
+    assert(strcmp(l->next->data, "time") == 0);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* value from settings */
562801
+    /* IncludeAuthData set to 'no' */
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    unsetenv("uReport_URL");
562801
+    unsetenv("uReport_SSLVerify");
562801
+    unsetenv("uReport_IncludeAuthData");
562801
+    unsetenv("uReport_AuthDataItems");
562801
+
562801
+    insert_map_string(settings, xstrdup("URL"), xstrdup("settings_url"));
562801
+    insert_map_string(settings, xstrdup("SSLVerify"), xstrdup("yes"));
562801
+    insert_map_string(settings, xstrdup("SSLClientAuth"), xstrdup(""));
562801
+    insert_map_string(settings, xstrdup("IncludeAuthData"), xstrdup("no"));
562801
+    insert_map_string(settings, xstrdup("AuthDataItems"), xstrdup("hostname"));
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    assert(strcmp(config.ur_url, "settings_url") == 0);
562801
+    assert(config.ur_ssl_verify == true);
562801
+
562801
+    l = config.ur_prefs.urp_auth_items;
562801
+    assert(l == NULL);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+    free_map_string(settings);
562801
+
562801
+    /* value from settings */
562801
+    /* IncludeAuthData set to 'yes' but AuthDataItems is empty. */
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    settings = new_map_string();
562801
+    insert_map_string(settings, xstrdup("URL"), xstrdup("settings_url"));
562801
+    insert_map_string(settings, xstrdup("SSLVerify"), xstrdup("yes"));
562801
+    insert_map_string(settings, xstrdup("SSLClientAuth"), xstrdup(""));
562801
+    insert_map_string(settings, xstrdup("IncludeAuthData"), xstrdup("yes"));
562801
+    insert_map_string(settings, xstrdup("AuthDataItems"), xstrdup(""));
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    assert(strcmp(config.ur_url, "settings_url") == 0);
562801
+    assert(config.ur_ssl_verify == true);
562801
+
562801
+    l = config.ur_prefs.urp_auth_items;
562801
+    assert(l == NULL);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+    free_map_string(settings);
562801
+
562801
+    /* value from settings */
562801
+    /* IncludeAuthData set to 'yes' */
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    settings = new_map_string();
562801
+    insert_map_string(settings, xstrdup("URL"), xstrdup("settings_url"));
562801
+    insert_map_string(settings, xstrdup("SSLVerify"), xstrdup("no"));
562801
+    insert_map_string(settings, xstrdup("SSLClientAuth"), xstrdup(""));
562801
+    insert_map_string(settings, xstrdup("IncludeAuthData"), xstrdup("yes"));
562801
+    insert_map_string(settings, xstrdup("AuthDataItems"), xstrdup("hostname, type"));
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    assert(strcmp(config.ur_url, "settings_url") == 0);
562801
+    assert(config.ur_ssl_verify == false);
562801
+
562801
+    l = config.ur_prefs.urp_auth_items;
562801
+    assert(strcmp(l->data, "hostname") == 0);
562801
+    assert(strcmp(l->next->data, "type") == 0);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+    free_map_string(settings);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+
562801
+## ------------------------------- ##
562801
+##  ureport_server_config_set_url  ##
562801
+## ------------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_config_set_url],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+
562801
+#define DESTROYED_POINTER (void *)0xdeadbeef
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    ureport_server_config_set_url(&config, strdup("url"));
562801
+
562801
+    assert(strcmp(config.ur_url, "url") == 0);
562801
+
562801
+    ureport_server_config_set_url(&config, strdup("next.url"));
562801
+
562801
+    assert(strcmp(config.ur_url, "next.url") == 0);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## --------------------------------------- ##
562801
+##  ureport_server_config_set_client_auth  ##
562801
+## --------------------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_config_set_client_auth],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+
562801
+#define DESTROYED_POINTER (void *)0xdeadbeef
562801
+#define RHSM_WEB_SERVICE_URL "https://api.access.redhat.com/rs/telemetry/abrt"
562801
+
562801
+#define TESTING_CERTS_CORRECT_DIR_PATH "../../ureport/certs/correct"
562801
+#define TESTING_CERTS_INCORRECT_CONTENT_DIR_PATH "../../ureport/certs/incorrect_content"
562801
+#define TESTING_PYTHONPATH "../../ureport/"
562801
+#define WRONG_TESTING_PYTHONPATH "../../ureportxxxxxx/"
562801
+
562801
+#define RHSMENT_PEM_DIR_PATH "/etc/pki/entitlement"
562801
+
562801
+#define RHSMENT_ENT_DATA_BEGIN_TAG "-----BEGIN ENTITLEMENT DATA-----"
562801
+#define RHSMENT_ENT_DATA_END_TAG "-----END ENTITLEMENT DATA-----"
562801
+#define RHSMENT_SIG_DATA_BEGIN_TAG "-----BEGIN RSA SIGNATURE-----"
562801
+#define RHSMENT_SIG_DATA_END_TAG "-----END RSA SIGNATURE-----"
562801
+
562801
+char *my_strdup(const char *str)
562801
+{
562801
+    if (str == NULL)
562801
+        return NULL;
562801
+    else
562801
+        return strdup(str);
562801
+}
562801
+
562801
+void set_ureport_server_config(struct ureport_server_config *config,
562801
+                                const char *url,
562801
+                                bool ver,
562801
+                                const char *cert,
562801
+                                const char *key,
562801
+                                const char *uname,
562801
+                                const char *passwd)
562801
+{
562801
+    config->ur_url = my_strdup(url);
562801
+    config->ur_ssl_verify = ver;
562801
+    config->ur_client_cert = my_strdup(cert);
562801
+    config->ur_client_key = my_strdup(key);
562801
+    config->ur_username = my_strdup(uname);
562801
+    config->ur_password = my_strdup(passwd);
562801
+
562801
+    return;
562801
+}
562801
+
562801
+void my_assert(const char *str1, const char *str2)
562801
+{
562801
+    if (str1 == NULL || str2 == NULL)
562801
+        assert( str1 == NULL && str2 == NULL );
562801
+    else
562801
+        assert(strcmp(str1, str2) == 0);
562801
+
562801
+    return;
562801
+}
562801
+
562801
+void assert_ureport_server_config(struct ureport_server_config *config,
562801
+                                const char *url,
562801
+                                bool ver,
562801
+                                const char *cert,
562801
+                                const char *key,
562801
+                                const char *username,
562801
+                                const char *password)
562801
+{
562801
+    my_assert(config->ur_url, url);
562801
+    assert(config->ur_ssl_verify == ver);
562801
+    my_assert(config->ur_client_cert, cert);
562801
+    my_assert(config->ur_client_key, key);
562801
+    my_assert(config->ur_username, username);
562801
+    my_assert(config->ur_password , password);
562801
+
562801
+    return;
562801
+}
562801
+
562801
+int test_ureport_server_config_set_client_auth_exit_code(struct ureport_server_config *config,
562801
+                                                         const char *client_auth)
562801
+{
562801
+    ureport_server_config_init(config);
562801
+
562801
+    pid_t pid = fork();
562801
+    if (pid < 0)
562801
+    {
562801
+        perror_msg("fork");
562801
+        return -1;
562801
+    }
562801
+
562801
+    if (pid == 0)
562801
+    {
562801
+        ureport_server_config_set_client_auth(config, client_auth);
562801
+        exit(0);
562801
+    }
562801
+    int status;
562801
+    wait(&status);
562801
+
562801
+    ureport_server_config_destroy(config);
562801
+
562801
+    return status;
562801
+}
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    ureport_server_config_set_client_auth(&config, NULL);
562801
+
562801
+    set_ureport_server_config(&config, "url", true, "cert", "key", "username", "passwd");
562801
+
562801
+    /* client_auth == NULL */
562801
+    ureport_server_config_set_client_auth(&config, NULL);
562801
+    assert_ureport_server_config(&config, "url", true, "cert", "key", "username", "passwd");
562801
+
562801
+    /* client_auth == "" */
562801
+    ureport_server_config_set_client_auth(&config, "");
562801
+    assert_ureport_server_config(&config, "url", true, NULL, NULL, "username", "passwd");
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* client_auth == rhsm */
562801
+    /* ur_url == NULL */
562801
+    /* no certs */
562801
+    char *empty_cert_dir = mkdtemp(strdup("/tmp/cert_XXXXXX"));
562801
+    assert(empty_cert_dir);
562801
+    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", empty_cert_dir, 1);
562801
+
562801
+    int status = test_ureport_server_config_set_client_auth_exit_code(&config, "rhsm");
562801
+    assert(status != 0 && status != -1);
562801
+
562801
+    assert(rmdir(empty_cert_dir) == 0);
562801
+
562801
+    /* client_auth == rhsm */
562801
+    /* ur_url == NULL */
562801
+    /* certs exists (incorrect content) */
562801
+
562801
+    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", TESTING_CERTS_INCORRECT_CONTENT_DIR_PATH, 1);
562801
+
562801
+    status = test_ureport_server_config_set_client_auth_exit_code(&config, "rhsm");
562801
+    assert(status != 0 && status != -1);
562801
+
562801
+    /* client_auth == rhsm */
562801
+    /* ur_url == NULL */
562801
+    /* certs exists (correct) */
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", TESTING_CERTS_CORRECT_DIR_PATH, 1);
562801
+
562801
+    ureport_server_config_set_client_auth(&config, "rhsm");
562801
+
562801
+    assert_ureport_server_config(&config, RHSM_WEB_SERVICE_URL, true,
562801
+                                TESTING_CERTS_CORRECT_DIR_PATH"/cert.pem",
562801
+                                TESTING_CERTS_CORRECT_DIR_PATH"/cert-key.pem",
562801
+                                NULL, NULL);
562801
+
562801
+    char *ent = xasprintf(RHSMENT_ENT_DATA_BEGIN_TAG"%s"RHSMENT_ENT_DATA_END_TAG, "entitlementdata");
562801
+    assert(0 == strcmp(ent,
562801
+                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Data")));
562801
+
562801
+    char *sig= xasprintf(RHSMENT_SIG_DATA_BEGIN_TAG"%s"RHSMENT_SIG_DATA_END_TAG, "rsasignature");
562801
+    assert(0 == strcmp(sig,
562801
+                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Sig")));
562801
+
562801
+    free(ent);
562801
+    free(sig);
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* client_auth == cert:key */
562801
+    /* ur_url == NULL */
562801
+    ureport_server_config_init(&config);
562801
+    set_ureport_server_config(&config, NULL, true, NULL, NULL, "username", "passwd");
562801
+    ureport_server_config_set_client_auth(&config, "cert:key");
562801
+    assert_ureport_server_config(&config, NULL, true, "cert", "key", NULL, NULL);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* client_auth == cert:key */
562801
+    /* ur_url != NULL */
562801
+    ureport_server_config_init(&config);
562801
+    set_ureport_server_config(&config, "url", true, NULL, NULL, "username", "passwd");
562801
+    ureport_server_config_set_client_auth(&config, "cert:key");
562801
+    assert_ureport_server_config(&config, "url", true, "cert", "key", NULL, NULL);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* wrong client_auth */
562801
+    int ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, "cert:");
562801
+    assert(ret_val != 0 && ret_val != -1);
562801
+    ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, ":key");
562801
+    assert(ret_val != 0 && ret_val != -1);
562801
+    ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, "cert");
562801
+    assert(ret_val != 0 && ret_val != -1);
562801
+
562801
+/* rhsm_config_get_entitlement_cert_dir */
562801
+/* certs exists (correct content) */
562801
+    unsetenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
562801
+    setenv("PYTHONPATH", TESTING_PYTHONPATH, 1);
562801
+
562801
+    ureport_server_config_init(&config);
562801
+    ureport_server_config_set_client_auth(&config, "rhsm");
562801
+
562801
+    char *abs_path_cert = realpath(TESTING_CERTS_CORRECT_DIR_PATH"/cert.pem", NULL);
562801
+    char *abs_path_key = realpath(TESTING_CERTS_CORRECT_DIR_PATH"/cert-key.pem", NULL);
562801
+
562801
+    assert_ureport_server_config(&config, RHSM_WEB_SERVICE_URL, true,
562801
+                                abs_path_cert,
562801
+                                abs_path_key,
562801
+                                NULL, NULL);
562801
+    free(abs_path_cert);
562801
+    free(abs_path_key);
562801
+
562801
+    ent = xasprintf(RHSMENT_ENT_DATA_BEGIN_TAG"%s"RHSMENT_ENT_DATA_END_TAG, "entitlementdata");
562801
+    assert(0 == strcmp(ent,
562801
+                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Data")));
562801
+
562801
+    sig= xasprintf(RHSMENT_SIG_DATA_BEGIN_TAG"%s"RHSMENT_SIG_DATA_END_TAG, "rsasignature");
562801
+    assert(0 == strcmp(sig,
562801
+                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Sig")));
562801
+
562801
+    free(ent);
562801
+    free(sig);
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    /* python script fails, '/etc/pki/entitlement' is returned  */
562801
+
562801
+    /* set cert dir path to '/etc/pki/entitlement' */
562801
+    /* store return value of ureport_server_config_set_client_auth */
562801
+    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", RHSMENT_PEM_DIR_PATH, 1);
562801
+
562801
+    int exp_ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, "rhsm");
562801
+
562801
+    /* Do the same with unset LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH and wrong PYTHONPATH */
562801
+    /* function rhsm_config_get_entitlement_cert_dir has to return RHSMENT_PEM_DIR_PATH */
562801
+    unsetenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
562801
+    setenv("PYTHONPATH", WRONG_TESTING_PYTHONPATH, 1);
562801
+
562801
+    int rec_ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, "rhsm");
562801
+
562801
+    /* we expect the same return value */
562801
+//    assert(exp_ret_val == rec_ret_val);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## -------------------------------------- ##
562801
+##  ureport_server_config_set_basic_auth  ##
562801
+## -------------------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_config_set_basic_auth],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+
562801
+void my_assert(const char *str1, const char *str2)
562801
+{
562801
+    if (str1 == NULL || str2 == NULL)
562801
+        assert( str1 == NULL && str2 == NULL );
562801
+    else
562801
+        assert(strcmp(str1, str2) == 0);
562801
+
562801
+    return;
562801
+}
562801
+
562801
+void assert_ureport_server_config(struct ureport_server_config *config,
562801
+                                const char *url,
562801
+                                bool ver,
562801
+                                const char *cert,
562801
+                                const char *key,
562801
+                                const char *username,
562801
+                                const char *password)
562801
+{
562801
+    my_assert(config->ur_url, url);
562801
+    assert(config->ur_ssl_verify == ver);
562801
+    my_assert(config->ur_client_cert, cert);
562801
+    my_assert(config->ur_client_key, key);
562801
+    my_assert(config->ur_username, username);
562801
+    my_assert(config->ur_password , password);
562801
+
562801
+    return;
562801
+}
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    ureport_server_config_set_basic_auth(&config, NULL, NULL);
562801
+    assert_ureport_server_config(&config, NULL, true, NULL, NULL, NULL, NULL);
562801
+
562801
+    ureport_server_config_set_basic_auth(&config, "usr", NULL);
562801
+    assert_ureport_server_config(&config, NULL, true, NULL, NULL, "usr", NULL);
562801
+
562801
+    ureport_server_config_set_basic_auth(&config, NULL, "passwd");
562801
+    assert_ureport_server_config(&config, NULL, true, NULL, NULL, NULL, "passwd");
562801
+
562801
+    ureport_server_config_set_basic_auth(&config, "usr", "passwd");
562801
+    assert_ureport_server_config(&config, NULL, true, NULL, NULL, "usr", "passwd");
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## ------------------------------------ ##
562801
+##  ureport_server_response_from_reply  ##
562801
+## ------------------------------------ ##
562801
+
562801
+AT_TESTFUN([ureport_server_response_from_reply],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+
562801
+
562801
+int main(void)
562801
+{
562801
+
562801
+    /* curl_resul is not CURL_OK */
562801
+    struct post_state ps;
562801
+
562801
+    ps.curl_result = 1;
562801
+    strcpy(ps.errmsg, "err");
562801
+    ps.body = (char *)"body";
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    ureport_server_config_set_url(&config, strdup("url"));
562801
+
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    /* curl_resul is CURLE_OK */
562801
+    /* http_resp_code == 404 */
562801
+    ps.curl_result = CURLE_OK;
562801
+    ps.http_resp_code = 404;
562801
+
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    ps.http_resp_code = 500;
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    ps.http_resp_code = 503;
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    ps.http_resp_code = 404;
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    ps.http_resp_code = 201;
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    /* unable parse json */
562801
+    ps.http_resp_code = 202;
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    /* correct json && invalid format */
562801
+    ps.body = (char *)"{ \"resultxxxxxxxx\" : true }";
562801
+    assert(ureport_server_response_from_reply(&ps, &config) == NULL);
562801
+
562801
+    /* correct json && valid format */
562801
+    ps.body = (char *)"{ 'result' : true, \
562801
+                         'message': 'message', \
562801
+                         'bthash': '691cf824e3e07457156125636e86c50279e29496', \
562801
+                         'reported_to': [ { 'type': 'url', \
562801
+                         'value': 'value', \
562801
+                         'reporter': 'ABRT Server' } ] }";
562801
+
562801
+    struct ureport_server_response *response = ureport_server_response_from_reply(&ps, &config);
562801
+    assert(strcmp(response->urr_value, "true") == 0);
562801
+    assert(strcmp(response->urr_message, "message") == 0);
562801
+    assert(strcmp(response->urr_bthash, "691cf824e3e07457156125636e86c50279e29496") == 0);
562801
+
562801
+    GList *urr_reported_to_list = response->urr_reported_to_list;
562801
+    assert(strcmp(urr_reported_to_list->data, "ABRT Server: URL=value") == 0);
562801
+
562801
+    ureport_server_response_free(response);
562801
+
562801
+    return 0;
562801
+
562801
+}
562801
+]])
562801
+
562801
+## ----------------------------------------- ##
562801
+##  ureport_server_response_save_in_dump_dir ##
562801
+## ----------------------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_response_save_in_dump_dir],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "dump_dir.h"
562801
+#include "problem_data.h"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    /* reported to*/
562801
+    struct post_state ps;
562801
+    ps.curl_result = CURLE_OK;
562801
+    ps.http_resp_code = 202;
562801
+    ps.body = (char *)"{ 'result' : true, \
562801
+                         'message': 'message', \
562801
+                         'bthash': '691cf824e3e07457156125636e86c50279e29496', \
562801
+                         'reported_to': [ { 'type': 'url', \
562801
+                         'value': 'value', \
562801
+                         'reporter': 'ABRT Server' } ] }";
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+    ureport_server_config_set_url(&config, strdup("url"));
562801
+
562801
+    struct dump_dir *dd = dd_create("./test", (uid_t)-1L, DEFAULT_DUMP_DIR_MODE);
562801
+    assert(dd != NULL);
562801
+    dd_create_basic_files(dd, (uid_t)-1L, NULL);
562801
+    dd_save_text(dd, FILENAME_TYPE, "CCpp");
562801
+    dd_close(dd);
562801
+
562801
+    struct ureport_server_response *response = ureport_server_response_from_reply(&ps, &config);
562801
+    assert(ureport_server_response_save_in_dump_dir(response, "./test", &config));
562801
+
562801
+    /* dump dir do not exist */
562801
+    assert(false == ureport_server_response_save_in_dump_dir(response, "not_existing_dir", &config));
562801
+
562801
+    dd = dd_opendir("./test", 0);
562801
+    char *reported_to = dd_load_text_ext(dd, FILENAME_REPORTED_TO, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE);
562801
+
562801
+    assert(strstr(reported_to, "uReport: BTHASH=691cf824e3e07457156125636e86c50279e29496") != NULL);
562801
+    assert(strstr(reported_to, "url/reports/bthash/691cf824e3e07457156125636e86c50279e29496") != NULL);
562801
+    assert(strstr(reported_to, "ABRT Server: URL=value") != NULL);
562801
+    /* not-reportable must not exist */
562801
+    assert(!dd_exist(dd, FILENAME_NOT_REPORTABLE));
562801
+
562801
+    free(config.ur_url);
562801
+    ureport_server_response_free(response);
562801
+    free(reported_to);
562801
+    dd_close(dd);
562801
+    delete_dump_dir("./test");
562801
+
562801
+    /* not-reportable*/
562801
+    ps.curl_result = CURLE_OK;
562801
+    ps.http_resp_code = 202;
562801
+    ps.body = (char *)"{ 'result' : true, \
562801
+                         'message': 'message', \
562801
+                         'solutions': [ { 'cause': 'solution_cause', \
562801
+                         'url': 'solution_url', \
562801
+                         'note': 'solution_note' } ], \
562801
+                         'bthash': '691cf824e3e07457156125636e86c50279e29496', \
562801
+                         'reported_to': [ { 'type': 'url', \
562801
+                         'value': 'value', \
562801
+                         'reporter': 'ABRT Server' } ] }";
562801
+
562801
+    ureport_server_config_init(&config);
562801
+    ureport_server_config_set_url(&config, strdup("url"));
562801
+
562801
+    dd = dd_create("./test", (uid_t)-1L, DEFAULT_DUMP_DIR_MODE);
562801
+    assert(dd != NULL);
562801
+    dd_create_basic_files(dd, (uid_t)-1L, NULL);
562801
+    dd_save_text(dd, FILENAME_TYPE, "CCpp");
562801
+    dd_close(dd);
562801
+
562801
+    response = ureport_server_response_from_reply(&ps, &config);
562801
+    assert(ureport_server_response_save_in_dump_dir(response, "./test", &config));
562801
+
562801
+    dd = dd_opendir("./test", 0);
562801
+    reported_to = dd_load_text_ext(dd, FILENAME_REPORTED_TO, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE);
562801
+
562801
+    assert(strstr(reported_to, "uReport: BTHASH=691cf824e3e07457156125636e86c50279e29496") != NULL);
562801
+    assert(strstr(reported_to, "url/reports/bthash/691cf824e3e07457156125636e86c50279e29496") != NULL);
562801
+    assert(strstr(reported_to, "ABRT Server: URL=value") != NULL);
562801
+    /* not-reportable must exist */
562801
+    char *not_reportable = dd_load_text_ext(dd, FILENAME_NOT_REPORTABLE, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE);
562801
+
562801
+    assert(strstr(not_reportable, "Your problem seems to be caused by solution_cause") != NULL);
562801
+
562801
+
562801
+    free(config.ur_url);
562801
+    ureport_server_response_free(response);
562801
+    free(reported_to);
562801
+    free(not_reportable);
562801
+    dd_close(dd);
562801
+    delete_dump_dir("./test");
562801
+
562801
+    return 0;
562801
+
562801
+}
562801
+]])
562801
+
562801
+
562801
+## --------------------------------------- ##
562801
+##  ureport_server_response_get_report_url ##
562801
+## --------------------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_server_response_get_report_url],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "problem_data.h"
562801
+
562801
+#define BTHASH_URL_SFX "reports/bthash/"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    /* reported to*/
562801
+    struct post_state ps;
562801
+    ps.curl_result = CURLE_OK;
562801
+    ps.http_resp_code = 202;
562801
+    ps.body = (char *)"{ 'result' : true, \
562801
+                         'message': 'message', \
562801
+                         'bthash': '691cf824e3e07457156125636e86c50279e29496', \
562801
+                         'reported_to': [ { 'type': 'url', \
562801
+                         'value': 'value', \
562801
+                         'reporter': 'ABRT Server' } ] }";
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+    ureport_server_config_set_url(&config, strdup("url"));
562801
+
562801
+    struct ureport_server_response *response = ureport_server_response_from_reply(&ps, &config);
562801
+
562801
+    char *report_url = ureport_server_response_get_report_url(response, &config);
562801
+
562801
+    char *expect_bthash_url = concat_path_file(config.ur_url, BTHASH_URL_SFX);
562801
+    char *expect_report_url = concat_path_file(expect_bthash_url, response->urr_bthash);
562801
+    free(expect_bthash_url);
562801
+
562801
+    assert(strcmp(report_url, expect_report_url) == 0);
562801
+
562801
+    free(config.ur_url);
562801
+    free(expect_report_url);
562801
+    free(report_url);
562801
+    ureport_server_response_free(response);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## ---------------- ##
562801
+##  ureport_do_post ##
562801
+## ---------------- ##
562801
+
562801
+AT_TESTFUN([ureport_do_post],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "problem_data.h"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct dump_dir *dd = dd_create("./test", (uid_t)-1L, DEFAULT_DUMP_DIR_MODE);
562801
+    assert(dd != NULL);
562801
+    dd_create_basic_files(dd, (uid_t)-1L, NULL);
562801
+    dd_save_text(dd, FILENAME_TYPE, "CCpp");
562801
+    dd_save_text(dd, FILENAME_ANALYZER, "CCpp");
562801
+    dd_save_text(dd, FILENAME_PKG_EPOCH, "pkg_epoch");
562801
+    dd_save_text(dd, FILENAME_PKG_ARCH, "pkg_arch");
562801
+    dd_save_text(dd, FILENAME_PKG_RELEASE, "pkg_release");
562801
+    dd_save_text(dd, FILENAME_PKG_VERSION, "pkg_version");
562801
+    dd_save_text(dd, FILENAME_PKG_NAME, "pkg_name");
562801
+    const char *bt = "{ \"signal\": 6, \"executable\": \"/usr/bin/will_abort\" }";
562801
+    dd_save_text(dd, FILENAME_CORE_BACKTRACE, bt);
562801
+    dd_close(dd);
562801
+
562801
+    char *json = ureport_from_dump_dir_ext("./test", NULL);
562801
+
562801
+    /* wrong url */
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+    struct post_state *post_state = ureport_do_post(json, &config, "not_exist");
562801
+    assert(post_state->curl_result == CURLE_COULDNT_RESOLVE_HOST);
562801
+
562801
+    free(post_state);
562801
+    free(json);
562801
+    ureport_server_config_destroy(&config);
562801
+    delete_dump_dir("./test");
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## --------------- ##
562801
+##  ureport_submit ##
562801
+## --------------- ##
562801
+
562801
+AT_TESTFUN([ureport_submit],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "problem_data.h"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct dump_dir *dd = dd_create("./test", (uid_t)-1L, DEFAULT_DUMP_DIR_MODE);
562801
+    assert(dd != NULL);
562801
+    dd_create_basic_files(dd, (uid_t)-1L, NULL);
562801
+    dd_save_text(dd, FILENAME_TYPE, "CCpp");
562801
+    dd_save_text(dd, FILENAME_ANALYZER, "CCpp");
562801
+    dd_save_text(dd, FILENAME_PKG_EPOCH, "pkg_epoch");
562801
+    dd_save_text(dd, FILENAME_PKG_ARCH, "pkg_arch");
562801
+    dd_save_text(dd, FILENAME_PKG_RELEASE, "pkg_release");
562801
+    dd_save_text(dd, FILENAME_PKG_VERSION, "pkg_version");
562801
+    dd_save_text(dd, FILENAME_PKG_NAME, "pkg_name");
562801
+    const char *bt = "{ \"signal\": 6, \"executable\": \"/usr/bin/will_abort\" }";
562801
+    dd_save_text(dd, FILENAME_CORE_BACKTRACE, bt);
562801
+    dd_close(dd);
562801
+
562801
+    char *json = ureport_from_dump_dir_ext("./test", NULL);
562801
+
562801
+    /* wrong url */
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+    struct ureport_server_response *response = ureport_submit(json, &config);
562801
+
562801
+    assert(response == NULL);
562801
+
562801
+    ureport_server_response_free(response);
562801
+    free(json);
562801
+    ureport_server_config_destroy(&config);
562801
+    delete_dump_dir("./test");
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## --------------------------- ##
562801
+## ureport_json_attachment_new ##
562801
+## --------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_json_attachment_new],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "problem_data.h"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    char *json = ureport_json_attachment_new("data_bthash", "data_type", "data_data");
562801
+    assert(strcmp(json, "{ \"bthash\": \"data_bthash\", \"type\": \"data_type\", \"data\": \"data_data\" }") == 0);
562801
+    free(json);
562801
+
562801
+    json = ureport_json_attachment_new("", "", "");
562801
+    assert(strcmp(json, "{ \"bthash\": \"\", \"type\": \"\", \"data\": \"\" }") == 0);
562801
+    free(json);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## --------------------- ##
562801
+## ureport_attach_string ##
562801
+## --------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_attach_string],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "problem_data.h"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    /* wrong url */
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    bool res = ureport_attach_string("691cf824e3e07457156125636e86c50279e29496", "email", "abrt@email.com", &config);
562801
+    assert(res == true);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## ------------------ ##
562801
+## ureport_attach_int ##
562801
+## ------------------ ##
562801
+
562801
+AT_TESTFUN([ureport_attach_int],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "problem_data.h"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    /* wrong url */
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    bool res = ureport_attach_int("691cf824e3e07457156125636e86c50279e29496", "count", 5, &config);
562801
+    assert(res == true);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
+## ------------------------- ##
562801
+## ureport_from_dump_dir_ext ##
562801
+## ------------------------- ##
562801
+
562801
+AT_TESTFUN([ureport_from_dump_dir_ext],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include "ureport.h"
562801
+#include <assert.h>
562801
+#include "libreport_curl.h"
562801
+#include "problem_data.h"
562801
+
562801
+int main(void)
562801
+{
562801
+    g_verbose=3;
562801
+
562801
+    struct dump_dir *dd = dd_create("./test", (uid_t)-1L, DEFAULT_DUMP_DIR_MODE);
562801
+    assert(dd != NULL);
562801
+    dd_create_basic_files(dd, (uid_t)-1L, NULL);
562801
+    dd_save_text(dd, FILENAME_TYPE, "CCpp");
562801
+    dd_save_text(dd, FILENAME_ANALYZER, "CCpp");
562801
+    dd_save_text(dd, FILENAME_PKG_EPOCH, "pkg_epoch");
562801
+    dd_save_text(dd, FILENAME_PKG_ARCH, "pkg_arch");
562801
+    dd_save_text(dd, FILENAME_PKG_RELEASE, "pkg_release");
562801
+    dd_save_text(dd, FILENAME_PKG_VERSION, "pkg_version");
562801
+    dd_save_text(dd, FILENAME_PKG_NAME, "pkg_name");
562801
+    const char *bt = "{ \"signal\": 6, \"executable\": \"/usr/bin/will_abort\" }";
562801
+    dd_save_text(dd, FILENAME_CORE_BACKTRACE, bt);
562801
+    dd_close(dd);
562801
+
562801
+    /* no auth */
562801
+    char *ureport = ureport_from_dump_dir_ext("./test", NULL);
562801
+    assert(strstr(ureport, "auth") == NULL);
562801
+    free(ureport);
562801
+
562801
+    /* auth */
562801
+    dd = dd_opendir("./test", 0);
562801
+    dd_save_text(dd, FILENAME_HOSTNAME, "env_hostname");
562801
+    dd_close(dd);
562801
+
562801
+    struct ureport_server_config config;
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    map_string_t *settings = new_map_string();
562801
+
562801
+    setenv("uReport_IncludeAuthData", "yes", 1);
562801
+    setenv("uReport_AuthDataItems", "hostname", 1);
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    ureport = ureport_from_dump_dir_ext("./test", &config.ur_prefs);
562801
+    assert(strstr(ureport, "auth") != NULL);
562801
+    assert(strstr(ureport, "\"hostname\": \"env_hostname\"") != NULL);
562801
+    free(ureport);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+    free_map_string(settings);
562801
+
562801
+    /* auth with unknown uReport_AuthDataItems */
562801
+    ureport_server_config_init(&config);
562801
+
562801
+    settings = new_map_string();
562801
+
562801
+    setenv("uReport_AuthDataItems", "hostname, unknown", 1);
562801
+
562801
+    ureport_server_config_load(&config, settings);
562801
+
562801
+    ureport = ureport_from_dump_dir_ext("./test", &config.ur_prefs);
562801
+    assert(strstr(ureport, "auth") != NULL);
562801
+    assert(strstr(ureport, "\"hostname\": \"env_hostname\"") != NULL);
562801
+    assert(strstr(ureport, "unknown") == NULL);
562801
+    free(ureport);
562801
+
562801
+    ureport_server_config_destroy(&config);
562801
+    free_map_string(settings);
562801
+    delete_dump_dir("./test");
562801
+
562801
+    return 0;
562801
+}
562801
+]])
562801
+
562801
diff --git a/tests/ureport/certs/correct/cert-key.pem b/tests/ureport/certs/correct/cert-key.pem
562801
new file mode 100644
562801
index 0000000..1516328
562801
--- /dev/null
562801
+++ b/tests/ureport/certs/correct/cert-key.pem
562801
@@ -0,0 +1,5 @@
562801
+-----BEGIN RSA PRIVATE KEY-----
562801
+rsa
562801
+private
562801
+key
562801
+-----END RSA PRIVATE KEY-----
562801
diff --git a/tests/ureport/certs/correct/cert.pem b/tests/ureport/certs/correct/cert.pem
562801
new file mode 100644
562801
index 0000000..ee54de3
562801
--- /dev/null
562801
+++ b/tests/ureport/certs/correct/cert.pem
562801
@@ -0,0 +1,13 @@
562801
+-----BEGIN CERTIFICATE-----
562801
+cer
562801
+tifica
562801
+te
562801
+-----END CERTIFICATE-----
562801
+-----BEGIN ENTITLEMENT DATA-----
562801
+entitlement
562801
+data
562801
+-----END ENTITLEMENT DATA-----
562801
+-----BEGIN RSA SIGNATURE-----
562801
+rsa
562801
+signature
562801
+-----END RSA SIGNATURE-----
562801
diff --git a/tests/ureport/certs/incorrect_content/cert-key.pem b/tests/ureport/certs/incorrect_content/cert-key.pem
562801
new file mode 100644
562801
index 0000000..1516328
562801
--- /dev/null
562801
+++ b/tests/ureport/certs/incorrect_content/cert-key.pem
562801
@@ -0,0 +1,5 @@
562801
+-----BEGIN RSA PRIVATE KEY-----
562801
+rsa
562801
+private
562801
+key
562801
+-----END RSA PRIVATE KEY-----
562801
diff --git a/tests/ureport/certs/incorrect_content/cert.pem b/tests/ureport/certs/incorrect_content/cert.pem
562801
new file mode 100644
562801
index 0000000..e69de29
562801
diff --git a/tests/ureport/rhsm/__init__.py b/tests/ureport/rhsm/__init__.py
562801
new file mode 100644
562801
index 0000000..e69de29
562801
diff --git a/tests/ureport/rhsm/config.py b/tests/ureport/rhsm/config.py
562801
new file mode 100644
562801
index 0000000..44483d8
562801
--- /dev/null
562801
+++ b/tests/ureport/rhsm/config.py
562801
@@ -0,0 +1,8 @@
562801
+import os
562801
+
562801
+def initConfig():
562801
+    return myConfig()
562801
+
562801
+class myConfig():
562801
+    def get(self, key, value):
562801
+        return os.path.abspath("../../ureport/certs/correct")
562801
-- 
562801
1.8.3.1
562801