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

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