test: Fix indentation
[libisds.git] / test / simline / isds_FindPersonalDataBox.c
blob84709d3b555eb4465bd6e67bbd5aa90a73cd008f
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_FindPersonalDataBox(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_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);
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_FindPersoanlDataBox");
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 = NULL
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 long int criteria_adCode = 1;
111 struct isds_Address criteria_address = {
112 .adCode = &criteria_adCode,
113 .adCity = "CA1",
114 .adDistrict = "CA2",
115 .adStreet = "CA3",
116 .adNumberInStreet = "CA4",
117 .adNumberInMunicipality = "CA5",
118 .adZipCode = "CA6",
119 .adState = "CA7"
121 _Bool criteria_aifoIsds = 1;
122 struct isds_DbOwnerInfo criteria = {
123 .dbID = "Cfoo123",
124 .dbType = NULL,
125 .ic = NULL,
126 .personName = &criteria_person_name,
127 .firmName = "C2",
128 .birthInfo = &criteria_birth_info,
129 .address = &criteria_address,
130 .nationality = "C3",
131 .email = NULL,
132 .telNumber = NULL,
133 .identifier = NULL,
134 .aifoIsds = &criteria_aifoIsds,
135 .registryCode = NULL,
136 .dbState = NULL,
137 .dbEffectiveOVM = NULL,
138 .dbOpenAddressing = NULL
140 struct server_owner_info server_criteria = {
141 .dbID = criteria.dbID,
142 .aifoIsds = criteria.aifoIsds,
143 .dbType = NULL,
144 .ic = NULL,
145 .pnFirstName = criteria.personName->pnFirstName,
146 .pnMiddleName = criteria.personName->pnMiddleName,
147 .pnLastName = criteria.personName->pnLastName,
148 .pnLastNameAtBirth = NULL,
149 .firmName = 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,
163 .email = NULL,
164 .telNumber = NULL,
165 .identifier = NULL,
166 .registryCode = NULL,
167 .dbState = NULL,
168 .dbEffectiveOVM = NULL,
169 .dbOpenAddressing = NULL
172 struct isds_PersonName person_name = {
173 .pnFirstName = "N1",
174 .pnMiddleName = "N2",
175 .pnLastName = "N3",
176 .pnLastNameAtBirth = NULL
178 struct tm biDate = {
179 .tm_year = 1,
180 .tm_mon = 2,
181 .tm_mday = 3
183 struct isds_BirthInfo birth_info = {
184 .biDate = &biDate,
185 .biCity = "B1",
186 .biCounty = "B2",
187 .biState = "B3"
189 long int adCode = 1;
190 struct isds_Address address = {
191 .adCode = &adCode,
192 .adCity = "A1",
193 .adDistrict = "A2",
194 .adStreet = "A3",
195 .adNumberInStreet = "A4",
196 .adNumberInMunicipality = "A5",
197 .adZipCode = "A6",
198 .adState = "A7"
200 _Bool aifo_isds = 1;
201 struct isds_DbOwnerInfo result = {
202 .dbID = "foo1234",
203 .dbType = NULL,
204 .ic = NULL,
205 .personName = &person_name,
206 .firmName = NULL,
207 .birthInfo = &birth_info,
208 .address = &address,
209 .nationality = "3",
210 .email = NULL,
211 .telNumber = NULL,
212 .identifier = NULL,
213 .aifoIsds = &aifo_isds,
214 .registryCode = NULL,
215 .dbState = NULL,
216 .dbEffectiveOVM = NULL,
217 .dbOpenAddressing = NULL
219 struct isds_DbOwnerInfo result2 = {
222 struct server_owner_info server_result = {
223 .dbID = result.dbID,
224 .aifoIsds = result.aifoIsds,
225 .dbType = NULL,
226 .ic = NULL,
227 .pnFirstName = result.personName->pnFirstName,
228 .pnMiddleName = result.personName->pnMiddleName,
229 .pnLastName = result.personName->pnLastName,
230 .pnLastNameAtBirth = NULL,
231 .firmName = 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,
245 .email_exists = 0,
246 .email = NULL,
247 .telNumber_exists = 0,
248 .telNumber = NULL,
249 .identifier = NULL,
250 .registryCode = NULL,
251 .dbState = NULL,
252 .dbEffectiveOVM = NULL,
253 .dbOpenAddressing = NULL
255 struct server_owner_info server_result2 = {
258 struct isds_list results2 = {
259 .next = NULL,
260 .data = &result2,
261 .destructor = NULL
263 struct isds_list results = {
264 .next = &results2,
265 .data = &result,
266 .destructor = NULL
268 struct server_list server_results2 = {
269 .next = NULL,
270 .data = &server_result2,
271 .destructor = NULL
273 struct server_list server_results = {
274 .next = &server_results2,
275 .data = &server_result,
276 .destructor = NULL
279 const struct arguments_DS_df_FindPersonalDataBox service_arguments = {
280 .status_code = "0000",
281 .status_message = "Ok.",
282 .criteria = &server_criteria,
283 .results_exists = 0,
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,
295 .services = services
297 error = start_server(&server_process, &url,
298 server_basic_authentication, &server_arguments, NULL);
299 if (error == -1) {
300 isds_ctx_free(&context);
301 isds_cleanup();
302 ABORT_UNIT(server_error);
304 TEST("login", test_login, IE_SUCCESS,
305 context, url, username, password, NULL, NULL);
306 free(url);
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);
314 isds_cleanup();
315 ABORT_UNIT(server_error);
320 /* Truncated response with one result */
321 char *url = NULL;
323 struct isds_DbOwnerInfo criteria = {
324 .dbID = "Cfoo123"
326 struct server_owner_info server_criteria = {
327 .dbID = criteria.dbID
330 struct isds_PersonName person_name = {
331 .pnFirstName = "N1",
332 .pnMiddleName = "N2",
333 .pnLastName = "N3",
334 .pnLastNameAtBirth = NULL
336 struct tm biDate = {
337 .tm_year = 1,
338 .tm_mon = 2,
339 .tm_mday = 3
341 struct isds_BirthInfo birth_info = {
342 .biDate = &biDate,
343 .biCity = "B1",
344 .biCounty = "B2",
345 .biState = "B3"
347 long int adCode = 4;
348 struct isds_Address address = {
349 .adCode = &adCode,
350 .adCity = "A1",
351 .adDistrict = "A2",
352 .adStreet = "A3",
353 .adNumberInStreet = "A4",
354 .adNumberInMunicipality = "A5",
355 .adZipCode = "A6",
356 .adState = "A7"
358 _Bool aifoIsds = 1;
359 struct isds_DbOwnerInfo result = {
360 .dbID = "foo1234",
361 .aifoIsds = &aifoIsds,
362 .personName = &person_name,
363 .birthInfo = &birth_info,
364 .address = &address,
365 .nationality = "3"
367 struct server_owner_info server_result = {
368 .dbID = result.dbID,
369 .aifoIsds = result.aifoIsds,
370 .dbType = NULL,
371 .ic = NULL,
372 .pnFirstName = result.personName->pnFirstName,
373 .pnMiddleName = result.personName->pnMiddleName,
374 .pnLastName = result.personName->pnLastName,
375 .pnLastNameAtBirth = NULL,
376 .firmName = 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,
390 .email_exists = 0,
391 .email = NULL,
392 .telNumber_exists = 0,
393 .telNumber = NULL,
394 .identifier = NULL,
395 .registryCode = NULL,
396 .dbState = NULL,
397 .dbEffectiveOVM = NULL,
398 .dbOpenAddressing = NULL
400 struct isds_list results = {
401 .next = NULL,
402 .data = &result,
403 .destructor = NULL
405 struct server_list server_results = {
406 .next = NULL,
407 .data = &server_result,
408 .destructor = NULL
411 const struct arguments_DS_df_FindDataBox service_arguments = {
412 .status_code = "0003",
413 .status_message = "Answer was truncated",
414 .criteria = &server_criteria,
415 .results_exists = 0,
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,
427 .services = services
429 error = start_server(&server_process, &url,
430 server_basic_authentication, &server_arguments, NULL);
431 if (error == -1) {
432 isds_ctx_free(&context);
433 isds_cleanup();
434 ABORT_UNIT(server_error);
436 TEST("login", test_login, IE_SUCCESS,
437 context, url, username, password, NULL, NULL);
438 free(url);
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);
446 isds_cleanup();
447 ABORT_UNIT(server_error);
452 /* Report 0002 server error as IE_NOEXIST */
453 char *url = NULL;
455 struct isds_DbOwnerInfo criteria = {
456 .dbID = "Cfoo123"
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,
466 .results_exists = 0,
467 .results = NULL
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,
478 .services = services
480 error = start_server(&server_process, &url,
481 server_basic_authentication, &server_arguments, NULL);
482 if (error == -1) {
483 isds_ctx_free(&context);
484 isds_cleanup();
485 ABORT_UNIT(server_error);
487 TEST("login", test_login, IE_SUCCESS,
488 context, url, username, password, NULL, NULL);
489 free(url);
491 TEST("Report 0002 server error as IE_NOEXIST",
492 test_isds_FindPersonalDataBox, IE_NOEXIST, context, &criteria,
493 NULL);
495 isds_logout(context);
496 if (stop_server(server_process)) {
497 isds_ctx_free(&context);
498 isds_cleanup();
499 ABORT_UNIT(server_error);
504 /* Report 5001 server error as IE_NOEXIST */
505 char *url = NULL;
507 struct isds_DbOwnerInfo criteria = {
508 .dbID = "Cfoo123"
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,
518 .results_exists = 0,
519 .results = NULL
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,
530 .services = services
532 error = start_server(&server_process, &url,
533 server_basic_authentication, &server_arguments, NULL);
534 if (error == -1) {
535 isds_ctx_free(&context);
536 isds_cleanup();
537 ABORT_UNIT(server_error);
539 TEST("login", test_login, IE_SUCCESS,
540 context, url, username, password, NULL, NULL);
541 free(url);
543 TEST("Report 0002 server error as IE_NOEXIST",
544 test_isds_FindPersonalDataBox, IE_NOEXIST, context, &criteria,
545 NULL);
547 isds_logout(context);
548 if (stop_server(server_process)) {
549 isds_ctx_free(&context);
550 isds_cleanup();
551 ABORT_UNIT(server_error);
558 isds_ctx_free(&context);
559 isds_cleanup();
560 SUM_TEST();