END_TEST START_TEST(test_service_present) { qeo_mgmt_url_ctx_t ctx = NULL; char* message = NULL; const char *url = NULL; qeo_mgmt_client_ctx_t mg_ctx; fail_if(s_ctx == NULL); message = get_services_messages(0); qeo_log_i("Testing message <%s>", message); curl_easy_mock_return_data(message, false); ctx = qeo_mgmt_url_init(s_ctx); mg_ctx.url_ctx = ctx; mg_ctx.curl_ctx = s_ctx; fail_if(ctx == NULL ); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_ENROLL_DEVICE, &url) == QMGMTCLIENT_OK); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_CHECK_POLICY, &url) == QMGMTCLIENT_OK); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_GET_POLICY, &url) == QMGMTCLIENT_OK); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_REGISTER_FORWARDER, &url) == QMGMTCLIENT_OK); qeo_mgmt_url_cleanup(ctx); message = get_services_messages(1); qeo_log_i("Testing message <%s>", message); curl_easy_mock_return_data(message, false); ctx = qeo_mgmt_url_init(s_ctx); mg_ctx.url_ctx = ctx; fail_if(ctx == NULL ); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_ENROLL_DEVICE, &url) == QMGMTCLIENT_OK); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_CHECK_POLICY, &url) == QMGMTCLIENT_EBADSERVICE); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_GET_POLICY, &url) == QMGMTCLIENT_OK); fail_unless(qeo_mgmt_url_get(&mg_ctx, mock_qeo_mgmt_client_ssl_ctx_cb, NULL, "blabla", QMGMT_URL_REGISTER_FORWARDER, &url) == QMGMTCLIENT_OK); qeo_mgmt_url_cleanup(ctx); }
END_TEST START_TEST(test_get_forwarders_detailed) { _forwarder_cb_helper helper = {0}; char* message = get_success_list_fwds(3); curl_easy_mock_clean(); curl_easy_mock_return_data(message, true); curl_easy_mock_ignore_and_return(CURLE_OK, true, CURLE_OK, CURLE_OK, CURLE_OK); ck_assert_int_eq(qeo_mgmt_client_get_forwarders_sync(s_ctx, TEST_URL, my_fwd_cb, (void*)&helper, my_ssl_cb, (void*)COOKIE_MAGIC_NUMBER), QMGMTCLIENT_OK); ck_assert_int_eq(helper.nrForwarders, 4); fail_unless(helper.forwarders[0]->deviceID == 1); fail_unless(helper.forwarders[0]->nrOfLocators == 2); fail_unless(helper.forwarders[0]->locators[0].port == 7400); fail_unless(helper.forwarders[0]->locators[0].type == QMGMT_LOCATORTYPE_TCPV4); fail_unless(strcmp(helper.forwarders[0]->locators[0].address, "212.118.224.153") == 0); fail_unless(helper.forwarders[0]->locators[1].port == 111); fail_unless(helper.forwarders[0]->locators[1].type == QMGMT_LOCATORTYPE_UDPV4); fail_unless(strcmp(helper.forwarders[0]->locators[1].address, "212.118.224.152") == 0); fail_unless(helper.forwarders[1]->deviceID == 2); fail_unless(helper.forwarders[1]->nrOfLocators == 1); fail_unless(helper.forwarders[1]->locators[0].port == 8080); fail_unless(helper.forwarders[1]->locators[0].type == QMGMT_LOCATORTYPE_UDPV6); fail_unless(strcmp(helper.forwarders[1]->locators[0].address, "fe80::250:bfff:feb7:c61e") == 0); free(helper.forwarders); }
static void list_forwarders_and_expect_error(qeo_mgmt_client_retcode_t expected, char* message, int line){ _forwarder_cb_helper helper = {0}; int i = 0; qeo_log_i("Testing message <%s> at line <%d>", message, line); curl_easy_mock_clean(); curl_easy_mock_return_data(message, true); curl_easy_mock_ignore_and_return(CURLE_OK, true, CURLE_OK, CURLE_OK, CURLE_OK); ck_assert_int_eq(qeo_mgmt_client_get_forwarders_sync(s_ctx, TEST_URL, my_fwd_cb, (void*)&helper, my_ssl_cb, (void*)COOKIE_MAGIC_NUMBER), expected); for (i = 0; i < helper.nrForwarders; ++i) { qeo_mgmt_client_free_forwarder(helper.forwarders[i]); } free(helper.forwarders); }
static void list_forwarders_and_expect_async(int nrForwarders, char* message, int line){ _forwarder_cb_helper helper = {0}; int i = 0; qeo_log_i("Testing message <%s> at line <%d> using async api", message, line); curl_easy_mock_clean(); curl_easy_mock_return_data(message, true); curl_easy_mock_ignore_and_return(CURLE_OK, true, CURLE_OK, CURLE_OK, CURLE_OK); ck_assert_int_eq(qeo_mgmt_client_get_forwarders(s_ctx, TEST_URL, my_fwd_cb, my_result_cb, (void*)&helper, my_ssl_cb, (void*)COOKIE_MAGIC_NUMBER), QMGMTCLIENT_OK); pthread_cond_wait(&s_cond, &s_mutex); ck_assert_int_eq(helper.nrForwarders, nrForwarders); for (i = 0; i < helper.nrForwarders; ++i) { qeo_mgmt_client_free_forwarder(helper.forwarders[i]); } free(helper.forwarders); }
END_TEST START_TEST(test_error_json) { int id = 0; qeo_mgmt_url_ctx_t ctx = NULL; qeo_mgmt_client_ctx_t mg_ctx; char* message = NULL; const char *url = NULL; fail_if(s_ctx == NULL); while ((message = get_error_messages(id))){ id++; qeo_log_i("Testing message <%s>", message); curl_easy_mock_return_data(message, false); ctx = qeo_mgmt_url_init(s_ctx); mg_ctx.url_ctx = ctx; mg_ctx.curl_ctx = s_ctx; fail_if(ctx == NULL); fail_if(qeo_mgmt_url_get(&mg_ctx, NULL, NULL, "blabla", QMGMT_URL_ENROLL_DEVICE, &url) == QMGMTCLIENT_OK); qeo_mgmt_url_cleanup(ctx); } }