From: sangwan.kwon Date: Thu, 24 Aug 2017 05:59:51 +0000 (-0400) Subject: Add expired password TC X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d521cba3ef27416f8e5722bcdd5e6ce3ee2379a3;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Add expired password TC Change-Id: Iafcc6a67bcf2dcb2473d008ed90516b9f195f1da Signed-off-by: sangwan.kwon --- diff --git a/src/auth-fw-passwd/auth-passwd.cpp b/src/auth-fw-passwd/auth-passwd.cpp index 90b5bb7d..40c0f3bf 100644 --- a/src/auth-fw-passwd/auth-passwd.cpp +++ b/src/auth-fw-passwd/auth-passwd.cpp @@ -22,6 +22,7 @@ #include #include /* for init/deinit */ +#include #include #include #include @@ -68,21 +69,14 @@ Policy check_passwd(password_type type, const char *token, int expected) 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) @@ -97,7 +91,15 @@ 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); @@ -123,7 +125,8 @@ RUNNER_TEST(T00111_check) 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) @@ -283,3 +286,37 @@ RUNNER_TEST(T00118_remove_password_with_min_complex_char_policy) 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); +}