Blame SOURCES/0140-testsuite-fix-test-for-ureport.patch

562801
From 34f32d66ba1224a8c2ccdae27c1bc7f8c97840b2 Mon Sep 17 00:00:00 2001
562801
From: Matej Habrnal <mhabrnal@redhat.com>
562801
Date: Wed, 27 May 2015 14:58:55 +0200
562801
Subject: [PATCH] testsuite: fix test for ureport
562801
562801
The fix is related to change in the use of rhsm certificate from
562801
entitiement to consumer and URL where the uReports are sended.
562801
562801
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
562801
---
562801
 tests/ureport.at                                   | 83 ++++++++++------------
562801
 tests/ureport/certs/correct/cert-key.pem           |  5 --
562801
 tests/ureport/certs/correct/key.pem                |  0
562801
 tests/ureport/certs/incorrect_content/cert-key.pem |  5 --
562801
 tests/ureport/certs/incorrect_content/cert.pem     |  0
562801
 tests/ureport/certs/only_cert/cert.pem             |  0
562801
 tests/ureport/certs/only_key/key.pem               |  0
562801
 7 files changed, 36 insertions(+), 57 deletions(-)
562801
 delete mode 100644 tests/ureport/certs/correct/cert-key.pem
562801
 create mode 100644 tests/ureport/certs/correct/key.pem
562801
 delete mode 100644 tests/ureport/certs/incorrect_content/cert-key.pem
562801
 delete mode 100644 tests/ureport/certs/incorrect_content/cert.pem
562801
 create mode 100644 tests/ureport/certs/only_cert/cert.pem
562801
 create mode 100644 tests/ureport/certs/only_key/key.pem
562801
562801
diff --git a/tests/ureport.at b/tests/ureport.at
562801
index 3a824a2..b5f79df 100644
562801
--- a/tests/ureport.at
562801
+++ b/tests/ureport.at
562801
@@ -261,7 +261,7 @@ int main(void)
562801
     setenv("uReport_HTTPAuth", "username:password", 1);
562801
     setenv("uReport_AuthDataItems", "hostname, time", 1);
562801
 
562801
-    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", TESTING_CERTS_CORRECT_DIR_PATH, 1);
562801
+    setenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH", TESTING_CERTS_CORRECT_DIR_PATH, 1);
562801
 
562801
     ureport_server_config_load(&config, settings);
562801
 
562801
@@ -276,7 +276,7 @@ int main(void)
562801
     assert(strcmp(l->data, "hostname") == 0);
562801
     assert(strcmp(l->next->data, "time") == 0);
562801
 
562801
-    unsetenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
562801
+    unsetenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH");
562801
 
562801
     unsetenv("uReport_SSLClientAuth");
562801
     unsetenv("uReport_HTTPAuth");
562801
@@ -296,7 +296,7 @@ int main(void)
562801
     insert_map_string(settings, xstrdup("HTTPAuth"), xstrdup("rhn-username:rhn-password"));
562801
     insert_map_string(settings, xstrdup("AuthDataItems"), xstrdup("hostname, type"));
562801
 
562801
-    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", TESTING_CERTS_CORRECT_DIR_PATH, 1);
562801
+    setenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH", TESTING_CERTS_CORRECT_DIR_PATH, 1);
562801
 
562801
     ureport_server_config_load(&config, settings);
562801
 
562801
@@ -311,7 +311,7 @@ int main(void)
562801
     assert(strcmp(l->data, "hostname") == 0);
562801
     assert(strcmp(l->next->data, "type") == 0);
562801
 
562801
-    unsetenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
562801
+    unsetenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH");
562801
 
562801
     free_map_string(settings);
562801
 
562801
@@ -366,19 +366,17 @@ AT_TESTFUN([ureport_server_config_set_client_auth],
562801
 #include <assert.h>
562801
 
562801
 #define DESTROYED_POINTER (void *)0xdeadbeef
562801
-#define RHSM_WEB_SERVICE_URL "https://api.access.redhat.com/rs/telemetry/abrt"
562801
+#define RHSM_WEB_SERVICE_URL "https://cert-api.access.redhat.com/rs/telemetry/abrt"
562801
 
562801
 #define TESTING_CERTS_CORRECT_DIR_PATH "../../ureport/certs/correct"
562801
-#define TESTING_CERTS_INCORRECT_CONTENT_DIR_PATH "../../ureport/certs/incorrect_content"
562801
+#define TESTING_CERTS_INCORRECT_ONLY_CERT_DIR_PATH "../../ureport/certs/only_cert"
562801
+#define TESTING_CERTS_INCORRECT_ONLY_KEY_DIR_PATH "../../ureport/certs/only_key"
562801
 #define TESTING_PYTHONPATH "../../ureport/"
562801
 #define WRONG_TESTING_PYTHONPATH "../../ureportxxxxxx/"
562801
 
562801
-#define RHSMENT_PEM_DIR_PATH "/etc/pki/entitlement"
562801
-
562801
-#define RHSMENT_ENT_DATA_BEGIN_TAG "-----BEGIN ENTITLEMENT DATA-----"
562801
-#define RHSMENT_ENT_DATA_END_TAG "-----END ENTITLEMENT DATA-----"
562801
-#define RHSMENT_SIG_DATA_BEGIN_TAG "-----BEGIN RSA SIGNATURE-----"
562801
-#define RHSMENT_SIG_DATA_END_TAG "-----END RSA SIGNATURE-----"
562801
+#define RHSMCON_PEM_DIR_PATH "/etc/pki/consumer"
562801
+#define RHSMCON_CERT_NAME "cert.pem"
562801
+#define RHSMCON_KEY_NAME "key.pem"
562801
 
562801
 char *my_strdup(const char *str)
562801
 {
562801
@@ -507,7 +505,7 @@ int main(void)
562801
     /* no certs */
562801
     char *empty_cert_dir = mkdtemp(strdup("/tmp/cert_XXXXXX"));
562801
     assert(empty_cert_dir);
562801
-    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", empty_cert_dir, 1);
562801
+    setenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH", empty_cert_dir, 1);
562801
 
562801
     int status = test_ureport_server_config_set_client_auth_exit_code_ext(&config, "rhsm", NULL, NULL);
562801
     assert(status == 0);
562801
@@ -516,9 +514,18 @@ int main(void)
562801
 
562801
     /* client_auth == rhsm */
562801
     /* ur_url == NULL */
562801
-    /* certs exists (incorrect content) */
562801
+    /* certs exists (only RHSMCON_CERT_NAME exists) */
562801
 
562801
-    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", TESTING_CERTS_INCORRECT_CONTENT_DIR_PATH, 1);
562801
+    setenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH", TESTING_CERTS_INCORRECT_ONLY_CERT_DIR_PATH, 1);
562801
+
562801
+    status = test_ureport_server_config_set_client_auth_exit_code_ext(&config, "rhsm", NULL, NULL);
562801
+    assert(status == 0);
562801
+
562801
+    /* client_auth == rhsm */
562801
+    /* ur_url == NULL */
562801
+    /* certs exists (only RHSMCON_KEY_NAME exists) */
562801
+
562801
+    setenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH", TESTING_CERTS_INCORRECT_ONLY_KEY_DIR_PATH, 1);
562801
 
562801
     status = test_ureport_server_config_set_client_auth_exit_code_ext(&config, "rhsm", NULL, NULL);
562801
     assert(status == 0);
562801
@@ -528,25 +535,15 @@ int main(void)
562801
     /* certs exists (correct) */
562801
     ureport_server_config_init(&config);
562801
 
562801
-    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", TESTING_CERTS_CORRECT_DIR_PATH, 1);
562801
+    setenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH", TESTING_CERTS_CORRECT_DIR_PATH, 1);
562801
 
562801
     ureport_server_config_set_client_auth(&config, "rhsm");
562801
 
562801
     assert_ureport_server_config(&config, RHSM_WEB_SERVICE_URL, true,
562801
                                 TESTING_CERTS_CORRECT_DIR_PATH"/cert.pem",
562801
-                                TESTING_CERTS_CORRECT_DIR_PATH"/cert-key.pem",
562801
+                                TESTING_CERTS_CORRECT_DIR_PATH"/key.pem",
562801
                                 NULL, NULL);
562801
 
562801
-    char *ent = xasprintf(RHSMENT_ENT_DATA_BEGIN_TAG"%s"RHSMENT_ENT_DATA_END_TAG, "entitlementdata");
562801
-    assert(0 == strcmp(ent,
562801
-                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Data")));
562801
-
562801
-    char *sig= xasprintf(RHSMENT_SIG_DATA_BEGIN_TAG"%s"RHSMENT_SIG_DATA_END_TAG, "rsasignature");
562801
-    assert(0 == strcmp(sig,
562801
-                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Sig")));
562801
-
562801
-    free(ent);
562801
-    free(sig);
562801
     ureport_server_config_destroy(&config);
562801
 
562801
     /* client_auth == cert:key */
562801
@@ -575,16 +572,16 @@ int main(void)
562801
     ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, "cert");
562801
     assert(ret_val != 0 && ret_val != -1);
562801
 
562801
-/* rhsm_config_get_entitlement_cert_dir */
562801
+/* rhsm_config_get_consumer_cert_dir */
562801
 /* certs exists (correct content) */
562801
-    unsetenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
562801
+    unsetenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH");
562801
     setenv("PYTHONPATH", TESTING_PYTHONPATH, 1);
562801
 
562801
     ureport_server_config_init(&config);
562801
     ureport_server_config_set_client_auth(&config, "rhsm");
562801
 
562801
     char *abs_path_cert = realpath(TESTING_CERTS_CORRECT_DIR_PATH"/cert.pem", NULL);
562801
-    char *abs_path_key = realpath(TESTING_CERTS_CORRECT_DIR_PATH"/cert-key.pem", NULL);
562801
+    char *abs_path_key = realpath(TESTING_CERTS_CORRECT_DIR_PATH"/key.pem", NULL);
562801
 
562801
     assert_ureport_server_config(&config, RHSM_WEB_SERVICE_URL, true,
562801
                                 abs_path_cert,
562801
@@ -593,29 +590,19 @@ int main(void)
562801
     free(abs_path_cert);
562801
     free(abs_path_key);
562801
 
562801
-    ent = xasprintf(RHSMENT_ENT_DATA_BEGIN_TAG"%s"RHSMENT_ENT_DATA_END_TAG, "entitlementdata");
562801
-    assert(0 == strcmp(ent,
562801
-                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Data")));
562801
-
562801
-    sig= xasprintf(RHSMENT_SIG_DATA_BEGIN_TAG"%s"RHSMENT_SIG_DATA_END_TAG, "rsasignature");
562801
-    assert(0 == strcmp(sig,
562801
-                        get_map_string_item_or_NULL(config.ur_http_headers, "X-RH-Entitlement-Sig")));
562801
-
562801
-    free(ent);
562801
-    free(sig);
562801
     ureport_server_config_destroy(&config);
562801
 
562801
-    /* python script fails, '/etc/pki/entitlement' is returned  */
562801
+    /* python script fails, '/etc/pki/consumer' is returned  */
562801
 
562801
-    /* set cert dir path to '/etc/pki/entitlement' */
562801
+    /* set cert dir path to '/etc/pki/consumer' */
562801
     /* store return value of ureport_server_config_set_client_auth */
562801
-    setenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH", RHSMENT_PEM_DIR_PATH, 1);
562801
+    setenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH", RHSMCON_PEM_DIR_PATH, 1);
562801
 
562801
     int exp_ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, "rhsm");
562801
 
562801
-    /* Do the same with unset LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH and wrong PYTHONPATH */
562801
-    /* function rhsm_config_get_entitlement_cert_dir has to return RHSMENT_PEM_DIR_PATH */
562801
-    unsetenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
562801
+    /* Do the same with unset LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH and wrong PYTHONPATH */
562801
+    /* function rhsm_config_get_consumer_cert_dir has to return RHSMCON_PEM_DIR_PATH */
562801
+    unsetenv("LIBREPORT_DEBUG_RHSMCON_PEM_DIR_PATH");
562801
     setenv("PYTHONPATH", WRONG_TESTING_PYTHONPATH, 1);
562801
 
562801
     int rec_ret_val = test_ureport_server_config_set_client_auth_exit_code(&config, "rhsm");
562801
@@ -1215,6 +1202,8 @@ AT_TESTFUN([ureport_server_config_load_basic_auth],
562801
 #include "libreport_curl.h"
562801
 #include "problem_data.h"
562801
 
562801
+#define RHSM_WEB_SERVICE_URL "https://cert-api.access.redhat.com/rs/telemetry/abrt"
562801
+
562801
 int main(void)
562801
 {
562801
     g_verbose=3;
562801
@@ -1241,7 +1230,7 @@ int main(void)
562801
 
562801
         assert(strcmp(config.ur_username, "rhn-user-name") == 0);
562801
         assert(strcmp(config.ur_password, "rhn-password") == 0);
562801
-        assert(strcmp(config.ur_url, "https://api.access.redhat.com/rs/telemetry/abrt") == 0);
562801
+        assert(strcmp(config.ur_url, RHSM_WEB_SERVICE_URL) == 0);
562801
 
562801
         unsetenv("LIBREPORT_DEBUG_PLUGINS_CONF_DIR");
562801
         ureport_server_config_destroy(&config);
562801
diff --git a/tests/ureport/certs/correct/cert-key.pem b/tests/ureport/certs/correct/cert-key.pem
562801
deleted file mode 100644
562801
index 1516328..0000000
562801
--- a/tests/ureport/certs/correct/cert-key.pem
562801
+++ /dev/null
562801
@@ -1,5 +0,0 @@
562801
------BEGIN RSA PRIVATE KEY-----
562801
-rsa
562801
-private
562801
-key
562801
------END RSA PRIVATE KEY-----
562801
diff --git a/tests/ureport/certs/correct/key.pem b/tests/ureport/certs/correct/key.pem
562801
new file mode 100644
562801
index 0000000..e69de29
562801
diff --git a/tests/ureport/certs/incorrect_content/cert-key.pem b/tests/ureport/certs/incorrect_content/cert-key.pem
562801
deleted file mode 100644
562801
index 1516328..0000000
562801
--- a/tests/ureport/certs/incorrect_content/cert-key.pem
562801
+++ /dev/null
562801
@@ -1,5 +0,0 @@
562801
------BEGIN RSA PRIVATE KEY-----
562801
-rsa
562801
-private
562801
-key
562801
------END RSA PRIVATE KEY-----
562801
diff --git a/tests/ureport/certs/incorrect_content/cert.pem b/tests/ureport/certs/incorrect_content/cert.pem
562801
deleted file mode 100644
562801
index e69de29..0000000
562801
diff --git a/tests/ureport/certs/only_cert/cert.pem b/tests/ureport/certs/only_cert/cert.pem
562801
new file mode 100644
562801
index 0000000..e69de29
562801
diff --git a/tests/ureport/certs/only_key/key.pem b/tests/ureport/certs/only_key/key.pem
562801
new file mode 100644
562801
index 0000000..e69de29
562801
-- 
562801
2.4.3
562801