#include <auth-passwd.h>
#include <auth-passwd-admin.h> /* for init/deinit */
+#include <ctime>
#include <chrono>
#include <thread>
#include <unistd.h>
return policy;
}
-Policy check_passwd_state(password_type type, int expected)
+int check_passwd_state(password_type type)
{
Policy policy;
- int ret = auth_passwd_check_passwd_state(
- type,
- &policy.current_attempts,
- &policy.max_attempts,
- &policy.valid_secs);
-
- RUNNER_ASSERT_MSG(ret == expected,
- "Returned value on auth_passwd_check_passwd_state() is different to expected. "
- "ret: " << ret << " and expected: " << expected);
-
- return policy;
+ return auth_passwd_check_passwd_state(type,
+ &policy.current_attempts,
+ &policy.max_attempts,
+ &policy.valid_secs);
}
bool check_passwd_reusable(password_type type, const char *token, int expected)
return is_reused ? true : false;
}
+void set_relative_date(int days)
+{
+ time_t as_is = ::time(NULL);
+ time_t to_be = as_is + (days * 86400);
+
+ int ret = ::stime(&to_be);
+ RUNNER_ASSERT_MSG(ret == 0, "Failed to set date. ret: " << ret);
}
+} // anonymous namespace
RUNNER_TEST_GROUP_INIT(T0010_AUTH_FW_PASSWD);
RUNNER_TEST(T00112_check_state)
{
- check_passwd_state(AUTH_PWD_NORMAL, AUTH_PASSWD_API_SUCCESS);
+ int ret = check_passwd_state(AUTH_PWD_NORMAL);
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to check state. ret: " << ret);
}
RUNNER_TEST(T00113_check_reusable)
ret = auth_passwd_set_passwd(AUTH_PWD_NORMAL, NULL, default_pass);
RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to set passwd. ret: " << ret);
}
+
+RUNNER_TEST(T00119_check_expire_policy)
+{
+ /* precondition : set validity(expire time) policy */
+ policy_h *policy = nullptr;
+ int ret = auth_passwd_new_policy(&policy);
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to make new policy. ret: " << ret);
+
+ ret = auth_passwd_set_user(policy, getuid());
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to set user. ret: " << ret);
+
+ ret = auth_passwd_set_validity(policy, 1);
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to set validity. ret: " << ret);
+
+ ret = auth_passwd_set_policy(policy);
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to set policy. ret: " << ret);
+
+ check_passwd(AUTH_PWD_NORMAL, default_pass, AUTH_PASSWD_API_SUCCESS);
+ ret = check_passwd_state(AUTH_PWD_NORMAL);
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to check state. ret: " << ret);
+
+ /* test : set date as +2 days */
+ set_relative_date(2);
+
+ check_passwd(AUTH_PWD_NORMAL, default_pass, AUTH_PASSWD_API_ERROR_PASSWORD_EXPIRED);
+ ret = check_passwd_state(AUTH_PWD_NORMAL);
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to check state. ret: " << ret);
+
+ /* restore */
+ set_relative_date(-2);
+ ret = auth_passwd_disable_policy(getuid());
+ RUNNER_ASSERT_MSG(ret == AUTH_PASSWD_API_SUCCESS, "Failed to disable policy. ret: " << ret);
+ auth_passwd_free_policy(policy);
+}