summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/chown.cc
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2021-04-28 16:14:52 -0700
committergVisor bot <gvisor-bot@google.com>2021-04-28 16:22:24 -0700
commite1149179f3d5d7cbacb160d5bee6b00fe64a08ae (patch)
treebf1537c80ce62848d5f483212ebbb0e3f49bb540 /test/syscalls/linux/chown.cc
parent704728d38fdb3ceaf8dfbfdba84eee183775b90c (diff)
Remove side effect from test cases
Restore capabilities for tests that need to change them. PiperOrigin-RevId: 371007047
Diffstat (limited to 'test/syscalls/linux/chown.cc')
-rw-r--r--test/syscalls/linux/chown.cc8
1 files changed, 2 insertions, 6 deletions
diff --git a/test/syscalls/linux/chown.cc b/test/syscalls/linux/chown.cc
index ff0d39343..b0c1b6f4a 100644
--- a/test/syscalls/linux/chown.cc
+++ b/test/syscalls/linux/chown.cc
@@ -91,9 +91,7 @@ using Chown =
class ChownParamTest : public ::testing::TestWithParam<Chown> {};
TEST_P(ChownParamTest, ChownFileSucceeds) {
- if (ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_CHOWN))) {
- ASSERT_NO_ERRNO(SetCapability(CAP_CHOWN, false));
- }
+ AutoCapability cap(CAP_CHOWN, false);
const auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
@@ -135,9 +133,7 @@ TEST_P(ChownParamTest, ChownFilePermissionDenied) {
// thread won't be able to open some log files after the test ends.
ScopedThread([&] {
// Drop privileges.
- if (HaveCapability(CAP_CHOWN).ValueOrDie()) {
- EXPECT_NO_ERRNO(SetCapability(CAP_CHOWN, false));
- }
+ AutoCapability cap(CAP_CHOWN, false);
// Change EUID and EGID.
//