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

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

Issue 205493005: Do minimal processing of gnubby data. Add request timeouts and send error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix parameter type Created 6 years, 9 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 2014 The Chromium Authors. All rights reserved. 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 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/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/timer/mock_timer.h"
6 #include "net/socket/stream_listen_socket.h" 8 #include "net/socket/stream_listen_socket.h"
7 #include "remoting/host/gnubby_auth_handler_posix.h" 9 #include "remoting/host/gnubby_auth_handler_posix.h"
10 #include "remoting/host/gnubby_socket.h"
8 #include "remoting/protocol/protocol_mock_objects.h" 11 #include "remoting/protocol/protocol_mock_objects.h"
9 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
10 13
11 namespace remoting { 14 namespace remoting {
12 15
13 using protocol::MockClientStub; 16 using protocol::MockClientStub;
14 17
15 using testing::_; 18 using testing::_;
16 using testing::Return; 19 using testing::Return;
17 20
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 62
60 // GnubbyAuthHandler interface for |auth_handler_posix_|. 63 // GnubbyAuthHandler interface for |auth_handler_posix_|.
61 GnubbyAuthHandler* auth_handler_; 64 GnubbyAuthHandler* auth_handler_;
62 65
63 // Stream delegate interface for |auth_handler_posix_|. 66 // Stream delegate interface for |auth_handler_posix_|.
64 net::StreamListenSocket::Delegate* delegate_; 67 net::StreamListenSocket::Delegate* delegate_;
65 68
66 // Mock client stub. 69 // Mock client stub.
67 MockClientStub client_stub_; 70 MockClientStub client_stub_;
68 71
72 base::MessageLoop message_loop_;
73
69 private: 74 private:
70 void OnConnect(int result); 75 void OnConnect(int result);
71 }; 76 };
72 77
73 void GnubbyAuthHandlerPosixTest::SetUp() { 78 void GnubbyAuthHandlerPosixTest::SetUp() {
74 auth_handler_posix_.reset(new GnubbyAuthHandlerPosix(&client_stub_)); 79 auth_handler_posix_.reset(new GnubbyAuthHandlerPosix(&client_stub_));
75 auth_handler_ = auth_handler_posix_.get(); 80 auth_handler_ = auth_handler_posix_.get();
76 delegate_ = auth_handler_posix_.get(); 81 delegate_ = auth_handler_posix_.get();
77 } 82 }
78 83
79 MATCHER_P2(EqualsDataMessage, id, data, "") { 84 MATCHER_P2(EqualsDataMessage, id, data, "") {
80 std::string connection_id = base::StringPrintf("\"connectionId\":%d", id); 85 std::string connection_id = base::StringPrintf("\"connectionId\":%d", id);
81 std::string json_message = base::StringPrintf("\"jsonMessage\":\"%s\"", data); 86 std::string data_message = base::StringPrintf("\"base64Data\":\"%s\"", data);
82 87
83 return (arg.type() == "gnubby-auth" && 88 return (arg.type() == "gnubby-auth" &&
84 arg.data().find("\"type\":\"data\"") != std::string::npos && 89 arg.data().find("\"type\":\"data\"") != std::string::npos &&
85 arg.data().find(connection_id) != std::string::npos && 90 arg.data().find(connection_id) != std::string::npos &&
86 arg.data().find(json_message) != std::string::npos); 91 arg.data().find(data_message) != std::string::npos);
87 } 92 }
88 93
89 TEST_F(GnubbyAuthHandlerPosixTest, HostDataMessageDelivered) { 94 TEST_F(GnubbyAuthHandlerPosixTest, HostDataMessageDelivered) {
90 EXPECT_CALL(client_stub_, 95 EXPECT_CALL(client_stub_,
91 DeliverHostMessage(EqualsDataMessage(42, "test_msg"))); 96 DeliverHostMessage(EqualsDataMessage(42, "test_msg")));
92 97
93 auth_handler_->DeliverHostDataMessage(42, "test_msg"); 98 auth_handler_->DeliverHostDataMessage(42, "test_msg");
94 } 99 }
95 100
96 TEST_F(GnubbyAuthHandlerPosixTest, DidClose) { 101 TEST_F(GnubbyAuthHandlerPosixTest, DidClose) {
97 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_); 102 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
98 103
99 delegate_->DidAccept(NULL, make_scoped_ptr(socket)); 104 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
100 ASSERT_TRUE(auth_handler_posix_->HasActiveSocketForTesting(socket)); 105 ASSERT_TRUE(auth_handler_posix_->HasActiveSocketForTesting(socket));
101 106
102 delegate_->DidClose(socket); 107 delegate_->DidClose(socket);
103 ASSERT_FALSE(auth_handler_posix_->HasActiveSocketForTesting(socket)); 108 ASSERT_FALSE(auth_handler_posix_->HasActiveSocketForTesting(socket));
104 } 109 }
105 110
106 TEST_F(GnubbyAuthHandlerPosixTest, DidRead) { 111 TEST_F(GnubbyAuthHandlerPosixTest, DidRead) {
107 EXPECT_CALL(client_stub_, DeliverHostMessage(_)); 112 EXPECT_CALL(client_stub_, DeliverHostMessage(_));
108 113
109 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_); 114 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
110 115
111 delegate_->DidAccept(NULL, make_scoped_ptr(socket)); 116 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
112 delegate_->DidRead(socket, reinterpret_cast<const char*>(request_data), 117 delegate_->DidRead(socket,
118 reinterpret_cast<const char*>(request_data),
113 sizeof(request_data)); 119 sizeof(request_data));
114 } 120 }
115 121
116 TEST_F(GnubbyAuthHandlerPosixTest, DidReadByteByByte) { 122 TEST_F(GnubbyAuthHandlerPosixTest, DidReadByteByByte) {
117 EXPECT_CALL(client_stub_, DeliverHostMessage(_)); 123 EXPECT_CALL(client_stub_, DeliverHostMessage(_));
118 124
119 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_); 125 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
120 126
121 delegate_->DidAccept(NULL, make_scoped_ptr(socket)); 127 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
122 for (unsigned int i = 0; i < sizeof(request_data); ++i) { 128 for (unsigned int i = 0; i < sizeof(request_data); ++i) {
123 delegate_->DidRead(socket, 129 delegate_->DidRead(
124 reinterpret_cast<const char *>(request_data + i), 1); 130 socket, reinterpret_cast<const char*>(request_data + i), 1);
125 } 131 }
126 } 132 }
127 133
134 TEST_F(GnubbyAuthHandlerPosixTest, DidReadTimeout) {
135 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
136
137 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
138 ASSERT_TRUE(auth_handler_posix_->HasActiveSocketForTesting(socket));
139
140 base::MockTimer* mock_timer = new base::MockTimer(false, false);
141 auth_handler_posix_->GetGnubbySocketForTesting(socket)
142 ->SetTimerForTesting(mock_timer);
143 delegate_->DidRead(socket, reinterpret_cast<const char*>(request_data), 1);
144 mock_timer->Fire();
145
146 ASSERT_FALSE(auth_handler_posix_->HasActiveSocketForTesting(socket));
147 }
148
149 TEST_F(GnubbyAuthHandlerPosixTest, ClientErrorMessageDelivered) {
150 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
151
152 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
153
154 std::string error_json = base::StringPrintf(
155 "{\"type\":\"error\",\"connectionId\":%d}",
156 auth_handler_posix_->GetConnectionIdForTesting(socket));
157
158 ASSERT_TRUE(auth_handler_posix_->HasActiveSocketForTesting(socket));
159 auth_handler_->DeliverClientMessage(error_json);
160 ASSERT_FALSE(auth_handler_posix_->HasActiveSocketForTesting(socket));
161 }
162
128 } // namespace remoting 163 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698