test: starting server returns URL instead of socket address
[libisds.git] / test / simline / basic_authentication.c
blob67bc1e4f2a78d513b90b47c4ce253136f5d99e21
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 struct isds_ctx *context = NULL;
41 char *url = NULL;
43 INIT_TEST("basic authentication");
45 if (unsetenv("http_proxy")) {
46 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
48 if (isds_init()) {
49 isds_cleanup();
50 ABORT_UNIT("isds_init() failed\n");
52 context = isds_ctx_create();
53 if (!context) {
54 isds_cleanup();
55 ABORT_UNIT("isds_ctx_create() failed\n");
59 const struct service_configuration services[] = {
60 { SERVICE_DS_Dz_DummyOperation, NULL },
61 { SERVICE_END, NULL }
63 const struct arguments_basic_authentication server_arguments = {
64 .username = username,
65 .password = password,
66 .isds_deviations = 1,
67 .services = services
69 error = start_server(&server_process, &url,
70 server_basic_authentication, &server_arguments, NULL);
71 if (error == -1) {
72 isds_ctx_free(&context);
73 isds_cleanup();
74 ABORT_UNIT(server_error);
77 TEST("invalid credentials", test_login, IE_NOT_LOGGED_IN, context,
78 url, "7777777", "nbuusr1", NULL, NULL);
80 TEST("valid login", test_login, IE_SUCCESS, context,
81 url, username, password, NULL, NULL);
83 if (stop_server(server_process)) {
84 ABORT_UNIT(server_error);
87 free(url);
88 url = NULL;
92 error = start_server(&server_process, &url,
93 server_out_of_order, NULL, NULL);
94 if (error == -1) {
95 isds_ctx_free(&context);
96 isds_cleanup();
97 ABORT_UNIT(server_error);
100 TEST("log into out-of-order server", test_login, IE_SOAP, context,
101 url, username, password, NULL, NULL);
103 if (stop_server(server_process)) {
104 ABORT_UNIT(server_error);
107 free(url);
108 url = NULL;
111 isds_ctx_free(&context);
112 isds_cleanup();
113 SUM_TEST();