50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl/*
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl Authors:
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl Pavel Reichl <preichl@redhat.com>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl Copyright (C) 2015 Red Hat
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl SSSD tests - ldap auth
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl This program is free software; you can redistribute it and/or modify
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl it under the terms of the GNU General Public License as published by
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl the Free Software Foundation; either version 3 of the License, or
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl (at your option) any later version.
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl This program is distributed in the hope that it will be useful,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl but WITHOUT ANY WARRANTY; without even the implied warranty of
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl GNU General Public License for more details.
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl You should have received a copy of the GNU General Public License
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl along with this program. If not, see <http://www.gnu.org/licenses/>.
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl*/
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include <stdarg.h>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include <stdlib.h>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include <stddef.h>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include <setjmp.h>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include <unistd.h>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include <sys/types.h>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include <cmocka.h>
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include "tests/common_check.h"
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include "providers/ldap/ldap_auth.h"
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl#include "tests/cmocka/test_expire_common.h"
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichlstruct check_pwexpire_policy_wrap_indata {
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl enum pwexpire type;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl void *time_fmt;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl};
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichlstatic void check_pwexpire_policy_wrap(void *in, void *_out)
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl{
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl errno_t ret;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl struct check_pwexpire_policy_wrap_indata *data =
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl (struct check_pwexpire_policy_wrap_indata*) in;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl ret = check_pwexpire_policy(data->type, data->time_fmt, NULL, 0);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl *(errno_t*)_out = ret;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl}
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichlstatic void test_pwexpire_krb(void **state)
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl{
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl struct expire_test_ctx *tc;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl enum pwexpire type = PWEXPIRE_KERBEROS;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl errno_t ret;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl tc = talloc_get_type(*state, struct expire_test_ctx);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl assert_non_null(tc);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl ret = check_pwexpire_policy(type,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl (void*) tc->invalid_longer_format, NULL, 0);
33e54a998f51558faaec82872a59723d2ceadb4fLukas Slebodnik assert_int_equal(ret, ERR_TIMESPEC_NOT_SUPPORTED);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl ret = check_pwexpire_policy(type, (void*) tc->invalid_format,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl NULL, 0);
33e54a998f51558faaec82872a59723d2ceadb4fLukas Slebodnik assert_int_equal(ret, ERR_TIMESPEC_NOT_SUPPORTED);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl ret = check_pwexpire_policy(type, (void*) tc->past_time,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl NULL, 0);
33e54a998f51558faaec82872a59723d2ceadb4fLukas Slebodnik assert_int_equal(ret, ERR_PASSWORD_EXPIRED);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl ret = check_pwexpire_policy(type, (void*) tc->future_time,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl NULL, 0);
33e54a998f51558faaec82872a59723d2ceadb4fLukas Slebodnik assert_int_equal(ret, EOK);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl /* changing time zone has no effect as time of expiration is in UTC */
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl struct check_pwexpire_policy_wrap_indata data;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl data.type = type;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl data.time_fmt = (void*)tc->future_time;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl expire_test_tz("GST-2",
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl check_pwexpire_policy_wrap,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl (void*)&data,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl (void*)&ret);
33e54a998f51558faaec82872a59723d2ceadb4fLukas Slebodnik assert_int_equal(ret, EOK);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl data.time_fmt = (void*)tc->past_time;
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl expire_test_tz("GST-2",
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl check_pwexpire_policy_wrap,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl (void*)&data,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl (void*)&ret);
33e54a998f51558faaec82872a59723d2ceadb4fLukas Slebodnik assert_int_equal(ret, ERR_PASSWORD_EXPIRED);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl}
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichlint main(void)
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl{
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl const struct CMUnitTest tests[] = {
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl cmocka_unit_test_setup_teardown(test_pwexpire_krb,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl expire_test_setup,
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl expire_test_teardown),
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl };
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl return cmocka_run_group_tests(tests, NULL, NULL);
50b8a36b0932a510e825ed1ad8103f81ead2b7d8Pavel Reichl}