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