legacy_password_test.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/test.h>
  19. #include <grub/dl.h>
  20. #include <grub/misc.h>
  21. #include <grub/crypto.h>
  22. #include <grub/legacy_parse.h>
  23. #include <grub/auth.h>
  24. GRUB_MOD_LICENSE ("GPLv3+");
  25. static struct
  26. {
  27. char **args;
  28. int argc;
  29. char entered[GRUB_AUTH_MAX_PASSLEN];
  30. int exp;
  31. } vectors[] = {
  32. { (char * []) { (char *) "hello", NULL }, 1, "hello", 1 },
  33. { (char * []) { (char *) "hello", NULL }, 1, "hi", 0 },
  34. { (char * []) { (char *) "hello", NULL }, 1, "hillo", 0 },
  35. { (char * []) { (char *) "hello", NULL }, 1, "hellw", 0 },
  36. { (char * []) { (char *) "hello", NULL }, 1, "hell", 0 },
  37. { (char * []) { (char *) "hello", NULL }, 1, "h", 0 },
  38. { (char * []) { (char *) "--md5", (char *) "$1$maL$OKEF0PD2k6eQ0Po8u4Gjr/",
  39. NULL }, 2, "hello", 1 },
  40. { (char * []) { (char *) "--md5", (char *) "$1$maL$OKEF0PD2k6eQ0Po8u4Gjr/",
  41. NULL }, 2, "hell", 0 },
  42. { (char * []) { (char *) "--md5", (char *) "$1$naL$BaFO8zGgmss1E76GsrAec1",
  43. NULL }, 2, "hello", 1 },
  44. { (char * []) { (char *) "--md5", (char *) "$1$naL$BaFO8zGgmss1E76GsrAec1",
  45. NULL }, 2, "hell", 0 },
  46. { (char * []) { (char *) "--md5", (char *) "$1$oaL$eyrazuM7TkxVkKgBim1WH1",
  47. NULL }, 2, "hi", 1 },
  48. { (char * []) { (char *) "--md5", (char *) "$1$oaL$eyrazuM7TkxVkKgBim1WH1",
  49. NULL }, 2, "hello", 0 },
  50. };
  51. static void
  52. legacy_password_test (void)
  53. {
  54. grub_size_t i;
  55. for (i = 0; i < ARRAY_SIZE (vectors); i++)
  56. grub_test_assert (grub_legacy_check_md5_password (vectors[i].argc,
  57. vectors[i].args,
  58. vectors[i].entered)
  59. == vectors[i].exp, "Bad password check (%d)", (int) i);
  60. }
  61. /* Register example_test method as a functional test. */
  62. GRUB_FUNCTIONAL_TEST (legacy_password_test, legacy_password_test);