logo

skeud

Simple and portable utilities to deal with user accounts (su, login)

common_test.c (1925B)


  1. // SPDX-FileCopyrightText: 2022 Haelwenn (lanodan) Monnier <contact+skeud@hacktivis.me>
  2. // SPDX-License-Identifier: MPL-2.0
  3. #include "common.h"
  4. #include <atf-c.h> // ATF*, atf*
  5. ATF_TC(smin_tc);
  6. ATF_TC_HEAD(smin_tc, tc) { atf_tc_set_md_var(tc, "descr", "smin returns correct values"); }
  7. ATF_TC_BODY(smin_tc, tc)
  8. {
  9. ATF_CHECK(smin(1, 2) == 1);
  10. ATF_CHECK(smin(1, 1) == 1);
  11. ATF_CHECK(smin(2, 1) == 1);
  12. }
  13. ATF_TC(hash_match_tc);
  14. ATF_TC_HEAD(hash_match_tc, tc)
  15. {
  16. atf_tc_set_md_var(tc, "descr", "hash_match returns correct values");
  17. }
  18. ATF_TC_BODY(hash_match_tc, tc)
  19. {
  20. // Maybe check for constant time somehow?
  21. ATF_CHECK(hash_match("foo", "foo"));
  22. ATF_CHECK(!hash_match("foo", "bar"));
  23. ATF_CHECK(!hash_match("foo", "fooo"));
  24. ATF_CHECK(!hash_match("fooo", "foo"));
  25. }
  26. ATF_TC(skeud_crypt_check_tc);
  27. ATF_TC_HEAD(skeud_crypt_check_tc, tc)
  28. {
  29. atf_tc_set_md_var(tc, "descr", "skeud_crypt_check returns correct values");
  30. }
  31. ATF_TC_BODY(skeud_crypt_check_tc, tc)
  32. {
  33. ATF_CHECK(!skeud_crypt_check(NULL, "foobar"));
  34. ATF_CHECK(!skeud_crypt_check("", "foobar"));
  35. ATF_CHECK(!skeud_crypt_check("x", "foobar"));
  36. ATF_CHECK(!skeud_crypt_check("foobar", "foobar"));
  37. // DES: openssl passwd -noverify
  38. ATF_CHECK(skeud_crypt_check("FmuFhHU.nJlkg", "foobar"));
  39. // MD5: openssl passwd -1 -noverify
  40. ATF_CHECK(skeud_crypt_check("$1$L0.ptviH$oU/aJvI7BwUtWXzeJ3nGU.", "foobar"));
  41. // SHA256: openssl passwd -5 -noverify
  42. ATF_CHECK(skeud_crypt_check("$5$8VryLuwDTzZ8MSZX$2UIaWB5LcMlhXv7UQIBcFeq8/Dr6PswXZP/SJ09L01B",
  43. "foobar"));
  44. // SHA512: openssl passwd -6 -noverify
  45. char *hash = "$6$QUEEGuX9dkGlNkTP$IJwcvb6tpm63hoOfm9QJjEgjte/OpcQS3S43zDN95G3diJ5Xc/OlhhbCkUyV/"
  46. "A0ARhgQj2D/4m/DWhwvvs3A91";
  47. ATF_CHECK(skeud_crypt_check(hash, "foobar"));
  48. }
  49. ATF_TP_ADD_TCS(tp)
  50. {
  51. ATF_TP_ADD_TC(tp, smin_tc);
  52. ATF_TP_ADD_TC(tp, hash_match_tc);
  53. ATF_TP_ADD_TC(tp, skeud_crypt_check_tc);
  54. return atf_no_error();
  55. }