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

Unified Diff: mojo/edk/system/core_unittest.cc

Issue 2012613002: Enforce/require MOJO_HANDLE_RIGHT_TRANSFER in sending handles via MojoWriteMessage(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | mojo/edk/system/handle_table.h » ('j') | mojo/public/c/system/message_pipe.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/core_unittest.cc
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
index 005dede1c62d15160a4dc3f8205f2c0701faf8d2..b2a080b4086d3dd3be1faa218b0a0cc77190f114 100644
--- a/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -1792,6 +1792,40 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing3) {
}
}
+// Tests not having versus not having the transfer right.
+TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing4) {
+ MojoHandle h0 = MOJO_HANDLE_INVALID;
+ MojoHandle h1 = MOJO_HANDLE_INVALID;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h0),
+ MakeUserPointer(&h1)));
+
+ MojoHandle h_transferrable = MOJO_HANDLE_INVALID;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->CreateSharedBuffer(NullUserPointer(), 100,
+ MakeUserPointer(&h_transferrable)));
+ MojoHandle h_not_transferrable = MOJO_HANDLE_INVALID;
+ EXPECT_EQ(MOJO_RESULT_OK, core()->DuplicateHandleWithReducedRights(
+ h_transferrable, MOJO_HANDLE_RIGHT_TRANSFER,
+ MakeUserPointer(&h_not_transferrable)));
+
+ // We can send |h_transferrable|.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->WriteMessage(h0, NullUserPointer(), 0,
+ MakeUserPointer(&h_transferrable), 1,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ // But not |h_not_transferrable|.
+ EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED,
+ core()->WriteMessage(h0, NullUserPointer(), 0,
+ MakeUserPointer(&h_not_transferrable), 1,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h0));
+ EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h1));
+ EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_not_transferrable));
+}
+
struct TestAsyncWaiter {
TestAsyncWaiter() : result(MOJO_RESULT_UNKNOWN) {}
« no previous file with comments | « no previous file | mojo/edk/system/handle_table.h » ('j') | mojo/public/c/system/message_pipe.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698