mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 19:21:53 +03:00
Add reciprocal test for password hashing and checking
This commit is contained in:
parent
2ae297fe0d
commit
6016b4b0ba
@ -14,7 +14,7 @@ static void test_hash_password_full(void) {
|
|||||||
log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data));
|
log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data));
|
||||||
|
|
||||||
for (unsigned c = 0; c < 2; c++)
|
for (unsigned c = 0; c < 2; c++)
|
||||||
FOREACH_STRING(i, "abc123", "password", "s3cr3t") {
|
FOREACH_STRING(i, "abc123", "h⸿sło") {
|
||||||
_cleanup_free_ char *hashed;
|
_cleanup_free_ char *hashed;
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
@ -23,6 +23,21 @@ static void test_hash_password_full(void) {
|
|||||||
assert_se(hash_password_full(i, NULL, NULL, &hashed) == 0);
|
assert_se(hash_password_full(i, NULL, NULL, &hashed) == 0);
|
||||||
log_debug("\"%s\" → \"%s\"", i, hashed);
|
log_debug("\"%s\" → \"%s\"", i, hashed);
|
||||||
log_info("crypt_r[a] buffer size: %i bytes", cd_size);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user