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

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

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/test/test_simple_task_runner.h"
6 #include "net/base/net_errors.h"
7 #include "net/socket/socket_test_util.h"
8 #include "remoting/host/gnubby_connection.h"
9 #include "remoting/host/host_mock_objects.h"
10 #include "remoting/protocol/protocol_mock_objects.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace remoting {
14
15 using protocol::MockClientStub;
16
17 using testing::_;
18
19 class GnubbyConnectionTest : public testing::Test {
20 public:
21 GnubbyConnectionTest() {}
22
23 virtual void SetUp() OVERRIDE;
24
25 protected:
26 // Create a mock connected socket.
27 net::MockTCPClientSocket* GetConnectedSocket(
28 net::StaticSocketDataProvider* socket_data);
29
30 // Object under test.
31 scoped_ptr<GnubbyConnection> connection_;
32
33 // Task runner for object under test.
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
35
36 // Mock gnubby auth handler that receives connection callbacks.
37 scoped_ptr<MockGnubbyAuthHandler> gnubby_auth_handler_;
38
39 // Mock gnubby connection factory for mock gnubby auth handler.
40 scoped_ptr<MockGnubbyConnectionFactory> gnubby_connection_factory_;
41
42 // Mock client stub.
43 MockClientStub client_stub_;
44
45 private:
46 void OnConnect(int result);
47 };
48
49 void GnubbyConnectionTest::SetUp() {
50 task_runner_ = new base::TestSimpleTaskRunner();
51
52 gnubby_connection_factory_.reset(new MockGnubbyConnectionFactory());
53 gnubby_auth_handler_.reset(new MockGnubbyAuthHandler(
54 task_runner_, gnubby_connection_factory_.get(), &client_stub_));
55 }
56
57 net::MockTCPClientSocket* GnubbyConnectionTest::GetConnectedSocket(
58 net::StaticSocketDataProvider* socket_data) {
59
60 net::AddressList addresses;
61 socket_data->set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK));
62 net::MockTCPClientSocket* socket =
63 new net::MockTCPClientSocket(addresses, NULL, socket_data);
64
65 int result = socket->Connect(
66 base::Bind(&GnubbyConnectionTest::OnConnect, base::Unretained(this)));
67 EXPECT_EQ(net::OK, result);
68 return socket;
69 }
70
71 void GnubbyConnectionTest::OnConnect(int result) {}
72
73 TEST_F(GnubbyConnectionTest, Read) {
74 EXPECT_CALL(*gnubby_auth_handler_, DeliverHostDataMessage(42, "test_msg"));
75 EXPECT_CALL(*gnubby_auth_handler_, ConnectionClosed(42));
76
77 net::MockRead read(net::SYNCHRONOUS, "test_msg");
78 net::MockRead close(net::SYNCHRONOUS, net::OK, "");
79 net::MockRead* read_and_close[] = {&read, &close};
80
81 net::StaticSocketDataProvider socket_data(
82 read_and_close[0], sizeof(read_and_close), NULL, 0);
83
84 connection_.reset(new GnubbyConnection(task_runner_,
85 gnubby_auth_handler_.get(),
86 42,
87 GetConnectedSocket(&socket_data)));
88 connection_->Read();
89 }
90
91 TEST_F(GnubbyConnectionTest, ReadFailed) {
92 EXPECT_CALL(*gnubby_auth_handler_, ConnectionError(42, net::ERR_FAILED));
93
94 net::MockRead read_fail(net::SYNCHRONOUS, net::ERR_FAILED);
95 net::StaticSocketDataProvider socket_data(&read_fail, 1, NULL, 0);
96
97 connection_.reset(new GnubbyConnection(task_runner_,
98 gnubby_auth_handler_.get(),
99 42,
100 GetConnectedSocket(&socket_data)));
101 connection_->Read();
102 }
103
104 TEST_F(GnubbyConnectionTest, WriteFailed) {
105 EXPECT_CALL(*gnubby_auth_handler_, ConnectionError(42, net::ERR_FAILED));
106
107 net::MockWrite write_fail(net::SYNCHRONOUS, net::ERR_FAILED);
108 net::StaticSocketDataProvider socket_data(NULL, 0, &write_fail, 1);
109
110 connection_.reset(new GnubbyConnection(task_runner_,
111 gnubby_auth_handler_.get(),
112 42,
113 GetConnectedSocket(&socket_data)));
114 connection_->Write("test_msg");
115 }
116
117 TEST_F(GnubbyConnectionTest, Write) {
118 net::MockWrite write(net::SYNCHRONOUS, "test_msg");
119 net::StaticSocketDataProvider socket_data(NULL, 0, &write, 1);
120
121 connection_.reset(new GnubbyConnection(task_runner_,
122 gnubby_auth_handler_.get(),
123 42,
124 GetConnectedSocket(&socket_data)));
125 connection_->Write("test_msg");
126 }
127
128 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698