From 7ff9d99e9e8b75930aa05b45eb21889eac8af014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 8 Jun 2021 13:48:10 +0200 Subject: [PATCH] test-libcrypt-util: print out default for password settings, run make_salt() a few times Inspired by https://fedoraproject.org/wiki/Changes/yescrypt_as_default_hashing_method_for_shadow. --- src/test/meson.build | 2 +- src/test/test-libcrypt-util.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/test/meson.build b/src/test/meson.build index c7b2bbfedc..29f488f4d8 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -224,7 +224,7 @@ tests += [ [['src/test/test-os-util.c']], [['src/test/test-libcrypt-util.c'], - [], [], [], '', 'timeout=120'], + [], [libcrypt], [], '', 'timeout=120'], [['src/test/test-escape.c']], diff --git a/src/test/test-libcrypt-util.c b/src/test/test-libcrypt-util.c index cd296d698e..360db2816d 100644 --- a/src/test/test-libcrypt-util.c +++ b/src/test/test-libcrypt-util.c @@ -10,6 +10,29 @@ #include "tests.h" #include "libcrypt-util.h" +static void test_crypt_preferred_method(void) { + log_info("/* %s */", __func__); + + log_info("crypt_preferred_method: %s", +#if HAVE_CRYPT_PREFERRED_METHOD + crypt_preferred_method() +#else + "(not available)" +#endif + ); +} + +static void test_make_salt(void) { + log_info("/* %s */", __func__); + + for (int i = 0; i < 10; i++) { + _cleanup_free_ char *t; + + assert_se(make_salt(&t) == 0); + log_info("%s", t); + } +} + static int test_hash_password(void) { log_info("/* %s */", __func__); @@ -93,6 +116,9 @@ int main(int argc, char *argv[]) { return log_tests_skipped("crypt_r() causes a buffer overflow on ppc64el, see https://github.com/systemd/systemd/pull/16981#issuecomment-691203787"); #endif + test_crypt_preferred_method(); + test_make_salt(); + if (!test_hash_password()) return log_tests_skipped("crypt doesn't support yescrypt or sha512crypt");