Fix using CURLOPT_XFERINFOFUNCTION curl option
[libisds.git] / test / simline / basic_authentication.c
blob3ec0a92608fa25fd3787840ce1c42a4084e06f52
1 #ifndef _POSIX_SOURCE
2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
3 #endif
5 #ifndef _BSD_SOURCE
6 #define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */
7 #endif
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */
10 #endif
12 #ifndef _XOPEN_SOURCE
13 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
14 #endif
16 #include "../test.h"
17 #include "server.h"
18 #include "isds.h"
20 static const char *username = "douglas";
21 static const char *password = "42";
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) {
28 isds_error err;
30 err = isds_login(context, url, username, password, pki_credentials, otp);
31 if (error != err)
32 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
33 isds_strerror(error), isds_strerror(err),
34 isds_long_message(context));
36 isds_logout(context);
37 PASS_TEST;
40 int main(void) {
41 int error;
42 pid_t server_process;
43 struct isds_ctx *context = NULL;
44 char *url = NULL;
46 INIT_TEST("basic authentication");
48 if (unsetenv("http_proxy")) {
49 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
51 if (isds_init()) {
52 isds_cleanup();
53 ABORT_UNIT("isds_init() failed\n");
55 context = isds_ctx_create();
56 if (!context) {
57 isds_cleanup();
58 ABORT_UNIT("isds_ctx_create() failed\n");
62 const struct service_configuration services[] = {
63 { SERVICE_DS_Dz_DummyOperation, NULL },
64 { SERVICE_END, NULL }
66 const struct arguments_basic_authentication server_arguments = {
67 .username = username,
68 .password = password,
69 .isds_deviations = 1,
70 .services = services
72 error = start_server(&server_process, &url,
73 server_basic_authentication, &server_arguments, NULL);
74 if (error == -1) {
75 isds_ctx_free(&context);
76 isds_cleanup();
77 ABORT_UNIT(server_error);
80 TEST("invalid credentials", test_login, IE_NOT_LOGGED_IN, context,
81 url, "7777777", "nbuusr1", NULL, NULL);
83 TEST("valid login", test_login, IE_SUCCESS, context,
84 url, username, password, NULL, NULL);
86 if (stop_server(server_process)) {
87 isds_ctx_free(&context);
88 isds_cleanup();
89 ABORT_UNIT(server_error);
92 free(url);
93 url = NULL;
97 error = start_server(&server_process, &url,
98 server_out_of_order, NULL, NULL);
99 if (error == -1) {
100 isds_ctx_free(&context);
101 isds_cleanup();
102 ABORT_UNIT(server_error);
105 TEST("log into out-of-order server", test_login, IE_SOAP, context,
106 url, username, password, NULL, NULL);
108 if (stop_server(server_process)) {
109 isds_ctx_free(&context);
110 isds_cleanup();
111 ABORT_UNIT(server_error);
114 free(url);
115 url = NULL;
118 isds_ctx_free(&context);
119 isds_cleanup();
120 SUM_TEST();