diff --git a/src/test/test-libcrypt-util.c b/src/test/test-libcrypt-util.c index 94bd4172eab..5c4958ed724 100644 --- a/src/test/test-libcrypt-util.c +++ b/src/test/test-libcrypt-util.c @@ -14,7 +14,7 @@ static void test_hash_password_full(void) { log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data)); for (unsigned c = 0; c < 2; c++) - FOREACH_STRING(i, "abc123", "password", "s3cr3t") { + FOREACH_STRING(i, "abc123", "h⸿sło") { _cleanup_free_ char *hashed; if (c == 0) @@ -23,6 +23,21 @@ static void test_hash_password_full(void) { assert_se(hash_password_full(i, NULL, NULL, &hashed) == 0); log_debug("\"%s\" → \"%s\"", i, hashed); log_info("crypt_r[a] buffer size: %i bytes", cd_size); + + assert_se(test_password_one(hashed, i) == true); + assert_se(test_password_one(i, hashed) <= 0); /* We get an error for non-utf8 */ + assert_se(test_password_one(hashed, "foobar") == false); + assert_se(test_password_many(STRV_MAKE(hashed), i) == true); + assert_se(test_password_many(STRV_MAKE(hashed), "foobar") == false); + assert_se(test_password_many(STRV_MAKE(hashed, hashed, hashed), "foobar") == false); + assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", + hashed, + "$y$j9T$SAayASazWZIQeJd9AS02m/$"), + i) == true); + assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", + hashed, + "$y$j9T$SAayASazWZIQeJd9AS02m/$"), + "") == false); } }