1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:37:46 +00:00

Tests: Convert unveil-test-failures.cpp to be LibTest based.

This commit is contained in:
Brian Gianforcaro 2021-04-27 02:39:32 -07:00 committed by Linus Groh
parent a9df58d7b2
commit 122869f086
3 changed files with 62 additions and 80 deletions

View file

@ -1,4 +1,6 @@
file(GLOB CMD_SOURCES CONFIGURE_DEPENDS "*.cpp")
file(GLOB LIBTEST_BASED_SOURCES "Test*.cpp")
list(REMOVE_ITEM CMD_SOURCES ${LIBTEST_BASED_SOURCES})
# FIXME: These tests do not use LibTest
foreach(CMD_SRC ${CMD_SOURCES})
@ -8,6 +10,11 @@ foreach(CMD_SRC ${CMD_SOURCES})
install(TARGETS ${CMD_NAME} RUNTIME DESTINATION usr/Tests/Kernel)
endforeach()
foreach(TEST_SRC ${LIBTEST_BASED_SOURCES})
serenity_test(${TEST_SRC} Kernel)
endforeach()
target_link_libraries(elf-execve-mmap-race LibPthread)
target_link_libraries(kill-pidtid-confusion LibPthread)
target_link_libraries(nanosleep-race-outbuf-munmap LibPthread)

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <unistd.h>
TEST_CASE(test_failures)
{
auto res = unveil("/etc", "r");
if (res < 0)
FAIL("unveil read only failed");
res = unveil("/etc", "w");
if (res >= 0)
FAIL("unveil write permitted after unveil read only");
res = unveil("/etc", "x");
if (res >= 0)
FAIL("unveil execute permitted after unveil read only");
res = unveil("/etc", "c");
if (res >= 0)
FAIL("unveil create permitted after unveil read only");
res = unveil("/tmp/doesnotexist", "c");
if (res < 0)
FAIL("unveil create on non-existent path failed");
res = unveil("/home", "b");
if (res < 0)
FAIL("unveil browse failed");
res = unveil("/home", "w");
if (res >= 0)
FAIL("unveil write permitted after unveil browse only");
res = unveil("/home", "x");
if (res >= 0)
FAIL("unveil execute permitted after unveil browse only");
res = unveil("/home", "c");
if (res >= 0)
FAIL("unveil create permitted after unveil browse only");
res = unveil(nullptr, nullptr);
if (res < 0)
FAIL("unveil state lock failed");
res = unveil("/bin", "w");
if (res >= 0)
FAIL("unveil permitted after unveil state locked");
}

View file

@ -1,80 +0,0 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <stdio.h>
#include <unistd.h>
int main()
{
int res = unveil("/etc", "r");
if (res < 0) {
fprintf(stderr, "FAIL, unveil read only failed\n");
return 1;
}
res = unveil("/etc", "w");
if (res >= 0) {
fprintf(stderr, "FAIL, unveil write permitted after unveil read only\n");
return 1;
}
res = unveil("/etc", "x");
if (res >= 0) {
fprintf(stderr, "FAIL, unveil execute permitted after unveil read only\n");
return 1;
}
res = unveil("/etc", "c");
if (res >= 0) {
fprintf(stderr, "FAIL, unveil create permitted after unveil read only\n");
return 1;
}
res = unveil("/tmp/doesnotexist", "c");
if (res < 0) {
fprintf(stderr, "FAIL, unveil create on non-existent path failed\n");
return 1;
}
res = unveil("/home", "b");
if (res < 0) {
fprintf(stderr, "FAIL, unveil browse failed\n");
return 1;
}
res = unveil("/home", "w");
if (res >= 0) {
fprintf(stderr, "FAIL, unveil write permitted after unveil browse only\n");
return 1;
}
res = unveil("/home", "x");
if (res >= 0) {
fprintf(stderr, "FAIL, unveil execute permitted after unveil browse only\n");
return 1;
}
res = unveil("/home", "c");
if (res >= 0) {
fprintf(stderr, "FAIL, unveil create permitted after unveil browse only\n");
return 1;
}
res = unveil(nullptr, nullptr);
if (res < 0) {
fprintf(stderr, "FAIL, unveil state lock failed\n");
return 1;
}
res = unveil("/bin", "w");
if (res >= 0) {
fprintf(stderr, "FAIL, unveil permitted after unveil state locked\n");
return 1;
}
printf("PASS\n");
return 0;
}