Line data Source code
1 : /*
2 : Authors:
3 : Pavel Reichl <preichl@redhat.com>
4 :
5 : Copyright (C) 2015 Red Hat
6 :
7 : SSSD tests - ldap auth
8 :
9 : This program is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include <stdarg.h>
24 : #include <stdlib.h>
25 : #include <stddef.h>
26 : #include <setjmp.h>
27 : #include <unistd.h>
28 : #include <sys/types.h>
29 : #include <cmocka.h>
30 :
31 : #include "tests/common_check.h"
32 : #include "providers/ldap/ldap_auth.h"
33 : #include "tests/cmocka/test_expire_common.h"
34 :
35 : struct check_pwexpire_policy_wrap_indata {
36 : enum pwexpire type;
37 : void *time_fmt;
38 : };
39 :
40 2 : static void check_pwexpire_policy_wrap(void *in, void *_out)
41 : {
42 : errno_t ret;
43 2 : struct check_pwexpire_policy_wrap_indata *data =
44 : (struct check_pwexpire_policy_wrap_indata*) in;
45 :
46 2 : ret = check_pwexpire_policy(data->type, data->time_fmt, NULL, 0);
47 2 : *(errno_t*)_out = ret;
48 2 : }
49 :
50 1 : static void test_pwexpire_krb(void **state)
51 : {
52 : struct expire_test_ctx *tc;
53 1 : enum pwexpire type = PWEXPIRE_KERBEROS;
54 : errno_t ret;
55 :
56 1 : tc = talloc_get_type(*state, struct expire_test_ctx);
57 1 : assert_non_null(tc);
58 :
59 1 : ret = check_pwexpire_policy(type,
60 1 : (void*) tc->invalid_longer_format, NULL, 0);
61 1 : assert_int_equal(ret, ERR_TIMESPEC_NOT_SUPPORTED);
62 :
63 1 : ret = check_pwexpire_policy(type, (void*) tc->invalid_format,
64 : NULL, 0);
65 1 : assert_int_equal(ret, ERR_TIMESPEC_NOT_SUPPORTED);
66 :
67 1 : ret = check_pwexpire_policy(type, (void*) tc->past_time,
68 : NULL, 0);
69 1 : assert_int_equal(ret, ERR_PASSWORD_EXPIRED);
70 :
71 1 : ret = check_pwexpire_policy(type, (void*) tc->future_time,
72 : NULL, 0);
73 1 : assert_int_equal(ret, EOK);
74 :
75 : /* changing time zone has no effect as time of expiration is in UTC */
76 : struct check_pwexpire_policy_wrap_indata data;
77 1 : data.type = type;
78 1 : data.time_fmt = (void*)tc->future_time;
79 1 : expire_test_tz("GST-2",
80 : check_pwexpire_policy_wrap,
81 : (void*)&data,
82 : (void*)&ret);
83 1 : assert_int_equal(ret, EOK);
84 :
85 1 : data.time_fmt = (void*)tc->past_time;
86 1 : expire_test_tz("GST-2",
87 : check_pwexpire_policy_wrap,
88 : (void*)&data,
89 : (void*)&ret);
90 1 : assert_int_equal(ret, ERR_PASSWORD_EXPIRED);
91 1 : }
92 :
93 1 : int main(void)
94 : {
95 1 : const struct CMUnitTest tests[] = {
96 : cmocka_unit_test_setup_teardown(test_pwexpire_krb,
97 : expire_test_setup,
98 : expire_test_teardown),
99 : };
100 :
101 1 : return cmocka_run_group_tests(tests, NULL, NULL);
102 : }
|