diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-08 15:28:21 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-15 11:52:30 +0200 |
commit | 6016b4b0ba6a5d47533b47f7f944116425594f41 (patch) | |
tree | c5918d9a792ad236be7978bbaec54d23f649784d /src/test/test-libcrypt-util.c | |
parent | Move test_password_{one,many} to libcrypt-util.c (diff) | |
download | systemd-6016b4b0ba6a5d47533b47f7f944116425594f41.tar.xz systemd-6016b4b0ba6a5d47533b47f7f944116425594f41.zip |
Add reciprocal test for password hashing and checking
Diffstat (limited to 'src/test/test-libcrypt-util.c')
-rw-r--r-- | src/test/test-libcrypt-util.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/test/test-libcrypt-util.c b/src/test/test-libcrypt-util.c index 94bd4172ea..5c4958ed72 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); } } |