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) */
17 #include "test_DbOwnerInfo.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
) {
31 err
= isds_login(context
, url
, username
, password
, pki_credentials
, otp
);
33 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
34 isds_strerror(error
), isds_strerror(err
),
35 isds_long_message(context
));
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
) {
45 struct isds_list
*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
);
62 if (compare_isds_DbOwnerInfo_lists(expected_results
, results
))
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");
81 ABORT_UNIT("isds_init() failed\n");
83 context
= isds_ctx_create();
86 ABORT_UNIT("isds_ctx_create() failed\n");
90 /* Full response with two results */
93 struct isds_PersonName criteria_person_name
= {
95 .pnMiddleName
= "CN2",
97 .pnLastNameAtBirth
= "CN4"
99 struct tm criteria_biDate
= {
104 struct isds_BirthInfo criteria_birth_info
= {
105 .biDate
= &criteria_biDate
,
110 struct isds_Address criteria_address
= {
115 .adNumberInStreet
= "CA4",
116 .adNumberInMunicipality
= "CA5",
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
= {
126 .dbType
= &criteria_dbType
,
128 .personName
= &criteria_person_name
,
130 .birthInfo
= &criteria_birth_info
,
131 .address
= &criteria_address
,
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
,
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
,
157 .adCity
= criteria
.address
->adCity
,
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
= {
176 .pnMiddleName
= "N2",
178 .pnLastNameAtBirth
= "N4"
185 struct isds_BirthInfo birth_info
= {
191 struct isds_Address address
= {
196 .adNumberInStreet
= "A4",
197 .adNumberInMunicipality
= "A5",
201 isds_DbType dbType
= DBTYPE_OVM
;
202 long int dbState
= 2;
203 _Bool dbEffectiveOVM
= 1;
204 _Bool dbOpenAddressing
= 1;
205 struct isds_DbOwnerInfo result
= {
209 .personName
= &person_name
,
211 .birthInfo
= &birth_info
,
220 .dbEffectiveOVM
= &dbEffectiveOVM
,
221 .dbOpenAddressing
= &dbOpenAddressing
223 struct isds_DbOwnerInfo result2
= {
226 struct server_owner_info server_result
= {
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
,
241 .adCity
= result
.address
->adCity
,
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
,
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
= {
267 struct isds_list results
= {
272 struct server_list server_results2
= {
274 .data
= &server_result2
,
277 struct server_list server_results
= {
278 .next
= &server_results2
,
279 .data
= &server_result
,
283 const struct arguments_DS_df_FindDataBox service_arguments
= {
284 .status_code
= "0000",
285 .status_message
= "Ok.",
286 .criteria
= &server_criteria
,
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,
301 error
= start_server(&server_process
, &url
,
302 server_basic_authentication
, &server_arguments
, NULL
);
304 isds_ctx_free(&context
);
306 ABORT_UNIT(server_error
);
308 TEST("login", test_login
, IE_SUCCESS
,
309 context
, url
, username
, password
, NULL
, NULL
);
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
);
319 ABORT_UNIT(server_error
);
324 /* Truncated response with one result */
327 struct isds_DbOwnerInfo criteria
= {
330 struct server_owner_info server_criteria
= {
331 .dbID
= criteria
.dbID
334 struct isds_PersonName person_name
= {
336 .pnMiddleName
= "N2",
338 .pnLastNameAtBirth
= "N4"
345 struct isds_BirthInfo birth_info
= {
351 struct isds_Address address
= {
356 .adNumberInStreet
= "A4",
357 .adNumberInMunicipality
= "A5",
361 isds_DbType dbType
= DBTYPE_OVM
;
362 long int dbState
= 2;
363 _Bool dbEffectiveOVM
= 1;
364 _Bool dbOpenAddressing
= 1;
365 struct isds_DbOwnerInfo result
= {
369 .personName
= &person_name
,
371 .birthInfo
= &birth_info
,
380 .dbEffectiveOVM
= &dbEffectiveOVM
,
381 .dbOpenAddressing
= &dbOpenAddressing
383 struct server_owner_info server_result
= {
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
,
398 .adCity
= result
.address
->adCity
,
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
,
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
= {
421 struct server_list server_results
= {
423 .data
= &server_result
,
427 const struct arguments_DS_df_FindDataBox service_arguments
= {
428 .status_code
= "0003",
429 .status_message
= "Answer was truncated",
430 .criteria
= &server_criteria
,
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,
445 error
= start_server(&server_process
, &url
,
446 server_basic_authentication
, &server_arguments
, NULL
);
448 isds_ctx_free(&context
);
450 ABORT_UNIT(server_error
);
452 TEST("login", test_login
, IE_SUCCESS
,
453 context
, url
, username
, password
, NULL
, NULL
);
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
);
463 ABORT_UNIT(server_error
);
470 /* Client must refuse DBTYPE_OVM_MAIN and DBTYPE_SYSTEM */
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,
488 error
= start_server(&server_process
, &url
,
489 server_basic_authentication
, &server_arguments
, NULL
);
491 isds_ctx_free(&context
);
493 ABORT_UNIT(server_error
);
495 TEST("login", test_login
, IE_SUCCESS
,
496 context
, url
, username
, password
, NULL
, NULL
);
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
);
510 ABORT_UNIT(server_error
);
515 /* Report 0002 server error as IE_NOEXIST */
518 struct isds_DbOwnerInfo criteria
= {
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
,
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,
543 error
= start_server(&server_process
, &url
,
544 server_basic_authentication
, &server_arguments
, NULL
);
546 isds_ctx_free(&context
);
548 ABORT_UNIT(server_error
);
550 TEST("login", test_login
, IE_SUCCESS
,
551 context
, url
, username
, password
, NULL
, NULL
);
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
);
561 ABORT_UNIT(server_error
);
566 /* Report 5001 server error as IE_NOEXIST */
569 struct isds_DbOwnerInfo criteria
= {
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
,
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,
594 error
= start_server(&server_process
, &url
,
595 server_basic_authentication
, &server_arguments
, NULL
);
597 isds_ctx_free(&context
);
599 ABORT_UNIT(server_error
);
601 TEST("login", test_login
, IE_SUCCESS
,
602 context
, url
, username
, password
, NULL
, NULL
);
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
);
612 ABORT_UNIT(server_error
);
619 isds_ctx_free(&context
);