test: starting server returns URL instead of socket address
[libisds.git] / test / simline / isds_delete_message_from_storage.c
blob29bc9787aeefb88ba8da6175e50ffb8549ceda00
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 struct isds_ctx *context = NULL;
53 char *url = 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");
60 if (isds_init()) {
61 isds_cleanup();
62 ABORT_UNIT("isds_init() failed\n");
64 context = isds_ctx_create();
65 if (!context) {
66 isds_cleanup();
67 ABORT_UNIT("isds_ctx_create() failed\n");
71 const struct arguments_DS_Dx_EraseMessage service_arguments = {
72 .message_id = "1234567",
73 .incoming = 1
75 const struct service_configuration services[] = {
76 { SERVICE_DS_Dz_DummyOperation, NULL },
77 { SERVICE_DS_Dx_EraseMessage, &service_arguments },
78 { SERVICE_END, NULL }
80 const struct arguments_basic_authentication server_arguments = {
81 .username = username,
82 .password = password,
83 .isds_deviations = 1,
84 .services = services
86 error = start_server(&server_process, &url,
87 server_basic_authentication, &server_arguments, NULL);
88 if (error == -1) {
89 isds_ctx_free(&context);
90 isds_cleanup();
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);
109 free(url);
110 url = NULL;
114 isds_logout(context);
115 isds_ctx_free(&context);
116 isds_cleanup();
117 SUM_TEST();