1#include <sys/cdefs.h> 2__FBSDID("$FreeBSD$"); 3 4#include <sys/types.h> 5#include <crypt.h> 6#include <unistd.h> 7 8#include <atf-c.h> 9 10#define LEET "0.s0.l33t" 11 12ATF_TC(md5); 13ATF_TC_HEAD(md5, tc) 14{ 15 16 atf_tc_set_md_var(tc, "descr", "Tests the MD5 based password hash"); 17} 18 19ATF_TC_BODY(md5, tc) 20{ 21 const char want[] = "$1$deadbeef$0Huu6KHrKLVWfqa4WljDE0"; 22 char *pw; 23 24 pw = crypt(LEET, want); 25 ATF_CHECK_STREQ(pw, want); 26} 27 28ATF_TC(invalid); 29ATF_TC_HEAD(invalid, tc) 30{ 31 32 atf_tc_set_md_var(tc, "descr", "Tests that invalid password fails"); 33} 34 35ATF_TC_BODY(invalid, tc) 36{ 37 const char want[] = "$1$cafebabe$0Huu6KHrKLVWfqa4WljDE0"; 38 char *pw; 39 40 pw = crypt(LEET, want); 41 ATF_CHECK(strcmp(pw, want) != 0); 42} 43 44/* 45 * This function must not do anything except enumerate 46 * the test cases, per atf-c-api(3). 47 */ 48ATF_TP_ADD_TCS(tp) 49{ 50 51 ATF_TP_ADD_TC(tp, md5); 52 ATF_TP_ADD_TC(tp, invalid); 53 return atf_no_error(); 54} 55