2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
6 #define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */
13 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
20 static const char *username
= "Doug1as$";
21 static const char *password
= "42aA#bc8";
24 static int test_login(const isds_error error
, struct isds_ctx
*context
,
25 const char *url
, const char *username
, const char *password
,
26 const struct isds_pki_credentials
*pki_credentials
,
27 struct isds_otp
*otp
) {
30 err
= isds_login(context
, url
, username
, password
, pki_credentials
, otp
);
32 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
33 isds_strerror(error
), isds_strerror(err
),
34 isds_long_message(context
));
39 static int compare_isds_PersonName(
40 const struct isds_PersonName
*expected_result
,
41 const struct isds_PersonName
*result
) {
43 TEST_POINTER_DUPLICITY(expected_result
, result
);
44 if (NULL
== expected_result
)
47 TEST_STRING_DUPLICITY(expected_result
->pnFirstName
, result
->pnFirstName
);
48 TEST_STRING_DUPLICITY(expected_result
->pnMiddleName
, result
->pnMiddleName
);
49 TEST_STRING_DUPLICITY(expected_result
->pnLastName
, result
->pnLastName
);
50 TEST_STRING_DUPLICITY(expected_result
->pnLastNameAtBirth
,
51 result
->pnLastNameAtBirth
);
56 static int compare_isds_BirthInfo(
57 const struct isds_BirthInfo
*expected_result
,
58 const struct isds_BirthInfo
*result
) {
60 TEST_POINTER_DUPLICITY(expected_result
, result
);
61 if (NULL
== expected_result
)
64 TEST_TMPTR_DUPLICITY(expected_result
->biDate
, result
->biDate
);
65 TEST_STRING_DUPLICITY(expected_result
->biCity
, result
->biCity
);
66 TEST_STRING_DUPLICITY(expected_result
->biCounty
, result
->biCounty
);
67 TEST_STRING_DUPLICITY(expected_result
->biState
, result
->biState
);
72 static int compare_isds_Address(
73 const struct isds_Address
*expected_result
,
74 const struct isds_Address
*result
) {
76 TEST_POINTER_DUPLICITY(expected_result
, result
);
77 if (NULL
== expected_result
)
80 TEST_INTPTR_DUPLICITY(expected_result
->adCode
, result
->adCode
);
81 TEST_STRING_DUPLICITY(expected_result
->adCity
, result
->adCity
);
82 TEST_STRING_DUPLICITY(expected_result
->adDistrict
, result
->adDistrict
);
83 TEST_STRING_DUPLICITY(expected_result
->adStreet
, result
->adStreet
);
84 TEST_STRING_DUPLICITY(expected_result
->adNumberInStreet
,
85 result
->adNumberInStreet
);
86 TEST_STRING_DUPLICITY(expected_result
->adNumberInMunicipality
,
87 result
->adNumberInMunicipality
);
88 TEST_STRING_DUPLICITY(expected_result
->adZipCode
, result
->adZipCode
);
89 TEST_STRING_DUPLICITY(expected_result
->adState
, result
->adState
);
94 static int compare_isds_DbOwnerInfo(
95 const struct isds_DbOwnerInfo
*expected_result
,
96 const struct isds_DbOwnerInfo
*result
) {
98 TEST_POINTER_DUPLICITY(expected_result
, result
);
99 if (NULL
== expected_result
)
102 TEST_STRING_DUPLICITY(expected_result
->dbID
, result
->dbID
);
103 TEST_INTPTR_DUPLICITY(expected_result
->dbType
, result
->dbType
);
104 TEST_STRING_DUPLICITY(expected_result
->ic
, result
->ic
);
105 if (compare_isds_PersonName(expected_result
->personName
,
108 TEST_STRING_DUPLICITY(expected_result
->firmName
, result
->firmName
);
109 if (compare_isds_BirthInfo(expected_result
->birthInfo
, result
->birthInfo
))
111 if (compare_isds_Address(expected_result
->address
, result
->address
))
113 TEST_STRING_DUPLICITY(expected_result
->nationality
, result
->nationality
);
114 TEST_STRING_DUPLICITY(expected_result
->email
, result
->email
);
115 TEST_STRING_DUPLICITY(expected_result
->telNumber
, result
->telNumber
);
116 TEST_STRING_DUPLICITY(expected_result
->identifier
, result
->identifier
);
117 TEST_BOOLEAN_DUPLICITY(expected_result
->aifoIsds
, result
->aifoIsds
);
118 TEST_STRING_DUPLICITY(expected_result
->registryCode
, result
->registryCode
);
119 TEST_INTPTR_DUPLICITY(expected_result
->dbState
, result
->dbState
);
120 TEST_BOOLEANPTR_DUPLICITY(expected_result
->dbEffectiveOVM
,
121 result
->dbEffectiveOVM
);
122 TEST_BOOLEANPTR_DUPLICITY(expected_result
->dbOpenAddressing
,
123 result
->dbOpenAddressing
);
128 static int compare_result_lists(const struct isds_list
*expected_list
,
129 const struct isds_list
*list
) {
130 const struct isds_list
*expected_item
, *item
;
133 for (i
= 1, expected_item
= expected_list
, item
= list
;
134 NULL
!= expected_item
&& NULL
!= item
;
135 i
++, expected_item
= expected_item
->next
, item
= item
->next
) {
136 if (compare_isds_DbOwnerInfo(
137 (struct isds_DbOwnerInfo
*)expected_item
->data
,
138 (struct isds_DbOwnerInfo
*)item
->data
))
141 if (NULL
!= expected_item
&& NULL
== item
)
142 FAIL_TEST("Result list is missing %d. item", i
);
143 if (NULL
== expected_item
&& NULL
!= item
)
144 FAIL_TEST("Result list has superfluous %d. item", i
);
149 static int test_isds_FindDataBox(const isds_error expected_error
,
150 struct isds_ctx
*context
,
151 const struct isds_DbOwnerInfo
*criteria
,
152 const struct isds_list
*expected_results
) {
154 struct isds_list
*results
;
155 TEST_CALLOC(results
);
157 error
= isds_FindDataBox(context
, criteria
, &results
);
158 TEST_DESTRUCTOR((void(*)(void*))isds_list_free
, &results
);
160 if (expected_error
!= error
) {
161 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
162 isds_strerror(expected_error
), isds_strerror(error
),
163 isds_long_message(context
));
166 if (IE_SUCCESS
!= error
&& IE_2BIG
!= error
) {
167 TEST_POINTER_IS_NULL(results
);
171 if (compare_result_lists(expected_results
, results
))
180 pid_t server_process
;
181 struct isds_ctx
*context
= NULL
;
183 INIT_TEST("isds_FindDataBox");
185 if (unsetenv("http_proxy")) {
186 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
190 ABORT_UNIT("isds_init() failed\n");
192 context
= isds_ctx_create();
195 ABORT_UNIT("isds_ctx_create() failed\n");
199 /* Full response with two results */
202 struct isds_PersonName criteria_person_name
= {
203 .pnFirstName
= "CN1",
204 .pnMiddleName
= "CN2",
206 .pnLastNameAtBirth
= "CN4"
208 struct tm criteria_biDate
= {
213 struct isds_BirthInfo criteria_birth_info
= {
214 .biDate
= &criteria_biDate
,
219 struct isds_Address criteria_address
= {
224 .adNumberInStreet
= "CA4",
225 .adNumberInMunicipality
= "CA5",
229 isds_DbType criteria_dbType
= DBTYPE_OVM
;
230 long int criteria_dbState
= 2;
231 _Bool criteria_dbEffectiveOVM
= 1;
232 _Bool criteria_dbOpenAddressing
= 1;
233 struct isds_DbOwnerInfo criteria
= {
235 .dbType
= &criteria_dbType
,
237 .personName
= &criteria_person_name
,
239 .birthInfo
= &criteria_birth_info
,
240 .address
= &criteria_address
,
246 .registryCode
= "C7",
247 .dbState
= &criteria_dbState
,
248 .dbEffectiveOVM
= &criteria_dbEffectiveOVM
,
249 .dbOpenAddressing
= &criteria_dbOpenAddressing
251 struct server_owner_info server_criteria
= {
252 .dbID
= criteria
.dbID
,
256 .pnFirstName
= criteria
.personName
->pnFirstName
,
257 .pnMiddleName
= criteria
.personName
->pnMiddleName
,
258 .pnLastName
= criteria
.personName
->pnLastName
,
259 .pnLastNameAtBirth
= criteria
.personName
->pnLastNameAtBirth
,
260 .firmName
= criteria
.firmName
,
261 .biDate
= criteria
.birthInfo
->biDate
,
262 .biCity
= criteria
.birthInfo
->biCity
,
263 .biCounty
= criteria
.birthInfo
->biCounty
,
264 .biState
= criteria
.birthInfo
->biState
,
266 .adCity
= criteria
.address
->adCity
,
268 .adStreet
= criteria
.address
->adStreet
,
269 .adNumberInStreet
= criteria
.address
->adNumberInStreet
,
270 .adNumberInMunicipality
= criteria
.address
->adNumberInMunicipality
,
271 .adZipCode
= criteria
.address
->adZipCode
,
272 .adState
= criteria
.address
->adState
,
273 .nationality
= criteria
.nationality
,
274 .email
= criteria
.email
,
275 .telNumber
= criteria
.telNumber
,
276 .identifier
= criteria
.identifier
,
277 .registryCode
= criteria
.registryCode
,
278 .dbState
= criteria
.dbState
,
279 .dbEffectiveOVM
= criteria
.dbEffectiveOVM
,
280 .dbOpenAddressing
= criteria
.dbOpenAddressing
283 struct isds_PersonName person_name
= {
285 .pnMiddleName
= "N2",
287 .pnLastNameAtBirth
= "N4"
294 struct isds_BirthInfo birth_info
= {
300 struct isds_Address address
= {
305 .adNumberInStreet
= "A4",
306 .adNumberInMunicipality
= "A5",
310 isds_DbType dbType
= DBTYPE_OVM
;
311 long int dbState
= 2;
312 _Bool dbEffectiveOVM
= 1;
313 _Bool dbOpenAddressing
= 1;
314 struct isds_DbOwnerInfo result
= {
318 .personName
= &person_name
,
320 .birthInfo
= &birth_info
,
329 .dbEffectiveOVM
= &dbEffectiveOVM
,
330 .dbOpenAddressing
= &dbOpenAddressing
332 struct isds_DbOwnerInfo result2
= {
335 struct server_owner_info server_result
= {
340 .pnFirstName
= result
.personName
->pnFirstName
,
341 .pnMiddleName
= result
.personName
->pnMiddleName
,
342 .pnLastName
= result
.personName
->pnLastName
,
343 .pnLastNameAtBirth
= result
.personName
->pnLastNameAtBirth
,
344 .firmName
= result
.firmName
,
345 .biDate
= result
.birthInfo
->biDate
,
346 .biCity
= result
.birthInfo
->biCity
,
347 .biCounty
= result
.birthInfo
->biCounty
,
348 .biState
= result
.birthInfo
->biState
,
350 .adCity
= result
.address
->adCity
,
352 .adStreet
= result
.address
->adStreet
,
353 .adNumberInStreet
= result
.address
->adNumberInStreet
,
354 .adNumberInMunicipality
= result
.address
->adNumberInMunicipality
,
355 .adZipCode
= result
.address
->adZipCode
,
356 .adState
= result
.address
->adState
,
357 .nationality
= result
.nationality
,
359 .email
= result
.email
,
360 .telNumber_exists
= 1,
361 .telNumber
= result
.telNumber
,
362 .identifier
= result
.identifier
,
363 .registryCode
= result
.registryCode
,
364 .dbState
= result
.dbState
,
365 .dbEffectiveOVM
= result
.dbEffectiveOVM
,
366 .dbOpenAddressing
= result
.dbOpenAddressing
368 struct server_owner_info server_result2
= {
371 struct isds_list results2
= {
376 struct isds_list results
= {
381 struct server_list server_results2
= {
383 .data
= &server_result2
,
386 struct server_list server_results
= {
387 .next
= &server_results2
,
388 .data
= &server_result
,
392 const struct arguments_DS_df_FindDataBox service_arguments
= {
393 .status_code
= "0000",
394 .status_message
= "Ok.",
395 .criteria
= &server_criteria
,
397 .results
= &server_results
399 const struct service_configuration services
[] = {
400 { SERVICE_DS_Dz_DummyOperation
, NULL
},
401 { SERVICE_DS_df_FindDataBox
, &service_arguments
},
402 { SERVICE_END
, NULL
}
404 const struct arguments_basic_authentication server_arguments
= {
405 .username
= username
,
406 .password
= password
,
407 .isds_deviations
= 1,
410 error
= start_server(&server_process
, &url
,
411 server_basic_authentication
, &server_arguments
, NULL
);
413 isds_ctx_free(&context
);
415 ABORT_UNIT(server_error
);
417 TEST("login", test_login
, IE_SUCCESS
,
418 context
, url
, username
, password
, NULL
, NULL
);
421 TEST("All data", test_isds_FindDataBox
, IE_SUCCESS
,
422 context
, &criteria
, &results
);
424 isds_logout(context
);
425 if (stop_server(server_process
)) {
426 isds_ctx_free(&context
);
428 ABORT_UNIT(server_error
);
433 /* Truncated response with one result */
436 struct isds_DbOwnerInfo criteria
= {
439 struct server_owner_info server_criteria
= {
440 .dbID
= criteria
.dbID
443 struct isds_PersonName person_name
= {
445 .pnMiddleName
= "N2",
447 .pnLastNameAtBirth
= "N4"
454 struct isds_BirthInfo birth_info
= {
460 struct isds_Address address
= {
465 .adNumberInStreet
= "A4",
466 .adNumberInMunicipality
= "A5",
470 isds_DbType dbType
= DBTYPE_OVM
;
471 long int dbState
= 2;
472 _Bool dbEffectiveOVM
= 1;
473 _Bool dbOpenAddressing
= 1;
474 struct isds_DbOwnerInfo result
= {
478 .personName
= &person_name
,
480 .birthInfo
= &birth_info
,
489 .dbEffectiveOVM
= &dbEffectiveOVM
,
490 .dbOpenAddressing
= &dbOpenAddressing
492 struct server_owner_info server_result
= {
497 .pnFirstName
= result
.personName
->pnFirstName
,
498 .pnMiddleName
= result
.personName
->pnMiddleName
,
499 .pnLastName
= result
.personName
->pnLastName
,
500 .pnLastNameAtBirth
= result
.personName
->pnLastNameAtBirth
,
501 .firmName
= result
.firmName
,
502 .biDate
= result
.birthInfo
->biDate
,
503 .biCity
= result
.birthInfo
->biCity
,
504 .biCounty
= result
.birthInfo
->biCounty
,
505 .biState
= result
.birthInfo
->biState
,
507 .adCity
= result
.address
->adCity
,
509 .adStreet
= result
.address
->adStreet
,
510 .adNumberInStreet
= result
.address
->adNumberInStreet
,
511 .adNumberInMunicipality
= result
.address
->adNumberInMunicipality
,
512 .adZipCode
= result
.address
->adZipCode
,
513 .adState
= result
.address
->adState
,
514 .nationality
= result
.nationality
,
516 .email
= result
.email
,
517 .telNumber_exists
= 1,
518 .telNumber
= result
.telNumber
,
519 .identifier
= result
.identifier
,
520 .registryCode
= result
.registryCode
,
521 .dbState
= result
.dbState
,
522 .dbEffectiveOVM
= result
.dbEffectiveOVM
,
523 .dbOpenAddressing
= result
.dbOpenAddressing
525 struct isds_list results
= {
530 struct server_list server_results
= {
532 .data
= &server_result
,
536 const struct arguments_DS_df_FindDataBox service_arguments
= {
537 .status_code
= "0003",
538 .status_message
= "Answer was truncated",
539 .criteria
= &server_criteria
,
541 .results
= &server_results
543 const struct service_configuration services
[] = {
544 { SERVICE_DS_Dz_DummyOperation
, NULL
},
545 { SERVICE_DS_df_FindDataBox
, &service_arguments
},
546 { SERVICE_END
, NULL
}
548 const struct arguments_basic_authentication server_arguments
= {
549 .username
= username
,
550 .password
= password
,
551 .isds_deviations
= 1,
554 error
= start_server(&server_process
, &url
,
555 server_basic_authentication
, &server_arguments
, NULL
);
557 isds_ctx_free(&context
);
559 ABORT_UNIT(server_error
);
561 TEST("login", test_login
, IE_SUCCESS
,
562 context
, url
, username
, password
, NULL
, NULL
);
565 TEST("Truncated asnwer", test_isds_FindDataBox
, IE_2BIG
,
566 context
, &criteria
, &results
);
568 isds_logout(context
);
569 if (stop_server(server_process
)) {
570 isds_ctx_free(&context
);
572 ABORT_UNIT(server_error
);
579 /* Client must refuse DBTYPE_OVM_MAIN and DBTYPE_SYSTEM */
582 isds_DbType criteria_dbType
= DBTYPE_OVM_MAIN
;
583 struct isds_DbOwnerInfo criteria
= {
584 .dbType
= &criteria_dbType
587 const struct service_configuration services
[] = {
588 { SERVICE_DS_Dz_DummyOperation
, NULL
},
589 { SERVICE_END
, NULL
}
591 const struct arguments_basic_authentication server_arguments
= {
592 .username
= username
,
593 .password
= password
,
594 .isds_deviations
= 1,
597 error
= start_server(&server_process
, &url
,
598 server_basic_authentication
, &server_arguments
, NULL
);
600 isds_ctx_free(&context
);
602 ABORT_UNIT(server_error
);
604 TEST("login", test_login
, IE_SUCCESS
,
605 context
, url
, username
, password
, NULL
, NULL
);
608 TEST("Invalid DBTYPE_OVM_MAIN", test_isds_FindDataBox
, IE_ENUM
,
609 context
, &criteria
, NULL
);
611 criteria_dbType
= DBTYPE_SYSTEM
;
612 TEST("Invalid DBTYPE_SYSTEM", test_isds_FindDataBox
, IE_ENUM
,
613 context
, &criteria
, NULL
);
615 isds_logout(context
);
616 if (stop_server(server_process
)) {
617 isds_ctx_free(&context
);
619 ABORT_UNIT(server_error
);
624 /* Report 0002 server error as IE_NOEXIST */
627 struct isds_DbOwnerInfo criteria
= {
630 struct server_owner_info server_criteria
= {
631 .dbID
= criteria
.dbID
634 const struct arguments_DS_df_FindDataBox service_arguments
= {
635 .status_code
= "0002",
636 .status_message
= "No such box",
637 .criteria
= &server_criteria
,
641 const struct service_configuration services
[] = {
642 { SERVICE_DS_Dz_DummyOperation
, NULL
},
643 { SERVICE_DS_df_FindDataBox
, &service_arguments
},
644 { SERVICE_END
, NULL
}
646 const struct arguments_basic_authentication server_arguments
= {
647 .username
= username
,
648 .password
= password
,
649 .isds_deviations
= 1,
652 error
= start_server(&server_process
, &url
,
653 server_basic_authentication
, &server_arguments
, NULL
);
655 isds_ctx_free(&context
);
657 ABORT_UNIT(server_error
);
659 TEST("login", test_login
, IE_SUCCESS
,
660 context
, url
, username
, password
, NULL
, NULL
);
663 TEST("Report 0002 server error as IE_NOEXIST", test_isds_FindDataBox
,
664 IE_NOEXIST
, context
, &criteria
, NULL
);
666 isds_logout(context
);
667 if (stop_server(server_process
)) {
668 isds_ctx_free(&context
);
670 ABORT_UNIT(server_error
);
675 /* Report 5001 server error as IE_NOEXIST */
678 struct isds_DbOwnerInfo criteria
= {
681 struct server_owner_info server_criteria
= {
682 .dbID
= criteria
.dbID
685 const struct arguments_DS_df_FindDataBox service_arguments
= {
686 .status_code
= "5001",
687 .status_message
= "No such box",
688 .criteria
= &server_criteria
,
692 const struct service_configuration services
[] = {
693 { SERVICE_DS_Dz_DummyOperation
, NULL
},
694 { SERVICE_DS_df_FindDataBox
, &service_arguments
},
695 { SERVICE_END
, NULL
}
697 const struct arguments_basic_authentication server_arguments
= {
698 .username
= username
,
699 .password
= password
,
700 .isds_deviations
= 1,
703 error
= start_server(&server_process
, &url
,
704 server_basic_authentication
, &server_arguments
, NULL
);
706 isds_ctx_free(&context
);
708 ABORT_UNIT(server_error
);
710 TEST("login", test_login
, IE_SUCCESS
,
711 context
, url
, username
, password
, NULL
, NULL
);
714 TEST("Report 0002 server error as IE_NOEXIST", test_isds_FindDataBox
,
715 IE_NOEXIST
, context
, &criteria
, NULL
);
717 isds_logout(context
);
718 if (stop_server(server_process
)) {
719 isds_ctx_free(&context
);
721 ABORT_UNIT(server_error
);
728 isds_ctx_free(&context
);