2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
6 #define _BSD_SOURCE /* For NI_MAXHOST */
10 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
17 static const char *username
= "Doug1as$";
18 static const char *password
= "42aA#bc8";
21 static int test_login(const isds_error error
, struct isds_ctx
*context
,
22 const char *url
, const char *username
, const char *password
,
23 const struct isds_pki_credentials
*pki_credentials
,
24 struct isds_otp
*otp
) {
27 err
= isds_login(context
, url
, username
, password
, pki_credentials
, otp
);
29 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
30 isds_strerror(error
), isds_strerror(err
),
31 isds_long_message(context
));
36 static int test_isds_resign_message(const isds_error error
,
37 struct isds_ctx
*context
, const void *data
, size_t length
,
38 _Bool request_valid_to
, const struct tm
*expected_valid_to
) {
41 size_t output_length
= 0;
42 struct tm
*valid_to
= NULL
;
44 err
= isds_resign_message(context
, data
, length
, &output
, &output_length
,
45 (request_valid_to
) ? &valid_to
: NULL
);
49 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
50 isds_strerror(error
), isds_strerror(err
),
51 isds_long_message(context
));
57 FAIL_TEST("No message returned");
59 if (length
!= output_length
) {
62 FAIL_TEST("Wrong size of returned message: "
63 "expected=%zd, returned=%zd", length
, output_length
);
65 if (strcmp(data
, output
)) {
68 FAIL_TEST("Returned message does not match input message: "
69 "expected=`%s', returned=`%s'", data
, output
);
72 if (0 != output_length
) {
75 FAIL_TEST("Output size is not 0 on error");
80 FAIL_TEST("Output data pointer is not NULL on error");
85 if (NULL
== expected_valid_to
) {
86 if (NULL
!= valid_to
) {
88 FAIL_TEST("Valid_to pointer is not NULL");
91 if (NULL
== valid_to
) {
93 FAIL_TEST("Valid_to pointer should not be NULL");
96 expected_valid_to
->tm_year
!= valid_to
->tm_year
||
97 expected_valid_to
->tm_mon
!= valid_to
->tm_mon
||
98 expected_valid_to
->tm_mday
!= valid_to
->tm_mday
102 strftime(expected
, sizeof(expected
), "%F", expected_valid_to
);
103 strftime(returned
, sizeof(returned
), "%F", valid_to
);
105 FAIL_TEST("Wrong valid_to date: expected=%s, returned=%s",
115 static void test_error(const char *code
, const isds_error expected_error
,
116 struct isds_ctx
*context
) {
117 struct arguments_DS_Dz_ResignISDSDocument service_arguments
= {
119 .status_message
= "some text",
122 const struct service_configuration services
[] = {
123 { SERVICE_DS_Dz_DummyOperation
, NULL
},
124 { SERVICE_DS_Dz_ResignISDSDocument
, &service_arguments
},
125 { SERVICE_END
, NULL
}
127 const struct arguments_basic_authentication server_arguments
= {
128 .username
= username
,
129 .password
= password
,
130 .isds_deviations
= 1,
133 const char data
[] = "Hello world!";
134 pid_t server_process
;
138 error
= start_server(&server_process
, &url
,
139 server_basic_authentication
, &server_arguments
, NULL
);
141 isds_ctx_free(&context
);
143 ABORT_UNIT(server_error
);
146 TEST("login", test_login
, IE_SUCCESS
,
147 context
, url
, username
, password
, NULL
, NULL
);
148 TEST(code
, test_isds_resign_message
,
149 expected_error
, context
, data
, sizeof(data
), 1, NULL
);
151 isds_logout(context
);
152 if (stop_server(server_process
)) {
153 ABORT_UNIT(server_error
);
159 int main(int argc
, char **argv
) {
161 pid_t server_process
;
162 struct isds_ctx
*context
= NULL
;
165 INIT_TEST("isds_resing_message");
167 if (unsetenv("http_proxy")) {
168 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
172 ABORT_UNIT("isds_init() failed\n");
174 context
= isds_ctx_create();
177 ABORT_UNIT("isds_ctx_create() failed\n");
182 const struct arguments_DS_Dz_ResignISDSDocument service_arguments
= {
183 .status_code
= "0000",
184 .status_message
= "some text",
187 const struct service_configuration services
[] = {
188 { SERVICE_DS_Dz_DummyOperation
, NULL
},
189 { SERVICE_DS_Dz_ResignISDSDocument
, &service_arguments
},
190 { SERVICE_END
, NULL
}
192 const struct arguments_basic_authentication server_arguments
= {
193 .username
= username
,
194 .password
= password
,
195 .isds_deviations
= 1,
198 memset(&date
, 0, sizeof(date
));
202 const char data
[] = "Hello world!";
204 error
= start_server(&server_process
, &url
,
205 server_basic_authentication
, &server_arguments
, NULL
);
207 isds_ctx_free(&context
);
209 ABORT_UNIT(server_error
);
212 TEST("prior logging in", test_isds_resign_message
,
213 IE_CONNECTION_CLOSED
, context
, data
, sizeof(data
), 1, NULL
);
214 TEST("login", test_login
, IE_SUCCESS
,
215 context
, url
, username
, password
, NULL
, NULL
);
216 TEST("NULL message", test_isds_resign_message
,
217 IE_INVAL
, context
, NULL
, 42, 1, NULL
);
218 TEST("empty message", test_isds_resign_message
,
219 IE_INVAL
, context
, "", 0, 1, NULL
);
220 TEST("valid message", test_isds_resign_message
,
221 IE_SUCCESS
, context
, data
, sizeof(data
), 1, &date
);
222 TEST("valid message without date", test_isds_resign_message
,
223 IE_SUCCESS
, context
, data
, sizeof(data
), 0, NULL
);
225 isds_logout(context
);
226 if (stop_server(server_process
)) {
227 ABORT_UNIT(server_error
);
233 test_error("2200", IE_INVAL
, context
);
234 test_error("2201", IE_NOTUNIQ
, context
);
235 test_error("2204", IE_INVAL
, context
);
236 test_error("2207", IE_ISDS
, context
);
238 isds_ctx_free(&context
);