test: Add TLS arguments to server
[libisds.git] / test / simline / basic_authentication.c
blob8415d4bed544943690b3e919613afcbfd1476c83
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 = "douglas";
18 static const char *password = "42";
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 isds_logout(context);
34 PASS_TEST;
37 int main(int argc, char **argv) {
38 int error;
39 pid_t server_process;
40 char *server_address = NULL;
41 struct isds_ctx *context = NULL;
42 char *url = NULL;
44 INIT_TEST("basic authentication");
46 if (unsetenv("http_proxy")) {
47 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
49 if (isds_init()) {
50 isds_cleanup();
51 ABORT_UNIT("isds_init() failed\n");
53 context = isds_ctx_create();
54 if (!context) {
55 isds_cleanup();
56 ABORT_UNIT("isds_ctx_create() failed\n");
60 const struct service_configuration services[] = {
61 { SERVICE_DS_Dz_DummyOperation, NULL },
62 { SERVICE_END, NULL }
64 const struct arguments_basic_authentication server_arguments = {
65 .tls = NULL,
66 .username = username,
67 .password = password,
68 .isds_deviations = 1,
69 .services = services
71 error = start_server(&server_process, &server_address,
72 server_basic_authentication, &server_arguments);
73 if (error == -1) {
74 isds_ctx_free(&context);
75 isds_cleanup();
76 ABORT_UNIT(server_error);
78 if (-1 == test_asprintf(&url, "http://%s/", server_address)) {
79 free(server_address);
80 stop_server(server_process);
81 isds_ctx_free(&context);
82 isds_cleanup();
83 ABORT_UNIT("Could not format ISDS URL");
85 free(server_address);
87 TEST("invalid credentials", test_login, IE_NOT_LOGGED_IN, context,
88 url, "7777777", "nbuusr1", NULL, NULL);
90 TEST("valid login", test_login, IE_SUCCESS, context,
91 url, username, password, NULL, NULL);
93 if (-1 == stop_server(server_process)) {
94 ABORT_UNIT(server_error);
97 free(url);
98 url = NULL;
102 error = start_server(&server_process, &server_address,
103 server_out_of_order, NULL);
104 if (error == -1) {
105 isds_ctx_free(&context);
106 isds_cleanup();
107 ABORT_UNIT(server_error);
109 if (-1 == test_asprintf(&url, "http://%s/", server_address)) {
110 free(server_address);
111 stop_server(server_process);
112 isds_ctx_free(&context);
113 isds_cleanup();
114 ABORT_UNIT("Could not format ISDS URL");
116 free(server_address);
118 TEST("log into out-of-order server", test_login, IE_SOAP, context,
119 url, username, password, NULL, NULL);
121 if (-1 == stop_server(server_process)) {
122 ABORT_UNIT(server_error);
125 free(url);
126 url = NULL;
129 isds_ctx_free(&context);
130 isds_cleanup();
131 SUM_TEST();