test: starting server returns URL instead of socket address
[libisds.git] / test / simline / isds_change_password.c
blob3bec5e2dd42d8985bae9c1b3bd44c46edb0b3e2a
1 #ifndef _POSIX_SOURCE
2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
3 #endif
5 #ifndef _BSD_SOURCE
6 #define _BSD_SOURCE /* For NI_MAXHOST */
7 #endif
9 #ifndef _XOPEN_SOURCE
10 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
11 #endif
13 #include "../test.h"
14 #include "server.h"
15 #include "isds.h"
17 static const char *username = "Doug1as$";
18 static const char *password = "42aA#bc8";
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) {
25 isds_error err;
27 err = isds_login(context, url, username, password, pki_credentials, otp);
28 if (error != err)
29 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
30 isds_strerror(error), isds_strerror(err),
31 isds_long_message(context));
33 PASS_TEST;
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, char **refnum) {
39 isds_error err;
41 err = isds_change_password(context, old_password, new_password, otp,
42 refnum);
43 if (error != err)
44 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
45 isds_strerror(error), isds_strerror(err),
46 isds_long_message(context));
48 PASS_TEST;
51 int main(int argc, char **argv) {
52 int error;
53 pid_t server_process;
54 struct isds_ctx *context = NULL;
55 char *url = NULL;
57 INIT_TEST("isds_change_password");
59 if (unsetenv("http_proxy")) {
60 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
62 if (isds_init()) {
63 isds_cleanup();
64 ABORT_UNIT("isds_init() failed\n");
66 context = isds_ctx_create();
67 if (!context) {
68 isds_cleanup();
69 ABORT_UNIT("isds_ctx_create() failed\n");
73 const struct arguments_DS_DsManage_ChangeISDSPassword service_arguments = {
74 .username = username,
75 .current_password = password
77 const struct service_configuration services[] = {
78 { SERVICE_DS_Dz_DummyOperation, NULL },
79 { SERVICE_DS_DsManage_ChangeISDSPassword, &service_arguments },
80 { SERVICE_END, NULL }
82 const struct arguments_basic_authentication server_arguments = {
83 .username = username,
84 .password = password,
85 .isds_deviations = 1,
86 .services = services
88 error = start_server(&server_process, &url,
89 server_basic_authentication, &server_arguments, NULL);
90 if (error == -1) {
91 isds_ctx_free(&context);
92 isds_cleanup();
93 ABORT_UNIT(server_error);
96 TEST("login", test_login, IE_SUCCESS,
97 context, url, username, password, NULL, NULL);
98 TEST("bad old password", test_isds_change_password, IE_INVAL,
99 context, "bad old password", "h2k$Aana", NULL, NULL);
100 TEST("too short (7 characters)", test_isds_change_password, IE_INVAL,
101 context, password, "aB34567", NULL, NULL);
102 TEST("too long (33 characters)", test_isds_change_password, IE_INVAL,
103 context, password, "aB3456789112345678921234567893123", NULL, NULL);
104 TEST("no upper case letter", test_isds_change_password, IE_INVAL,
105 context, password, "1bcdefgh", NULL, NULL);
106 TEST("no lower case letter", test_isds_change_password, IE_INVAL,
107 context, password, "1BCDEFGH", NULL, NULL);
108 TEST("no digit", test_isds_change_password, IE_INVAL,
109 context, password, "aBCDEFGH", NULL, NULL);
110 TEST("forbidden space", test_isds_change_password, IE_INVAL,
111 context, password, " h2k$Aan", NULL, NULL);
112 TEST("reused password", test_isds_change_password, IE_INVAL,
113 context, password, password, NULL, NULL);
114 TEST("password contains user ID", test_isds_change_password, IE_INVAL,
115 context, password, username, NULL, NULL);
116 TEST("sequence of the same characters", test_isds_change_password,
117 IE_INVAL, context, password, "h222k$Aa", NULL, NULL);
118 TEST("forbiden prefix qwert", test_isds_change_password,
119 IE_INVAL, context, password, "qwert$A8", NULL, NULL);
120 TEST("forbiden prefix asdgf", test_isds_change_password,
121 IE_INVAL, context, password, "asdgf$A8", NULL, NULL);
122 TEST("forbiden prefix 12345", test_isds_change_password,
123 IE_INVAL, context, password, "12345$Aa", NULL, NULL);
124 TEST("valid request", test_isds_change_password, IE_SUCCESS,
125 context, password, "h2k$Aana", NULL, NULL);
127 if (stop_server(server_process)) {
128 ABORT_UNIT(server_error);
131 free(url);
132 url = NULL;
136 isds_logout(context);
137 isds_ctx_free(&context);
138 isds_cleanup();
139 SUM_TEST();