diff --git a/test/test.c b/test/test.c index 18950f2..1ca3c15 100644 --- a/test/test.c +++ b/test/test.c @@ -96,7 +96,7 @@ void test_rejectNA(void) { // pam_panic_pw tests void test_writePassword(void) { - char encpw[2][99]; + char encpw[2][256]; strcpy(encpw[0], crypt(GOODPASSWORD, "$6$somesalt")); strcpy(encpw[1], crypt(BADPASSWORD, "$6$somesalt")); @@ -113,11 +113,10 @@ void test_passwordCheckFromFile(void) { FILE *f = fopen(PASSWORDFILE, "r"); size_t len = 0; - ssize_t read; if(f){ int i = 0; - while(read = getline(&line, &len, f)){ + while(getline(&line, &len, f)){ strncpy(buf[i], line, len); if(++i > 1) break; @@ -136,6 +135,36 @@ void test_passwordCheckFromFile(void) { } +void test_badPasswordCheckFromFile(void) { + + int ret; + char buf[2][256]; + char* line = NULL; + + FILE *f = fopen(PASSWORDFILE, "r"); + size_t len = 0; + + if(f){ + int i = 0; + while(getline(&line, &len, f)){ + strncpy(buf[i], line, len); + if(++i > 1) + break; + } + if(ferror(f)) + CU_FAIL("Some error occured with the password file."); + fclose(f); + } + + + ret = strcmp(strtok(buf[0], "\n"), crypt(BADPASSWORD, buf[0])) == 0; + CU_ASSERT_FALSE(ret); + + ret = strcmp(strtok(buf[1], "\n"), crypt(GOODPASSWORD, buf[1])) == 0; + CU_ASSERT_FALSE(ret); + +} + int main(void) { @@ -169,7 +198,8 @@ int main(void) { || (NULL == CU_add_test(pSuiteReject, "Reject: Poweroff?", test_rejectPoweroff)) || (NULL == CU_add_test(pSuiteReject, "Reject: Nothing?", test_rejectNA)) || (NULL == CU_add_test(pSuitePasswordWrite, "pam_panic_pw: Write password?", test_writePassword)) - || (NULL == CU_add_test(pSuitePasswordWrite, "pam_panic_pw: Passwords from file work?", test_passwordCheckFromFile)) + || (NULL == CU_add_test(pSuitePasswordWrite, "pam_panic_pw: Check with right password?", test_passwordCheckFromFile)) + || (NULL == CU_add_test(pSuitePasswordWrite, "pam_panic_pw: Check with wrong password?", test_badPasswordCheckFromFile)) ) { CU_cleanup_registry(); return CU_get_error();