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

Side by Side Diff: mojo/public/platform/native/system_impl_private_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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file tests the C API, but using the explicit MojoSystemImpl parameter. 5 // This file tests the C API, but using the explicit MojoSystemImpl parameter.
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "mojo/public/platform/native/system_impl_private.h" 9 #include "mojo/public/platform/native/system_impl_private.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED, 716 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED,
717 MojoSystemImplDuplicateHandle(sys1, h2, &h3)); 717 MojoSystemImplDuplicateHandle(sys1, h2, &h3));
718 EXPECT_EQ(MOJO_HANDLE_INVALID, h3); 718 EXPECT_EQ(MOJO_HANDLE_INVALID, h3);
719 719
720 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1)); 720 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1));
721 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h2)); 721 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h2));
722 722
723 // 2 SystemImpls are leaked... 723 // 2 SystemImpls are leaked...
724 } 724 }
725 725
726 TEST(CoreTest, MessagePipeChecksTransferRight) {
727 MojoSystemImpl sys = MojoSystemImplCreateImpl();
728
729 MojoHandle h0 = MOJO_HANDLE_INVALID;
730 MojoHandle h1 = MOJO_HANDLE_INVALID;
731 EXPECT_EQ(MOJO_RESULT_OK,
732 MojoSystemImplCreateMessagePipe(sys, nullptr, &h0, &h1));
733
734 // Create a shared buffer (which is transferrable and duplicatable).
735 MojoHandle h_transferrable = MOJO_HANDLE_INVALID;
736 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplCreateSharedBuffer(sys, nullptr, 100,
737 &h_transferrable));
738
739 // Make a non-transferrable duplicate handle.
740 MojoHandle h_not_transferrable = MOJO_HANDLE_INVALID;
741 EXPECT_EQ(MOJO_RESULT_OK,
742 MojoSystemImplDuplicateHandleWithReducedRights(
743 sys, h_transferrable, MOJO_HANDLE_RIGHT_TRANSFER,
744 &h_not_transferrable));
745
746 // |h_transferrable| can be transferred.
747 EXPECT_EQ(MOJO_RESULT_OK,
748 MojoSystemImplWriteMessage(sys, h0, nullptr, 0u, &h_transferrable,
749 1u, MOJO_WRITE_MESSAGE_FLAG_NONE));
750
751 // |h_not_transferrable| can be transferred.
752 EXPECT_EQ(
753 MOJO_RESULT_PERMISSION_DENIED,
754 MojoSystemImplWriteMessage(sys, h0, nullptr, 0u, &h_not_transferrable, 1u,
755 MOJO_WRITE_MESSAGE_FLAG_NONE));
756
757 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys, h0));
758 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys, h1));
759 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys, h_not_transferrable));
760
761 // 1 SystemImpl is leaked...
762 }
763
726 } // namespace 764 } // namespace
727 } // namespace mojo 765 } // namespace mojo
OLDNEW
« mojo/public/c/system/message_pipe.h ('K') | « mojo/public/c/system/tests/core_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698