OLD | NEW |
---|---|
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 "remoting/protocol/jingle_session.h" | 5 #include "remoting/protocol/jingle_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 #include "net/socket/socket.h" | 11 #include "net/socket/socket.h" |
12 #include "net/socket/stream_socket.h" | 12 #include "net/socket/stream_socket.h" |
13 #include "remoting/base/constants.h" | 13 #include "remoting/base/constants.h" |
14 #include "remoting/protocol/authenticator.h" | 14 #include "remoting/protocol/authenticator.h" |
15 #include "remoting/protocol/channel_authenticator.h" | 15 #include "remoting/protocol/channel_authenticator.h" |
16 #include "remoting/protocol/connection_tester.h" | 16 #include "remoting/protocol/connection_tester.h" |
17 #include "remoting/protocol/fake_authenticator.h" | 17 #include "remoting/protocol/fake_authenticator.h" |
18 #include "remoting/protocol/jingle_session_manager.h" | 18 #include "remoting/protocol/jingle_session_manager.h" |
19 #include "remoting/protocol/libjingle_transport_factory.h" | 19 #include "remoting/protocol/libjingle_transport_factory.h" |
20 #include "remoting/jingle_glue/jingle_thread.h" | 20 #include "remoting/jingle_glue/jingle_thread.h" |
21 #include "remoting/jingle_glue/fake_signal_strategy.h" | 21 #include "remoting/jingle_glue/fake_signal_strategy.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 using testing::_; | 25 using testing::_; |
26 using testing::AtLeast; | |
26 using testing::AtMost; | 27 using testing::AtMost; |
27 using testing::DeleteArg; | 28 using testing::DeleteArg; |
28 using testing::DoAll; | 29 using testing::DoAll; |
29 using testing::InSequence; | 30 using testing::InSequence; |
30 using testing::Invoke; | 31 using testing::Invoke; |
31 using testing::InvokeWithoutArgs; | 32 using testing::InvokeWithoutArgs; |
32 using testing::Return; | 33 using testing::Return; |
33 using testing::SaveArg; | 34 using testing::SaveArg; |
34 using testing::SetArgumentPointee; | 35 using testing::SetArgumentPointee; |
35 using testing::WithArg; | 36 using testing::WithArg; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 if (client_server_.get()) { | 164 if (client_server_.get()) { |
164 client_server_->Close(); | 165 client_server_->Close(); |
165 client_server_.reset(); | 166 client_server_.reset(); |
166 } | 167 } |
167 host_signal_strategy_.reset(); | 168 host_signal_strategy_.reset(); |
168 client_signal_strategy_.reset(); | 169 client_signal_strategy_.reset(); |
169 } | 170 } |
170 | 171 |
171 void InitiateConnection(int auth_round_trips, | 172 void InitiateConnection(int auth_round_trips, |
172 FakeAuthenticator::Action auth_action, | 173 FakeAuthenticator::Action auth_action, |
173 bool expect_fail) { | 174 bool expect_fail, bool expect_session_route_change) { |
174 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 175 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
175 .WillOnce(DoAll( | 176 .WillOnce(DoAll( |
176 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 177 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
177 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 178 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
178 | 179 |
179 { | 180 { |
180 InSequence dummy; | 181 InSequence dummy; |
181 | 182 |
182 EXPECT_CALL(host_session_event_handler_, | 183 EXPECT_CALL(host_session_event_handler_, |
183 OnSessionStateChange(Session::CONNECTED)) | 184 OnSessionStateChange(Session::CONNECTED)) |
184 .Times(AtMost(1)); | 185 .Times(AtMost(1)); |
185 if (expect_fail) { | 186 if (expect_fail) { |
186 EXPECT_CALL(host_session_event_handler_, | 187 EXPECT_CALL(host_session_event_handler_, |
187 OnSessionStateChange(Session::FAILED)) | 188 OnSessionStateChange(Session::FAILED)) |
188 .Times(1); | 189 .Times(1); |
189 } else { | 190 } else { |
190 EXPECT_CALL(host_session_event_handler_, | 191 EXPECT_CALL(host_session_event_handler_, |
191 OnSessionStateChange(Session::AUTHENTICATED)) | 192 OnSessionStateChange(Session::AUTHENTICATED)) |
192 .Times(1); | 193 .Times(1); |
193 // Expect that the connection will be closed eventually. | 194 // Expect that the connection will be closed eventually. |
194 EXPECT_CALL(host_session_event_handler_, | 195 EXPECT_CALL(host_session_event_handler_, |
195 OnSessionStateChange(Session::CLOSED)) | 196 OnSessionStateChange(Session::CLOSED)) |
196 .Times(AtMost(1)); | 197 .Times(AtMost(1)); |
197 } | 198 } |
198 } | 199 } |
200 if (expect_session_route_change) { | |
Sergey Ulanov
2012/07/23 22:05:37
It's better to put this in CreateChannel() as we e
simonmorris
2012/07/23 22:21:25
Done.
| |
201 EXPECT_CALL(host_session_event_handler_, | |
202 OnSessionRouteChange(kChannelName, _)) | |
203 .Times(AtLeast(1)); | |
204 } | |
199 | 205 |
200 { | 206 { |
201 InSequence dummy; | 207 InSequence dummy; |
202 | 208 |
203 EXPECT_CALL(client_session_event_handler_, | 209 EXPECT_CALL(client_session_event_handler_, |
204 OnSessionStateChange(Session::CONNECTED)) | 210 OnSessionStateChange(Session::CONNECTED)) |
205 .Times(AtMost(1)); | 211 .Times(AtMost(1)); |
206 if (expect_fail) { | 212 if (expect_fail) { |
207 EXPECT_CALL(client_session_event_handler_, | 213 EXPECT_CALL(client_session_event_handler_, |
208 OnSessionStateChange(Session::FAILED)) | 214 OnSessionStateChange(Session::FAILED)) |
209 .Times(1); | 215 .Times(1); |
210 } else { | 216 } else { |
211 EXPECT_CALL(client_session_event_handler_, | 217 EXPECT_CALL(client_session_event_handler_, |
212 OnSessionStateChange(Session::AUTHENTICATED)) | 218 OnSessionStateChange(Session::AUTHENTICATED)) |
213 .Times(1); | 219 .Times(1); |
214 // Expect that the connection will be closed eventually. | 220 // Expect that the connection will be closed eventually. |
215 EXPECT_CALL(client_session_event_handler_, | 221 EXPECT_CALL(client_session_event_handler_, |
216 OnSessionStateChange(Session::CLOSED)) | 222 OnSessionStateChange(Session::CLOSED)) |
217 .Times(AtMost(1)); | 223 .Times(AtMost(1)); |
218 } | 224 } |
219 } | 225 } |
226 if (expect_session_route_change) { | |
227 EXPECT_CALL(client_session_event_handler_, | |
228 OnSessionRouteChange(kChannelName, _)) | |
229 .Times(AtLeast(1)); | |
230 } | |
220 | 231 |
221 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 232 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
222 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); | 233 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); |
223 | 234 |
224 client_session_ = client_server_->Connect( | 235 client_session_ = client_server_->Connect( |
225 kHostJid, authenticator.Pass(), | 236 kHostJid, authenticator.Pass(), |
226 CandidateSessionConfig::CreateDefault()); | 237 CandidateSessionConfig::CreateDefault()); |
227 client_session_->SetEventHandler(&client_session_event_handler_); | 238 client_session_->SetEventHandler(&client_session_event_handler_); |
228 | 239 |
229 message_loop_->RunAllPending(); | 240 message_loop_->RunAllPending(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 client_session_ = client_server_->Connect( | 307 client_session_ = client_server_->Connect( |
297 kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault()); | 308 kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault()); |
298 client_session_->SetEventHandler(&client_session_event_handler_); | 309 client_session_->SetEventHandler(&client_session_event_handler_); |
299 | 310 |
300 message_loop_->RunAllPending(); | 311 message_loop_->RunAllPending(); |
301 } | 312 } |
302 | 313 |
303 // Verify that we can connect two endpoints with single-step authentication. | 314 // Verify that we can connect two endpoints with single-step authentication. |
304 TEST_F(JingleSessionTest, Connect) { | 315 TEST_F(JingleSessionTest, Connect) { |
305 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 316 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
306 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 317 InitiateConnection(1, FakeAuthenticator::ACCEPT, false, false); |
307 | 318 |
308 // Verify that the client specified correct initiator value. | 319 // Verify that the client specified correct initiator value. |
309 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); | 320 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); |
310 const buzz::XmlElement* initiate_xml = | 321 const buzz::XmlElement* initiate_xml = |
311 host_signal_strategy_->received_messages().front(); | 322 host_signal_strategy_->received_messages().front(); |
312 const buzz::XmlElement* jingle_element = | 323 const buzz::XmlElement* jingle_element = |
313 initiate_xml->FirstNamed(buzz::QName(kJingleNamespace, "jingle")); | 324 initiate_xml->FirstNamed(buzz::QName(kJingleNamespace, "jingle")); |
314 ASSERT_TRUE(jingle_element); | 325 ASSERT_TRUE(jingle_element); |
315 ASSERT_EQ(kClientJid, | 326 ASSERT_EQ(kClientJid, |
316 jingle_element->Attr(buzz::QName("", "initiator"))); | 327 jingle_element->Attr(buzz::QName("", "initiator"))); |
317 } | 328 } |
318 | 329 |
319 // Verify that we can connect two endpoints with multi-step authentication. | 330 // Verify that we can connect two endpoints with multi-step authentication. |
320 TEST_F(JingleSessionTest, ConnectWithMultistep) { | 331 TEST_F(JingleSessionTest, ConnectWithMultistep) { |
321 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 332 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
322 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); | 333 InitiateConnection(3, FakeAuthenticator::ACCEPT, false, false); |
323 } | 334 } |
324 | 335 |
325 // Verify that connection is terminated when single-step auth fails. | 336 // Verify that connection is terminated when single-step auth fails. |
326 TEST_F(JingleSessionTest, ConnectWithBadAuth) { | 337 TEST_F(JingleSessionTest, ConnectWithBadAuth) { |
327 CreateSessionManagers(1, FakeAuthenticator::REJECT); | 338 CreateSessionManagers(1, FakeAuthenticator::REJECT); |
328 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 339 InitiateConnection(1, FakeAuthenticator::ACCEPT, true, false); |
329 } | 340 } |
330 | 341 |
331 // Verify that connection is terminated when multi-step auth fails. | 342 // Verify that connection is terminated when multi-step auth fails. |
332 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { | 343 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { |
333 CreateSessionManagers(3, FakeAuthenticator::REJECT); | 344 CreateSessionManagers(3, FakeAuthenticator::REJECT); |
334 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); | 345 InitiateConnection(3, FakeAuthenticator::ACCEPT, true, false); |
335 } | 346 } |
336 | 347 |
337 // Verify that data can be sent over stream channel. | 348 // Verify that data can be sent over stream channel. |
338 TEST_F(JingleSessionTest, TestStreamChannel) { | 349 TEST_F(JingleSessionTest, TestStreamChannel) { |
339 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 350 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
340 ASSERT_NO_FATAL_FAILURE( | 351 ASSERT_NO_FATAL_FAILURE( |
341 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 352 InitiateConnection(1, FakeAuthenticator::ACCEPT, false, true)); |
342 | 353 |
343 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | 354 ASSERT_NO_FATAL_FAILURE(CreateChannel()); |
344 | 355 |
345 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 356 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
346 kMessageSize, kMessages); | 357 kMessageSize, kMessages); |
347 tester.Start(); | 358 tester.Start(); |
348 message_loop_->Run(); | 359 message_loop_->Run(); |
349 tester.CheckResults(); | 360 tester.CheckResults(); |
350 } | 361 } |
351 | 362 |
352 // Verify that we can connect channels with multistep auth. | 363 // Verify that we can connect channels with multistep auth. |
353 TEST_F(JingleSessionTest, TestMultistepAuthStreamChannel) { | 364 TEST_F(JingleSessionTest, TestMultistepAuthStreamChannel) { |
354 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 365 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
355 ASSERT_NO_FATAL_FAILURE( | 366 ASSERT_NO_FATAL_FAILURE( |
356 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | 367 InitiateConnection(3, FakeAuthenticator::ACCEPT, false, true)); |
357 | 368 |
358 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | 369 ASSERT_NO_FATAL_FAILURE(CreateChannel()); |
359 | 370 |
360 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 371 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
361 kMessageSize, kMessages); | 372 kMessageSize, kMessages); |
362 tester.Start(); | 373 tester.Start(); |
363 message_loop_->Run(); | 374 message_loop_->Run(); |
364 tester.CheckResults(); | 375 tester.CheckResults(); |
365 } | 376 } |
366 | 377 |
367 // Verify that we shutdown properly when channel authentication fails. | 378 // Verify that we shutdown properly when channel authentication fails. |
368 TEST_F(JingleSessionTest, TestFailedChannelAuth) { | 379 TEST_F(JingleSessionTest, TestFailedChannelAuth) { |
369 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); | 380 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); |
370 ASSERT_NO_FATAL_FAILURE( | 381 ASSERT_NO_FATAL_FAILURE( |
371 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 382 InitiateConnection(1, FakeAuthenticator::ACCEPT, false, true)); |
372 | 383 |
373 client_session_->CreateStreamChannel(kChannelName, base::Bind( | 384 client_session_->CreateStreamChannel(kChannelName, base::Bind( |
374 &JingleSessionTest::OnClientChannelCreated, base::Unretained(this))); | 385 &JingleSessionTest::OnClientChannelCreated, base::Unretained(this))); |
375 host_session_->CreateStreamChannel(kChannelName, base::Bind( | 386 host_session_->CreateStreamChannel(kChannelName, base::Bind( |
376 &JingleSessionTest::OnHostChannelCreated, base::Unretained(this))); | 387 &JingleSessionTest::OnHostChannelCreated, base::Unretained(this))); |
377 | 388 |
378 // Terminate the message loop when we get rejection notification | 389 // Terminate the message loop when we get rejection notification |
379 // from the host. | 390 // from the host. |
380 EXPECT_CALL(host_channel_callback_, OnDone(NULL)) | 391 EXPECT_CALL(host_channel_callback_, OnDone(NULL)) |
381 .WillOnce(QuitThread()); | 392 .WillOnce(QuitThread()); |
382 EXPECT_CALL(client_channel_callback_, OnDone(_)) | 393 EXPECT_CALL(client_channel_callback_, OnDone(_)) |
383 .Times(AtMost(1)); | 394 .Times(AtMost(1)); |
384 | 395 |
385 message_loop_->Run(); | 396 message_loop_->Run(); |
386 | 397 |
387 EXPECT_TRUE(!host_socket_.get()); | 398 EXPECT_TRUE(!host_socket_.get()); |
388 } | 399 } |
389 | 400 |
390 } // namespace protocol | 401 } // namespace protocol |
391 } // namespace remoting | 402 } // namespace remoting |
OLD | NEW |