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
= "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
) {
30 err
= isds_login(context
, url
, username
, password
, pki_credentials
, otp
);
32 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
33 isds_strerror(error
), isds_strerror(err
),
34 isds_long_message(context
));
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
) {
44 err
= isds_change_password(context
, old_password
, new_password
, otp
,
47 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
48 isds_strerror(error
), isds_strerror(err
),
49 isds_long_message(context
));
57 struct isds_ctx
*context
= NULL
;
60 INIT_TEST("isds_change_password");
62 if (unsetenv("http_proxy")) {
63 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
67 ABORT_UNIT("isds_init() failed\n");
69 context
= isds_ctx_create();
72 ABORT_UNIT("isds_ctx_create() failed\n");
76 const struct arguments_DS_DsManage_ChangeISDSPassword service_arguments
= {
78 .current_password
= password
80 const struct service_configuration services
[] = {
81 { SERVICE_DS_Dz_DummyOperation
, NULL
},
82 { SERVICE_DS_DsManage_ChangeISDSPassword
, &service_arguments
},
85 const struct arguments_basic_authentication server_arguments
= {
91 error
= start_server(&server_process
, &url
,
92 server_basic_authentication
, &server_arguments
, NULL
);
94 isds_ctx_free(&context
);
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
);
133 ABORT_UNIT(server_error
);
141 isds_logout(context
);
142 isds_ctx_free(&context
);