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/gnubby_extension_session.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | 8 |
7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
9 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
14 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
15 #include "base/timer/mock_timer.h" | 18 #include "base/timer/mock_timer.h" |
16 #include "base/values.h" | 19 #include "base/values.h" |
17 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
18 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
19 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
20 #include "net/socket/unix_domain_client_socket_posix.h" | 23 #include "net/socket/unix_domain_client_socket_posix.h" |
21 #include "remoting/host/host_mock_objects.h" | 24 #include "remoting/host/host_mock_objects.h" |
22 #include "remoting/host/security_key/gnubby_auth_handler.h" | 25 #include "remoting/host/security_key/gnubby_auth_handler.h" |
23 #include "remoting/host/security_key/gnubby_extension_session.h" | |
24 #include "remoting/proto/internal.pb.h" | 26 #include "remoting/proto/internal.pb.h" |
25 #include "remoting/protocol/client_stub.h" | 27 #include "remoting/protocol/client_stub.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
28 | 30 |
29 namespace remoting { | 31 namespace remoting { |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 // Test gnubby request data. | 35 // Test gnubby request data. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 ASSERT_TRUE(message_.type() == "gnubby-auth" || | 89 ASSERT_TRUE(message_.type() == "gnubby-auth" || |
88 message_.type() == "auth-v1"); | 90 message_.type() == "auth-v1"); |
89 ASSERT_NE(message_.data().find("\"type\":\"data\""), std::string::npos); | 91 ASSERT_NE(message_.data().find("\"type\":\"data\""), std::string::npos); |
90 ASSERT_NE(message_.data().find(connection_id), std::string::npos); | 92 ASSERT_NE(message_.data().find(connection_id), std::string::npos); |
91 ASSERT_NE(message_.data().find(data_message), std::string::npos); | 93 ASSERT_NE(message_.data().find(data_message), std::string::npos); |
92 } | 94 } |
93 | 95 |
94 private: | 96 private: |
95 protocol::ExtensionMessage message_; | 97 protocol::ExtensionMessage message_; |
96 scoped_ptr<base::RunLoop> run_loop_; | 98 std::unique_ptr<base::RunLoop> run_loop_; |
97 | 99 |
98 DISALLOW_COPY_AND_ASSIGN(TestClientStub); | 100 DISALLOW_COPY_AND_ASSIGN(TestClientStub); |
99 }; | 101 }; |
100 | 102 |
101 class GnubbyExtensionSessionTest : public testing::Test { | 103 class GnubbyExtensionSessionTest : public testing::Test { |
102 public: | 104 public: |
103 GnubbyExtensionSessionTest() | 105 GnubbyExtensionSessionTest() |
104 : gnubby_extension_session_(new GnubbyExtensionSession(&client_stub_)) { | 106 : gnubby_extension_session_(new GnubbyExtensionSession(&client_stub_)) { |
105 // We want to retain ownership of mock object so we can use it to inject | 107 // We want to retain ownership of mock object so we can use it to inject |
106 // events into the extension session. The mock object should not be used | 108 // events into the extension session. The mock object should not be used |
107 // once |gnubby_extension_session_| is destroyed. | 109 // once |gnubby_extension_session_| is destroyed. |
108 mock_gnubby_auth_handler_ = new MockGnubbyAuthHandler(); | 110 mock_gnubby_auth_handler_ = new MockGnubbyAuthHandler(); |
109 gnubby_extension_session_->SetGnubbyAuthHandlerForTesting( | 111 gnubby_extension_session_->SetGnubbyAuthHandlerForTesting( |
110 make_scoped_ptr(mock_gnubby_auth_handler_)); | 112 base::WrapUnique(mock_gnubby_auth_handler_)); |
111 } | 113 } |
112 | 114 |
113 void WaitForAndVerifyHostMessage() { | 115 void WaitForAndVerifyHostMessage() { |
114 client_stub_.WaitForDeliverHostMessage( | 116 client_stub_.WaitForDeliverHostMessage( |
115 base::TimeDelta::FromMilliseconds(500)); | 117 base::TimeDelta::FromMilliseconds(500)); |
116 base::ListValue expected_data; | 118 base::ListValue expected_data; |
117 | 119 |
118 // Skip first four bytes. | 120 // Skip first four bytes. |
119 for (size_t i = 4; i < sizeof(kRequestData); ++i) { | 121 for (size_t i = 4; i < sizeof(kRequestData); ++i) { |
120 expected_data.AppendInteger(kRequestData[i]); | 122 expected_data.AppendInteger(kRequestData[i]); |
(...skipping 12 matching lines...) Expand all Loading... |
133 message.set_data("{\"type\":\"control\",\"option\":\"auth-v1\"}"); | 135 message.set_data("{\"type\":\"control\",\"option\":\"auth-v1\"}"); |
134 | 136 |
135 ASSERT_TRUE(gnubby_extension_session_->OnExtensionMessage(nullptr, nullptr, | 137 ASSERT_TRUE(gnubby_extension_session_->OnExtensionMessage(nullptr, nullptr, |
136 message)); | 138 message)); |
137 } | 139 } |
138 | 140 |
139 protected: | 141 protected: |
140 base::MessageLoopForIO message_loop_; | 142 base::MessageLoopForIO message_loop_; |
141 | 143 |
142 // Object under test. | 144 // Object under test. |
143 scoped_ptr<GnubbyExtensionSession> gnubby_extension_session_; | 145 std::unique_ptr<GnubbyExtensionSession> gnubby_extension_session_; |
144 | 146 |
145 MockGnubbyAuthHandler* mock_gnubby_auth_handler_ = nullptr; | 147 MockGnubbyAuthHandler* mock_gnubby_auth_handler_ = nullptr; |
146 | 148 |
147 TestClientStub client_stub_; | 149 TestClientStub client_stub_; |
148 | 150 |
149 private: | 151 private: |
150 DISALLOW_COPY_AND_ASSIGN(GnubbyExtensionSessionTest); | 152 DISALLOW_COPY_AND_ASSIGN(GnubbyExtensionSessionTest); |
151 }; | 153 }; |
152 | 154 |
153 TEST_F(GnubbyExtensionSessionTest, GnubbyConnectionCreated_ValidMessage) { | 155 TEST_F(GnubbyExtensionSessionTest, GnubbyConnectionCreated_ValidMessage) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 mock_gnubby_auth_handler_->GetSendMessageCallback().Run(42, "test_msg"); | 372 mock_gnubby_auth_handler_->GetSendMessageCallback().Run(42, "test_msg"); |
371 | 373 |
372 client_stub_.WaitForDeliverHostMessage( | 374 client_stub_.WaitForDeliverHostMessage( |
373 base::TimeDelta::FromMilliseconds(500)); | 375 base::TimeDelta::FromMilliseconds(500)); |
374 | 376 |
375 // Expects a JSON array of the ASCII character codes for "test_msg". | 377 // Expects a JSON array of the ASCII character codes for "test_msg". |
376 client_stub_.CheckHostDataMessage(42, "[116,101,115,116,95,109,115,103]"); | 378 client_stub_.CheckHostDataMessage(42, "[116,101,115,116,95,109,115,103]"); |
377 } | 379 } |
378 | 380 |
379 } // namespace remoting | 381 } // namespace remoting |
OLD | NEW |