2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
6 #define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */
13 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
20 static const char *username
= "Doug1as$";
21 static const char *password
= "42aA#bc8";
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
) {
30 err
= isds_login(context
, url
, username
, password
, pki_credentials
, otp
);
32 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
33 isds_strerror(error
), isds_strerror(err
),
34 isds_long_message(context
));
39 static int test_isds_ping(const isds_error error
, struct isds_ctx
*context
) {
42 err
= isds_ping(context
);
45 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
46 isds_strerror(error
), isds_strerror(err
),
47 isds_long_message(context
));
57 struct isds_ctx
*context
= NULL
;
60 INIT_TEST("isds_ping");
62 if (unsetenv("http_proxy")) {
63 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
67 ABORT_UNIT("isds_init() failed\n");
69 context
= isds_ctx_create();
72 ABORT_UNIT("isds_ctx_create() failed\n");
76 const struct service_configuration services
[] = {
77 { SERVICE_DS_Dz_DummyOperation
, NULL
},
80 const struct arguments_basic_authentication server_arguments
= {
87 error
= start_server(&server_process
, &url
,
88 server_basic_authentication
, &server_arguments
, NULL
);
90 isds_ctx_free(&context
);
92 ABORT_UNIT(server_error
);
95 TEST("prior logging in", test_isds_ping
,
96 IE_CONNECTION_CLOSED
, context
);
97 TEST("login", test_login
, IE_SUCCESS
,
98 context
, url
, username
, password
, NULL
, NULL
);
99 TEST("after logging in", test_isds_ping
,
100 IE_SUCCESS
, context
);
102 /* Terminate server without loggin out, we will exhibit calls on the
103 * logged-in context later. */
104 if (stop_server(server_process
)) {
105 isds_ctx_free(&context
);
107 ABORT_UNIT(server_error
);
113 /* Shorten network timeout to make tests faster */
114 if (isds_set_timeout(context
, 500) != IE_SUCCESS
) {
115 isds_ctx_free(&context
);
117 ABORT_UNIT("isds_set_timeout() failed");
119 TEST("when server disappears", test_isds_ping
,
120 IE_NETWORK
, context
);
122 isds_logout(context
);
123 TEST("after logging out", test_isds_ping
,
124 IE_CONNECTION_CLOSED
, context
);
126 isds_ctx_free(&context
);