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
));
45 static int test_logout(const isds_error error
, struct isds_ctx
*context
) {
48 err
= isds_logout(context
);
50 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
51 isds_strerror(error
), isds_strerror(err
),
52 isds_long_message(context
));
57 static int test_ping(const isds_error error
, struct isds_ctx
*context
) {
60 err
= isds_ping(context
);
62 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
63 isds_strerror(error
), isds_strerror(err
),
64 isds_long_message(context
));
72 struct isds_ctx
*context
= NULL
;
75 struct isds_otp otp_credentials
= {
79 INIT_TEST("HOTP authentication");
81 if (unsetenv("http_proxy")) {
82 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
86 ABORT_UNIT("isds_init() failed\n");
88 context
= isds_ctx_create();
91 ABORT_UNIT("isds_ctx_create() failed\n");
95 const struct service_configuration services
[] = {
96 { SERVICE_DS_Dz_DummyOperation
, NULL
},
99 const struct arguments_otp_authentication server_arguments
= {
100 .method
= AUTH_OTP_HMAC
,
101 .username
= username
,
102 .password
= password
,
104 .isds_deviations
= 1,
107 error
= start_server(&server_process
, &url
,
108 server_otp_authentication
, &server_arguments
, NULL
);
110 isds_ctx_free(&context
);
112 ABORT_UNIT(server_error
);
115 otp_credentials
.otp_code
= NULL
;
116 TEST("Invalid password and missing OTP code", test_login
,
117 IE_NOT_LOGGED_IN
, OTP_RESOLUTION_BAD_AUTHENTICATION
, context
,
118 url
, "7777777", "nbuusr1", NULL
, &otp_credentials
);
119 isds_logout(context
);
121 otp_credentials
.otp_code
= (char *) otp_code
;
122 TEST("Invalid password and valid OTP code", test_login
,
123 IE_NOT_LOGGED_IN
, OTP_RESOLUTION_BAD_AUTHENTICATION
, context
,
124 url
, "7777777", "nbuusr1", NULL
, &otp_credentials
);
125 isds_logout(context
);
127 otp_credentials
.otp_code
= NULL
;
128 TEST("Valid password but missing OTP code", test_login
,
129 IE_NOT_LOGGED_IN
, OTP_RESOLUTION_BAD_AUTHENTICATION
, context
,
130 url
, username
, password
, NULL
, &otp_credentials
);
131 isds_logout(context
);
133 otp_credentials
.otp_code
= "666";
134 TEST("Valid password but invalid OTP code", test_login
,
135 IE_NOT_LOGGED_IN
, OTP_RESOLUTION_BAD_AUTHENTICATION
, context
,
136 url
, username
, password
, NULL
, &otp_credentials
);
137 isds_logout(context
);
139 otp_credentials
.otp_code
= (char *) otp_code
;
140 TEST("Valid password and valid OTP code", test_login
,
141 IE_SUCCESS
, OTP_RESOLUTION_SUCCESS
, context
,
142 url
, username
, password
, NULL
, &otp_credentials
);
143 TEST("Ping after succesfull OTP log-in", test_ping
,
144 IE_SUCCESS
, context
);
145 TEST("Log-out after successfull log-in", test_logout
,
146 IE_SUCCESS
, context
);
148 TEST("Ping after log-out after succesfull OTP log-in", test_ping
,
149 IE_CONNECTION_CLOSED
, context
);
151 if (stop_server(server_process
)) {
152 isds_ctx_free(&context
);
154 ABORT_UNIT(server_error
);
162 error
= start_server(&server_process
, &url
,
163 server_out_of_order
, NULL
, NULL
);
165 isds_ctx_free(&context
);
167 ABORT_UNIT(server_error
);
170 otp_credentials
.otp_code
= "666";
171 TEST("log into out-of-order server", test_login
,
172 IE_SOAP
, OTP_RESOLUTION_UNKNOWN
, context
,
173 url
, username
, password
, NULL
, &otp_credentials
);
174 isds_logout(context
);
176 if (stop_server(server_process
)) {
177 isds_ctx_free(&context
);
179 ABORT_UNIT(server_error
);
186 isds_ctx_free(&context
);