mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add test for O_TRUNC
b/36576592 calls out an edge case previously not supported by HostFS. HostFS is currently being removed, meaning gVisor supports this feature. Simply add the test to open_test. PiperOrigin-RevId: 314610226
This commit is contained in:
committed by
gVisor bot
parent
7da69fe971
commit
d8d86f0f3a
@@ -416,6 +416,29 @@ TEST_F(OpenTest, CanTruncateWriteOnlyNoReadPermission_NoRandomSave) {
|
||||
EXPECT_EQ(stat.st_size, 0);
|
||||
}
|
||||
|
||||
TEST_F(OpenTest, CanTruncateWithStrangePermissions) {
|
||||
ASSERT_NO_ERRNO(SetCapability(CAP_DAC_OVERRIDE, false));
|
||||
ASSERT_NO_ERRNO(SetCapability(CAP_DAC_READ_SEARCH, false));
|
||||
const DisableSave ds; // Permissions are dropped.
|
||||
std::string path = NewTempAbsPath();
|
||||
int fd;
|
||||
// Create a file without user permissions.
|
||||
EXPECT_THAT( // SAVE_BELOW
|
||||
fd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 055),
|
||||
SyscallSucceeds());
|
||||
EXPECT_THAT(close(fd), SyscallSucceeds());
|
||||
|
||||
// Cannot open file because we are owner and have no permissions set.
|
||||
EXPECT_THAT(open(path.c_str(), O_RDONLY), SyscallFailsWithErrno(EACCES));
|
||||
|
||||
// We *can* chmod the file, because we are the owner.
|
||||
EXPECT_THAT(chmod(path.c_str(), 0755), SyscallSucceeds());
|
||||
|
||||
// Now we can open the file again.
|
||||
EXPECT_THAT(fd = open(path.c_str(), O_RDWR), SyscallSucceeds());
|
||||
EXPECT_THAT(close(fd), SyscallSucceeds());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace testing
|
||||
|
||||
Reference in New Issue
Block a user