From eac08584a45f7e4f33b33f1bc62875c6d127a37e Mon Sep 17 00:00:00 2001 From: Pawel Polawski Date: Thu, 7 Feb 2013 18:54:26 +0100 Subject: [PATCH] Fix security-server passwor failing tests. [Issue#] SSDWSSP-85 [Cause] Fix security-server-password failing tests. [Problem] Some of security-server password tests fails. [Solution] Tests fixed. [Verification] None of security-server password tests should fail. Change-Id: Ibd111e61bf0ea255ae6b3884e4a4ffe9cca3e19f --- .../security_server_tests_password.cpp | 474 ++++++++++++--------- 1 file changed, 279 insertions(+), 195 deletions(-) diff --git a/tests/security-server-tests/security_server_tests_password.cpp b/tests/security-server-tests/security_server_tests_password.cpp index 9a9d524..d024a18 100644 --- a/tests/security-server-tests/security_server_tests_password.cpp +++ b/tests/security-server-tests/security_server_tests_password.cpp @@ -4,9 +4,12 @@ /* * @file security_server_tests_password.cpp * @author Bumjin Im (bj.im@samsung.com) - * @author Mariusz Domanski (m.domanski@samsung.com) - * @version 1.0 + * @author Pawel Polawski (p.polawski@partner.samsung.com) + * @version 2.0 * @brief Test cases for security server + * + * WARNING: In this file test order is very important. They have to always be run + * in correct order. This is done by correct test case names ("tcXX_"). */ #include @@ -25,353 +28,434 @@ #include #include "test.h" -unsigned long i=1; -unsigned int attempt, max_attempt, expire_sec, temp_sec; -struct timeval cur_time; -char buf1[33], buf2[33]; -struct dirent **mydirent; - -char ** argvv; - -/* deprecated info for old c-style binary - * still useful for understanding the test itself - * - * Usage: - * cmd password1 password2 - * Example: - * cmd 123456 abcdef - */ - -int dir_filter(const struct dirent *entry) -{ - if ((strcmp(entry->d_name, ".") == 0) || - (strcmp(entry->d_name, "..") == 0) || - (strcmp(entry->d_name, "attempts") ==0) || - (strcmp(entry->d_name, "history") ==0) ) - return (0); - else - return (1); -} - RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_PASSWORD); -RUNNER_TEST(tc_security_server_is_pwd_empty_no_pwd_case) +RUNNER_TEST(tc01_clear_environment) { + int ret; + unsigned int attempt, max_attempt, expire_sec; + if(getuid() == 0) { system("rm /opt/data/security-server/*"); sync(); - int ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); - RUNNER_ASSERT(!(ret != SECURITY_SERVER_API_ERROR_NO_PASSWORD || attempt != 0 || max_attempt != 0 || expire_sec != 0)); + ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); + + RUNNER_ASSERT(expire_sec == 0); + RUNNER_ASSERT(max_attempt == 0); + RUNNER_ASSERT(attempt == 0); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD); } else { LOGD("To run the test as non root user, please remove password files (/opt/data/security-server/*) in root shell\n"); LOGD("If not, you will see some failures\n"); + RUNNER_IGNORED_MSG("I'm not root"); } } -RUNNER_TEST(tc_security_server_set_pwd_validity_there_is_no_password_yet) +RUNNER_TEST(tc02_security_server_set_pwd_validity) { - RUNNER_ASSERT(security_server_set_pwd_validity(10) == SECURITY_SERVER_API_ERROR_NO_PASSWORD); - RUNNER_ASSERT(security_server_set_pwd_validity(11) == SECURITY_SERVER_API_ERROR_NO_PASSWORD); + int ret; + + ret = security_server_set_pwd_validity(10); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD); + + ret = security_server_set_pwd_validity(11); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD); } -RUNNER_TEST(tc_security_server_set_pwd_max_challenge_there_is_no_password_yet) +RUNNER_TEST(tc03_security_server_set_pwd_max_challenge) { - RUNNER_ASSERT(security_server_set_pwd_max_challenge(5) == SECURITY_SERVER_API_ERROR_NO_PASSWORD); - RUNNER_ASSERT(security_server_set_pwd_max_challenge(6) == SECURITY_SERVER_API_ERROR_NO_PASSWORD); + int ret; + + ret = security_server_set_pwd_max_challenge(5); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD); + + ret = security_server_set_pwd_max_challenge(6); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD); } -RUNNER_TEST(tc_security_server_chk_pwd_too_long_password_case) +RUNNER_TEST(tc04_security_server_chk_pwd_too_long_password_case) { - int ret = security_server_chk_pwd("abcdefghijklmnopqrstuvwxyz0123456", &attempt, &max_attempt, &expire_sec); /* 33 chars */ + int ret; + unsigned int attempt, max_attempt, expire_sec; + + ret = security_server_chk_pwd("abcdefghijklmnopqrstuvwxyz0123456", &attempt, &max_attempt, &expire_sec); /* 33 chars */ RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); } -RUNNER_TEST(tc_security_server_chk_pwd_null_input_case) +RUNNER_TEST(tc05_security_server_chk_pwd_null_input_case) { - int ret = security_server_chk_pwd(NULL, &attempt, &max_attempt, &expire_sec); + int ret; + unsigned int attempt, max_attempt, expire_sec; + + ret = security_server_chk_pwd(NULL, &attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); + ret = security_server_chk_pwd("password", NULL, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); + ret = security_server_chk_pwd("password", &attempt, NULL, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); + ret = security_server_chk_pwd("password", &attempt, &max_attempt, NULL); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); } -RUNNER_TEST(tc_security_server_chk_pwd_no_password_case) +RUNNER_TEST(tc06_security_server_chk_pwd_no_password_case) { - int ret = security_server_chk_pwd("isthisempty", &attempt, &max_attempt, &expire_sec); - RUNNER_ASSERT(!(ret != SECURITY_SERVER_API_ERROR_NO_PASSWORD || max_attempt != 0 || expire_sec != 0)); + int ret; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + ret = security_server_chk_pwd("isthisempty", &attempt, &max_attempt, &expire_sec); + + RUNNER_ASSERT(expire_sec == 0); + RUNNER_ASSERT(max_attempt == 0); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD); } -RUNNER_TEST(tc_security_server_set_pwd_null_input_case) +RUNNER_TEST(tc07_security_server_set_pwd_null_input_case) { - RUNNER_ASSERT(security_server_set_pwd(NULL, NULL, 0, 0) == SECURITY_SERVER_API_ERROR_INPUT_PARAM); + int ret; + + ret = security_server_set_pwd(NULL, NULL, 0, 0); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); } -RUNNER_TEST(tc_security_server_set_pwd_too_long_input_param) +RUNNER_TEST(tc08_security_server_set_pwd_too_long_input_param) { - int ret = security_server_set_pwd("abcdefghijklmnopqrstuvwxyz0123456", "abcdefghijklmnopqrstuvwxyz0123456", 0, 0); + int ret; + + ret = security_server_set_pwd("abcdefghijklmnopqrstuvwxyz0123456", "abcdefghijklmnopqrstuvwxyz0123456", 0, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); } -RUNNER_TEST(tc_security_server_set_pwd_normal_case_when_current_pwd_is_empty) +RUNNER_TEST(tc09_security_server_set_pwd_current_pwd_empty) { - RUNNER_ASSERT(security_server_set_pwd(NULL, argvv[1], 0, 0) == SECURITY_SERVER_API_SUCCESS); + int ret; + + sleep(1); + ret = security_server_set_pwd(NULL, "12345", 0, 0); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); } -RUNNER_TEST(tc_security_server_set_pwd_validity_normal_case_when_there_is_a_password) +RUNNER_TEST(tc10_security_server_set_pwd_validity) { - RUNNER_ASSERT(security_server_set_pwd_validity(1) == SECURITY_SERVER_API_SUCCESS); - RUNNER_ASSERT(security_server_set_pwd_validity(2) == SECURITY_SERVER_API_SUCCESS); - RUNNER_ASSERT(security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec) == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); - RUNNER_ASSERT(expire_sec >= 172798 && expire_sec <= 172800); // About 2 days in seconds +-1 second + int ret; + + ret = security_server_set_pwd_validity(1); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + + ret = security_server_set_pwd_validity(2); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); } -RUNNER_TEST(tc_security_server_set_pwd_max_challenge_normal_case_when_there_is_a_password) +RUNNER_TEST(tc11_security_server_is_pwd_valid) { - RUNNER_ASSERT(security_server_set_pwd_max_challenge(5) == SECURITY_SERVER_API_SUCCESS); - RUNNER_ASSERT(security_server_set_pwd_max_challenge(6) == SECURITY_SERVER_API_SUCCESS); - RUNNER_ASSERT(security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec) == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); - RUNNER_ASSERT (6 == max_attempt); + int ret; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); + RUNNER_ASSERT((expire_sec > 172795) && (expire_sec < 172805)); } -RUNNER_TEST(tc_security_server_chk_pwd_normal_correct_pwd_case) +RUNNER_TEST(tc12_security_server_set_pwd_max_challenge) { - int ret = security_server_chk_pwd(argvv[1], &attempt, &max_attempt, &expire_sec); + int ret; + + ret = security_server_set_pwd_max_challenge(5); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + + ret = security_server_set_pwd_max_challenge(6); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); } -RUNNER_TEST(tc_security_server_is_pwd_empty_password_exists) +RUNNER_TEST(tc13_security_server_is_pwd_valid) +{ + int ret; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); + //printf("RET: %d\r\n", ret); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); + RUNNER_ASSERT(max_attempt == 6); +} + +RUNNER_TEST(tc14_security_server_chk_pwd) { - int ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); + int ret; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + //password bellow must be the same as in tc09 + ret = security_server_chk_pwd("12345", &attempt, &max_attempt, &expire_sec); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + + sleep(1); + ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); + //printf("RET: %d\r\n", ret); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); } -RUNNER_TEST(tc_security_server_chk_pwd_incorrect_pwd_case) +RUNNER_TEST(tc15_security_server_chk_incorrect_pwd) { - (argvv[1])[0]++; - int ret = security_server_chk_pwd(argvv[1], &attempt, &max_attempt, &expire_sec); + int ret; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + //password here should not match the one from tc14 and tc09 + ret = security_server_chk_pwd("02345", &attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); - (argvv[1])[0]--; } -RUNNER_TEST(tc_security_server_set_pwd_incorrect_current_password) +RUNNER_TEST(tc16_security_server_set_pwd_incorrect_current) { - (argvv[1])[0]++; - int ret = security_server_set_pwd(argvv[1], argvv[2], 0, 0); + int ret; + + sleep(1); + //1st password here should not match the one from tc14 and tc09 + ret = security_server_set_pwd("02345", "abcde", 0, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); - (argvv[1])[0]--; } -RUNNER_TEST(tc_security_server_set_pwd_correct_password) +RUNNER_TEST(tc17_security_server_set_pwd_correct_current) { - int ret = security_server_set_pwd(argvv[1], argvv[2], 0, 0); + int ret; + + sleep(1); + //1st password here should match the one from tc14 and tc09 + ret = security_server_set_pwd("12345", "abcde", 0, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); } -RUNNER_TEST(tc_security_server_chk_pwd_check_increasing_attempts_with_reset_when_correct_password_has_been_checked) +RUNNER_TEST(tc18_security_server_attempt_exceeding) { - int ret = security_server_set_pwd(argvv[2], argvv[1], 10, 0); + int ret; + int i; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + ret = security_server_set_pwd("abcde", "12345", 10, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - for(i=0;i<5;i++) - { - LOGD("%d\n", i+1); - ret = security_server_chk_pwd(argvv[2], &attempt, &max_attempt, &expire_sec); - RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); - RUNNER_ASSERT(attempt == (i+1)); + + printf("5 subtests started..."); + for (i = 0; i < 5; i++) { sleep(1); + + ret = security_server_chk_pwd("abcde", &attempt, &max_attempt, &expire_sec); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); + RUNNER_ASSERT(attempt == i + 1); } - LOGD("%d\n", i+1); - ret = security_server_chk_pwd(argvv[1], &attempt, &max_attempt, &expire_sec); + printf("DONE\n"); + + sleep(1); + ret = security_server_chk_pwd("12345", &attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - LOGD("%d\n", i+2); + + sleep(1); ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); - RUNNER_ASSERT(!(attempt != 0 || max_attempt != 10)); + RUNNER_ASSERT(attempt == 0); + RUNNER_ASSERT(max_attempt == 10); } -RUNNER_TEST(tc_security_server_chk_pwd_attempt_exceeding_case) +RUNNER_TEST(tc19_security_server_attempt_exceeding) { - for(i=0;i<10;i++) - { - LOGD("%d\n", i+1); - int ret = security_server_chk_pwd(argvv[2], &attempt, &max_attempt, &expire_sec); - RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); - RUNNER_ASSERT(attempt == (i+1)); + int ret; + int i; + unsigned int attempt, max_attempt, expire_sec; + + printf("10 subtests started..."); + for (i = 0; i < 10; i++) { sleep(1); + + ret = security_server_chk_pwd("abcde", &attempt, &max_attempt, &expire_sec); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); + RUNNER_ASSERT(attempt == i + 1); } - LOGD("%d\n", i+1); - int ret = security_server_chk_pwd(argvv[1], &attempt, &max_attempt, &expire_sec); + printf("DONE\n"); + + sleep(1); + ret = security_server_chk_pwd("12345", &attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MAX_ATTEMPTS_EXCEEDED); } -RUNNER_TEST(tc_security_server_reset_pwd_reset_current_password) +RUNNER_TEST(tc20_security_server_reset_pwd) { - RUNNER_ASSERT(security_server_reset_pwd(argvv[1],0, 0) == SECURITY_SERVER_API_SUCCESS); + int ret; + + sleep(1); + ret = security_server_reset_pwd("12345",0, 0); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); } -RUNNER_TEST(tc_security_server_set_pwd_check_expiration) +RUNNER_TEST(tc21_security_server_check_expiration) { - int ret = security_server_set_pwd(argvv[1], argvv[2], 10, 1); + int ret; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + ret = security_server_set_pwd("12345", "abcde", 10, 1); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + sleep(1); ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); - RUNNER_ASSERT(expire_sec <= 86400 && expire_sec >= 86398); + RUNNER_ASSERT((expire_sec < 86402) && (expire_sec > 86396)); } -RUNNER_TEST(tc_security_server_chk_pwd_check_expiration_sec_decreasing) +RUNNER_TEST(tc23_security_server_set_pwd_history) { - int ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec); - RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST); + int ret; + sleep(1); - temp_sec = 0; - for(i=0;i<5;i++) - { - expire_sec = 0; - ret = security_server_chk_pwd(argvv[2], &attempt, &max_attempt, &expire_sec); - RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - RUNNER_ASSERT(!(temp_sec != 0 && ((temp_sec -expire_sec) > 2) && ((temp_sec -expire_sec) < 1))); - temp_sec = expire_sec; - LOGD("%d\n", expire_sec); - sleep(1); - } -} + ret = security_server_set_pwd_history(100); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); -RUNNER_TEST(tc_security_server_chk_pwd_check_expiration_with_system_time_change) -{ - int ret = gettimeofday(&cur_time, NULL); - RUNNER_ASSERT(ret >= 0); - cur_time.tv_sec += (expire_sec -4); - ret = settimeofday(&cur_time, NULL); - RUNNER_ASSERT(ret >= 0); - temp_sec = 0; - for(i=0;i<5;i++) - { - expire_sec = 0; - ret = security_server_chk_pwd(argvv[2], &attempt, &max_attempt, &expire_sec); - RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS || ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED); - if(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED) - break; - RUNNER_ASSERT(!(temp_sec != 0 && ((temp_sec -expire_sec) > 2) && ((temp_sec -expire_sec) < 1))); - temp_sec = expire_sec; - LOGD("%d\n", expire_sec); - sleep(1); - } - RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED); + sleep(1); + ret = security_server_set_pwd_history(-5); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM); + + sleep(1); + ret = security_server_set_pwd_history(10); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); } -RUNNER_TEST(tc_security_server_set_pwd_history_too_big_and_small_number) +int dir_filter(const struct dirent *entry) { - RUNNER_ASSERT(security_server_set_pwd_history(100) == SECURITY_SERVER_API_ERROR_INPUT_PARAM); - RUNNER_ASSERT(security_server_set_pwd_history(-5) == SECURITY_SERVER_API_ERROR_INPUT_PARAM); + if ((strcmp(entry->d_name, ".") == 0) || + (strcmp(entry->d_name, "..") == 0) || + (strcmp(entry->d_name, "attempts") ==0) || + (strcmp(entry->d_name, "history") ==0) ) + return (0); + else + return (1); } -RUNNER_TEST(tc_security_server_set_pwd_history_normal_case) +void clean_password_dir(void) { - RUNNER_ASSERT(security_server_set_pwd_history(10) == SECURITY_SERVER_API_SUCCESS); + int ret; + int i; + struct dirent **mydirent; + + ret = scandir("/opt/data/security-server", &mydirent, &dir_filter, alphasort); + i = ret; + while (i--) + free(mydirent[i]); + free(mydirent); } -RUNNER_TEST(tc_security_server_set_pwd_history_check_history_is_working) +RUNNER_TEST(tc24_security_server_check_history) { - int ret = security_server_reset_pwd("history1",0, 0); - RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - LOGD("1\n"); + int ret; + int i; + char buf1[33], buf2[33]; + + clean_password_dir(); + sleep(1); - for(i=1;i<11;i++) - { + ret = security_server_reset_pwd("history0", 0, 0); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + + printf("11 subtests started..."); + for (i = 0; i < 11; i++) { sprintf(buf1, "history%d", i); - sprintf(buf2, "history%d", i+1); + sprintf(buf2, "history%d", i + 1); + + sleep(1); ret = security_server_set_pwd(buf1, buf2, 0, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - LOGD("%d\n", i+1); - sleep(1); } + printf("DONE\n"); + + sleep(1); ret = security_server_set_pwd("history11", "history1", 0, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + sleep(1); ret = security_server_set_pwd("history1", "history8", 0, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_REUSED); -} -RUNNER_TEST(tc_security_server_set_pwd_check_garbage_collection) -{ - int ret = security_server_set_pwd("history1", "history12", 0, 0); - sprintf(buf1, "history12"); - RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - LOGD("12\n"); sleep(1); - for(i=12;i<60;i++) - { + ret = security_server_set_pwd("history1", "history12", 0, 0); + RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + + printf("48 subtests started..."); + for (i = 12; i < 60; i++) { + sleep(1); + sprintf(buf1, "history%d", i); - sprintf(buf2, "history%d", i+1); + sprintf(buf2, "history%d", i + 1); + ret = security_server_set_pwd(buf1, buf2, 0, 0); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - LOGD("%d\n", i+1); - sleep(1); - } - ret = scandir("/opt/data/security-server", &mydirent, &dir_filter, alphasort); - i = ret; - while((i--)) - { - free(mydirent[i]); } - free(mydirent); - RUNNER_ASSERT( ret == 50 || ret == 51); + printf("DONE\n"); + + clean_password_dir(); } -RUNNER_TEST(tc_security_server_chk_pwd_incorrect_with_replay_attack) +RUNNER_TEST(tc25_security_server_replay_attack) { - int ret = security_server_chk_pwd("quickquickquick", &attempt, &max_attempt, &expire_sec); - do - { - i = i + 100000; + int ret; + int i = 0; + unsigned int attempt, max_attempt, expire_sec; + + sleep(1); + ret = security_server_chk_pwd("quickquickquick", &attempt, &max_attempt, &expire_sec); + + while (ret == SECURITY_SERVER_API_ERROR_PASSWORD_RETRY_TIMER) { + i += 100000; + ret = security_server_chk_pwd("quickquickquick", &attempt, &max_attempt, &expire_sec); usleep(i); } - while(ret == SECURITY_SERVER_API_ERROR_PASSWORD_RETRY_TIMER); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); - i = i - 100000; - LOGD("Last interval was %d.%06d sec.\n", (i /1000000), (i % 1000000) ); } -RUNNER_TEST(tc_security_server_chk_pwd_wrong_challenge_on_expired_password) +RUNNER_TEST(tc26_security_server_challenge_on_expired_password) { - sleep(2); - int ret = security_server_set_pwd("history60", "newpwd23", 4, 1); + int ret; + unsigned int attempt, max_attempt, expire_sec; + struct timeval cur_time; + + sleep(1); + ret = security_server_set_pwd("history60", "newpwd23", 4, 1); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); - sleep(2); + + sleep(1); ret = security_server_chk_pwd("newpwd23", &attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS); + ret = gettimeofday(&cur_time, NULL); - RUNNER_ASSERT(ret >= 0); + RUNNER_ASSERT(ret > -1); + cur_time.tv_sec += (expire_sec + 1); ret = settimeofday(&cur_time, NULL); - RUNNER_ASSERT(ret >= 0); - sleep(2); + RUNNER_ASSERT(ret > -1); + + sleep(1); ret = security_server_chk_pwd("newpwd23", &attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED); - sleep(2); + + sleep(1); ret = security_server_chk_pwd("newpwd23_invalid", &attempt, &max_attempt, &expire_sec); RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH); } + + int main(int argc, char *argv[]) { - int argcc = 3; - char a[7] = {'1','2','3','4','5','6',0}; - char * argvtmp[] = {argv[0], a, "abcdef"}; - argvv = argvtmp; - - int status = - DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); + int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); return status; } -- 2.7.4