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 "remoting/host/security_key/security_key_auth_handler.h" | 5 #include "remoting/host/security_key/security_key_auth_handler.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "ipc/ipc_channel.h" | 16 #include "ipc/ipc_channel.h" |
17 #include "ipc/ipc_listener.h" | 17 #include "ipc/ipc_listener.h" |
18 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
19 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
20 #include "mojo/edk/test/scoped_ipc_support.h" | 20 #include "mojo/edk/embedder/scoped_ipc_support.h" |
21 #include "remoting/host/host_mock_objects.h" | 21 #include "remoting/host/host_mock_objects.h" |
22 #include "remoting/host/security_key/fake_security_key_ipc_client.h" | 22 #include "remoting/host/security_key/fake_security_key_ipc_client.h" |
23 #include "remoting/host/security_key/fake_security_key_ipc_server.h" | 23 #include "remoting/host/security_key/fake_security_key_ipc_server.h" |
24 #include "remoting/host/security_key/security_key_ipc_constants.h" | 24 #include "remoting/host/security_key/security_key_ipc_constants.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 const int kConnectionId1 = 1; | 29 const int kConnectionId1 = 1; |
30 const int kConnectionId2 = 2; | 30 const int kConnectionId2 = 2; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, | 81 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, |
82 int connection_id); | 82 int connection_id); |
83 | 83 |
84 // Returns a unique IPC channel handle which prevents conflicts when running | 84 // Returns a unique IPC channel handle which prevents conflicts when running |
85 // tests concurrently. | 85 // tests concurrently. |
86 std::string GetUniqueTestChannelHandle(); | 86 std::string GetUniqueTestChannelHandle(); |
87 | 87 |
88 // IPC tests require a valid MessageLoop to run. | 88 // IPC tests require a valid MessageLoop to run. |
89 base::MessageLoopForIO message_loop_; | 89 base::MessageLoopForIO message_loop_; |
90 | 90 |
91 mojo::edk::test::ScopedIPCSupport ipc_support_; | 91 mojo::edk::ScopedIPCSupport ipc_support_; |
92 | 92 |
93 // Used to allow |message_loop_| to run during tests. The instance is reset | 93 // Used to allow |message_loop_| to run during tests. The instance is reset |
94 // after each stage of the tests has been completed. | 94 // after each stage of the tests has been completed. |
95 std::unique_ptr<base::RunLoop> run_loop_; | 95 std::unique_ptr<base::RunLoop> run_loop_; |
96 | 96 |
97 // The object under test. | 97 // The object under test. |
98 std::unique_ptr<SecurityKeyAuthHandler> auth_handler_; | 98 std::unique_ptr<SecurityKeyAuthHandler> auth_handler_; |
99 | 99 |
100 // Set as the default factory to create SecurityKeyIpcServerFactory | 100 // Set as the default factory to create SecurityKeyIpcServerFactory |
101 // instances, this class will track each objects creation and allow the tests | 101 // instances, this class will track each objects creation and allow the tests |
102 // to access it and use it for driving tests and validating state. | 102 // to access it and use it for driving tests and validating state. |
103 FakeSecurityKeyIpcServerFactory ipc_server_factory_; | 103 FakeSecurityKeyIpcServerFactory ipc_server_factory_; |
104 | 104 |
105 // Used to validate the object under test uses the correct ID when | 105 // Used to validate the object under test uses the correct ID when |
106 // communicating over the IPC channel. | 106 // communicating over the IPC channel. |
107 int last_connection_id_received_ = -1; | 107 int last_connection_id_received_ = -1; |
108 | 108 |
109 // Stores the contents of the last IPC message received for validation. | 109 // Stores the contents of the last IPC message received for validation. |
110 std::string last_message_received_; | 110 std::string last_message_received_; |
111 | 111 |
112 private: | 112 private: |
113 testing::NiceMock<MockClientSessionDetails> mock_client_session_details_; | 113 testing::NiceMock<MockClientSessionDetails> mock_client_session_details_; |
114 | 114 |
115 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerWinTest); | 115 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerWinTest); |
116 }; | 116 }; |
117 | 117 |
118 SecurityKeyAuthHandlerWinTest::SecurityKeyAuthHandlerWinTest() | 118 SecurityKeyAuthHandlerWinTest::SecurityKeyAuthHandlerWinTest() |
119 : ipc_support_(message_loop_.task_runner()), | 119 : ipc_support_(message_loop_.task_runner(), |
| 120 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST), |
120 run_loop_(new base::RunLoop()) { | 121 run_loop_(new base::RunLoop()) { |
121 auth_handler_ = remoting::SecurityKeyAuthHandler::Create( | 122 auth_handler_ = remoting::SecurityKeyAuthHandler::Create( |
122 &mock_client_session_details_, | 123 &mock_client_session_details_, |
123 base::Bind(&SecurityKeyAuthHandlerWinTest::SendMessageToClient, | 124 base::Bind(&SecurityKeyAuthHandlerWinTest::SendMessageToClient, |
124 base::Unretained(this)), | 125 base::Unretained(this)), |
125 /*file_task_runner=*/nullptr); | 126 /*file_task_runner=*/nullptr); |
126 } | 127 } |
127 | 128 |
128 SecurityKeyAuthHandlerWinTest::~SecurityKeyAuthHandlerWinTest() {} | 129 SecurityKeyAuthHandlerWinTest::~SecurityKeyAuthHandlerWinTest() {} |
129 | 130 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 ASSERT_FALSE(fake_ipc_server.get()); | 423 ASSERT_FALSE(fake_ipc_server.get()); |
423 ASSERT_FALSE(auth_handler_->IsValidConnectionId(kConnectionId1)); | 424 ASSERT_FALSE(auth_handler_->IsValidConnectionId(kConnectionId1)); |
424 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 425 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
425 | 426 |
426 // Attempt to connect again after the error. | 427 // Attempt to connect again after the error. |
427 EstablishIpcConnection(&fake_ipc_client, kConnectionId2, channel_handle, | 428 EstablishIpcConnection(&fake_ipc_client, kConnectionId2, channel_handle, |
428 /*close_connection=*/true); | 429 /*close_connection=*/true); |
429 } | 430 } |
430 | 431 |
431 } // namespace remoting | 432 } // namespace remoting |
OLD | NEW |