/
githubmirror
/
libreport
Обзор
Документация
Войти
/
githubmirror
/
libreport
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/bugzilla_plugin.at.in
407 строк
16 KB
Michal Fabik
Fix build --without-bugzilla
12 сен 2022, 12:42
12 сен 2022, 12:42
4b25e48
Код
Авторство
О чём код?
# -*- Autotest -*- AT_BANNER([Bugzilla]) ## ------------------- ## ## report_Bugzilla_xml ## ## ------------------- ## AT_TESTFUN_COND([report_Bugzilla_xml], [[ #include "testsuite.h" TS_MAIN { event_config_t *conf = new_event_config("report_Bugzilla"); load_event_description_from_file(conf, "../../../src/plugins/report_Bugzilla.xml"); TS_ASSERT_STRING_EQ(ec_get_screen_name(conf), "Bugzilla", "Screen name"); TS_ASSERT_STRING_EQ(ec_get_description(conf), "Report to Bugzilla bug tracker", "Description"); TS_ASSERT_STRING_EQ(conf->ec_requires_items, "component,duphash,os_release", "Correct required items"); TS_ASSERT_STRING_EQ(conf->ec_exclude_items_by_default, "coredump,count,event_log,reported_to,vmcore", "Correct excluded items by default"); TS_ASSERT_STRING_EQ(conf->ec_exclude_items_always, NULL, "Not-defined excluded items always"); TS_ASSERT_FALSE(conf->ec_exclude_binary_items); TS_ASSERT_STRING_EQ(conf->ec_include_items_by_default, NULL, "Not-defined included items by default"); TS_ASSERT_SIGNED_EQ(conf->ec_minimal_rating, 3); TS_ASSERT_FALSE(conf->ec_skip_review); TS_ASSERT_FALSE(conf->ec_sending_sensitive_data); TS_ASSERT_TRUE(conf->ec_supports_restricted_access); event_option_t options[10] = { { .eo_value = NULL, .eo_label = (char *)"API key", .eo_note_html = (char *)"You can generate the API key for your Bugzilla account <a href=\"https://bugzilla.redhat.com/userprefs.cgi?tab=apikey\">here</a>", .eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 0, .is_advanced = 0, }, { .eo_value = (char *)"@RED_HAT_BUGZILLA_CREATE_PRIVATE@", .eo_label = (char *)"Restrict access", .eo_note_html = (char *)"Restrict access to the created bugzilla ticket allowing only users from specified groups to view it (see advanced settings for more details)", .eo_type = OPTION_TYPE_BOOL, .eo_allow_empty = 0, .is_advanced = 0, }, { .eo_value = (char *)"@RED_HAT_BUGZILLA_PRIVATE_GROUPS@", .eo_label = (char *)"Groups", .eo_note_html = (char *)"Restrict the access to specified groups <a href=\"https://github.com/abrt/abrt/wiki/FAQ#creating-private-bugzilla-tickets\">?</a>", .eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 1, .is_advanced = 1, }, { .eo_value = (char *)"https://bugzilla.redhat.com", .eo_label = (char *)"Bugzilla URL", .eo_note_html = (char *)"Address of Bugzilla server", .eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 0, .is_advanced = 1, }, { .eo_value = (char *)"yes", .eo_label = (char *)"Verify SSL", .eo_note_html = (char *)"Check SSL key validity", .eo_type = OPTION_TYPE_BOOL, .eo_allow_empty = 0, .is_advanced = 1, }, { .eo_value = NULL, .eo_label = (char *)"Bugzilla product", .eo_note_html = (char *)"Specify this only if you needed different product than specified in /etc/os-release", .eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 1, .is_advanced = 1, }, { .eo_value = NULL, .eo_label = (char *)"Bugzilla product version", .eo_note_html = (char *)"Specify this only if you needed different product version than specified in /etc/os-release", .eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 1, .is_advanced = 1, }, { .eo_value = NULL, .eo_label = (char *)"HTTP Proxy", .eo_note_html = (char *)"Sets the proxy server to use for HTTP", .eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 1, .is_advanced = 1, }, { .eo_value = NULL, .eo_label = (char *)"HTTPS Proxy", .eo_note_html = (char *)"Sets the proxy server to use for HTTPS", .eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 1, .is_advanced = 1, }, }; const char *option_names[] = { "Bugzilla_APIKey", "Bugzilla_CreatePrivate", "Bugzilla_PrivateGroups", "Bugzilla_BugzillaURL", "Bugzilla_SSLVerify", "Bugzilla_Product", "Bugzilla_ProductVersion", "http_proxy", "HTTPS_PROXY" }; for (unsigned i = 0; i < ARRAY_SIZE(option_names); ++i) { event_option_t *eo = get_event_option_from_list(option_names[i], conf->options); TS_ASSERT_PTR_IS_NOT_NULL_MESSAGE(eo, option_names[i]); if (eo == NULL) continue; TS_ASSERT_STRING_EQ(eo->eo_value, options[i].eo_value, option_names[i]); TS_ASSERT_STRING_EQ(eo->eo_label, options[i].eo_label, option_names[i]); TS_ASSERT_STRING_EQ(eo->eo_note_html, options[i].eo_note_html, option_names[i]); TS_ASSERT_SIGNED_OP_MESSAGE(eo->eo_type, ==, options[i].eo_type, option_names[i]); TS_ASSERT_SIGNED_OP_MESSAGE(eo->eo_allow_empty, ==, options[i].eo_allow_empty, option_names[i]); TS_ASSERT_SIGNED_OP_MESSAGE(eo->is_advanced, ==, options[i].is_advanced, option_names[i]); } free_event_config(conf); } TS_RETURN_MAIN ]], [test "x$BUILD_BUGZILLA" != 'xyes']) AT_TESTFUN_COND([rhbz_functions], [[ #define PACKAGE_NAME "libreport" #define VERSION "1.0" #include "testsuite.h" #include "internal_libreport.h" #include "client.h" #include "abrt_xmlrpc.h" #include "rhbz.h" #include "proxies.c" #include "rhbz.c" #include "abrt_xmlrpc.c" #include <errno.h> #include <string.h> TS_MAIN { pid_t pid = fork(); if (pid == 0) { int ret = 0; const char *argv[] = { "../../mock_bugzilla_server/mock_bugzilla_server.py", NULL }; ret = execv((char *)argv[0], (char * const *)argv); if (ret == -1) { printf("execv failed: %s\n", strerror(errno)); } } else if (pid > 0) { libreport_g_verbose = 3; char cwd_buf[PATH_MAX + 1]; static const char *dirs[] = { NULL, NULL, }; dirs[0] = getcwd(cwd_buf, sizeof(cwd_buf)); static int dir_flags[] = { CONF_DIR_FLAG_NONE, -1, }; unlink("libreport.conf"); FILE *lrf = fopen("libreport.conf", "wx"); assert(lrf != NULL); fprintf(lrf, "AlwaysExcludedElements = maps, var_log_messages, proc_pid_status"); fclose(lrf); assert(libreport_load_global_configuration_from_dirs(dirs, dir_flags)); struct bugzilla_struct { char *b_login; char *b_password; const char *b_bugzilla_url; const char *b_bugzilla_xmlrpc; char *b_product; char *b_product_version; const char *b_DontMatchComponents; int b_ssl_verify; int b_create_private; GList *b_private_groups; }; sleep(3); struct bugzilla_struct rhbz = { 0 }; rhbz.b_bugzilla_url = "http://localhost:8080/"; rhbz.b_bugzilla_xmlrpc = g_build_filename(rhbz.b_bugzilla_url, "xmlrpc.cgi", NULL); rhbz.b_ssl_verify = FALSE; xmlrpc_env env; xmlrpc_env_init(&env); xmlrpc_client_setup_global_const(&env); if (env.fault_occurred) printf("Error in setup_global_const: %s\n", env.fault_string); xmlrpc_env_clean(&env); struct abrt_xmlrpc *client = abrt_xmlrpc_new_client(rhbz.b_bugzilla_xmlrpc, rhbz.b_ssl_verify); { TS_ASSERT_TRUE(rhbz_login(client, "captainnemo", "giantsquidsalad")); } /*{ xmlrpc_value *result = abrt_xmlrpc_call(client, "Product.get", "{s:(s)}", "names", "Fedora"); xmlrpc_value *product_list = rhbz_get_member("products", result); xmlrpc_DECREF(result); xmlrpc_value *product = rhbz_array_item_at(product_list, 0); xmlrpc_DECREF(product_list); g_autofree char *product_description = (char *)rhbz_bug_read_item("description", product, RHBZ_READ_STR); xmlrpc_DECREF(product); TS_ASSERT_STRING_EQ(product_description, "bog standard OS", "Checking product description"); }*/ { int bug_id = -1; problem_data_t *problem_data = create_problem_data_for_reporting("../../sample_problems/1"); bug_id = rhbz_new_bug(client, problem_data, "Red Hat Enterprise Linux 8", "8.0", "gdb doesn't work", "It's been broken for ages", rhbz.b_create_private, rhbz.b_private_groups ); TS_ASSERT_SIGNED_EQ(bug_id, 0); const char *bt = problem_data_get_content_or_NULL(problem_data, "backtrace"); int ret = rhbz_attach_blob(client, "0", "backtrace", bt, strlen(bt), RHBZ_MINOR_UPDATE); TS_ASSERT_SIGNED_EQ(ret, 0); g_hash_table_destroy(problem_data); } { int bug_id = -1; problem_data_t *problem_data = create_problem_data_for_reporting("../../sample_problems/2"); bug_id = rhbz_new_bug(client, problem_data, "Red Hat Enterprise Linux 8", "8.0", "gdb doesn't work", "It's been broken for ages", rhbz.b_create_private, rhbz.b_private_groups ); TS_ASSERT_SIGNED_EQ(bug_id, 1); g_hash_table_destroy(problem_data); } { int bug_id = -1; problem_data_t *problem_data = create_problem_data_for_reporting("../../sample_problems/3"); bug_id = rhbz_new_bug(client, problem_data, "Fedora", "33", "afmw doesn't work", "It's been broken for ages", rhbz.b_create_private, rhbz.b_private_groups ); TS_ASSERT_SIGNED_EQ(bug_id, 2); g_hash_table_destroy(problem_data); } g_free((void *)rhbz.b_bugzilla_xmlrpc); { xmlrpc_value *sub_components = rhbz_get_sub_components(client, "Red Hat Enterprise Linux 8", "unknown"); char *sub_component = rhbz_get_default_sub_component("unknown", sub_components); TS_ASSERT_STRING_EQ(sub_component, "torpedoes", "Picking a sub_component when no default is hardcoded"); g_free(sub_component); if (sub_components) xmlrpc_DECREF(sub_components); } { rhbz_mail_to_cc(client, 0, "dev1@example.com", RHBZ_MINOR_UPDATE); rhbz_mail_to_cc(client, 0, "dev2@example.com", RHBZ_MINOR_UPDATE); xmlrpc_value *search = abrt_xmlrpc_call(client, "Bug.search", "{s:s,s:(ss)}", "quicksearch", "ALL product:\"Red Hat Enterprise Linux 8\"", "include_fields", "id", "cc"); xmlrpc_value *bugs = rhbz_get_member("bugs", search); xmlrpc_DECREF(search); xmlrpc_value *bug = rhbz_array_item_at(bugs, 0); xmlrpc_DECREF(bugs); GList *cc_list = rhbz_bug_cc(bug); xmlrpc_DECREF(bug); TS_ASSERT_STRING_EQ(g_list_nth_data(cc_list, 0), "dev1@example.com", "Checking updated bug cc list"); TS_ASSERT_STRING_EQ(g_list_nth_data(cc_list, 1), "dev2@example.com", "Checking updated bug cc list"); g_list_free_full(cc_list, g_free); } { rhbz_set_url(client, 1, "http://example.com/bug123", RHBZ_MINOR_UPDATE); xmlrpc_value *search = abrt_xmlrpc_call(client, "Bug.search", "{s:s,s:(ss)}", "quicksearch", "ALL product:\"Red Hat Enterprise Linux 8\" url:\"http://example.com/bug123\"", "include_fields", "id", "url"); xmlrpc_value *bugs = rhbz_get_member("bugs", search); xmlrpc_DECREF(search); xmlrpc_value *bug = rhbz_array_item_at(bugs, 0); xmlrpc_DECREF(bugs); g_autofree char *updated_url = (char *)rhbz_bug_read_item("url", bug, RHBZ_READ_STR); TS_ASSERT_STRING_EQ(updated_url, "http://example.com/bug123", "Checking updated bug url"); xmlrpc_DECREF(bug); } { xmlrpc_value *all_bugs = rhbz_search_duphash(client, "Red Hat Enterprise Linux 8", NULL, NULL, "abrt_hash:(null);"); TS_ASSERT_SIGNED_EQ(rhbz_array_size(all_bugs), 2); xmlrpc_DECREF(all_bugs); } { rhbz_close_as_duplicate(client, 1, 0, RHBZ_MINOR_UPDATE); xmlrpc_value *search = abrt_xmlrpc_call(client, "Bug.search", "{s:s,s:(ssss)}", "quicksearch", "ALL resolution:\"DUPLICATE\"", "include_fields", "id", "status", "resolution", "dupe_of"); xmlrpc_value *bugs = rhbz_get_member("bugs", search); xmlrpc_DECREF(search); xmlrpc_value *bug = rhbz_array_item_at(bugs, 0); xmlrpc_DECREF(bugs); char *status = (char *)rhbz_bug_read_item("status", bug, RHBZ_READ_STR); char *resolution = (char *)rhbz_bug_read_item("resolution", bug, RHBZ_READ_STR); int *dupe_of = (int *)rhbz_bug_read_item("dupe_of", bug, RHBZ_READ_INT); xmlrpc_DECREF(bug); TS_ASSERT_STRING_EQ(status, "CLOSED", "Checking closed bug status"); TS_ASSERT_STRING_EQ(resolution, "DUPLICATE", "Checking closed bug resolution"); TS_ASSERT_SIGNED_EQ(*dupe_of, 0); g_free(status); g_free(resolution); g_free(dupe_of); } { struct bug_info *my_bug = rhbz_bug_info(client, 0); TS_ASSERT_STRING_EQ(my_bug->bi_product, "Red Hat Enterprise Linux 8", "bug_info.bi_product"); TS_ASSERT_STRING_EQ(my_bug->bi_reporter, "captainnemo", "bug_info.bi_reporter"); TS_ASSERT_STRING_EQ(my_bug->bi_status, "NEW", "bug_info.bi_status"); TS_ASSERT_STRING_EQ(my_bug->bi_platform, "x86_64", "bug_info.bi_platform"); free_bug_info(my_bug); } { struct bug_info *my_bug = rhbz_bug_info(client, 1); struct bug_info *origin = rhbz_find_origin_bug_closed_duplicate(client, my_bug); TS_ASSERT_SIGNED_EQ(origin->bi_id, 0); free_bug_info(my_bug); free_bug_info(origin); } { rhbz_add_comment(client, 0, "some comment", 0); GList *comment_list = rhbz_comments(client, 0); TS_ASSERT_STRING_EQ(g_list_nth_data(comment_list, 0), "some comment", "Checking add_comment"); g_list_free_full(comment_list, g_free); } { rhbz_logout(client); } { xmlrpc_value *stop = abrt_xmlrpc_call(client, "Bugzilla.stop_server", "{}"); xmlrpc_DECREF(stop); } abrt_xmlrpc_free_client(client); } else // pid == -1 { printf("fork failed: %s\n", strerror(errno)); return 1; } } TS_RETURN_MAIN ]], [test "x$BUILD_BUGZILLA" != 'xyes'])