From 4d976e3c72a0e64ed4e8a8bc80188134abda2e63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Sun, 27 Dec 2015 14:47:08 +0100 Subject: [PATCH] test: Add test for isds_FindDataBox() --- test/simline/Makefile.am | 3 +- test/simline/isds_FindDataBox.c | 1287 ++++++++++++++++++++++----------------- test/simline/service.c | 354 ++++++++++- test/simline/services.h | 46 ++ 4 files changed, 1121 insertions(+), 569 deletions(-) rewrite test/simline/isds_FindDataBox.c (60%) diff --git a/test/simline/Makefile.am b/test/simline/Makefile.am index abdd1e3..5179eb3 100644 --- a/test/simline/Makefile.am +++ b/test/simline/Makefile.am @@ -18,7 +18,7 @@ if BUILD_CURL TESTS += basic_authentication hotp_authentication totp_authentication \ certificate_user_password_authentication \ isds_change_password isds_get_commercial_credit \ - isds_find_box_by_fulltext \ + isds_find_box_by_fulltext isds_FindDataBox \ hotp_isds_change_password totp_isds_change_password \ isds_delete_message_from_storage isds_ping isds_resign_message endif @@ -53,6 +53,7 @@ certificate_user_password_authentication_SOURCES = \ isds_change_password_SOURCES = isds_change_password.c $(common) isds_get_commercial_credit_SOURCES = isds_get_commercial_credit.c $(common) isds_find_box_by_fulltext_SOURCES = isds_find_box_by_fulltext.c $(common) +isds_FindDataBox_SOURCES = isds_FindDataBox.c $(common) hotp_isds_change_password_SOURCES = hotp_isds_change_password.c $(common) totp_isds_change_password_SOURCES = totp_isds_change_password.c $(common) isds_delete_message_from_storage_SOURCES = isds_delete_message_from_storage.c $(common) diff --git a/test/simline/isds_FindDataBox.c b/test/simline/isds_FindDataBox.c dissimilarity index 60% index a8e60e0..2b7fad7 100644 --- a/test/simline/isds_FindDataBox.c +++ b/test/simline/isds_FindDataBox.c @@ -1,556 +1,731 @@ -#ifndef _POSIX_SOURCE -#define _POSIX_SOURCE /* For getaddrinfo(3) */ -#endif - -#ifndef _BSD_SOURCE -#define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */ -#endif -#ifndef _DEFAULT_SOURCE -#define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */ -#endif - -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 600 /* For unsetenv(3) */ -#endif - -#include "../test.h" -#include "server.h" -#include "isds.h" - -static const char *username = "Doug1as$"; -static const char *password = "42aA#bc8"; - - -static int test_login(const isds_error error, struct isds_ctx *context, - const char *url, const char *username, const char *password, - const struct isds_pki_credentials *pki_credentials, - struct isds_otp *otp) { - isds_error err; - - err = isds_login(context, url, username, password, pki_credentials, otp); - if (error != err) - FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)", - isds_strerror(error), isds_strerror(err), - isds_long_message(context)); - - PASS_TEST; -} - -static int compare_match_lists(const char *label, - const char *expected_string, const struct isds_list *expected_list, - const char* string, const struct isds_list *list) { - const struct isds_list *expected_item, *item; - ptrdiff_t expected_offset, offset; - int i; - - for (i = 1, expected_item = expected_list, item = list; - NULL != expected_item && NULL != item; - i++, expected_item = expected_item->next, item = item->next) { - expected_offset = (char *)expected_item->data - expected_string; - offset = (char *)item->data - string; - if (expected_offset != offset) - FAIL_TEST("%d. %s match offsets differ: expected=%td, got=%td", - i, label, expected_offset, offset); - } - if (NULL != expected_item && NULL == item) - FAIL_TEST("%s match offsets list is missing %d. item", label, i); - if (NULL == expected_item && NULL != item) - FAIL_TEST("%s match offsets list has superfluous %d. item", label, i); - - return 0; -} - -static int compare_fulltext_results( - const struct isds_fulltext_result *expected_result, - const struct isds_fulltext_result *result) { - - TEST_POINTER_DUPLICITY(expected_result, result); - - TEST_STRING_DUPLICITY(expected_result->dbID, result->dbID); - TEST_INT_DUPLICITY(expected_result->dbType, result->dbType); - TEST_STRING_DUPLICITY(expected_result->name, result->name); - if (compare_match_lists("start name", - expected_result->name, expected_result->name_match_start, - result->name, result->name_match_start)) - return 1; - if (compare_match_lists("end name", - expected_result->name, expected_result->name_match_end, - result->name, result->name_match_end)) - return 1; - TEST_STRING_DUPLICITY(expected_result->address, result->address); - if (compare_match_lists("start address", - expected_result->address, expected_result->address_match_start, - result->address, result->address_match_start)) - return 1; - if (compare_match_lists("end address", - expected_result->address, expected_result->address_match_end, - result->address, result->address_match_end)) - return 1; - TEST_STRING_DUPLICITY(expected_result->ic, result->ic); - TEST_TMPTR_DUPLICITY(expected_result->biDate, result->biDate); - TEST_BOOLEAN_DUPLICITY(expected_result->dbEffectiveOVM, - result->dbEffectiveOVM); - TEST_BOOLEAN_DUPLICITY(expected_result->active, result->active); - TEST_BOOLEAN_DUPLICITY(expected_result->public_sending, - result->public_sending); - TEST_BOOLEAN_DUPLICITY(expected_result->commercial_sending, - result->commercial_sending); - return 0; -} - -static int compare_result_lists(const struct isds_list *expected_list, - const struct isds_list *list) { - const struct isds_list *expected_item, *item; - int i; - - for (i = 1, expected_item = expected_list, item = list; - NULL != expected_item && NULL != item; - i++, expected_item = expected_item->next, item = item->next) { - if (compare_fulltext_results( - (struct isds_fulltext_result *)expected_item->data, - (struct isds_fulltext_result *)item->data)) - return 1; - } - if (NULL != expected_item && NULL == item) - FAIL_TEST("Result list is missing %d. item", i); - if (NULL == expected_item && NULL != item) - FAIL_TEST("Result list has superfluous %d. item", i); - - return 0; -} - -struct test_destructor_argument { - unsigned long int *total_matching_boxes; - unsigned long int *current_page_beginning; - unsigned long int *current_page_size; - _Bool *last_page; - struct isds_list *results; -}; - -static void test_destructor(void *argument) { - if (NULL == argument) return; - free(((struct test_destructor_argument *)argument)->total_matching_boxes); - free(((struct test_destructor_argument *)argument)->current_page_beginning); - free(((struct test_destructor_argument *)argument)->current_page_size); - free(((struct test_destructor_argument *)argument)->last_page); - isds_list_free( - &((struct test_destructor_argument *)argument)->results - ); -} - -static int test_isds_find_box_by_fulltext(const isds_error expected_error, - struct isds_ctx *context, - const char *query, - const isds_fulltext_target *target, - const isds_DbType *box_type, - const unsigned long int *page_size, - const unsigned long int *page_number, - const _Bool *track_matches, - const unsigned long int *expected_total_matching_boxes, - const unsigned long int *expected_current_page_beginning, - const unsigned long int *expected_current_page_size, - const _Bool *expected_last_page, - const struct isds_list *expected_results) { - isds_error error; - struct test_destructor_argument allocated; - TEST_FILL_INT(allocated.total_matching_boxes); - TEST_FILL_INT(allocated.current_page_beginning); - TEST_FILL_INT(allocated.current_page_size); - TEST_FILL_INT(allocated.last_page); - TEST_CALLOC(allocated.results); - - error = isds_find_box_by_fulltext(context, - query, target, box_type, page_size, page_number, track_matches, - &allocated.total_matching_boxes, - &allocated.current_page_beginning, - &allocated.current_page_size, - &allocated.last_page, - &allocated.results); - TEST_DESTRUCTOR(test_destructor, &allocated); - - if (expected_error != error) { - FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)", - isds_strerror(expected_error), isds_strerror(error), - isds_long_message(context)); - } - - if (IE_SUCCESS != error) { - TEST_POINTER_IS_NULL(allocated.total_matching_boxes); - TEST_POINTER_IS_NULL(allocated.current_page_beginning); - TEST_POINTER_IS_NULL(allocated.current_page_size); - TEST_POINTER_IS_NULL(allocated.last_page); - TEST_POINTER_IS_NULL(allocated.results); - PASS_TEST; - } - - TEST_INTPTR_DUPLICITY(expected_total_matching_boxes, - allocated.total_matching_boxes); - TEST_INTPTR_DUPLICITY(expected_current_page_beginning, - allocated.current_page_beginning); - TEST_INTPTR_DUPLICITY(expected_current_page_size, - allocated.current_page_size); - TEST_BOOLEANPTR_DUPLICITY(expected_last_page, - allocated.last_page); - - if (compare_result_lists(expected_results, allocated.results)) - return 1; - - - PASS_TEST; -} - -int main(void) { - int error; - pid_t server_process; - struct isds_ctx *context = NULL; - - INIT_TEST("isds_find_box_by_fulltext"); - - if (unsetenv("http_proxy")) { - ABORT_UNIT("Could not remove http_proxy variable from environment\n"); - } - if (isds_init()) { - isds_cleanup(); - ABORT_UNIT("isds_init() failed\n"); - } - context = isds_ctx_create(); - if (!context) { - isds_cleanup(); - ABORT_UNIT("isds_ctx_create() failed\n"); - } - - { - /* Full response */ - char *url = NULL; - - struct isds_list name_match_start = { - .next = NULL, - .data = NULL, - .destructor = NULL - }; - struct isds_list name_match_end = { - .next = NULL, - .data = NULL, - .destructor = NULL - }; - struct isds_list address_match_start = { - .next = NULL, - .data = NULL, - .destructor = NULL - }; - struct isds_list address_match_end = { - .next = NULL, - .data = NULL, - .destructor = NULL - }; - struct isds_fulltext_result result = { - .dbID = "foo1234", - .dbType = DBTYPE_OVM, - .name = "Foo name", - .name_match_start = &name_match_start, - .name_match_end = &name_match_end, - .address = "Address foo", - .address_match_start = &address_match_start, - .address_match_end = &address_match_end, - .ic = "Foo IC", - .biDate = NULL, - .dbEffectiveOVM = 1, - .active = 1, - .public_sending = 1, - .commercial_sending = 1 - }; - name_match_start.data = &result.name[0]; - name_match_end.data = &result.name[3]; - address_match_start.data = &result.address[8]; - address_match_end.data = &result.address[11]; - struct server_db_result server_result = { - .id = "foo1234", - .type = "OVM", - .name = "|$*HL_START*$|Foo|$*HL_END*$| name", - .address = "Address |$*HL_START*$|foo|$*HL_END*$|", - .birth_date = NULL, - .ic = "Foo IC", - .ovm = 1, - .send_options = "ALL" - }; - const struct isds_list results = { - .next = NULL, - .data = &result, - .destructor = NULL - }; - const struct server_list server_results = { - .next = NULL, - .data = &server_result, - .destructor = NULL - }; - - - isds_fulltext_target target = FULLTEXT_ALL; - isds_DbType box_type = DBTYPE_SYSTEM; - long int search_page_number = 42; - long int search_page_size = 43; - _Bool search_highlighting_value = 1; - unsigned long int total_count = 44; - unsigned long int current_count = 1; - unsigned long int position = 43 * 42; - _Bool last_page = 1; - const struct arguments_DS_df_ISDSSearch2 service_arguments = { - .status_code = "0000", - .status_message = "Ok.", - .search_text = "foo", - .search_type = "GENERAL", - .search_scope = "ALL", - .search_page_number = &search_page_number, - .search_page_size = &search_page_size, - .search_highlighting_value = &search_highlighting_value, - .total_count = &total_count, - .current_count = ¤t_count, - .position = &position, - .last_page = &last_page, - .results_exists = 0, - .results = &server_results - }; - const struct service_configuration services[] = { - { SERVICE_DS_Dz_DummyOperation, NULL }, - { SERVICE_DS_df_ISDSSearch2, &service_arguments }, - { SERVICE_END, NULL } - }; - const struct arguments_basic_authentication server_arguments = { - .username = username, - .password = password, - .isds_deviations = 1, - .services = services - }; - error = start_server(&server_process, &url, - server_basic_authentication, &server_arguments, NULL); - if (error == -1) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - TEST("login", test_login, IE_SUCCESS, - context, url, username, password, NULL, NULL); - free(url); - - TEST("All data", test_isds_find_box_by_fulltext, IE_SUCCESS, - context, service_arguments.search_text, &target, &box_type, - (unsigned long int *)service_arguments.search_page_size, - (unsigned long int *)service_arguments.search_page_number, - service_arguments.search_highlighting_value, - service_arguments.total_count, - service_arguments.position, - service_arguments.current_count, - service_arguments.last_page, - &results); - - isds_logout(context); - if (stop_server(server_process)) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - } - - - { - /* Client must support DBTYPE_OVM_MAIN, send an empty reponse */ - char *url = NULL; - - isds_fulltext_target target = FULLTEXT_ALL; - isds_DbType box_type = DBTYPE_OVM_MAIN; - long int search_page_number = 42; - long int search_page_size = 43; - unsigned long int total_count = 0; - unsigned long int current_count = 0; - unsigned long int position = 43 * 42; - _Bool last_page = 1; - const struct arguments_DS_df_ISDSSearch2 service_arguments = { - .status_code = "0000", - .status_message = "No boxes match", - .search_text = "foo", - .search_type = "GENERAL", - .search_scope = "OVM_MAIN", - .search_page_number = &search_page_number, - .search_page_size = &search_page_size, - .search_highlighting_value = NULL, - .total_count = &total_count, - .current_count = ¤t_count, - .position = &position, - .last_page = &last_page, - .results_exists = 1, - .results = NULL - }; - const struct service_configuration services[] = { - { SERVICE_DS_Dz_DummyOperation, NULL }, - { SERVICE_DS_df_ISDSSearch2, &service_arguments }, - { SERVICE_END, NULL } - }; - const struct arguments_basic_authentication server_arguments = { - .username = username, - .password = password, - .isds_deviations = 1, - .services = services - }; - error = start_server(&server_process, &url, - server_basic_authentication, &server_arguments, NULL); - if (error == -1) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - TEST("login", test_login, IE_SUCCESS, - context, url, username, password, NULL, NULL); - free(url); - - TEST("DBTYPE_OVM_MAIN", test_isds_find_box_by_fulltext, IE_SUCCESS, - context, service_arguments.search_text, &target, &box_type, - (unsigned long int *)service_arguments.search_page_size, - (unsigned long int *)service_arguments.search_page_number, - service_arguments.search_highlighting_value, - service_arguments.total_count, - service_arguments.position, - service_arguments.current_count, - service_arguments.last_page, - NULL); - - isds_logout(context); - if (stop_server(server_process)) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - } - - - { - /* Empty response due to an error */ - char *url = NULL; - - long int search_page_number = 42; - long int search_page_size = 43; - const struct arguments_DS_df_ISDSSearch2 service_arguments = { - .status_code = "1156", - .status_message = "pageSize is too large", - .search_text = "foo", - .search_type = NULL, - .search_scope = NULL, - .search_page_number = &search_page_number, - .search_page_size = &search_page_size, - .search_highlighting_value = NULL, - .total_count = NULL, - .current_count = NULL, - .position = NULL, - .last_page = NULL, - .results_exists = 0, - .results = NULL - }; - const struct service_configuration services[] = { - { SERVICE_DS_Dz_DummyOperation, NULL }, - { SERVICE_DS_df_ISDSSearch2, &service_arguments }, - { SERVICE_END, NULL } - }; - const struct arguments_basic_authentication server_arguments = { - .username = username, - .password = password, - .isds_deviations = 1, - .services = services - }; - error = start_server(&server_process, &url, - server_basic_authentication, &server_arguments, NULL); - if (error == -1) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - TEST("login", test_login, IE_SUCCESS, - context, url, username, password, NULL, NULL); - free(url); - - TEST("No data", test_isds_find_box_by_fulltext, IE_2BIG, - context, service_arguments.search_text, NULL, NULL, - (unsigned long int *)service_arguments.search_page_size, - (unsigned long int *)service_arguments.search_page_number, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL); - - isds_logout(context); - if (stop_server(server_process)) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - } - - - { - /* Successful response without a mandatory element must be discarded - * by the client, otherwise a garbage would appear in the output - * arguments. */ - char *url = NULL; - - const struct arguments_DS_df_ISDSSearch2 service_arguments = { - .status_code = "0000", - .status_message = "totalCount is missing", - .search_text = "foo", - .search_type = NULL, - .search_scope = NULL, - .search_page_number = NULL, - .search_page_size = NULL, - .search_highlighting_value = NULL, - .total_count = NULL, - .current_count = NULL, - .position = NULL, - .last_page = NULL, - .results_exists = 0, - .results = NULL - }; - const struct service_configuration services[] = { - { SERVICE_DS_Dz_DummyOperation, NULL }, - { SERVICE_DS_df_ISDSSearch2, &service_arguments }, - { SERVICE_END, NULL } - }; - const struct arguments_basic_authentication server_arguments = { - .username = username, - .password = password, - .isds_deviations = 1, - .services = services - }; - error = start_server(&server_process, &url, - server_basic_authentication, &server_arguments, NULL); - if (error == -1) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - TEST("login", test_login, IE_SUCCESS, - context, url, username, password, NULL, NULL); - free(url); - - TEST("Missing totalCount in a response", test_isds_find_box_by_fulltext, - IE_SUCCESS, context, service_arguments.search_text, NULL, NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL); - - isds_logout(context); - if (stop_server(server_process)) { - isds_ctx_free(&context); - isds_cleanup(); - ABORT_UNIT(server_error); - } - } - - - isds_ctx_free(&context); - isds_cleanup(); - SUM_TEST(); -} +#ifndef _POSIX_SOURCE +#define _POSIX_SOURCE /* For getaddrinfo(3) */ +#endif + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */ +#endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */ +#endif + +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 /* For unsetenv(3) */ +#endif + +#include "../test.h" +#include "server.h" +#include "isds.h" + +static const char *username = "Doug1as$"; +static const char *password = "42aA#bc8"; + + +static int test_login(const isds_error error, struct isds_ctx *context, + const char *url, const char *username, const char *password, + const struct isds_pki_credentials *pki_credentials, + struct isds_otp *otp) { + isds_error err; + + err = isds_login(context, url, username, password, pki_credentials, otp); + if (error != err) + FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)", + isds_strerror(error), isds_strerror(err), + isds_long_message(context)); + + PASS_TEST; +} + +static int compare_isds_PersonName( + const struct isds_PersonName *expected_result, + const struct isds_PersonName *result) { + + TEST_POINTER_DUPLICITY(expected_result, result); + if (NULL == expected_result) + return 0; + + TEST_STRING_DUPLICITY(expected_result->pnFirstName, result->pnFirstName); + TEST_STRING_DUPLICITY(expected_result->pnMiddleName, result->pnMiddleName); + TEST_STRING_DUPLICITY(expected_result->pnLastName, result->pnLastName); + TEST_STRING_DUPLICITY(expected_result->pnLastNameAtBirth, + result->pnLastNameAtBirth); + + return 0; +}; + +static int compare_isds_BirthInfo( + const struct isds_BirthInfo *expected_result, + const struct isds_BirthInfo *result) { + + TEST_POINTER_DUPLICITY(expected_result, result); + if (NULL == expected_result) + return 0; + + TEST_TMPTR_DUPLICITY(expected_result->biDate, result->biDate); + TEST_STRING_DUPLICITY(expected_result->biCity, result->biCity); + TEST_STRING_DUPLICITY(expected_result->biCounty, result->biCounty); + TEST_STRING_DUPLICITY(expected_result->biState, result->biState); + + return 0; +}; + +static int compare_isds_Address( + const struct isds_Address *expected_result, + const struct isds_Address *result) { + + TEST_POINTER_DUPLICITY(expected_result, result); + if (NULL == expected_result) + return 0; + + TEST_INTPTR_DUPLICITY(expected_result->adCode, result->adCode); + TEST_STRING_DUPLICITY(expected_result->adCity, result->adCity); + TEST_STRING_DUPLICITY(expected_result->adDistrict, result->adDistrict); + TEST_STRING_DUPLICITY(expected_result->adStreet, result->adStreet); + TEST_STRING_DUPLICITY(expected_result->adNumberInStreet, + result->adNumberInStreet); + TEST_STRING_DUPLICITY(expected_result->adNumberInMunicipality, + result->adNumberInMunicipality); + TEST_STRING_DUPLICITY(expected_result->adZipCode, result->adZipCode); + TEST_STRING_DUPLICITY(expected_result->adState, result->adState); + + return 0; +}; + +static int compare_isds_DbOwnerInfo( + const struct isds_DbOwnerInfo *expected_result, + const struct isds_DbOwnerInfo *result) { + + TEST_POINTER_DUPLICITY(expected_result, result); + if (NULL == expected_result) + return 0; + + TEST_STRING_DUPLICITY(expected_result->dbID, result->dbID); + TEST_INTPTR_DUPLICITY(expected_result->dbType, result->dbType); + TEST_STRING_DUPLICITY(expected_result->ic, result->ic); + if (compare_isds_PersonName(expected_result->personName, + result->personName)) + return 1; + TEST_STRING_DUPLICITY(expected_result->firmName, result->firmName); + if (compare_isds_BirthInfo(expected_result->birthInfo, result->birthInfo)) + return 1; + if (compare_isds_Address(expected_result->address, result->address)) + return 1; + TEST_STRING_DUPLICITY(expected_result->nationality, result->nationality); + TEST_STRING_DUPLICITY(expected_result->email, result->email); + TEST_STRING_DUPLICITY(expected_result->telNumber, result->telNumber); + TEST_STRING_DUPLICITY(expected_result->identifier, result->identifier); + TEST_BOOLEAN_DUPLICITY(expected_result->aifoIsds, result->aifoIsds); + TEST_STRING_DUPLICITY(expected_result->registryCode, result->registryCode); + TEST_INTPTR_DUPLICITY(expected_result->dbState, result->dbState); + TEST_BOOLEANPTR_DUPLICITY(expected_result->dbEffectiveOVM, + result->dbEffectiveOVM); + TEST_BOOLEANPTR_DUPLICITY(expected_result->dbOpenAddressing, + result->dbOpenAddressing); + + return 0; +} + +static int compare_result_lists(const struct isds_list *expected_list, + const struct isds_list *list) { + const struct isds_list *expected_item, *item; + int i; + + for (i = 1, expected_item = expected_list, item = list; + NULL != expected_item && NULL != item; + i++, expected_item = expected_item->next, item = item->next) { + if (compare_isds_DbOwnerInfo( + (struct isds_DbOwnerInfo *)expected_item->data, + (struct isds_DbOwnerInfo *)item->data)) + return 1; + } + if (NULL != expected_item && NULL == item) + FAIL_TEST("Result list is missing %d. item", i); + if (NULL == expected_item && NULL != item) + FAIL_TEST("Result list has superfluous %d. item", i); + + return 0; +} + +static int test_isds_FindDataBox(const isds_error expected_error, + struct isds_ctx *context, + const struct isds_DbOwnerInfo *criteria, + const struct isds_list *expected_results) { + isds_error error; + struct isds_list *results; + TEST_CALLOC(results); + + error = isds_FindDataBox(context, criteria, &results); + TEST_DESTRUCTOR((void(*)(void*))isds_list_free, &results); + + if (expected_error != error) { + FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)", + isds_strerror(expected_error), isds_strerror(error), + isds_long_message(context)); + } + + if (IE_SUCCESS != error && IE_2BIG != error) { + TEST_POINTER_IS_NULL(results); + PASS_TEST; + } + + if (compare_result_lists(expected_results, results)) + return 1; + + + PASS_TEST; +} + +int main(void) { + int error; + pid_t server_process; + struct isds_ctx *context = NULL; + + INIT_TEST("isds_FindDataBox"); + + if (unsetenv("http_proxy")) { + ABORT_UNIT("Could not remove http_proxy variable from environment\n"); + } + if (isds_init()) { + isds_cleanup(); + ABORT_UNIT("isds_init() failed\n"); + } + context = isds_ctx_create(); + if (!context) { + isds_cleanup(); + ABORT_UNIT("isds_ctx_create() failed\n"); + } + + { + /* Full response with two results */ + char *url = NULL; + + struct isds_PersonName criteria_person_name = { + .pnFirstName = "CN1", + .pnMiddleName = "CN2", + .pnLastName = "CN3", + .pnLastNameAtBirth = "CN4" + }; + struct tm criteria_biDate = { + .tm_year = 4, + .tm_mon = 5, + .tm_mday = 6 + }; + struct isds_BirthInfo criteria_birth_info = { + .biDate = &criteria_biDate, + .biCity = "CB1", + .biCounty = "CB2", + .biState = "CB3" + }; + struct isds_Address criteria_address = { + .adCode = NULL, + .adCity = "CA1", + .adDistrict = "CA2", + .adStreet = "CA3", + .adNumberInStreet = "CA4", + .adNumberInMunicipality = "CA5", + .adZipCode = "CA6", + .adState = "CA7" + }; + isds_DbType criteria_dbType = DBTYPE_OVM; + long int criteria_dbState = 2; + _Bool criteria_dbEffectiveOVM = 1; + _Bool criteria_dbOpenAddressing = 1; + struct isds_DbOwnerInfo criteria = { + .dbID = "Cfoo123", + .dbType = &criteria_dbType, + .ic = "C1", + .personName = &criteria_person_name, + .firmName = "C2", + .birthInfo = &criteria_birth_info, + .address = &criteria_address, + .nationality = "C3", + .email = "C4", + .telNumber = "C5", + .identifier = "C6", + .aifoIsds = NULL, + .registryCode = "C7", + .dbState = &criteria_dbState, + .dbEffectiveOVM = &criteria_dbEffectiveOVM, + .dbOpenAddressing = &criteria_dbOpenAddressing + }; + struct server_owner_info server_criteria = { + .dbID = criteria.dbID, + .aifoIsds = NULL, + .dbType = "OVM", + .ic = criteria.ic, + .pnFirstName = criteria.personName->pnFirstName, + .pnMiddleName = criteria.personName->pnMiddleName, + .pnLastName = criteria.personName->pnLastName, + .pnLastNameAtBirth = criteria.personName->pnLastNameAtBirth, + .firmName = criteria.firmName, + .biDate = criteria.birthInfo->biDate, + .biCity = criteria.birthInfo->biCity, + .biCounty = criteria.birthInfo->biCounty, + .biState = criteria.birthInfo->biState, + .adCode = NULL, + .adCity = criteria.address->adCity, + .adDistrict = NULL, + .adStreet = criteria.address->adStreet, + .adNumberInStreet = criteria.address->adNumberInStreet, + .adNumberInMunicipality = criteria.address->adNumberInMunicipality, + .adZipCode = criteria.address->adZipCode, + .adState = criteria.address->adState, + .nationality = criteria.nationality, + .email = criteria.email, + .telNumber = criteria.telNumber, + .identifier = criteria.identifier, + .registryCode = criteria.registryCode, + .dbState = criteria.dbState, + .dbEffectiveOVM = criteria.dbEffectiveOVM, + .dbOpenAddressing = criteria.dbOpenAddressing + }; + + struct isds_PersonName person_name = { + .pnFirstName = "N1", + .pnMiddleName = "N2", + .pnLastName = "N3", + .pnLastNameAtBirth = "N4" + }; + struct tm biDate = { + .tm_year = 1, + .tm_mon = 2, + .tm_mday = 3 + }; + struct isds_BirthInfo birth_info = { + .biDate = &biDate, + .biCity = "B1", + .biCounty = "B2", + .biState = "B3" + }; + struct isds_Address address = { + .adCode = NULL, + .adCity = "A1", + .adDistrict = NULL, + .adStreet = "A3", + .adNumberInStreet = "A4", + .adNumberInMunicipality = "A5", + .adZipCode = "A6", + .adState = "A7" + }; + isds_DbType dbType = DBTYPE_OVM; + long int dbState = 2; + _Bool dbEffectiveOVM = 1; + _Bool dbOpenAddressing = 1; + struct isds_DbOwnerInfo result = { + .dbID = "foo1234", + .dbType = &dbType, + .ic = "1", + .personName = &person_name, + .firmName = "2", + .birthInfo = &birth_info, + .address = &address, + .nationality = "3", + .email = "4", + .telNumber = "5", + .identifier = "6", + .aifoIsds = NULL, + .registryCode = "7", + .dbState = &dbState, + .dbEffectiveOVM = &dbEffectiveOVM, + .dbOpenAddressing = &dbOpenAddressing + }; + struct isds_DbOwnerInfo result2 = { + 0 + }; + struct server_owner_info server_result = { + .dbID = result.dbID, + .aifoIsds = NULL, + .dbType = "OVM", + .ic = result.ic, + .pnFirstName = result.personName->pnFirstName, + .pnMiddleName = result.personName->pnMiddleName, + .pnLastName = result.personName->pnLastName, + .pnLastNameAtBirth = result.personName->pnLastNameAtBirth, + .firmName = result.firmName, + .biDate = result.birthInfo->biDate, + .biCity = result.birthInfo->biCity, + .biCounty = result.birthInfo->biCounty, + .biState = result.birthInfo->biState, + .adCode = NULL, + .adCity = result.address->adCity, + .adDistrict = NULL, + .adStreet = result.address->adStreet, + .adNumberInStreet = result.address->adNumberInStreet, + .adNumberInMunicipality = result.address->adNumberInMunicipality, + .adZipCode = result.address->adZipCode, + .adState = result.address->adState, + .nationality = result.nationality, + .email_exists = 1, + .email = result.email, + .telNumber_exists = 1, + .telNumber = result.telNumber, + .identifier = result.identifier, + .registryCode = result.registryCode, + .dbState = result.dbState, + .dbEffectiveOVM = result.dbEffectiveOVM, + .dbOpenAddressing = result.dbOpenAddressing + }; + struct server_owner_info server_result2 = { + 0 + }; + struct isds_list results2 = { + .next = NULL, + .data = &result2, + .destructor = NULL + }; + struct isds_list results = { + .next = &results2, + .data = &result, + .destructor = NULL + }; + struct server_list server_results2 = { + .next = NULL, + .data = &server_result2, + .destructor = NULL + }; + struct server_list server_results = { + .next = &server_results2, + .data = &server_result, + .destructor = NULL + }; + + const struct arguments_DS_df_FindDataBox service_arguments = { + .status_code = "0000", + .status_message = "Ok.", + .criteria = &server_criteria, + .results_exists = 0, + .results = &server_results + }; + const struct service_configuration services[] = { + { SERVICE_DS_Dz_DummyOperation, NULL }, + { SERVICE_DS_df_FindDataBox, &service_arguments }, + { SERVICE_END, NULL } + }; + const struct arguments_basic_authentication server_arguments = { + .username = username, + .password = password, + .isds_deviations = 1, + .services = services + }; + error = start_server(&server_process, &url, + server_basic_authentication, &server_arguments, NULL); + if (error == -1) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + TEST("login", test_login, IE_SUCCESS, + context, url, username, password, NULL, NULL); + free(url); + + TEST("All data", test_isds_FindDataBox, IE_SUCCESS, + context, &criteria, &results); + + isds_logout(context); + if (stop_server(server_process)) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + } + + { + /* Truncated response with one result */ + char *url = NULL; + + struct isds_DbOwnerInfo criteria = { + .dbID = "Cfoo123" + }; + struct server_owner_info server_criteria = { + .dbID = criteria.dbID + }; + + struct isds_PersonName person_name = { + .pnFirstName = "N1", + .pnMiddleName = "N2", + .pnLastName = "N3", + .pnLastNameAtBirth = "N4" + }; + struct tm biDate = { + .tm_year = 1, + .tm_mon = 2, + .tm_mday = 3 + }; + struct isds_BirthInfo birth_info = { + .biDate = &biDate, + .biCity = "B1", + .biCounty = "B2", + .biState = "B3" + }; + struct isds_Address address = { + .adCode = NULL, + .adCity = "A1", + .adDistrict = NULL, + .adStreet = "A3", + .adNumberInStreet = "A4", + .adNumberInMunicipality = "A5", + .adZipCode = "A6", + .adState = "A7" + }; + isds_DbType dbType = DBTYPE_OVM; + long int dbState = 2; + _Bool dbEffectiveOVM = 1; + _Bool dbOpenAddressing = 1; + struct isds_DbOwnerInfo result = { + .dbID = "foo1234", + .dbType = &dbType, + .ic = "1", + .personName = &person_name, + .firmName = "2", + .birthInfo = &birth_info, + .address = &address, + .nationality = "3", + .email = "4", + .telNumber = "5", + .identifier = "6", + .aifoIsds = NULL, + .registryCode = "7", + .dbState = &dbState, + .dbEffectiveOVM = &dbEffectiveOVM, + .dbOpenAddressing = &dbOpenAddressing + }; + struct server_owner_info server_result = { + .dbID = result.dbID, + .aifoIsds = NULL, + .dbType = "OVM", + .ic = result.ic, + .pnFirstName = result.personName->pnFirstName, + .pnMiddleName = result.personName->pnMiddleName, + .pnLastName = result.personName->pnLastName, + .pnLastNameAtBirth = result.personName->pnLastNameAtBirth, + .firmName = result.firmName, + .biDate = result.birthInfo->biDate, + .biCity = result.birthInfo->biCity, + .biCounty = result.birthInfo->biCounty, + .biState = result.birthInfo->biState, + .adCode = NULL, + .adCity = result.address->adCity, + .adDistrict = NULL, + .adStreet = result.address->adStreet, + .adNumberInStreet = result.address->adNumberInStreet, + .adNumberInMunicipality = result.address->adNumberInMunicipality, + .adZipCode = result.address->adZipCode, + .adState = result.address->adState, + .nationality = result.nationality, + .email_exists = 1, + .email = result.email, + .telNumber_exists = 1, + .telNumber = result.telNumber, + .identifier = result.identifier, + .registryCode = result.registryCode, + .dbState = result.dbState, + .dbEffectiveOVM = result.dbEffectiveOVM, + .dbOpenAddressing = result.dbOpenAddressing + }; + struct isds_list results = { + .next = NULL, + .data = &result, + .destructor = NULL + }; + struct server_list server_results = { + .next = NULL, + .data = &server_result, + .destructor = NULL + }; + + const struct arguments_DS_df_FindDataBox service_arguments = { + .status_code = "0003", + .status_message = "Answer was truncated", + .criteria = &server_criteria, + .results_exists = 0, + .results = &server_results + }; + const struct service_configuration services[] = { + { SERVICE_DS_Dz_DummyOperation, NULL }, + { SERVICE_DS_df_FindDataBox, &service_arguments }, + { SERVICE_END, NULL } + }; + const struct arguments_basic_authentication server_arguments = { + .username = username, + .password = password, + .isds_deviations = 1, + .services = services + }; + error = start_server(&server_process, &url, + server_basic_authentication, &server_arguments, NULL); + if (error == -1) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + TEST("login", test_login, IE_SUCCESS, + context, url, username, password, NULL, NULL); + free(url); + + TEST("Truncated asnwer", test_isds_FindDataBox, IE_2BIG, + context, &criteria, &results); + + isds_logout(context); + if (stop_server(server_process)) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + } + + + + { + /* Client must refuse DBTYPE_OVM_MAIN and DBTYPE_SYSTEM */ + char *url = NULL; + + isds_DbType criteria_dbType = DBTYPE_OVM_MAIN; + struct isds_DbOwnerInfo criteria = { + .dbType = &criteria_dbType + }; + + const struct service_configuration services[] = { + { SERVICE_DS_Dz_DummyOperation, NULL }, + { SERVICE_END, NULL } + }; + const struct arguments_basic_authentication server_arguments = { + .username = username, + .password = password, + .isds_deviations = 1, + .services = services + }; + error = start_server(&server_process, &url, + server_basic_authentication, &server_arguments, NULL); + if (error == -1) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + TEST("login", test_login, IE_SUCCESS, + context, url, username, password, NULL, NULL); + free(url); + + TEST("Invalid DBTYPE_OVM_MAIN", test_isds_FindDataBox, IE_ENUM, + context, &criteria, NULL); + + criteria_dbType = DBTYPE_SYSTEM; + TEST("Invalid DBTYPE_SYSTEM", test_isds_FindDataBox, IE_ENUM, + context, &criteria, NULL); + + isds_logout(context); + if (stop_server(server_process)) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + } + + { + /* Report 0002 server error as IE_NOEXIST */ + char *url = NULL; + + struct isds_DbOwnerInfo criteria = { + .dbID = "Cfoo123" + }; + struct server_owner_info server_criteria = { + .dbID = criteria.dbID + }; + + const struct arguments_DS_df_FindDataBox service_arguments = { + .status_code = "0002", + .status_message = "No such box", + .criteria = &server_criteria, + .results_exists = 0, + .results = NULL + }; + const struct service_configuration services[] = { + { SERVICE_DS_Dz_DummyOperation, NULL }, + { SERVICE_DS_df_FindDataBox, &service_arguments }, + { SERVICE_END, NULL } + }; + const struct arguments_basic_authentication server_arguments = { + .username = username, + .password = password, + .isds_deviations = 1, + .services = services + }; + error = start_server(&server_process, &url, + server_basic_authentication, &server_arguments, NULL); + if (error == -1) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + TEST("login", test_login, IE_SUCCESS, + context, url, username, password, NULL, NULL); + free(url); + + TEST("Report 0002 server error as IE_NOEXIST", test_isds_FindDataBox, + IE_NOEXIST, context, &criteria, NULL); + + isds_logout(context); + if (stop_server(server_process)) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + } + + { + /* Report 5001 server error as IE_NOEXIST */ + char *url = NULL; + + struct isds_DbOwnerInfo criteria = { + .dbID = "Cfoo123" + }; + struct server_owner_info server_criteria = { + .dbID = criteria.dbID + }; + + const struct arguments_DS_df_FindDataBox service_arguments = { + .status_code = "5001", + .status_message = "No such box", + .criteria = &server_criteria, + .results_exists = 0, + .results = NULL + }; + const struct service_configuration services[] = { + { SERVICE_DS_Dz_DummyOperation, NULL }, + { SERVICE_DS_df_FindDataBox, &service_arguments }, + { SERVICE_END, NULL } + }; + const struct arguments_basic_authentication server_arguments = { + .username = username, + .password = password, + .isds_deviations = 1, + .services = services + }; + error = start_server(&server_process, &url, + server_basic_authentication, &server_arguments, NULL); + if (error == -1) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + TEST("login", test_login, IE_SUCCESS, + context, url, username, password, NULL, NULL); + free(url); + + TEST("Report 0002 server error as IE_NOEXIST", test_isds_FindDataBox, + IE_NOEXIST, context, &criteria, NULL); + + isds_logout(context); + if (stop_server(server_process)) { + isds_ctx_free(&context); + isds_cleanup(); + ABORT_UNIT(server_error); + } + } + + + + + isds_ctx_free(&context); + isds_cleanup(); + SUM_TEST(); +} diff --git a/test/simline/service.c b/test/simline/service.c index 644ba0e..25ef43e 100644 --- a/test/simline/service.c +++ b/test/simline/service.c @@ -279,6 +279,42 @@ static http_error element_exists(const char **code, char **message, } +/* Locate a children element. + * @code is a static output ISDS error code + * @error_message is a reallocated output ISDS error message + * @xpath_ctx is a current XPath context + * @element_name is name of an element to select + * @node is output pointer to located element node + * @return HTTP_ERROR_SUCCESS or an appropriate error code. */ +static http_error select_element(const char **code, char **message, + xmlXPathContextPtr xpath_ctx, const char *element_name, + xmlNodePtr *node) { + xmlXPathObjectPtr result = NULL; + + result = xmlXPathEvalExpression(BAD_CAST element_name, xpath_ctx); + if (NULL == result) { + return HTTP_ERROR_SERVER; + } + if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { + xmlXPathFreeObject(result); + *code = "9999"; + test_asprintf(message, "Element %s does not exist", element_name); + return HTTP_ERROR_CLIENT; + } else { + if (result->nodesetval->nodeNr > 1) { + xmlXPathFreeObject(result); + *code = "9999"; + test_asprintf(message, "Multiple %s element", element_name); + return HTTP_ERROR_CLIENT; + } + } + *node = result->nodesetval->nodeTab[0]; + xmlXPathFreeObject(result); + + return HTTP_ERROR_SUCCESS; +} + + /* Extract @element_name's value as a string. * @code is a static output ISDS error code * @error_message is a reallocated output ISDS error message @@ -327,6 +363,18 @@ leave: } +/* Compare dates represented by pointer to struct tm. + * @return 0 if equalued, non-0 otherwise. */ +static int datecmp(const struct tm *a, const struct tm *b) { + if (NULL == a && b == NULL) return 0; + if ((NULL == a && b != NULL) || (NULL != a && b == NULL)) return 1; + if (a->tm_year != b->tm_year) return 1; + if (a->tm_mon != b->tm_mon) return 1; + if (a->tm_mday != b->tm_mday) return 1; + return 0; +} + + /* Checks an @element_name's value is an @expected_value string. * @code is a static output ISDS error code * @error_message is a reallocated output ISDS error message @@ -541,6 +589,77 @@ leave: } +/* Checks an @element_name's value is an @expected_value date. + * @code is a static output ISDS error code + * @error_message is an reallocated output ISDS error message + * @xpath_ctx is a current XPath context + * @element_name is name of a element to check + * @must_exist is true if the @element_name must exist even if @expected_value + * is NULL. + * @expected_value is an expected boolean value + * @return HTTP_ERROR_SUCCESS if the @element_name element's value is + * @expected_value. HTTP_ERROR_CLIENT if not equaled, HTTP_ERROR_SERVER if an + * internal error occured. */ +static http_error element_equals_date(const char **code, char **message, + xmlXPathContextPtr xpath_ctx, const char *element_name, + _Bool must_exist, const struct tm *expected_value) { + http_error error = HTTP_ERROR_SUCCESS; + char *string = NULL; + struct tm value; + + if (must_exist) { + error = element_exists(code, message, xpath_ctx, element_name, 0); + if (HTTP_ERROR_SUCCESS != error) + goto leave; + } + + error = extract_string(code, message, xpath_ctx, element_name, &string); + if (HTTP_ERROR_SUCCESS != error) + goto leave; + + if (NULL != expected_value) { + if (NULL == string) { + *code = "9999"; + test_asprintf(message, "Empty %s element", element_name); + error = HTTP_ERROR_CLIENT; + goto leave; + } + error = _server_datestring2tm(string, &value); + if (error) { + if (error == HTTP_ERROR_CLIENT) { \ + test_asprintf(message, "%s value is not a valid date: %s", + element_name, string); + } + goto leave; + } + if (datecmp(expected_value, &value)) { + *code = "9999"; + test_asprintf(message, "Unexpected %s element value: " + "expected=%d-%02d-%02d, got=%d-%02d-%02d", element_name, + expected_value->tm_year + 1900, expected_value->tm_mon + 1, + expected_value->tm_mday, + value.tm_year + 1900, value.tm_mon + 1, value.tm_mday); + error = HTTP_ERROR_CLIENT; + goto leave; + } + } else { + if (NULL != string && *string != '\0') { + *code = "9999"; + test_asprintf(message, + "Unexpected %s element value: " + "expected empty value, got=`%s'", + element_name, string); + error = HTTP_ERROR_CLIENT; + goto leave; + } + } + +leave: + free(string); + return error; +} + + /* Insert dmStatus or similar subtree * @parent is element to insert to * @dm is true for dmStatus, otherwise dbStatus @@ -610,18 +729,6 @@ static http_error timeval2timestring(const struct timeval *time, } -/* Compare dates represented by pointer to struct tm. - * @return 0 if equalued, non-0 otherwise. */ -static int datecmp(const struct tm *a, const struct tm *b) { - if (NULL == a && b == NULL) return 0; - if ((NULL == a && b != NULL) || (NULL != a && b == NULL)) return 1; - if (a->tm_year != b->tm_year) return 1; - if (a->tm_mon != b->tm_mon) return 1; - if (a->tm_mday != b->tm_mday) return 1; - return 0; -} - - /* Implement DummyOperation */ static http_error service_DummyOperation( xmlXPathContextPtr xpath_ctx, @@ -944,6 +1051,226 @@ leave: } +/* Insert list of search results as XSD:tDbOwnersArray XML tree. + * @isds_response is XML node with the response + * @results is list of struct server_owner_info *. + * @create_empty_root is true to create dbResults element even if @results is + * empty. */ +static http_error insert_tDbOwnersArray(xmlNodePtr isds_response, + const struct server_list *results, _Bool create_empty_root) { + http_error error = HTTP_ERROR_SUCCESS; + xmlNodePtr root, entry; + + if (NULL == isds_response) return HTTP_ERROR_SERVER; + + if (NULL != results || create_empty_root) + INSERT_ELEMENT(root, isds_response, "dbResults"); + + if (NULL == results) return HTTP_ERROR_SUCCESS; + + for (const struct server_list *item = results; NULL != item; + item = item->next) { + const struct server_owner_info *result = + (struct server_owner_info *)item->data; + + INSERT_ELEMENT(entry, root, "dbOwnerInfo"); + if (NULL == result) continue; + + INSERT_STRING(entry, "dbID", result->dbID); + /* Ignore aifoIsds */ + INSERT_STRING(entry, "dbType", result->dbType); + INSERT_STRING(entry, "ic", result->ic); + INSERT_STRING(entry, "pnFirstName", result->pnFirstName); + INSERT_STRING(entry, "pnMiddleName", result->pnMiddleName); + INSERT_STRING(entry, "pnLastName", result->pnLastName); + INSERT_STRING(entry, "pnLastNameAtBirth", result->pnLastNameAtBirth); + INSERT_STRING(entry, "firmName", result->firmName); + INSERT_TMPTR(entry, "biDate", result->biDate); + INSERT_STRING(entry, "biCity", result->biCity); + INSERT_STRING(entry, "biCounty", result->biCounty); + INSERT_STRING(entry, "biState", result->biState); + /* Ignore adCode */ + INSERT_STRING(entry, "adCity", result->adCity); + /* Ignore adDistrict */ + INSERT_STRING(entry, "adStreet", result->adStreet); + INSERT_STRING(entry, "adNumberInStreet", result->adNumberInStreet); + INSERT_STRING(entry, "adNumberInMunicipality", + result->adNumberInMunicipality); + INSERT_STRING(entry, "adZipCode", result->adZipCode); + INSERT_STRING(entry, "adState", result->adState); + INSERT_STRING(entry, "nationality", result->nationality); + if (result->email_exists || result->email != NULL) { + INSERT_STRING(entry, "email", result->email); + } + if (result->telNumber_exists || result->telNumber != NULL) { + INSERT_STRING(entry, "telNumber", result->telNumber); + } + INSERT_STRING(entry, "identifier", result->identifier); + INSERT_STRING(entry, "registryCode", result->registryCode); + INSERT_LONGINTPTR(entry, "dbState", result->dbState); + INSERT_BOOLEANPTR(entry, "dbEffectiveOVM", result->dbEffectiveOVM); + INSERT_BOOLEANPTR(entry, "dbOpenAddressing", result->dbOpenAddressing); + } + +leave: + return error; +} + + +/* Implement FindDataBox. + * @arguments is pointer to struct arguments_DS_df_FindDataBox */ +static http_error service_FindDataBox( + xmlXPathContextPtr xpath_ctx, + xmlNodePtr isds_response, + const void *arguments) { + http_error error = HTTP_ERROR_SUCCESS; + const char *code = "9999"; + char *message = NULL; + const struct arguments_DS_df_FindDataBox *configuration = + (const struct arguments_DS_df_FindDataBox *)arguments; + char *string = NULL; + xmlNodePtr node; + + if (NULL == configuration || NULL == configuration->status_code || + NULL == configuration->status_message) { + error = HTTP_ERROR_SERVER; + goto leave; + } + + /* Check request */ + error = select_element(&code, &message, xpath_ctx, "isds:dbOwnerInfo", + &node); + if (error) goto leave; + xpath_ctx->node = node; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:dbID", 1, configuration->criteria->dbID); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:dbType", 1, configuration->criteria->dbType); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:ic", 1, configuration->criteria->ic); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:pnFirstName", 1, configuration->criteria->pnFirstName); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:pnMiddleName", 1, configuration->criteria->pnMiddleName); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:pnLastName", 1, configuration->criteria->pnLastName); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:pnLastNameAtBirth", 1, configuration->criteria->pnLastNameAtBirth); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:firmName", 1, configuration->criteria->firmName); + if (error) goto leave; + + error = element_equals_date(&code, &message, xpath_ctx, + "isds:biDate", 1, configuration->criteria->biDate); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:biCity", 1, configuration->criteria->biCity); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:biCounty", 1, configuration->criteria->biCounty); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:biState", 1, configuration->criteria->biState); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:adCity", 1, configuration->criteria->adCity); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:adStreet", 1, configuration->criteria->adStreet); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:adNumberInStreet", 1, + configuration->criteria->adNumberInStreet); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:adNumberInMunicipality", 1, + configuration->criteria->adNumberInMunicipality); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:adZipCode", 1, configuration->criteria->adZipCode); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:adState", 1, configuration->criteria->adState); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:nationality", 1, configuration->criteria->nationality); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:email", 0, configuration->criteria->email); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:telNumber", 0, configuration->criteria->telNumber); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:identifier", 1, configuration->criteria->identifier); + if (error) goto leave; + + error = element_equals_string(&code, &message, xpath_ctx, + "isds:registryCode", 1, configuration->criteria->registryCode); + if (error) goto leave; + + error = element_equals_integer(&code, &message, xpath_ctx, + "isds:dbState", 1, configuration->criteria->dbState); + if (error) goto leave; + + error = element_equals_boolean(&code, &message, xpath_ctx, + "isds:dbEffectiveOVM", 1, configuration->criteria->dbEffectiveOVM); + if (error) goto leave; + + error = element_equals_boolean(&code, &message, xpath_ctx, + "isds:dbOpenAddressing", 1, + configuration->criteria->dbOpenAddressing); + if (error) goto leave; + + /* Build response */ + if ((error = insert_tDbOwnersArray(isds_response, configuration->results, + configuration->results_exists))) { + goto leave; + } + + code = configuration->status_code; + message = strdup(configuration->status_message); + +leave: + if (HTTP_ERROR_SERVER != error) { + http_error next_error = insert_isds_status(isds_response, 0, + BAD_CAST code, BAD_CAST message, NULL); + if (HTTP_ERROR_SUCCESS != next_error) error = next_error; + } + free(string); + free(message); + return error; +} + + /* Implement ISDSSearch2. * @arguments is pointer to struct arguments_DS_df_ISDSSearch2 */ static http_error service_ISDSSearch2( @@ -1284,6 +1611,9 @@ static struct service services[] = { { SERVICE_DS_df_DataBoxCreditInfo, "DS/df", BAD_CAST ISDS_NS, BAD_CAST "DataBoxCreditInfo", service_DataBoxCreditInfo }, + { SERVICE_DS_df_FindDataBox, + "DS/df", BAD_CAST ISDS_NS, BAD_CAST "FindDataBox", + service_FindDataBox }, { SERVICE_DS_df_ISDSSearch2, "DS/df", BAD_CAST ISDS_NS, BAD_CAST "ISDSSearch2", service_ISDSSearch2 }, diff --git a/test/simline/services.h b/test/simline/services.h index e1b09e3..1eb2ab9 100644 --- a/test/simline/services.h +++ b/test/simline/services.h @@ -10,6 +10,7 @@ typedef enum { SERVICE_asws_changePassword_ChangePasswordOTP, SERVICE_asws_changePassword_SendSMSCode, SERVICE_DS_df_DataBoxCreditInfo, + SERVICE_DS_df_FindDataBox, SERVICE_DS_df_ISDSSearch2, SERVICE_DS_DsManage_ChangeISDSPassword, SERVICE_DS_Dx_EraseMessage, @@ -102,6 +103,41 @@ struct server_db_result { char *send_options; /* dbSendOptions value */ }; +/* Union of tdbOwnerInfo and tdbPersonalOwnerInfo XSD types */ +struct server_owner_info { + char *dbID; + _Bool *aifoIsds; + char *dbType; + char *ic; + char *pnFirstName; + char *pnMiddleName; + char *pnLastName; + char *pnLastNameAtBirth; + char *firmName; + struct tm *biDate; + char *biCity; + char *biCounty; + char *biState; + long int *adCode; + char *adCity; + char *adDistrict; + char *adStreet; + char *adNumberInStreet; + char *adNumberInMunicipality; + char *adZipCode; + char *adState; + char *nationality; + _Bool email_exists; /* Return empty email element */ + char *email; + _Bool telNumber_exists; /* Return empty telNumber element */ + char *telNumber; + char *identifier; + char *registryCode; + long int *dbState; + _Bool *dbEffectiveOVM; + _Bool *dbOpenAddressing; +}; + /* General linked list */ struct server_list { struct server_list *next; /* Next list item, @@ -122,6 +158,16 @@ struct arguments_DS_df_DataBoxCreditInfo { const struct server_list *history; /* Return this ciRecords */ }; +struct arguments_DS_df_FindDataBox { + const char *status_code; + const char *status_message; + const struct server_owner_info *criteria; /* generilized tDbOwnerInfo */ + const _Bool results_exists; /* Return dbResults element */ + const struct server_list *results; /* Return list of + struct server_owner_info * as + dbResults */ +}; + struct arguments_DS_df_ISDSSearch2 { const char *status_code; const char *status_message; -- 2.11.4.GIT