Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: chromeos/process_test.cc

Issue 6865041: libchromeos: Support setting uid/gid of child processes in process.h (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/common.git@master
Patch Set: improve comments Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/process_mock.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/process_test.cc
diff --git a/chromeos/process_test.cc b/chromeos/process_test.cc
index 98d4bf8637567834320ed99faf87b6e100831feb..f7d11c5984ca50d32ccf288b796ecb5c85bf6663 100644
--- a/chromeos/process_test.cc
+++ b/chromeos/process_test.cc
@@ -92,7 +92,7 @@ TEST_F(ProcessTest, NonZeroReturnValue) {
TEST_F(ProcessTest, BadOutputFile) {
process_.AddArg(kBinEcho);
process_.RedirectOutput("/bad/path");
- EXPECT_EQ(127, process_.Run());
+ EXPECT_EQ(Process::kErrorExitStatus, process_.Run());
}
TEST_F(ProcessTest, ExistingOutputFile) {
@@ -101,12 +101,12 @@ TEST_F(ProcessTest, ExistingOutputFile) {
EXPECT_FALSE(file_util::PathExists(FilePath(output_file_)));
EXPECT_EQ(0, process_.Run());
EXPECT_TRUE(file_util::PathExists(FilePath(output_file_)));
- EXPECT_EQ(127, process_.Run());
+ EXPECT_EQ(Process::kErrorExitStatus, process_.Run());
}
TEST_F(ProcessTest, BadExecutable) {
process_.AddArg("false");
- EXPECT_EQ(127, process_.Run());
+ EXPECT_EQ(Process::kErrorExitStatus, process_.Run());
}
void ProcessTest::CheckStderrCaptured() {
@@ -196,8 +196,46 @@ TEST_F(ProcessTest, RedirectStdinUsingPipe) {
ExpectFileEquals(kMessage, output_file_.c_str());
}
+TEST_F(ProcessTest, WithSameUid) {
+ gid_t uid = geteuid();
+ process_.AddArg(kBinEcho);
+ process_.SetUid(uid);
+ EXPECT_EQ(0, process_.Run());
+}
+
+TEST_F(ProcessTest, WithSameGid) {
+ gid_t gid = getegid();
+ process_.AddArg(kBinEcho);
+ process_.SetGid(gid);
+ EXPECT_EQ(0, process_.Run());
+}
+
+TEST_F(ProcessTest, WithIllegalUid) {
+ ASSERT_NE(0, geteuid());
+ process_.AddArg(kBinEcho);
+ process_.SetUid(0);
+ EXPECT_EQ(Process::kErrorExitStatus, process_.Run());
+ std::string contents;
+ EXPECT_TRUE(file_util::ReadFileToString(FilePath(output_file_),
+ &contents));
+ EXPECT_NE(std::string::npos,
+ contents.find("Unable to set UID to 0: 1\n"));
+}
+
+TEST_F(ProcessTest, WithIllegalGid) {
+ ASSERT_NE(0, getegid());
+ process_.AddArg(kBinEcho);
+ process_.SetGid(0);
+ EXPECT_EQ(Process::kErrorExitStatus, process_.Run());
+ std::string contents;
+ EXPECT_TRUE(file_util::ReadFileToString(FilePath(output_file_),
+ &contents));
+ EXPECT_NE(std::string::npos,
+ contents.find("Unable to set GID to 0: 1\n"));
+}
+
TEST_F(ProcessTest, NoParams) {
- EXPECT_EQ(127, process_.Run());
+ EXPECT_EQ(Process::kErrorExitStatus, process_.Run());
}
TEST_F(ProcessTest, SegFaultHandling) {
« no previous file with comments | « chromeos/process_mock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698