]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - lib/libcrypt/tests/crypt_tests.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / lib / libcrypt / tests / crypt_tests.c
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
12 ATF_TC(md5);
13 ATF_TC_HEAD(md5, tc)
14 {
15
16         atf_tc_set_md_var(tc, "descr", "Tests the MD5 based password hash");
17 }
18
19 ATF_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
28 ATF_TC(invalid);
29 ATF_TC_HEAD(invalid, tc)
30 {
31
32         atf_tc_set_md_var(tc, "descr", "Tests that invalid password fails");
33 }
34
35 ATF_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  */
48 ATF_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 }