test: Fix indentation
[libisds.git] / test / simline / isds_FindDataBox.c
blobc5a54d2a73a5502d25d1143228c74a87bc8967fa
1 #ifndef _POSIX_SOURCE
2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
3 #endif
5 #ifndef _BSD_SOURCE
6 #define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */
7 #endif
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */
10 #endif
12 #ifndef _XOPEN_SOURCE
13 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
14 #endif
16 #include "../test.h"
17 #include "test_DbOwnerInfo.h"
18 #include "server.h"
19 #include "isds.h"
21 static const char *username = "Doug1as$";
22 static const char *password = "42aA#bc8";
25 static int test_login(const isds_error error, struct isds_ctx *context,
26 const char *url, const char *username, const char *password,
27 const struct isds_pki_credentials *pki_credentials,
28 struct isds_otp *otp) {
29 isds_error err;
31 err = isds_login(context, url, username, password, pki_credentials, otp);
32 if (error != err)
33 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
34 isds_strerror(error), isds_strerror(err),
35 isds_long_message(context));
37 PASS_TEST;
40 static int test_isds_FindDataBox(const isds_error expected_error,
41 struct isds_ctx *context,
42 const struct isds_DbOwnerInfo *criteria,
43 const struct isds_list *expected_results) {
44 isds_error error;
45 struct isds_list *results;
46 TEST_CALLOC(results);
48 error = isds_FindDataBox(context, criteria, &results);
49 TEST_DESTRUCTOR((void(*)(void*))isds_list_free, &results);
51 if (expected_error != error) {
52 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
53 isds_strerror(expected_error), isds_strerror(error),
54 isds_long_message(context));
57 if (IE_SUCCESS != error && IE_2BIG != error) {
58 TEST_POINTER_IS_NULL(results);
59 PASS_TEST;
62 if (compare_isds_DbOwnerInfo_lists(expected_results, results))
63 return 1;
66 PASS_TEST;
69 int main(void) {
70 int error;
71 pid_t server_process;
72 struct isds_ctx *context = NULL;
74 INIT_TEST("isds_FindDataBox");
76 if (unsetenv("http_proxy")) {
77 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
79 if (isds_init()) {
80 isds_cleanup();
81 ABORT_UNIT("isds_init() failed\n");
83 context = isds_ctx_create();
84 if (!context) {
85 isds_cleanup();
86 ABORT_UNIT("isds_ctx_create() failed\n");
90 /* Full response with two results */
91 char *url = NULL;
93 struct isds_PersonName criteria_person_name = {
94 .pnFirstName = "CN1",
95 .pnMiddleName = "CN2",
96 .pnLastName = "CN3",
97 .pnLastNameAtBirth = "CN4"
99 struct tm criteria_biDate = {
100 .tm_year = 4,
101 .tm_mon = 5,
102 .tm_mday = 6
104 struct isds_BirthInfo criteria_birth_info = {
105 .biDate = &criteria_biDate,
106 .biCity = "CB1",
107 .biCounty = "CB2",
108 .biState = "CB3"
110 struct isds_Address criteria_address = {
111 .adCode = NULL,
112 .adCity = "CA1",
113 .adDistrict = "CA2",
114 .adStreet = "CA3",
115 .adNumberInStreet = "CA4",
116 .adNumberInMunicipality = "CA5",
117 .adZipCode = "CA6",
118 .adState = "CA7"
120 isds_DbType criteria_dbType = DBTYPE_OVM;
121 long int criteria_dbState = 2;
122 _Bool criteria_dbEffectiveOVM = 1;
123 _Bool criteria_dbOpenAddressing = 1;
124 struct isds_DbOwnerInfo criteria = {
125 .dbID = "Cfoo123",
126 .dbType = &criteria_dbType,
127 .ic = "C1",
128 .personName = &criteria_person_name,
129 .firmName = "C2",
130 .birthInfo = &criteria_birth_info,
131 .address = &criteria_address,
132 .nationality = "C3",
133 .email = "C4",
134 .telNumber = "C5",
135 .identifier = "C6",
136 .aifoIsds = NULL,
137 .registryCode = "C7",
138 .dbState = &criteria_dbState,
139 .dbEffectiveOVM = &criteria_dbEffectiveOVM,
140 .dbOpenAddressing = &criteria_dbOpenAddressing
142 struct server_owner_info server_criteria = {
143 .dbID = criteria.dbID,
144 .aifoIsds = NULL,
145 .dbType = "OVM",
146 .ic = criteria.ic,
147 .pnFirstName = criteria.personName->pnFirstName,
148 .pnMiddleName = criteria.personName->pnMiddleName,
149 .pnLastName = criteria.personName->pnLastName,
150 .pnLastNameAtBirth = criteria.personName->pnLastNameAtBirth,
151 .firmName = criteria.firmName,
152 .biDate = criteria.birthInfo->biDate,
153 .biCity = criteria.birthInfo->biCity,
154 .biCounty = criteria.birthInfo->biCounty,
155 .biState = criteria.birthInfo->biState,
156 .adCode = NULL,
157 .adCity = criteria.address->adCity,
158 .adDistrict = NULL,
159 .adStreet = criteria.address->adStreet,
160 .adNumberInStreet = criteria.address->adNumberInStreet,
161 .adNumberInMunicipality = criteria.address->adNumberInMunicipality,
162 .adZipCode = criteria.address->adZipCode,
163 .adState = criteria.address->adState,
164 .nationality = criteria.nationality,
165 .email = criteria.email,
166 .telNumber = criteria.telNumber,
167 .identifier = criteria.identifier,
168 .registryCode = criteria.registryCode,
169 .dbState = criteria.dbState,
170 .dbEffectiveOVM = criteria.dbEffectiveOVM,
171 .dbOpenAddressing = criteria.dbOpenAddressing
174 struct isds_PersonName person_name = {
175 .pnFirstName = "N1",
176 .pnMiddleName = "N2",
177 .pnLastName = "N3",
178 .pnLastNameAtBirth = "N4"
180 struct tm biDate = {
181 .tm_year = 1,
182 .tm_mon = 2,
183 .tm_mday = 3
185 struct isds_BirthInfo birth_info = {
186 .biDate = &biDate,
187 .biCity = "B1",
188 .biCounty = "B2",
189 .biState = "B3"
191 struct isds_Address address = {
192 .adCode = NULL,
193 .adCity = "A1",
194 .adDistrict = NULL,
195 .adStreet = "A3",
196 .adNumberInStreet = "A4",
197 .adNumberInMunicipality = "A5",
198 .adZipCode = "A6",
199 .adState = "A7"
201 isds_DbType dbType = DBTYPE_OVM;
202 long int dbState = 2;
203 _Bool dbEffectiveOVM = 1;
204 _Bool dbOpenAddressing = 1;
205 struct isds_DbOwnerInfo result = {
206 .dbID = "foo1234",
207 .dbType = &dbType,
208 .ic = "1",
209 .personName = &person_name,
210 .firmName = "2",
211 .birthInfo = &birth_info,
212 .address = &address,
213 .nationality = "3",
214 .email = "4",
215 .telNumber = "5",
216 .identifier = "6",
217 .aifoIsds = NULL,
218 .registryCode = "7",
219 .dbState = &dbState,
220 .dbEffectiveOVM = &dbEffectiveOVM,
221 .dbOpenAddressing = &dbOpenAddressing
223 struct isds_DbOwnerInfo result2 = {
226 struct server_owner_info server_result = {
227 .dbID = result.dbID,
228 .aifoIsds = NULL,
229 .dbType = "OVM",
230 .ic = result.ic,
231 .pnFirstName = result.personName->pnFirstName,
232 .pnMiddleName = result.personName->pnMiddleName,
233 .pnLastName = result.personName->pnLastName,
234 .pnLastNameAtBirth = result.personName->pnLastNameAtBirth,
235 .firmName = result.firmName,
236 .biDate = result.birthInfo->biDate,
237 .biCity = result.birthInfo->biCity,
238 .biCounty = result.birthInfo->biCounty,
239 .biState = result.birthInfo->biState,
240 .adCode = NULL,
241 .adCity = result.address->adCity,
242 .adDistrict = NULL,
243 .adStreet = result.address->adStreet,
244 .adNumberInStreet = result.address->adNumberInStreet,
245 .adNumberInMunicipality = result.address->adNumberInMunicipality,
246 .adZipCode = result.address->adZipCode,
247 .adState = result.address->adState,
248 .nationality = result.nationality,
249 .email_exists = 1,
250 .email = result.email,
251 .telNumber_exists = 1,
252 .telNumber = result.telNumber,
253 .identifier = result.identifier,
254 .registryCode = result.registryCode,
255 .dbState = result.dbState,
256 .dbEffectiveOVM = result.dbEffectiveOVM,
257 .dbOpenAddressing = result.dbOpenAddressing
259 struct server_owner_info server_result2 = {
262 struct isds_list results2 = {
263 .next = NULL,
264 .data = &result2,
265 .destructor = NULL
267 struct isds_list results = {
268 .next = &results2,
269 .data = &result,
270 .destructor = NULL
272 struct server_list server_results2 = {
273 .next = NULL,
274 .data = &server_result2,
275 .destructor = NULL
277 struct server_list server_results = {
278 .next = &server_results2,
279 .data = &server_result,
280 .destructor = NULL
283 const struct arguments_DS_df_FindDataBox service_arguments = {
284 .status_code = "0000",
285 .status_message = "Ok.",
286 .criteria = &server_criteria,
287 .results_exists = 0,
288 .results = &server_results
290 const struct service_configuration services[] = {
291 { SERVICE_DS_Dz_DummyOperation, NULL },
292 { SERVICE_DS_df_FindDataBox, &service_arguments },
293 { SERVICE_END, NULL }
295 const struct arguments_basic_authentication server_arguments = {
296 .username = username,
297 .password = password,
298 .isds_deviations = 1,
299 .services = services
301 error = start_server(&server_process, &url,
302 server_basic_authentication, &server_arguments, NULL);
303 if (error == -1) {
304 isds_ctx_free(&context);
305 isds_cleanup();
306 ABORT_UNIT(server_error);
308 TEST("login", test_login, IE_SUCCESS,
309 context, url, username, password, NULL, NULL);
310 free(url);
312 TEST("All data", test_isds_FindDataBox, IE_SUCCESS,
313 context, &criteria, &results);
315 isds_logout(context);
316 if (stop_server(server_process)) {
317 isds_ctx_free(&context);
318 isds_cleanup();
319 ABORT_UNIT(server_error);
324 /* Truncated response with one result */
325 char *url = NULL;
327 struct isds_DbOwnerInfo criteria = {
328 .dbID = "Cfoo123"
330 struct server_owner_info server_criteria = {
331 .dbID = criteria.dbID
334 struct isds_PersonName person_name = {
335 .pnFirstName = "N1",
336 .pnMiddleName = "N2",
337 .pnLastName = "N3",
338 .pnLastNameAtBirth = "N4"
340 struct tm biDate = {
341 .tm_year = 1,
342 .tm_mon = 2,
343 .tm_mday = 3
345 struct isds_BirthInfo birth_info = {
346 .biDate = &biDate,
347 .biCity = "B1",
348 .biCounty = "B2",
349 .biState = "B3"
351 struct isds_Address address = {
352 .adCode = NULL,
353 .adCity = "A1",
354 .adDistrict = NULL,
355 .adStreet = "A3",
356 .adNumberInStreet = "A4",
357 .adNumberInMunicipality = "A5",
358 .adZipCode = "A6",
359 .adState = "A7"
361 isds_DbType dbType = DBTYPE_OVM;
362 long int dbState = 2;
363 _Bool dbEffectiveOVM = 1;
364 _Bool dbOpenAddressing = 1;
365 struct isds_DbOwnerInfo result = {
366 .dbID = "foo1234",
367 .dbType = &dbType,
368 .ic = "1",
369 .personName = &person_name,
370 .firmName = "2",
371 .birthInfo = &birth_info,
372 .address = &address,
373 .nationality = "3",
374 .email = "4",
375 .telNumber = "5",
376 .identifier = "6",
377 .aifoIsds = NULL,
378 .registryCode = "7",
379 .dbState = &dbState,
380 .dbEffectiveOVM = &dbEffectiveOVM,
381 .dbOpenAddressing = &dbOpenAddressing
383 struct server_owner_info server_result = {
384 .dbID = result.dbID,
385 .aifoIsds = NULL,
386 .dbType = "OVM",
387 .ic = result.ic,
388 .pnFirstName = result.personName->pnFirstName,
389 .pnMiddleName = result.personName->pnMiddleName,
390 .pnLastName = result.personName->pnLastName,
391 .pnLastNameAtBirth = result.personName->pnLastNameAtBirth,
392 .firmName = result.firmName,
393 .biDate = result.birthInfo->biDate,
394 .biCity = result.birthInfo->biCity,
395 .biCounty = result.birthInfo->biCounty,
396 .biState = result.birthInfo->biState,
397 .adCode = NULL,
398 .adCity = result.address->adCity,
399 .adDistrict = NULL,
400 .adStreet = result.address->adStreet,
401 .adNumberInStreet = result.address->adNumberInStreet,
402 .adNumberInMunicipality = result.address->adNumberInMunicipality,
403 .adZipCode = result.address->adZipCode,
404 .adState = result.address->adState,
405 .nationality = result.nationality,
406 .email_exists = 1,
407 .email = result.email,
408 .telNumber_exists = 1,
409 .telNumber = result.telNumber,
410 .identifier = result.identifier,
411 .registryCode = result.registryCode,
412 .dbState = result.dbState,
413 .dbEffectiveOVM = result.dbEffectiveOVM,
414 .dbOpenAddressing = result.dbOpenAddressing
416 struct isds_list results = {
417 .next = NULL,
418 .data = &result,
419 .destructor = NULL
421 struct server_list server_results = {
422 .next = NULL,
423 .data = &server_result,
424 .destructor = NULL
427 const struct arguments_DS_df_FindDataBox service_arguments = {
428 .status_code = "0003",
429 .status_message = "Answer was truncated",
430 .criteria = &server_criteria,
431 .results_exists = 0,
432 .results = &server_results
434 const struct service_configuration services[] = {
435 { SERVICE_DS_Dz_DummyOperation, NULL },
436 { SERVICE_DS_df_FindDataBox, &service_arguments },
437 { SERVICE_END, NULL }
439 const struct arguments_basic_authentication server_arguments = {
440 .username = username,
441 .password = password,
442 .isds_deviations = 1,
443 .services = services
445 error = start_server(&server_process, &url,
446 server_basic_authentication, &server_arguments, NULL);
447 if (error == -1) {
448 isds_ctx_free(&context);
449 isds_cleanup();
450 ABORT_UNIT(server_error);
452 TEST("login", test_login, IE_SUCCESS,
453 context, url, username, password, NULL, NULL);
454 free(url);
456 TEST("Truncated answer", test_isds_FindDataBox, IE_2BIG,
457 context, &criteria, &results);
459 isds_logout(context);
460 if (stop_server(server_process)) {
461 isds_ctx_free(&context);
462 isds_cleanup();
463 ABORT_UNIT(server_error);
470 /* Client must refuse DBTYPE_OVM_MAIN and DBTYPE_SYSTEM */
471 char *url = NULL;
473 isds_DbType criteria_dbType = DBTYPE_OVM_MAIN;
474 struct isds_DbOwnerInfo criteria = {
475 .dbType = &criteria_dbType
478 const struct service_configuration services[] = {
479 { SERVICE_DS_Dz_DummyOperation, NULL },
480 { SERVICE_END, NULL }
482 const struct arguments_basic_authentication server_arguments = {
483 .username = username,
484 .password = password,
485 .isds_deviations = 1,
486 .services = services
488 error = start_server(&server_process, &url,
489 server_basic_authentication, &server_arguments, NULL);
490 if (error == -1) {
491 isds_ctx_free(&context);
492 isds_cleanup();
493 ABORT_UNIT(server_error);
495 TEST("login", test_login, IE_SUCCESS,
496 context, url, username, password, NULL, NULL);
497 free(url);
499 TEST("Invalid DBTYPE_OVM_MAIN", test_isds_FindDataBox, IE_ENUM,
500 context, &criteria, NULL);
502 criteria_dbType = DBTYPE_SYSTEM;
503 TEST("Invalid DBTYPE_SYSTEM", test_isds_FindDataBox, IE_ENUM,
504 context, &criteria, NULL);
506 isds_logout(context);
507 if (stop_server(server_process)) {
508 isds_ctx_free(&context);
509 isds_cleanup();
510 ABORT_UNIT(server_error);
515 /* Report 0002 server error as IE_NOEXIST */
516 char *url = NULL;
518 struct isds_DbOwnerInfo criteria = {
519 .dbID = "Cfoo123"
521 struct server_owner_info server_criteria = {
522 .dbID = criteria.dbID
525 const struct arguments_DS_df_FindDataBox service_arguments = {
526 .status_code = "0002",
527 .status_message = "No such box",
528 .criteria = &server_criteria,
529 .results_exists = 0,
530 .results = NULL
532 const struct service_configuration services[] = {
533 { SERVICE_DS_Dz_DummyOperation, NULL },
534 { SERVICE_DS_df_FindDataBox, &service_arguments },
535 { SERVICE_END, NULL }
537 const struct arguments_basic_authentication server_arguments = {
538 .username = username,
539 .password = password,
540 .isds_deviations = 1,
541 .services = services
543 error = start_server(&server_process, &url,
544 server_basic_authentication, &server_arguments, NULL);
545 if (error == -1) {
546 isds_ctx_free(&context);
547 isds_cleanup();
548 ABORT_UNIT(server_error);
550 TEST("login", test_login, IE_SUCCESS,
551 context, url, username, password, NULL, NULL);
552 free(url);
554 TEST("Report 0002 server error as IE_NOEXIST", test_isds_FindDataBox,
555 IE_NOEXIST, context, &criteria, NULL);
557 isds_logout(context);
558 if (stop_server(server_process)) {
559 isds_ctx_free(&context);
560 isds_cleanup();
561 ABORT_UNIT(server_error);
566 /* Report 5001 server error as IE_NOEXIST */
567 char *url = NULL;
569 struct isds_DbOwnerInfo criteria = {
570 .dbID = "Cfoo123"
572 struct server_owner_info server_criteria = {
573 .dbID = criteria.dbID
576 const struct arguments_DS_df_FindDataBox service_arguments = {
577 .status_code = "5001",
578 .status_message = "No such box",
579 .criteria = &server_criteria,
580 .results_exists = 0,
581 .results = NULL
583 const struct service_configuration services[] = {
584 { SERVICE_DS_Dz_DummyOperation, NULL },
585 { SERVICE_DS_df_FindDataBox, &service_arguments },
586 { SERVICE_END, NULL }
588 const struct arguments_basic_authentication server_arguments = {
589 .username = username,
590 .password = password,
591 .isds_deviations = 1,
592 .services = services
594 error = start_server(&server_process, &url,
595 server_basic_authentication, &server_arguments, NULL);
596 if (error == -1) {
597 isds_ctx_free(&context);
598 isds_cleanup();
599 ABORT_UNIT(server_error);
601 TEST("login", test_login, IE_SUCCESS,
602 context, url, username, password, NULL, NULL);
603 free(url);
605 TEST("Report 0002 server error as IE_NOEXIST", test_isds_FindDataBox,
606 IE_NOEXIST, context, &criteria, NULL);
608 isds_logout(context);
609 if (stop_server(server_process)) {
610 isds_ctx_free(&context);
611 isds_cleanup();
612 ABORT_UNIT(server_error);
619 isds_ctx_free(&context);
620 isds_cleanup();
621 SUM_TEST();