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
= "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
) {
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
, char **refnum
) {
41 err
= isds_change_password(context
, old_password
, new_password
, otp
,
44 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
45 isds_strerror(error
), isds_strerror(err
),
46 isds_long_message(context
));
51 int main(int argc
, char **argv
) {
54 char *server_address
= NULL
;
55 struct isds_ctx
*context
= NULL
;
58 INIT_TEST("isds_change_password");
60 if (unsetenv("http_proxy")) {
61 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
65 ABORT_UNIT("isds_init() failed\n");
67 context
= isds_ctx_create();
70 ABORT_UNIT("isds_ctx_create() failed\n");
74 const struct arguments_DS_DsManage_ChangeISDSPassword service_arguments
= {
76 .current_password
= password
78 const struct service_configuration services
[] = {
79 { SERVICE_DS_Dz_DummyOperation
, NULL
},
80 { SERVICE_DS_DsManage_ChangeISDSPassword
, &service_arguments
},
83 const struct arguments_basic_authentication server_arguments
= {
89 error
= start_server(&server_process
, &server_address
,
90 server_basic_authentication
, &server_arguments
, NULL
);
92 isds_ctx_free(&context
);
94 ABORT_UNIT(server_error
);
96 if (-1 == test_asprintf(&url
, "http://%s/", server_address
)) {
98 stop_server(server_process
);
99 isds_ctx_free(&context
);
101 ABORT_UNIT("Could not format ISDS URL");
103 free(server_address
);
105 TEST("login", test_login
, IE_SUCCESS
,
106 context
, url
, username
, password
, NULL
, NULL
);
107 TEST("bad old password", test_isds_change_password
, IE_INVAL
,
108 context
, "bad old password", "h2k$Aana", NULL
, NULL
);
109 TEST("too short (7 characters)", test_isds_change_password
, IE_INVAL
,
110 context
, password
, "aB34567", NULL
, NULL
);
111 TEST("too long (33 characters)", test_isds_change_password
, IE_INVAL
,
112 context
, password
, "aB3456789112345678921234567893123", NULL
, NULL
);
113 TEST("no upper case letter", test_isds_change_password
, IE_INVAL
,
114 context
, password
, "1bcdefgh", NULL
, NULL
);
115 TEST("no lower case letter", test_isds_change_password
, IE_INVAL
,
116 context
, password
, "1BCDEFGH", NULL
, NULL
);
117 TEST("no digit", test_isds_change_password
, IE_INVAL
,
118 context
, password
, "aBCDEFGH", NULL
, NULL
);
119 TEST("forbidden space", test_isds_change_password
, IE_INVAL
,
120 context
, password
, " h2k$Aan", NULL
, NULL
);
121 TEST("reused password", test_isds_change_password
, IE_INVAL
,
122 context
, password
, password
, NULL
, NULL
);
123 TEST("password contains user ID", test_isds_change_password
, IE_INVAL
,
124 context
, password
, username
, NULL
, NULL
);
125 TEST("sequence of the same characters", test_isds_change_password
,
126 IE_INVAL
, context
, password
, "h222k$Aa", NULL
, NULL
);
127 TEST("forbiden prefix qwert", test_isds_change_password
,
128 IE_INVAL
, context
, password
, "qwert$A8", NULL
, NULL
);
129 TEST("forbiden prefix asdgf", test_isds_change_password
,
130 IE_INVAL
, context
, password
, "asdgf$A8", NULL
, NULL
);
131 TEST("forbiden prefix 12345", test_isds_change_password
,
132 IE_INVAL
, context
, password
, "12345$Aa", NULL
, NULL
);
133 TEST("valid request", test_isds_change_password
, IE_SUCCESS
,
134 context
, password
, "h2k$Aana", NULL
, NULL
);
136 if (stop_server(server_process
)) {
137 ABORT_UNIT(server_error
);
145 isds_logout(context
);
146 isds_ctx_free(&context
);