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 ABORT_UNIT(server_error
);
162 int main(int argc
, char **argv
) {
164 pid_t server_process
;
165 struct isds_ctx
*context
= NULL
;
168 INIT_TEST("isds_resing_message");
170 if (unsetenv("http_proxy")) {
171 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
175 ABORT_UNIT("isds_init() failed\n");
177 context
= isds_ctx_create();
180 ABORT_UNIT("isds_ctx_create() failed\n");
185 const struct arguments_DS_Dz_ResignISDSDocument service_arguments
= {
186 .status_code
= "0000",
187 .status_message
= "some text",
190 const struct service_configuration services
[] = {
191 { SERVICE_DS_Dz_DummyOperation
, NULL
},
192 { SERVICE_DS_Dz_ResignISDSDocument
, &service_arguments
},
193 { SERVICE_END
, NULL
}
195 const struct arguments_basic_authentication server_arguments
= {
196 .username
= username
,
197 .password
= password
,
198 .isds_deviations
= 1,
201 memset(&date
, 0, sizeof(date
));
205 const char data
[] = "Hello world!";
207 error
= start_server(&server_process
, &url
,
208 server_basic_authentication
, &server_arguments
, NULL
);
210 isds_ctx_free(&context
);
212 ABORT_UNIT(server_error
);
215 TEST("prior logging in", test_isds_resign_message
,
216 IE_CONNECTION_CLOSED
, context
, data
, sizeof(data
), 1, NULL
);
217 TEST("login", test_login
, IE_SUCCESS
,
218 context
, url
, username
, password
, NULL
, NULL
);
219 TEST("NULL message", test_isds_resign_message
,
220 IE_INVAL
, context
, NULL
, 42, 1, NULL
);
221 TEST("empty message", test_isds_resign_message
,
222 IE_INVAL
, context
, "", 0, 1, NULL
);
223 TEST("valid message", test_isds_resign_message
,
224 IE_SUCCESS
, context
, data
, sizeof(data
), 1, &date
);
225 TEST("valid message without date", test_isds_resign_message
,
226 IE_SUCCESS
, context
, data
, sizeof(data
), 0, NULL
);
228 isds_logout(context
);
229 if (stop_server(server_process
)) {
230 ABORT_UNIT(server_error
);
236 test_error("2200", IE_INVAL
, context
);
237 test_error("2201", IE_NOTUNIQ
, context
);
238 test_error("2204", IE_INVAL
, context
);
239 test_error("2207", IE_ISDS
, context
);
241 isds_ctx_free(&context
);