common_test.c (1925B)
- // SPDX-FileCopyrightText: 2022 Haelwenn (lanodan) Monnier <contact+skeud@hacktivis.me>
- // SPDX-License-Identifier: MPL-2.0
- #include "common.h"
- #include <atf-c.h> // ATF*, atf*
- ATF_TC(smin_tc);
- ATF_TC_HEAD(smin_tc, tc) { atf_tc_set_md_var(tc, "descr", "smin returns correct values"); }
- ATF_TC_BODY(smin_tc, tc)
- {
- ATF_CHECK(smin(1, 2) == 1);
- ATF_CHECK(smin(1, 1) == 1);
- ATF_CHECK(smin(2, 1) == 1);
- }
- ATF_TC(hash_match_tc);
- ATF_TC_HEAD(hash_match_tc, tc)
- {
- atf_tc_set_md_var(tc, "descr", "hash_match returns correct values");
- }
- ATF_TC_BODY(hash_match_tc, tc)
- {
- // Maybe check for constant time somehow?
- ATF_CHECK(hash_match("foo", "foo"));
- ATF_CHECK(!hash_match("foo", "bar"));
- ATF_CHECK(!hash_match("foo", "fooo"));
- ATF_CHECK(!hash_match("fooo", "foo"));
- }
- ATF_TC(skeud_crypt_check_tc);
- ATF_TC_HEAD(skeud_crypt_check_tc, tc)
- {
- atf_tc_set_md_var(tc, "descr", "skeud_crypt_check returns correct values");
- }
- ATF_TC_BODY(skeud_crypt_check_tc, tc)
- {
- ATF_CHECK(!skeud_crypt_check(NULL, "foobar"));
- ATF_CHECK(!skeud_crypt_check("", "foobar"));
- ATF_CHECK(!skeud_crypt_check("x", "foobar"));
- ATF_CHECK(!skeud_crypt_check("foobar", "foobar"));
- // DES: openssl passwd -noverify
- ATF_CHECK(skeud_crypt_check("FmuFhHU.nJlkg", "foobar"));
- // MD5: openssl passwd -1 -noverify
- ATF_CHECK(skeud_crypt_check("$1$L0.ptviH$oU/aJvI7BwUtWXzeJ3nGU.", "foobar"));
- // SHA256: openssl passwd -5 -noverify
- ATF_CHECK(skeud_crypt_check("$5$8VryLuwDTzZ8MSZX$2UIaWB5LcMlhXv7UQIBcFeq8/Dr6PswXZP/SJ09L01B",
- "foobar"));
- // SHA512: openssl passwd -6 -noverify
- char *hash = "$6$QUEEGuX9dkGlNkTP$IJwcvb6tpm63hoOfm9QJjEgjte/OpcQS3S43zDN95G3diJ5Xc/OlhhbCkUyV/"
- "A0ARhgQj2D/4m/DWhwvvs3A91";
- ATF_CHECK(skeud_crypt_check(hash, "foobar"));
- }
- ATF_TP_ADD_TCS(tp)
- {
- ATF_TP_ADD_TC(tp, smin_tc);
- ATF_TP_ADD_TC(tp, hash_match_tc);
- ATF_TP_ADD_TC(tp, skeud_crypt_check_tc);
- return atf_no_error();
- }