1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

Tests: Add test coverage for sys$pledge(..) argument validation

This commit is contained in:
Brian Gianforcaro 2021-07-23 09:26:48 -07:00 committed by Andreas Kling
parent e4b86aa5d8
commit c2282ee28d

View file

@ -4,7 +4,9 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <LibTest/TestCase.h>
#include <errno.h>
#include <unistd.h>
TEST_CASE(test_nonexistent_pledge)
@ -14,6 +16,31 @@ TEST_CASE(test_nonexistent_pledge)
FAIL("Pledging on existent promises should fail.");
}
TEST_CASE(test_pledge_argument_validation)
{
const auto long_argument = String::repeated('a', 2048);
auto res = pledge(long_argument.characters(), "stdio");
EXPECT_EQ(res, -1);
EXPECT_EQ(errno, E2BIG);
res = pledge("stdio", long_argument.characters());
EXPECT_EQ(res, -1);
EXPECT_EQ(errno, E2BIG);
res = pledge(long_argument.characters(), long_argument.characters());
EXPECT_EQ(res, -1);
EXPECT_EQ(errno, E2BIG);
res = pledge("fake", "stdio");
EXPECT_EQ(res, -1);
EXPECT_EQ(errno, EINVAL);
res = pledge("stdio", "fake");
EXPECT_EQ(res, -1);
EXPECT_EQ(errno, EINVAL);
}
TEST_CASE(test_pledge_failures)
{
auto res = pledge("stdio unix rpath", "stdio");