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_delete_message_from_storage(const isds_error error
,
37 struct isds_ctx
*context
, const char *message_id
, _Bool incoming
) {
40 err
= isds_delete_message_from_storage(context
, message_id
, incoming
);
42 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
43 isds_strerror(error
), isds_strerror(err
),
44 isds_long_message(context
));
49 int main(int argc
, char **argv
) {
52 struct isds_ctx
*context
= NULL
;
55 INIT_TEST("isds_delete_message_from_storage");
57 if (unsetenv("http_proxy")) {
58 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
62 ABORT_UNIT("isds_init() failed\n");
64 context
= isds_ctx_create();
67 ABORT_UNIT("isds_ctx_create() failed\n");
71 const struct arguments_DS_Dx_EraseMessage service_arguments
= {
72 .message_id
= "1234567",
75 const struct service_configuration services
[] = {
76 { SERVICE_DS_Dz_DummyOperation
, NULL
},
77 { SERVICE_DS_Dx_EraseMessage
, &service_arguments
},
80 const struct arguments_basic_authentication server_arguments
= {
86 error
= start_server(&server_process
, &url
,
87 server_basic_authentication
, &server_arguments
, NULL
);
89 isds_ctx_free(&context
);
91 ABORT_UNIT(server_error
);
94 TEST("prior logging in", test_isds_delete_message_from_storage
,
95 IE_CONNECTION_CLOSED
, context
, "1234567", 1);
96 TEST("login", test_login
, IE_SUCCESS
,
97 context
, url
, username
, password
, NULL
, NULL
);
98 TEST("bad message ID", test_isds_delete_message_from_storage
, IE_INVAL
,
99 context
, "1000000", 1);
100 TEST("bad direction", test_isds_delete_message_from_storage
, IE_INVAL
,
101 context
, "1234567", 0);
102 TEST("good ID and direction", test_isds_delete_message_from_storage
,
103 IE_SUCCESS
, context
, "1234567", 1);
105 if (stop_server(server_process
)) {
106 ABORT_UNIT(server_error
);
114 isds_logout(context
);
115 isds_ctx_free(&context
);