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 char *server_address
= NULL
;
53 struct isds_ctx
*context
= 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");
63 ABORT_UNIT("isds_init() failed\n");
65 context
= isds_ctx_create();
68 ABORT_UNIT("isds_ctx_create() failed\n");
72 const struct arguments_DS_Dx_EraseMessage service_arguments
= {
73 .message_id
= "1234567",
76 const struct service_configuration services
[] = {
77 { SERVICE_DS_Dz_DummyOperation
, NULL
},
78 { SERVICE_DS_Dx_EraseMessage
, &service_arguments
},
81 const struct arguments_basic_authentication server_arguments
= {
87 error
= start_server(&server_process
, &server_address
,
88 server_basic_authentication
, &server_arguments
, NULL
);
90 isds_ctx_free(&context
);
92 ABORT_UNIT(server_error
);
94 if (-1 == test_asprintf(&url
, "http://%s/", server_address
)) {
96 stop_server(server_process
);
97 isds_ctx_free(&context
);
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
);
123 isds_logout(context
);
124 isds_ctx_free(&context
);