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 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 arguments_DS_DsManage_ChangeISDSPassword service_arguments
= {
75 .current_password
= password
77 const struct service_configuration services
[] = {
78 { SERVICE_DS_Dz_DummyOperation
, NULL
},
79 { SERVICE_DS_DsManage_ChangeISDSPassword
, &service_arguments
},
82 const struct arguments_basic_authentication server_arguments
= {
88 error
= start_server(&server_process
, &url
,
89 server_basic_authentication
, &server_arguments
, NULL
);
91 isds_ctx_free(&context
);
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
);
136 isds_logout(context
);
137 isds_ctx_free(&context
);