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
= "douglas";
21 static const char *password
= "42";
22 static const char *otp_code
= "314";
25 static int test_login(const isds_error error
,
26 const isds_otp_resolution resolution
, struct isds_ctx
*context
,
27 const char *url
, const char *username
, const char *password
,
28 const struct isds_pki_credentials
*pki_credentials
,
29 struct isds_otp
*otp
) {
32 err
= isds_login(context
, url
, username
, password
, pki_credentials
, otp
);
34 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
35 isds_strerror(error
), isds_strerror(err
),
36 isds_long_message(context
));
37 if (otp
!= NULL
&& resolution
!= otp
->resolution
)
38 FAIL_TEST("Wrong OTP resolution: expected=%d, returned=%d (%s)",
39 resolution
, otp
->resolution
, isds_long_message(context
));
46 static int test_logout(const isds_error error
, struct isds_ctx
*context
) {
49 err
= isds_logout(context
);
51 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
52 isds_strerror(error
), isds_strerror(err
),
53 isds_long_message(context
));
58 static int test_ping(const isds_error error
, struct isds_ctx
*context
) {
61 err
= isds_ping(context
);
63 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
64 isds_strerror(error
), isds_strerror(err
),
65 isds_long_message(context
));
73 struct isds_ctx
*context
= NULL
;
76 struct isds_otp otp_credentials
= {
80 INIT_TEST("TOTP authentication");
82 if (unsetenv("http_proxy")) {
83 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
87 ABORT_UNIT("isds_init() failed\n");
89 context
= isds_ctx_create();
92 ABORT_UNIT("isds_ctx_create() failed\n");
96 const struct service_configuration services
[] = {
97 { SERVICE_DS_Dz_DummyOperation
, NULL
},
100 const struct arguments_otp_authentication server_arguments
= {
101 .method
= AUTH_OTP_TIME
,
102 .username
= username
,
103 .password
= password
,
104 .otp
= (char *) otp_code
,
105 .isds_deviations
= 1,
108 error
= start_server(&server_process
, &url
,
109 server_otp_authentication
, &server_arguments
, NULL
);
111 isds_ctx_free(&context
);
113 ABORT_UNIT(server_error
);
116 otp_credentials
.otp_code
= NULL
;
117 TEST("First phase with invalid password", test_login
,
118 IE_NOT_LOGGED_IN
, OTP_RESOLUTION_BAD_AUTHENTICATION
, context
,
119 url
, "7777777", "nbuusr1", NULL
, &otp_credentials
);
120 isds_logout(context
);
122 otp_credentials
.otp_code
= NULL
;
123 TEST("First phase with valid password", test_login
,
124 IE_PARTIAL_SUCCESS
, OTP_RESOLUTION_TOTP_SENT
, context
,
125 url
, username
, password
, NULL
, &otp_credentials
);
126 isds_logout(context
);
128 otp_credentials
.otp_code
= (char *) otp_code
;
129 TEST("Second phase with invalid password", test_login
,
130 IE_NOT_LOGGED_IN
, OTP_RESOLUTION_BAD_AUTHENTICATION
, context
,
131 url
, "7777777", "nbuusr1", NULL
, &otp_credentials
);
132 isds_logout(context
);
134 otp_credentials
.otp_code
= "666";
135 TEST("Second phase with valid password but invalid OTP code", test_login
,
136 IE_NOT_LOGGED_IN
, OTP_RESOLUTION_BAD_AUTHENTICATION
, context
,
137 url
, username
, password
, NULL
, &otp_credentials
);
138 isds_logout(context
);
140 otp_credentials
.otp_code
= (char *) otp_code
;
141 TEST("Second phase with valid password and valid OTP code", test_login
,
142 IE_SUCCESS
, OTP_RESOLUTION_SUCCESS
, context
,
143 url
, username
, password
, NULL
, &otp_credentials
);
144 TEST("Ping after succesfull OTP log-in", test_ping
,
145 IE_SUCCESS
, context
);
146 TEST("Log-out after successfull log-in", test_logout
,
147 IE_SUCCESS
, context
);
149 TEST("Ping after log-out after succesfull OTP log-in", test_ping
,
150 IE_CONNECTION_CLOSED
, context
);
152 if (stop_server(server_process
)) {
153 isds_ctx_free(&context
);
155 ABORT_UNIT(server_error
);
163 error
= start_server(&server_process
, &url
,
164 server_out_of_order
, NULL
, NULL
);
166 isds_ctx_free(&context
);
168 ABORT_UNIT(server_error
);
171 otp_credentials
.otp_code
= "666";
172 TEST("log into out-of-order server", test_login
,
173 IE_SOAP
, OTP_RESOLUTION_UNKNOWN
, context
,
174 url
, username
, password
, NULL
, &otp_credentials
);
175 isds_logout(context
);
177 if (stop_server(server_process
)) {
178 isds_ctx_free(&context
);
180 ABORT_UNIT(server_error
);
187 isds_ctx_free(&context
);