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
));
36 static int test_isds_change_password(const isds_error error
,
37 struct isds_ctx
*context
, const char *old_password
,
38 const char *new_password
, struct isds_otp
*otp
) {
41 err
= isds_change_password(context
, old_password
, new_password
, otp
);
43 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
44 isds_strerror(error
), isds_strerror(err
),
45 isds_long_message(context
));
50 int main(int argc
, char **argv
) {
53 char *server_address
= NULL
;
54 struct isds_ctx
*context
= NULL
;
57 INIT_TEST("isds_change_password");
59 if (unsetenv("http_proxy")) {
60 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
64 ABORT_UNIT("isds_init() failed\n");
66 context
= isds_ctx_create();
69 ABORT_UNIT("isds_ctx_create() failed\n");
73 const struct service_configuration services
[] = {
74 { SERVICE_DS_Dz_DummyOperation
, NULL
},
75 { SERVICE_DS_DsManage_ChangeISDSPassword
, password
},
78 const struct arguments_basic_authentication server_arguments
= {
84 error
= start_server(&server_process
, &server_address
,
85 server_basic_authentication
, &server_arguments
);
87 isds_ctx_free(&context
);
89 ABORT_UNIT(server_error
);
91 if (-1 == test_asprintf(&url
, "http://%s/", server_address
)) {
93 stop_server(server_process
);
94 isds_ctx_free(&context
);
96 ABORT_UNIT("Could not format ISDS URL");
100 TEST("login", test_login
, IE_SUCCESS
, context
,
101 url
, username
, password
, NULL
, NULL
);
102 TEST("bad old password", test_isds_change_password
, IE_INVAL
, context
,
103 "bad old password", "h2k$aana", NULL
);
104 TEST("valid request", test_isds_change_password
, IE_SUCCESS
, context
,
105 password
, "h2k$aana", NULL
);
107 if (-1 == stop_server(server_process
)) {
108 ABORT_UNIT(server_error
);
116 isds_logout(context
);
117 isds_ctx_free(&context
);