Skip to content

Commit

Permalink
Merge pull request #970 from hzeller/work-around-test-run-as-root
Browse files Browse the repository at this point in the history
Skip permission test if tests are run as root.
  • Loading branch information
hzeller authored Oct 4, 2021
2 parents cb60b63 + ec99dcd commit 6bab432
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions common/util/file_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,16 @@ TEST(FileUtil, StatusErrorReporting) {
// this test here.
// TODO: Can we make permission-denied test that works on Windows ?

// Enforce a permission denied situation
// TODO: Issue #963 - if this turns out to not always succeed to chmod
// we should just skip the test.
const int chmod_result = chmod(test_file.c_str(), 0);
EXPECT_EQ(chmod_result, 0);

content.clear();
status = file::GetContents(test_file, &content);
EXPECT_FALSE(status.ok()) << "Expected permission denied for " << test_file;
EXPECT_EQ(status.code(), absl::StatusCode::kPermissionDenied) << status;
EXPECT_TRUE(content.empty()) << "'" << content << "'";
// Issue #963 - if this test is run as root, the permission issue
// will not manifest. Also if chmod() did not succeed. Skip in this case.
if (geteuid() != 0 && chmod(test_file.c_str(), 0) == 0) {
// Enforce a permission denied situation
content.clear();
status = file::GetContents(test_file, &content);
EXPECT_FALSE(status.ok()) << "Expected permission denied for " << test_file;
EXPECT_EQ(status.code(), absl::StatusCode::kPermissionDenied) << status;
EXPECT_TRUE(content.empty()) << "'" << content << "'";
}
#endif
}

Expand Down

0 comments on commit 6bab432

Please sign in to comment.