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

Side by Side Diff: remoting/host/client_session_unittest.cc

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change authorization socket flag name Created 6 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/test/test_simple_task_runner.h"
6 #include "remoting/base/auto_thread_task_runner.h" 7 #include "remoting/base/auto_thread_task_runner.h"
7 #include "remoting/base/constants.h" 8 #include "remoting/base/constants.h"
8 #include "remoting/host/audio_capturer.h" 9 #include "remoting/host/audio_capturer.h"
9 #include "remoting/host/client_session.h" 10 #include "remoting/host/client_session.h"
10 #include "remoting/host/desktop_environment.h" 11 #include "remoting/host/desktop_environment.h"
11 #include "remoting/host/host_mock_objects.h" 12 #include "remoting/host/host_mock_objects.h"
12 #include "remoting/host/screen_capturer_fake.h" 13 #include "remoting/host/screen_capturer_fake.h"
13 #include "remoting/protocol/protocol_mock_objects.h" 14 #include "remoting/protocol/protocol_mock_objects.h"
15 #include "testing/gmock/include/gmock/gmock-matchers.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 17 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
16 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" 18 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
17 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h" 19 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h"
18 20
19 namespace remoting { 21 namespace remoting {
20 22
21 using protocol::MockConnectionToClient; 23 using protocol::MockConnectionToClient;
22 using protocol::MockClientStub; 24 using protocol::MockClientStub;
23 using protocol::MockHostStub; 25 using protocol::MockHostStub;
24 using protocol::MockInputStub; 26 using protocol::MockInputStub;
25 using protocol::MockSession; 27 using protocol::MockSession;
26 using protocol::MockVideoStub; 28 using protocol::MockVideoStub;
27 using protocol::SessionConfig; 29 using protocol::SessionConfig;
28 30
29 using testing::_; 31 using testing::_;
30 using testing::AnyNumber; 32 using testing::AnyNumber;
31 using testing::AtMost; 33 using testing::AtMost;
32 using testing::DeleteArg; 34 using testing::DeleteArg;
33 using testing::DoAll; 35 using testing::DoAll;
34 using testing::Expectation; 36 using testing::Expectation;
35 using testing::Return; 37 using testing::Return;
36 using testing::ReturnRef; 38 using testing::ReturnRef;
37 using testing::Sequence; 39 using testing::Sequence;
40 using testing::StrEq;
41 using testing::StrictMock;
38 42
39 namespace { 43 namespace {
40 44
41 ACTION_P2(InjectClipboardEvent, connection, event) { 45 ACTION_P2(InjectClipboardEvent, connection, event) {
42 connection->clipboard_stub()->InjectClipboardEvent(event); 46 connection->clipboard_stub()->InjectClipboardEvent(event);
43 } 47 }
44 48
45 ACTION_P2(InjectKeyEvent, connection, event) { 49 ACTION_P2(InjectKeyEvent, connection, event) {
46 connection->input_stub()->InjectKeyEvent(event); 50 connection->input_stub()->InjectKeyEvent(event);
47 } 51 }
48 52
49 ACTION_P2(InjectMouseEvent, connection, event) { 53 ACTION_P2(InjectMouseEvent, connection, event) {
50 connection->input_stub()->InjectMouseEvent(event); 54 connection->input_stub()->InjectMouseEvent(event);
51 } 55 }
52 56
53 ACTION_P2(LocalMouseMoved, client_session, event) { 57 ACTION_P2(LocalMouseMoved, client_session, event) {
54 client_session->OnLocalMouseMoved( 58 client_session->OnLocalMouseMoved(
55 webrtc::DesktopVector(event.x(), event.y())); 59 webrtc::DesktopVector(event.x(), event.y()));
56 } 60 }
57 61
58 } // namespace 62 ACTION_P2(SetGnubbyAuthHandlerForTesting, client_session, gnubby_auth_handler) {
63 client_session->SetGnubbyAuthHandlerForTesting(gnubby_auth_handler);
64 }
65
66 ACTION_P2(DeliverClientMessage, client_session, message) {
67 client_session->DeliverClientMessage(message);
68 }
69
70 }
59 71
60 class ClientSessionTest : public testing::Test { 72 class ClientSessionTest : public testing::Test {
61 public: 73 public:
62 ClientSessionTest() : client_jid_("user@domain/rest-of-jid") {} 74 ClientSessionTest() : client_jid_("user@domain/rest-of-jid") {}
63 75
64 virtual void SetUp() OVERRIDE; 76 virtual void SetUp() OVERRIDE;
65 virtual void TearDown() OVERRIDE; 77 virtual void TearDown() OVERRIDE;
66 78
67 // Disconnects the client session. 79 // Disconnects the client session.
68 void DisconnectClientSession(); 80 void DisconnectClientSession();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 &session_event_handler_, 172 &session_event_handler_,
161 ui_task_runner, // Audio thread. 173 ui_task_runner, // Audio thread.
162 ui_task_runner, // Input thread. 174 ui_task_runner, // Input thread.
163 ui_task_runner, // Capture thread. 175 ui_task_runner, // Capture thread.
164 ui_task_runner, // Encode thread. 176 ui_task_runner, // Encode thread.
165 ui_task_runner, // Network thread. 177 ui_task_runner, // Network thread.
166 ui_task_runner, // UI thread. 178 ui_task_runner, // UI thread.
167 connection.PassAs<protocol::ConnectionToClient>(), 179 connection.PassAs<protocol::ConnectionToClient>(),
168 desktop_environment_factory_.get(), 180 desktop_environment_factory_.get(),
169 base::TimeDelta(), 181 base::TimeDelta(),
170 NULL)); 182 NULL,
183 false));
171 } 184 }
172 185
173 void ClientSessionTest::TearDown() { 186 void ClientSessionTest::TearDown() {
174 // Verify that the client session has been stopped. 187 // Verify that the client session has been stopped.
175 EXPECT_TRUE(!client_session_); 188 EXPECT_TRUE(!client_session_);
176 } 189 }
177 190
178 void ClientSessionTest::DisconnectClientSession() { 191 void ClientSessionTest::DisconnectClientSession() {
179 client_session_->DisconnectSession(); 192 client_session_->DisconnectSession();
180 // MockSession won't trigger OnConnectionClosed, so fake it. 193 // MockSession won't trigger OnConnectionClosed, so fake it.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 300 }
288 301
289 MATCHER_P2(EqualsMouseEvent, x, y, "") { 302 MATCHER_P2(EqualsMouseEvent, x, y, "") {
290 return arg.x() == x && arg.y() == y; 303 return arg.x() == x && arg.y() == y;
291 } 304 }
292 305
293 MATCHER_P2(EqualsMouseButtonEvent, button, down, "") { 306 MATCHER_P2(EqualsMouseButtonEvent, button, down, "") {
294 return arg.button() == button && arg.button_down() == down; 307 return arg.button() == button && arg.button_down() == down;
295 } 308 }
296 309
297 } 310 } // namespace
298 311
299 TEST_F(ClientSessionTest, InputStubFilter) { 312 TEST_F(ClientSessionTest, InputStubFilter) {
300 protocol::KeyEvent key_event1; 313 protocol::KeyEvent key_event1;
301 key_event1.set_pressed(true); 314 key_event1.set_pressed(true);
302 key_event1.set_usb_keycode(1); 315 key_event1.set_usb_keycode(1);
303 316
304 protocol::KeyEvent key_event2_down; 317 protocol::KeyEvent key_event2_down;
305 key_event2_down.set_pressed(true); 318 key_event2_down.set_pressed(true);
306 key_event2_down.set_usb_keycode(2); 319 key_event2_down.set_usb_keycode(2);
307 320
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 expected_event.y()))) 545 expected_event.y())))
533 .After(connected) 546 .After(connected)
534 .WillOnce(DoAll( 547 .WillOnce(DoAll(
535 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 548 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
536 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 549 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
537 550
538 ConnectClientSession(); 551 ConnectClientSession();
539 message_loop_.Run(); 552 message_loop_.Run();
540 } 553 }
541 554
555 TEST_F(ClientSessionTest, NoGnubbyAuth) {
556 protocol::ExtensionMessage message;
557 message.set_type("gnubby-auth");
558 message.set_data("test");
559
560 Expectation authenticated =
561 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
562 .WillOnce(Return(true));
563 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
564 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
565 .After(authenticated)
566 .WillOnce(DoAll(
567 DeliverClientMessage(client_session_.get(), message),
568 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
569 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
570 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
571
572 ConnectClientSession();
573 message_loop_.Run();
574 }
575
576 TEST_F(ClientSessionTest, EnableGnubbyAuth) {
577 // Lifetime controlled by object under test.
578 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler(
579 &client_stub_);
580
581 protocol::ExtensionMessage message;
582 message.set_type("gnubby-auth");
583 message.set_data("test");
584
585 Expectation authenticated =
586 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
587 .WillOnce(Return(true));
588 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
589 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
590 .After(authenticated)
591 .WillOnce(DoAll(
592 SetGnubbyAuthHandlerForTesting(client_session_.get(),
593 gnubby_auth_handler),
594 DeliverClientMessage(client_session_.get(), message),
595 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
596 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
597 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_));
598 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
599
600 ConnectClientSession();
601 message_loop_.Run();
602 }
603
542 } // namespace remoting 604 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698