/*
* Use this instead of security_server_chk_pwd directly to verify the function output.
* For example:
- * verify_chk_pwd(__LINE__, "password", SECURITY_SERVER_API_SUCCESS, 2, 5, 10000, "debug string")
+ * verify_chk_pwd("password", SECURITY_SERVER_API_SUCCESS, 2, 5, "debug string")
*/
-void verify_chk_pwd_basic(
+void verify_chk_pwd (
const char* challenge,
int expected_result,
unsigned int expected_current_attempt,
unsigned int expected_max_attempt,
- unsigned int expected_valid_secs,
- const std::string &info)
+ const std::string &info = std::string())
{
/* ensure that initial values differ from expected ones */
unsigned int attempt = expected_current_attempt - 1;
unsigned int max_attempt = expected_max_attempt - 1;
- unsigned int expire_sec = expected_valid_secs - 1;
+ unsigned int expire_sec = PASSWORD_INFINITE_EXPIRATION_TIME - 1;
usleep(PASSWORD_RETRY_TIMEOUT_US);
int ret = security_server_chk_pwd(challenge, &attempt, &max_attempt, &expire_sec);
info << "security_server_chk_pwd returned max_attempt = " << max_attempt <<
" (expected: " << expected_max_attempt << ")");
- // validate expire seconds
- if (expected_valid_secs == PASSWORD_INFINITE_EXPIRATION_TIME) {
- RUNNER_ASSERT_MSG_BT(expire_sec == expected_valid_secs,
- info << "security_server_chk_pwd returned expire_sec = " << expire_sec <<
- " (expected: " << expected_valid_secs << ")");
- } else {
- // because of sleeps in test code we need to check period of time.
- unsigned int begin = expected_valid_secs > 5 ? expected_valid_secs - 5 : 0;
- unsigned int end = expected_valid_secs + 5;
-
- RUNNER_ASSERT_MSG_BT(expire_sec >= begin && expire_sec <= end,
- info << "security_server_chk_pwd returned expire_sec = " << expire_sec <<
- " (expected: <" << begin << "," << end << ")");
- }
-}
-
-/* This function is required because we cannot use default value in expected_valid_secs in
- * verify_chk_pwd_basic and define Tracker at the same time. */
-void verify_chk_pwd(
- const char *challenge,
- int expected_result,
- unsigned int expected_current_attempt,
- unsigned int expected_max_attempt,
- const std::string &info = std::string())
-{
- verify_chk_pwd_basic(
- challenge,
- expected_result,
- expected_current_attempt,
- expected_max_attempt,
- PASSWORD_INFINITE_EXPIRATION_TIME,
- info);
+ RUNNER_ASSERT_MSG_BT(expire_sec == PASSWORD_INFINITE_EXPIRATION_TIME,
+ info << "security_server_chk_pwd returned expire_sec = " << expire_sec <<
+ " (expected: " << PASSWORD_INFINITE_EXPIRATION_TIME << ")");
}
-
/**
* Reach last attempt few times in a row (before exceeding max_attempt).
*/