From 173f71121e47a8e59371b7e5cf8aa5669cd7dc10 Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzelewski Date: Tue, 18 Feb 2014 13:51:49 +0100 Subject: [PATCH] Add test for security_server_is_pwd_valid. [Issue#] N/A [Cause] Korea claims that this function returns 0 after date was moved back. [Bug] Not found. [Solution] N/A [Verification] Build, run tests. Change-Id: I317a21692a360fa3dafa6b9d067899aebd68db43 --- .../security_server_tests_password.cpp | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/tests/security-server-tests/security_server_tests_password.cpp b/tests/security-server-tests/security_server_tests_password.cpp index 25fdcc4c..85207935 100644 --- a/tests/security-server-tests/security_server_tests_password.cpp +++ b/tests/security-server-tests/security_server_tests_password.cpp @@ -48,10 +48,21 @@ const char* FOURTH_TEST_PASSWORD = "FOURTHPASS"; RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_PASSWORD); struct SystemClock { - SystemClock(time_t shift) + SystemClock(time_t sft) : m_original(time(0)) + , m_shift(0) { - time_t shifted = m_original + shift; + shift(sft); + } + + SystemClock() + : m_original(time(0)) + , m_shift(0) + {} + + void shift(time_t sft) { + m_shift += sft; + time_t shifted = m_original + m_shift; RUNNER_ASSERT_BT(0 == stime(&shifted)); } @@ -65,6 +76,7 @@ struct SystemClock { } private: time_t m_original; + time_t m_shift; }; @@ -1509,6 +1521,37 @@ RUNNER_TEST(tc52_security_server_is_pwd_valid) " atempt=" << attempt << " maxAttempt=" << maxAttempt << " validSec=" << validSec); } +RUNNER_TEST(tc53_security_server_is_pwd_valid) +{ + reset_security_server(); + + int ret = security_server_set_pwd(NULL, TEST_PASSWORD, 0, 3); + RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS, "ret = " << ret); + + unsigned int attempt, maxAttempt, validSec; + attempt = maxAttempt = validSec = 0; + + // password shoudl be valid for 3 days == (60*60*24*3) 259200 seconds + ret = security_server_is_pwd_valid(&attempt, &maxAttempt, &validSec); + RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST, "ret = " << ret); + RUNNER_ASSERT_MSG_BT((validSec > 259000) && (validSec < 260000), "validSec = " << validSec); + + SystemClock clock; + clock.shift(-60*60*24); // one day back + + // password should be valid for 4 days == (60*60*24*4) 345600 seconds + ret = security_server_is_pwd_valid(&attempt, &maxAttempt, &validSec); + RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST, "ret = " << ret); + RUNNER_ASSERT_MSG_BT((validSec > 345000) && (validSec < 346000), "validSec = " << validSec); + + clock.shift(-60*60*24*2); // 3 days back + + // password shoudl be valid for 6 days == (60*60*24*6) 518400 seconds + ret = security_server_is_pwd_valid(&attempt, &maxAttempt, &validSec); + RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST, "ret = " << ret); + RUNNER_ASSERT_MSG_BT((validSec > 518000) && (validSec < 519000), "validSec = " << validSec); +} + int main(int argc, char *argv[]) { SummaryCollector::Register(); -- 2.34.1