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

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