Add expired password TC 63/145863/2 auth-fw-passwd
authorsangwan.kwon <sangwan.kwon@samsung.com>
Thu, 24 Aug 2017 05:59:51 +0000 (01:59 -0400)
committersangwan.kwon <sangwan.kwon@samsung.com>
Fri, 25 Aug 2017 08:27:23 +0000 (04:27 -0400)
Change-Id: Iafcc6a67bcf2dcb2473d008ed90516b9f195f1da
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
src/auth-fw-passwd/auth-passwd.cpp

index 90b5bb7df90190a6a8a87b0382768e0d770e91a0..40c0f3bf95273e7958280ad49b8d77f2e2fea33a 100644 (file)
@@ -22,6 +22,7 @@
 #include <auth-passwd.h>
 #include <auth-passwd-admin.h> /* for init/deinit */
 
+#include <ctime>
 #include <chrono>
 #include <thread>
 #include <unistd.h>
@@ -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);
+}