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