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 test_isds_resign_message(const isds_error error
,
40 struct isds_ctx
*context
, const void *data
, size_t length
,
41 _Bool request_valid_to
, const struct tm
*expected_valid_to
) {
44 size_t output_length
= 0;
45 struct tm
*valid_to
= NULL
;
47 err
= isds_resign_message(context
, data
, length
, &output
, &output_length
,
48 (request_valid_to
) ? &valid_to
: NULL
);
52 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
53 isds_strerror(error
), isds_strerror(err
),
54 isds_long_message(context
));
60 FAIL_TEST("No message returned");
62 if (length
!= output_length
) {
65 FAIL_TEST("Wrong size of returned message: "
66 "expected=%zd, returned=%zd", length
, output_length
);
68 if (strcmp(data
, output
)) {
71 FAIL_TEST("Returned message does not match input message: "
72 "expected=`%s', returned=`%s'", data
, output
);
75 if (0 != output_length
) {
78 FAIL_TEST("Output size is not 0 on error");
83 FAIL_TEST("Output data pointer is not NULL on error");
88 if (NULL
== expected_valid_to
) {
89 if (NULL
!= valid_to
) {
91 FAIL_TEST("Valid_to pointer is not NULL");
94 if (NULL
== valid_to
) {
96 FAIL_TEST("Valid_to pointer should not be NULL");
99 expected_valid_to
->tm_year
!= valid_to
->tm_year
||
100 expected_valid_to
->tm_mon
!= valid_to
->tm_mon
||
101 expected_valid_to
->tm_mday
!= valid_to
->tm_mday
105 strftime(expected
, sizeof(expected
), "%F", expected_valid_to
);
106 strftime(returned
, sizeof(returned
), "%F", valid_to
);
108 FAIL_TEST("Wrong valid_to date: expected=%s, returned=%s",
118 static void test_error(const char *code
, const isds_error expected_error
,
119 struct isds_ctx
*context
) {
120 struct arguments_DS_Dz_ResignISDSDocument service_arguments
= {
122 .status_message
= "some text",
125 const struct service_configuration services
[] = {
126 { SERVICE_DS_Dz_DummyOperation
, NULL
},
127 { SERVICE_DS_Dz_ResignISDSDocument
, &service_arguments
},
128 { SERVICE_END
, NULL
}
130 const struct arguments_basic_authentication server_arguments
= {
131 .username
= username
,
132 .password
= password
,
133 .isds_deviations
= 1,
136 const char data
[] = "Hello world!";
137 pid_t server_process
;
141 error
= start_server(&server_process
, &url
,
142 server_basic_authentication
, &server_arguments
, NULL
);
144 isds_ctx_free(&context
);
146 ABORT_UNIT(server_error
);
149 TEST("login", test_login
, IE_SUCCESS
,
150 context
, url
, username
, password
, NULL
, NULL
);
151 TEST(code
, test_isds_resign_message
,
152 expected_error
, context
, data
, sizeof(data
), 1, NULL
);
154 isds_logout(context
);
155 if (stop_server(server_process
)) {
156 isds_ctx_free(&context
);
158 ABORT_UNIT(server_error
);
166 pid_t server_process
;
167 struct isds_ctx
*context
= NULL
;
170 INIT_TEST("isds_resing_message");
172 if (unsetenv("http_proxy")) {
173 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
177 ABORT_UNIT("isds_init() failed\n");
179 context
= isds_ctx_create();
182 ABORT_UNIT("isds_ctx_create() failed\n");
187 const struct arguments_DS_Dz_ResignISDSDocument service_arguments
= {
188 .status_code
= "0000",
189 .status_message
= "some text",
192 const struct service_configuration services
[] = {
193 { SERVICE_DS_Dz_DummyOperation
, NULL
},
194 { SERVICE_DS_Dz_ResignISDSDocument
, &service_arguments
},
195 { SERVICE_END
, NULL
}
197 const struct arguments_basic_authentication server_arguments
= {
198 .username
= username
,
199 .password
= password
,
200 .isds_deviations
= 1,
203 memset(&date
, 0, sizeof(date
));
207 const char data
[] = "Hello world!";
209 error
= start_server(&server_process
, &url
,
210 server_basic_authentication
, &server_arguments
, NULL
);
212 isds_ctx_free(&context
);
214 ABORT_UNIT(server_error
);
217 TEST("prior logging in", test_isds_resign_message
,
218 IE_CONNECTION_CLOSED
, context
, data
, sizeof(data
), 1, NULL
);
219 TEST("login", test_login
, IE_SUCCESS
,
220 context
, url
, username
, password
, NULL
, NULL
);
221 TEST("NULL message", test_isds_resign_message
,
222 IE_INVAL
, context
, NULL
, 42, 1, NULL
);
223 TEST("empty message", test_isds_resign_message
,
224 IE_INVAL
, context
, "", 0, 1, NULL
);
225 TEST("valid message", test_isds_resign_message
,
226 IE_SUCCESS
, context
, data
, sizeof(data
), 1, &date
);
227 TEST("valid message without date", test_isds_resign_message
,
228 IE_SUCCESS
, context
, data
, sizeof(data
), 0, NULL
);
230 isds_logout(context
);
231 if (stop_server(server_process
)) {
232 isds_ctx_free(&context
);
234 ABORT_UNIT(server_error
);
240 test_error("2200", IE_INVAL
, context
);
241 test_error("2201", IE_NOTUNIQ
, context
);
242 test_error("2204", IE_INVAL
, context
);
243 test_error("2207", IE_ISDS
, context
);
245 isds_ctx_free(&context
);