diff options
author | Kevin Krakauer <krakauer@google.com> | 2021-03-25 11:58:35 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-25 12:00:24 -0700 |
commit | 6b085ba47715a3e7283ec383c1ddf0f8b14dc60c (patch) | |
tree | c55adcf3a82c08be8ee85fda0f90b9ba5f720afc /test | |
parent | c27fac421b760e62a8becf5d2c53ddbdf4ae5a4c (diff) |
setgid: skip tests when we can't find usable GIDs
PiperOrigin-RevId: 365092320
Diffstat (limited to 'test')
-rw-r--r-- | test/syscalls/linux/setgid.cc | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/test/syscalls/linux/setgid.cc b/test/syscalls/linux/setgid.cc index 98f8f3dfe..ce61bc36d 100644 --- a/test/syscalls/linux/setgid.cc +++ b/test/syscalls/linux/setgid.cc @@ -107,16 +107,7 @@ PosixErrorOr<std::pair<gid_t, gid_t>> Groups() { if (!capable.ValueOrDie()) { return PosixError(EPERM, "missing CAP_SETGID"); } - gid_t gid = getegid(); - auto cleanup1 = Setegid(gid); - if (!cleanup1.ok()) { - return cleanup1.error(); - } - auto cleanup2 = Setegid(kNobody); - if (!cleanup2.ok()) { - return cleanup2.error(); - } - return std::pair<gid_t, gid_t>(gid, kNobody); + return std::pair<gid_t, gid_t>(getegid(), kNobody); } class SetgidDirTest : public ::testing::Test { @@ -132,6 +123,12 @@ class SetgidDirTest : public ::testing::Test { SKIP_IF(!groups.ok()); groups_ = groups.ValueOrDie(); + // Ensure we can actually use both groups. + auto cleanup1 = Setegid(groups_.first); + SKIP_IF(!cleanup1.ok()); + auto cleanup2 = Setegid(groups_.second); + SKIP_IF(!cleanup2.ok()); + auto cleanup = Setegid(groups_.first); temp_dir_ = ASSERT_NO_ERRNO_AND_VALUE( TempPath::CreateDirWith(GetAbsoluteTestTmpdir(), 0777 /* mode */)); |