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_FindPersonalDataBox(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_FindPersonalDataBox(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_FindPersoanlDataBox");
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
= NULL
99 struct tm criteria_biDate
= {
104 struct isds_BirthInfo criteria_birth_info
= {
105 .biDate
= &criteria_biDate
,
110 long int criteria_adCode
= 1;
111 struct isds_Address criteria_address
= {
112 .adCode
= &criteria_adCode
,
116 .adNumberInStreet
= "CA4",
117 .adNumberInMunicipality
= "CA5",
121 _Bool criteria_aifoIsds
= 1;
122 struct isds_DbOwnerInfo criteria
= {
126 .personName
= &criteria_person_name
,
128 .birthInfo
= &criteria_birth_info
,
129 .address
= &criteria_address
,
134 .aifoIsds
= &criteria_aifoIsds
,
135 .registryCode
= NULL
,
137 .dbEffectiveOVM
= NULL
,
138 .dbOpenAddressing
= NULL
140 struct server_owner_info server_criteria
= {
141 .dbID
= criteria
.dbID
,
142 .aifoIsds
= criteria
.aifoIsds
,
145 .pnFirstName
= criteria
.personName
->pnFirstName
,
146 .pnMiddleName
= criteria
.personName
->pnMiddleName
,
147 .pnLastName
= criteria
.personName
->pnLastName
,
148 .pnLastNameAtBirth
= NULL
,
150 .biDate
= criteria
.birthInfo
->biDate
,
151 .biCity
= criteria
.birthInfo
->biCity
,
152 .biCounty
= criteria
.birthInfo
->biCounty
,
153 .biState
= criteria
.birthInfo
->biState
,
154 .adCode
= criteria
.address
->adCode
,
155 .adCity
= criteria
.address
->adCity
,
156 .adDistrict
= criteria
.address
->adDistrict
,
157 .adStreet
= criteria
.address
->adStreet
,
158 .adNumberInStreet
= criteria
.address
->adNumberInStreet
,
159 .adNumberInMunicipality
= criteria
.address
->adNumberInMunicipality
,
160 .adZipCode
= criteria
.address
->adZipCode
,
161 .adState
= criteria
.address
->adState
,
162 .nationality
= criteria
.nationality
,
166 .registryCode
= NULL
,
168 .dbEffectiveOVM
= NULL
,
169 .dbOpenAddressing
= NULL
172 struct isds_PersonName person_name
= {
174 .pnMiddleName
= "N2",
176 .pnLastNameAtBirth
= NULL
183 struct isds_BirthInfo birth_info
= {
190 struct isds_Address address
= {
195 .adNumberInStreet
= "A4",
196 .adNumberInMunicipality
= "A5",
201 struct isds_DbOwnerInfo result
= {
205 .personName
= &person_name
,
207 .birthInfo
= &birth_info
,
213 .aifoIsds
= &aifo_isds
,
214 .registryCode
= NULL
,
216 .dbEffectiveOVM
= NULL
,
217 .dbOpenAddressing
= NULL
219 struct isds_DbOwnerInfo result2
= {
222 struct server_owner_info server_result
= {
224 .aifoIsds
= result
.aifoIsds
,
227 .pnFirstName
= result
.personName
->pnFirstName
,
228 .pnMiddleName
= result
.personName
->pnMiddleName
,
229 .pnLastName
= result
.personName
->pnLastName
,
230 .pnLastNameAtBirth
= NULL
,
232 .biDate
= result
.birthInfo
->biDate
,
233 .biCity
= result
.birthInfo
->biCity
,
234 .biCounty
= result
.birthInfo
->biCounty
,
235 .biState
= result
.birthInfo
->biState
,
236 .adCode
= result
.address
->adCode
,
237 .adCity
= result
.address
->adCity
,
238 .adDistrict
= result
.address
->adDistrict
,
239 .adStreet
= result
.address
->adStreet
,
240 .adNumberInStreet
= result
.address
->adNumberInStreet
,
241 .adNumberInMunicipality
= result
.address
->adNumberInMunicipality
,
242 .adZipCode
= result
.address
->adZipCode
,
243 .adState
= result
.address
->adState
,
244 .nationality
= result
.nationality
,
247 .telNumber_exists
= 0,
250 .registryCode
= NULL
,
252 .dbEffectiveOVM
= NULL
,
253 .dbOpenAddressing
= NULL
255 struct server_owner_info server_result2
= {
258 struct isds_list results2
= {
263 struct isds_list results
= {
268 struct server_list server_results2
= {
270 .data
= &server_result2
,
273 struct server_list server_results
= {
274 .next
= &server_results2
,
275 .data
= &server_result
,
279 const struct arguments_DS_df_FindPersonalDataBox service_arguments
= {
280 .status_code
= "0000",
281 .status_message
= "Ok.",
282 .criteria
= &server_criteria
,
284 .results
= &server_results
286 const struct service_configuration services
[] = {
287 { SERVICE_DS_Dz_DummyOperation
, NULL
},
288 { SERVICE_DS_df_FindPersonalDataBox
, &service_arguments
},
289 { SERVICE_END
, NULL
}
291 const struct arguments_basic_authentication server_arguments
= {
292 .username
= username
,
293 .password
= password
,
294 .isds_deviations
= 1,
297 error
= start_server(&server_process
, &url
,
298 server_basic_authentication
, &server_arguments
, NULL
);
300 isds_ctx_free(&context
);
302 ABORT_UNIT(server_error
);
304 TEST("login", test_login
, IE_SUCCESS
,
305 context
, url
, username
, password
, NULL
, NULL
);
308 TEST("All data", test_isds_FindPersonalDataBox
, IE_SUCCESS
,
309 context
, &criteria
, &results
);
311 isds_logout(context
);
312 if (stop_server(server_process
)) {
313 isds_ctx_free(&context
);
315 ABORT_UNIT(server_error
);
320 /* Truncated response with one result */
323 struct isds_DbOwnerInfo criteria
= {
326 struct server_owner_info server_criteria
= {
327 .dbID
= criteria
.dbID
330 struct isds_PersonName person_name
= {
332 .pnMiddleName
= "N2",
334 .pnLastNameAtBirth
= NULL
341 struct isds_BirthInfo birth_info
= {
348 struct isds_Address address
= {
353 .adNumberInStreet
= "A4",
354 .adNumberInMunicipality
= "A5",
359 struct isds_DbOwnerInfo result
= {
361 .aifoIsds
= &aifoIsds
,
362 .personName
= &person_name
,
363 .birthInfo
= &birth_info
,
367 struct server_owner_info server_result
= {
369 .aifoIsds
= result
.aifoIsds
,
372 .pnFirstName
= result
.personName
->pnFirstName
,
373 .pnMiddleName
= result
.personName
->pnMiddleName
,
374 .pnLastName
= result
.personName
->pnLastName
,
375 .pnLastNameAtBirth
= NULL
,
377 .biDate
= result
.birthInfo
->biDate
,
378 .biCity
= result
.birthInfo
->biCity
,
379 .biCounty
= result
.birthInfo
->biCounty
,
380 .biState
= result
.birthInfo
->biState
,
381 .adCode
= result
.address
->adCode
,
382 .adCity
= result
.address
->adCity
,
383 .adDistrict
= result
.address
->adDistrict
,
384 .adStreet
= result
.address
->adStreet
,
385 .adNumberInStreet
= result
.address
->adNumberInStreet
,
386 .adNumberInMunicipality
= result
.address
->adNumberInMunicipality
,
387 .adZipCode
= result
.address
->adZipCode
,
388 .adState
= result
.address
->adState
,
389 .nationality
= result
.nationality
,
392 .telNumber_exists
= 0,
395 .registryCode
= NULL
,
397 .dbEffectiveOVM
= NULL
,
398 .dbOpenAddressing
= NULL
400 struct isds_list results
= {
405 struct server_list server_results
= {
407 .data
= &server_result
,
411 const struct arguments_DS_df_FindDataBox service_arguments
= {
412 .status_code
= "0003",
413 .status_message
= "Answer was truncated",
414 .criteria
= &server_criteria
,
416 .results
= &server_results
418 const struct service_configuration services
[] = {
419 { SERVICE_DS_Dz_DummyOperation
, NULL
},
420 { SERVICE_DS_df_FindPersonalDataBox
, &service_arguments
},
421 { SERVICE_END
, NULL
}
423 const struct arguments_basic_authentication server_arguments
= {
424 .username
= username
,
425 .password
= password
,
426 .isds_deviations
= 1,
429 error
= start_server(&server_process
, &url
,
430 server_basic_authentication
, &server_arguments
, NULL
);
432 isds_ctx_free(&context
);
434 ABORT_UNIT(server_error
);
436 TEST("login", test_login
, IE_SUCCESS
,
437 context
, url
, username
, password
, NULL
, NULL
);
440 TEST("Truncated answer", test_isds_FindPersonalDataBox
, IE_2BIG
,
441 context
, &criteria
, &results
);
443 isds_logout(context
);
444 if (stop_server(server_process
)) {
445 isds_ctx_free(&context
);
447 ABORT_UNIT(server_error
);
452 /* Report 0002 server error as IE_NOEXIST */
455 struct isds_DbOwnerInfo criteria
= {
458 struct server_owner_info server_criteria
= {
459 .dbID
= criteria
.dbID
462 const struct arguments_DS_df_FindPersonalDataBox service_arguments
= {
463 .status_code
= "0002",
464 .status_message
= "No such box",
465 .criteria
= &server_criteria
,
469 const struct service_configuration services
[] = {
470 { SERVICE_DS_Dz_DummyOperation
, NULL
},
471 { SERVICE_DS_df_FindPersonalDataBox
, &service_arguments
},
472 { SERVICE_END
, NULL
}
474 const struct arguments_basic_authentication server_arguments
= {
475 .username
= username
,
476 .password
= password
,
477 .isds_deviations
= 1,
480 error
= start_server(&server_process
, &url
,
481 server_basic_authentication
, &server_arguments
, NULL
);
483 isds_ctx_free(&context
);
485 ABORT_UNIT(server_error
);
487 TEST("login", test_login
, IE_SUCCESS
,
488 context
, url
, username
, password
, NULL
, NULL
);
491 TEST("Report 0002 server error as IE_NOEXIST",
492 test_isds_FindPersonalDataBox
, IE_NOEXIST
, context
, &criteria
,
495 isds_logout(context
);
496 if (stop_server(server_process
)) {
497 isds_ctx_free(&context
);
499 ABORT_UNIT(server_error
);
504 /* Report 5001 server error as IE_NOEXIST */
507 struct isds_DbOwnerInfo criteria
= {
510 struct server_owner_info server_criteria
= {
511 .dbID
= criteria
.dbID
514 const struct arguments_DS_df_FindPersonalDataBox service_arguments
= {
515 .status_code
= "5001",
516 .status_message
= "No such box",
517 .criteria
= &server_criteria
,
521 const struct service_configuration services
[] = {
522 { SERVICE_DS_Dz_DummyOperation
, NULL
},
523 { SERVICE_DS_df_FindPersonalDataBox
, &service_arguments
},
524 { SERVICE_END
, NULL
}
526 const struct arguments_basic_authentication server_arguments
= {
527 .username
= username
,
528 .password
= password
,
529 .isds_deviations
= 1,
532 error
= start_server(&server_process
, &url
,
533 server_basic_authentication
, &server_arguments
, NULL
);
535 isds_ctx_free(&context
);
537 ABORT_UNIT(server_error
);
539 TEST("login", test_login
, IE_SUCCESS
,
540 context
, url
, username
, password
, NULL
, NULL
);
543 TEST("Report 0002 server error as IE_NOEXIST",
544 test_isds_FindPersonalDataBox
, IE_NOEXIST
, context
, &criteria
,
547 isds_logout(context
);
548 if (stop_server(server_process
)) {
549 isds_ctx_free(&context
);
551 ABORT_UNIT(server_error
);
558 isds_ctx_free(&context
);