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
= "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
) {
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
));
37 int main(int argc
, char **argv
) {
40 char *server_address
= NULL
;
41 struct isds_ctx
*context
= NULL
;
44 INIT_TEST("basic authentication");
46 if (unsetenv("http_proxy")) {
47 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
51 ABORT_UNIT("isds_init() failed\n");
53 context
= isds_ctx_create();
56 ABORT_UNIT("isds_ctx_create() failed\n");
60 const struct arguments_basic_authentication server_arguments
= {
65 error
= start_server(&server_process
, &server_address
,
66 server_basic_authentication
, &server_arguments
);
68 isds_ctx_free(&context
);
70 ABORT_UNIT(server_error
);
72 if (-1 == test_asprintf(&url
, "http://%s/", server_address
)) {
74 stop_server(server_process
);
75 isds_ctx_free(&context
);
77 ABORT_UNIT("Could not format ISDS URL");
81 TEST("invalid credentials", test_login
, IE_NOT_LOGGED_IN
, context
,
82 url
, "7777777", "nbuusr1", NULL
, NULL
);
84 TEST("valid login", test_login
, IE_SUCCESS
, context
,
85 url
, username
, password
, NULL
, NULL
);
87 if (-1 == stop_server(server_process
)) {
88 ABORT_UNIT(server_error
);
96 error
= start_server(&server_process
, &server_address
,
97 server_out_of_order
, NULL
);
99 isds_ctx_free(&context
);
101 ABORT_UNIT(server_error
);
103 if (-1 == test_asprintf(&url
, "http://%s/", server_address
)) {
104 free(server_address
);
105 stop_server(server_process
);
106 isds_ctx_free(&context
);
108 ABORT_UNIT("Could not format ISDS URL");
110 free(server_address
);
112 TEST("log into out-of-order server", test_login
, IE_SOAP
, context
,
113 url
, username
, password
, NULL
, NULL
);
115 if (-1 == stop_server(server_process
)) {
116 ABORT_UNIT(server_error
);
123 isds_ctx_free(&context
);