TestKernelUnveil.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <unistd.h>
  8. TEST_CASE(test_failures)
  9. {
  10. auto res = unveil("/etc", "r");
  11. if (res < 0)
  12. FAIL("unveil read only failed");
  13. res = unveil("/etc", "w");
  14. if (res >= 0)
  15. FAIL("unveil write permitted after unveil read only");
  16. res = unveil("/etc", "x");
  17. if (res >= 0)
  18. FAIL("unveil execute permitted after unveil read only");
  19. res = unveil("/etc", "c");
  20. if (res >= 0)
  21. FAIL("unveil create permitted after unveil read only");
  22. res = unveil("/tmp/doesnotexist", "c");
  23. if (res < 0)
  24. FAIL("unveil create on non-existent path failed");
  25. res = unveil("/home", "b");
  26. if (res < 0)
  27. FAIL("unveil browse failed");
  28. res = unveil("/home", "w");
  29. if (res >= 0)
  30. FAIL("unveil write permitted after unveil browse only");
  31. res = unveil("/home", "x");
  32. if (res >= 0)
  33. FAIL("unveil execute permitted after unveil browse only");
  34. res = unveil("/home", "c");
  35. if (res >= 0)
  36. FAIL("unveil create permitted after unveil browse only");
  37. res = unveil(nullptr, nullptr);
  38. if (res < 0)
  39. FAIL("unveil state lock failed");
  40. res = unveil("/bin", "w");
  41. if (res >= 0)
  42. FAIL("unveil permitted after unveil state locked");
  43. }