diff options
Diffstat (limited to 'lib/libcrypt/tests')
-rw-r--r-- | lib/libcrypt/tests/Makefile | 10 | ||||
-rw-r--r-- | lib/libcrypt/tests/Makefile.depend | 19 | ||||
-rw-r--r-- | lib/libcrypt/tests/crypt_tests.c | 52 |
3 files changed, 81 insertions, 0 deletions
diff --git a/lib/libcrypt/tests/Makefile b/lib/libcrypt/tests/Makefile new file mode 100644 index 000000000000..f64fafe3c8cb --- /dev/null +++ b/lib/libcrypt/tests/Makefile @@ -0,0 +1,10 @@ +ATF_TESTS_C+= crypt_tests + +NETBSD_ATF_TESTS_C+= crypt_test + +CFLAGS+= -I${.CURDIR:H} +LIBADD= crypt + +.include <netbsd-tests.test.mk> + +.include <bsd.test.mk> diff --git a/lib/libcrypt/tests/Makefile.depend b/lib/libcrypt/tests/Makefile.depend new file mode 100644 index 000000000000..6204df652c5d --- /dev/null +++ b/lib/libcrypt/tests/Makefile.depend @@ -0,0 +1,19 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + gnu/lib/csu \ + include \ + include/xlocale \ + lib/${CSU_DIR} \ + lib/atf/libatf-c \ + lib/libc \ + lib/libcompiler_rt \ + lib/libcrypt \ + lib/libnetbsd \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/libcrypt/tests/crypt_tests.c b/lib/libcrypt/tests/crypt_tests.c new file mode 100644 index 000000000000..2ab0b65db83b --- /dev/null +++ b/lib/libcrypt/tests/crypt_tests.c @@ -0,0 +1,52 @@ +#include <sys/cdefs.h> +#include <sys/types.h> +#include <crypt.h> +#include <unistd.h> + +#include <atf-c.h> + +#define LEET "0.s0.l33t" + +ATF_TC(md5); +ATF_TC_HEAD(md5, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Tests the MD5 based password hash"); +} + +ATF_TC_BODY(md5, tc) +{ + const char want[] = "$1$deadbeef$0Huu6KHrKLVWfqa4WljDE0"; + char *pw; + + pw = crypt(LEET, want); + ATF_CHECK_STREQ(pw, want); +} + +ATF_TC(invalid); +ATF_TC_HEAD(invalid, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Tests that invalid password fails"); +} + +ATF_TC_BODY(invalid, tc) +{ + const char want[] = "$1$cafebabe$0Huu6KHrKLVWfqa4WljDE0"; + char *pw; + + pw = crypt(LEET, want); + ATF_CHECK(strcmp(pw, want) != 0); +} + +/* + * This function must not do anything except enumerate + * the test cases, per atf-c-api(3). + */ +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, md5); + ATF_TP_ADD_TC(tp, invalid); + return atf_no_error(); +} |