Add another test, remove unnecessary ssize_t var
This commit is contained in:
parent
37b11825a7
commit
e8f8ab39e4
38
test/test.c
38
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();
|
||||
|
Loading…
Reference in New Issue
Block a user