| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 ConnectTest* connect_test_; | 116 ConnectTest* connect_test_; |
| 117 | 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(TestService); | 118 DISALLOW_COPY_AND_ASSIGN(TestService); |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 // test::ServiceTest: | 121 // test::ServiceTest: |
| 122 void SetUp() override { | 122 void SetUp() override { |
| 123 test::ServiceTest::SetUp(); | 123 test::ServiceTest::SetUp(); |
| 124 // We need to connect to the package first to force the shell to read the | 124 // We need to connect to the package first to force the service manager to |
| 125 // read the |
| 125 // package app's manifest and register aliases for the applications it | 126 // package app's manifest and register aliases for the applications it |
| 126 // provides. | 127 // provides. |
| 127 test::mojom::ConnectTestServicePtr root_service; | 128 test::mojom::ConnectTestServicePtr root_service; |
| 128 std::unique_ptr<Connection> connection = | 129 std::unique_ptr<Connection> connection = |
| 129 connector()->Connect(kTestPackageName); | 130 connector()->Connect(kTestPackageName); |
| 130 connection->GetInterface(&root_service); | 131 connection->GetInterface(&root_service); |
| 131 base::RunLoop run_loop; | 132 base::RunLoop run_loop; |
| 132 std::string root_name; | 133 std::string root_name; |
| 133 root_service->GetTitle( | 134 root_service->GetTitle( |
| 134 base::Bind(&ReceiveOneString, &root_name, &run_loop)); | 135 base::Bind(&ReceiveOneString, &root_name, &run_loop)); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 base::RunLoop loop; | 358 base::RunLoop loop; |
| 358 user_id_test->ConnectToClassAppAsDifferentUser( | 359 user_id_test->ConnectToClassAppAsDifferentUser( |
| 359 target, | 360 target, |
| 360 base::Bind(&ReceiveConnectionResult, &result, &result_identity, &loop)); | 361 base::Bind(&ReceiveConnectionResult, &result, &result_identity, &loop)); |
| 361 loop.Run(); | 362 loop.Run(); |
| 362 } | 363 } |
| 363 EXPECT_EQ(mojom::ConnectResult::ACCESS_DENIED, result); | 364 EXPECT_EQ(mojom::ConnectResult::ACCESS_DENIED, result); |
| 364 EXPECT_FALSE(target == result_identity); | 365 EXPECT_FALSE(target == result_identity); |
| 365 } | 366 } |
| 366 | 367 |
| 367 // There are various other tests (shell, lifecycle) that test valid client | 368 // There are various other tests (service manager, lifecycle) that test valid |
| 369 // client |
| 368 // process specifications. This is the only one for blocking. | 370 // process specifications. This is the only one for blocking. |
| 369 TEST_F(ConnectTest, ConnectToClientProcess_Blocked) { | 371 TEST_F(ConnectTest, ConnectToClientProcess_Blocked) { |
| 370 std::unique_ptr<Connection> connection = | 372 std::unique_ptr<Connection> connection = |
| 371 connector()->Connect(kTestDriverName); | 373 connector()->Connect(kTestDriverName); |
| 372 test::mojom::ClientProcessTestPtr client_process_test; | 374 test::mojom::ClientProcessTestPtr client_process_test; |
| 373 connection->GetInterface(&client_process_test); | 375 connection->GetInterface(&client_process_test); |
| 374 mojom::ConnectResult result; | 376 mojom::ConnectResult result; |
| 375 Identity result_identity; | 377 Identity result_identity; |
| 376 { | 378 { |
| 377 base::RunLoop loop; | 379 base::RunLoop loop; |
| 378 client_process_test->LaunchAndConnectToProcess( | 380 client_process_test->LaunchAndConnectToProcess( |
| 379 base::Bind(&ReceiveConnectionResult, &result, &result_identity, &loop)); | 381 base::Bind(&ReceiveConnectionResult, &result, &result_identity, &loop)); |
| 380 loop.Run(); | 382 loop.Run(); |
| 381 } | 383 } |
| 382 EXPECT_EQ(mojom::ConnectResult::ACCESS_DENIED, result); | 384 EXPECT_EQ(mojom::ConnectResult::ACCESS_DENIED, result); |
| 383 } | 385 } |
| 384 | 386 |
| 385 // Verifies that a client with the "all_users" capability class can receive | 387 // Verifies that a client with the "all_users" capability class can receive |
| 386 // connections from clients run as other users. | 388 // connections from clients run as other users. |
| 387 TEST_F(ConnectTest, AllUsersSingleton) { | 389 TEST_F(ConnectTest, AllUsersSingleton) { |
| 388 // Connect to an instance with an explicitly different user_id. This supplied | 390 // Connect to an instance with an explicitly different user_id. This supplied |
| 389 // user id should be ignored by the shell (which will generate its own | 391 // user id should be ignored by the service manager (which will generate its |
| 392 // own |
| 390 // synthetic user id for all-user singleton instances). | 393 // synthetic user id for all-user singleton instances). |
| 391 const std::string singleton_userid = base::GenerateGUID(); | 394 const std::string singleton_userid = base::GenerateGUID(); |
| 392 Connector::ConnectParams params( | 395 Connector::ConnectParams params( |
| 393 Identity(kTestSingletonAppName, singleton_userid)); | 396 Identity(kTestSingletonAppName, singleton_userid)); |
| 394 std::unique_ptr<Connection> connection = connector()->Connect(¶ms); | 397 std::unique_ptr<Connection> connection = connector()->Connect(¶ms); |
| 395 { | 398 { |
| 396 base::RunLoop loop; | 399 base::RunLoop loop; |
| 397 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 400 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 398 loop.Run(); | 401 loop.Run(); |
| 399 EXPECT_NE(connection->GetRemoteIdentity().user_id(), singleton_userid); | 402 EXPECT_NE(connection->GetRemoteIdentity().user_id(), singleton_userid); |
| 400 } | 403 } |
| 401 // This connects using the current client's user_id. It should be bound to the | 404 // This connects using the current client's user_id. It should be bound to the |
| 402 // same service started above, with the same shell-generated user id. | 405 // same service started above, with the same service manager-generated user |
| 406 // id. |
| 403 std::unique_ptr<Connection> inherit_connection = | 407 std::unique_ptr<Connection> inherit_connection = |
| 404 connector()->Connect(kTestSingletonAppName); | 408 connector()->Connect(kTestSingletonAppName); |
| 405 { | 409 { |
| 406 base::RunLoop loop; | 410 base::RunLoop loop; |
| 407 inherit_connection->AddConnectionCompletedClosure( | 411 inherit_connection->AddConnectionCompletedClosure( |
| 408 base::Bind(&QuitLoop, &loop)); | 412 base::Bind(&QuitLoop, &loop)); |
| 409 loop.Run(); | 413 loop.Run(); |
| 410 EXPECT_EQ(inherit_connection->GetRemoteIdentity().user_id(), | 414 EXPECT_EQ(inherit_connection->GetRemoteIdentity().user_id(), |
| 411 connection->GetRemoteIdentity().user_id()); | 415 connection->GetRemoteIdentity().user_id()); |
| 412 } | 416 } |
| 413 } | 417 } |
| 414 | 418 |
| 415 } // namespace service_manager | 419 } // namespace service_manager |
| OLD | NEW |