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