l10n: Update translation catalogues
[libisds.git] / test / simline / isds_change_password.c
blob967a6ec6318194671c6548b75e246fd2afbc090f
1 #ifndef _POSIX_SOURCE
2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
3 #endif
5 #ifndef _BSD_SOURCE
6 #define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */
7 #endif
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */
10 #endif
12 #ifndef _XOPEN_SOURCE
13 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
14 #endif
16 #include "../test.h"
17 #include "server.h"
18 #include "isds.h"
20 static const char *username = "Doug1as$";
21 static const char *password = "42aA#bc8";
24 static int test_login(const isds_error error, struct isds_ctx *context,
25 const char *url, const char *username, const char *password,
26 const struct isds_pki_credentials *pki_credentials,
27 struct isds_otp *otp) {
28 isds_error err;
30 err = isds_login(context, url, username, password, pki_credentials, otp);
31 if (error != err)
32 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
33 isds_strerror(error), isds_strerror(err),
34 isds_long_message(context));
36 PASS_TEST;
39 static int test_isds_change_password(const isds_error error,
40 struct isds_ctx *context, const char *old_password,
41 const char *new_password, struct isds_otp *otp, char **refnum) {
42 isds_error err;
44 err = isds_change_password(context, old_password, new_password, otp,
45 refnum);
46 if (error != err)
47 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
48 isds_strerror(error), isds_strerror(err),
49 isds_long_message(context));
51 PASS_TEST;
54 int main(void) {
55 int error;
56 pid_t server_process;
57 struct isds_ctx *context = NULL;
58 char *url = NULL;
60 INIT_TEST("isds_change_password");
62 if (unsetenv("http_proxy")) {
63 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
65 if (isds_init()) {
66 isds_cleanup();
67 ABORT_UNIT("isds_init() failed\n");
69 context = isds_ctx_create();
70 if (!context) {
71 isds_cleanup();
72 ABORT_UNIT("isds_ctx_create() failed\n");
76 const struct arguments_DS_DsManage_ChangeISDSPassword service_arguments = {
77 .username = username,
78 .current_password = password
80 const struct service_configuration services[] = {
81 { SERVICE_DS_Dz_DummyOperation, NULL },
82 { SERVICE_DS_DsManage_ChangeISDSPassword, &service_arguments },
83 { SERVICE_END, NULL }
85 const struct arguments_basic_authentication server_arguments = {
86 .username = username,
87 .password = password,
88 .isds_deviations = 1,
89 .services = services
91 error = start_server(&server_process, &url,
92 server_basic_authentication, &server_arguments, NULL);
93 if (error == -1) {
94 isds_ctx_free(&context);
95 isds_cleanup();
96 ABORT_UNIT(server_error);
99 TEST("login", test_login, IE_SUCCESS,
100 context, url, username, password, NULL, NULL);
101 TEST("bad old password", test_isds_change_password, IE_INVAL,
102 context, "bad old password", "h2k$Aana", NULL, NULL);
103 TEST("too short (7 characters)", test_isds_change_password, IE_INVAL,
104 context, password, "aB34567", NULL, NULL);
105 TEST("too long (33 characters)", test_isds_change_password, IE_INVAL,
106 context, password, "aB3456789112345678921234567893123", NULL, NULL);
107 TEST("no upper case letter", test_isds_change_password, IE_INVAL,
108 context, password, "1bcdefgh", NULL, NULL);
109 TEST("no lower case letter", test_isds_change_password, IE_INVAL,
110 context, password, "1BCDEFGH", NULL, NULL);
111 TEST("no digit", test_isds_change_password, IE_INVAL,
112 context, password, "aBCDEFGH", NULL, NULL);
113 TEST("forbidden space", test_isds_change_password, IE_INVAL,
114 context, password, " h2k$Aan", NULL, NULL);
115 TEST("reused password", test_isds_change_password, IE_INVAL,
116 context, password, password, NULL, NULL);
117 TEST("password contains user ID", test_isds_change_password, IE_INVAL,
118 context, password, username, NULL, NULL);
119 TEST("sequence of the same characters", test_isds_change_password,
120 IE_INVAL, context, password, "h222k$Aa", NULL, NULL);
121 TEST("forbiden prefix qwert", test_isds_change_password,
122 IE_INVAL, context, password, "qwert$A8", NULL, NULL);
123 TEST("forbiden prefix asdgf", test_isds_change_password,
124 IE_INVAL, context, password, "asdgf$A8", NULL, NULL);
125 TEST("forbiden prefix 12345", test_isds_change_password,
126 IE_INVAL, context, password, "12345$Aa", NULL, NULL);
127 TEST("valid request", test_isds_change_password, IE_SUCCESS,
128 context, password, "h2k$Aana", NULL, NULL);
130 if (stop_server(server_process)) {
131 isds_ctx_free(&context);
132 isds_cleanup();
133 ABORT_UNIT(server_error);
136 free(url);
137 url = NULL;
141 isds_logout(context);
142 isds_ctx_free(&context);
143 isds_cleanup();
144 SUM_TEST();