test: Report server crash in simline tests
[libisds.git] / test / simline / isds_delete_message_from_storage.c
blobdbf4283b316c7d3324af2fb823c71870101ab62c
1 #ifndef _POSIX_SOURCE
2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
3 #endif
5 #ifndef _BSD_SOURCE
6 #define _BSD_SOURCE /* For NI_MAXHOST */
7 #endif
9 #ifndef _XOPEN_SOURCE
10 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
11 #endif
13 #include "../test.h"
14 #include "server.h"
15 #include "isds.h"
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) {
25 isds_error err;
27 err = isds_login(context, url, username, password, pki_credentials, otp);
28 if (error != err)
29 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
30 isds_strerror(error), isds_strerror(err),
31 isds_long_message(context));
33 PASS_TEST;
36 static int test_isds_delete_message_from_storage(const isds_error error,
37 struct isds_ctx *context, const char *message_id, _Bool incoming) {
38 isds_error err;
40 err = isds_delete_message_from_storage(context, message_id, incoming);
41 if (error != err)
42 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
43 isds_strerror(error), isds_strerror(err),
44 isds_long_message(context));
46 PASS_TEST;
49 int main(int argc, char **argv) {
50 int error;
51 pid_t server_process;
52 char *server_address = NULL;
53 struct isds_ctx *context = NULL;
54 char *url = NULL;
56 INIT_TEST("isds_delete_message_from_storage");
58 if (unsetenv("http_proxy")) {
59 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
61 if (isds_init()) {
62 isds_cleanup();
63 ABORT_UNIT("isds_init() failed\n");
65 context = isds_ctx_create();
66 if (!context) {
67 isds_cleanup();
68 ABORT_UNIT("isds_ctx_create() failed\n");
72 const struct arguments_DS_Dx_EraseMessage service_arguments = {
73 .message_id = "1234567",
74 .incoming = 1
76 const struct service_configuration services[] = {
77 { SERVICE_DS_Dz_DummyOperation, NULL },
78 { SERVICE_DS_Dx_EraseMessage, &service_arguments },
79 { SERVICE_END, NULL }
81 const struct arguments_basic_authentication server_arguments = {
82 .username = username,
83 .password = password,
84 .isds_deviations = 1,
85 .services = services
87 error = start_server(&server_process, &server_address,
88 server_basic_authentication, &server_arguments, NULL);
89 if (error == -1) {
90 isds_ctx_free(&context);
91 isds_cleanup();
92 ABORT_UNIT(server_error);
94 if (-1 == test_asprintf(&url, "http://%s/", server_address)) {
95 free(server_address);
96 stop_server(server_process);
97 isds_ctx_free(&context);
98 isds_cleanup();
99 ABORT_UNIT("Could not format ISDS URL");
101 free(server_address);
103 TEST("prior logging in", test_isds_delete_message_from_storage,
104 IE_CONNECTION_CLOSED, context, "1234567", 1);
105 TEST("login", test_login, IE_SUCCESS,
106 context, url, username, password, NULL, NULL);
107 TEST("bad message ID", test_isds_delete_message_from_storage, IE_INVAL,
108 context, "1000000", 1);
109 TEST("bad direction", test_isds_delete_message_from_storage, IE_INVAL,
110 context, "1234567", 0);
111 TEST("good ID and direction", test_isds_delete_message_from_storage,
112 IE_SUCCESS, context, "1234567", 1);
114 if (stop_server(server_process)) {
115 ABORT_UNIT(server_error);
118 free(url);
119 url = NULL;
123 isds_logout(context);
124 isds_ctx_free(&context);
125 isds_cleanup();
126 SUM_TEST();