| 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/authenticator_test_base.h" | 5 #include "remoting/protocol/authenticator_test_base.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 ASSERT_TRUE(file_util::ReadFileToString(key_path, &key_string)); | 53 ASSERT_TRUE(file_util::ReadFileToString(key_path, &key_string)); |
| 54 std::vector<uint8> key_vector( | 54 std::vector<uint8> key_vector( |
| 55 reinterpret_cast<const uint8*>(key_string.data()), | 55 reinterpret_cast<const uint8*>(key_string.data()), |
| 56 reinterpret_cast<const uint8*>(key_string.data() + | 56 reinterpret_cast<const uint8*>(key_string.data() + |
| 57 key_string.length())); | 57 key_string.length())); |
| 58 private_key_.reset( | 58 private_key_.reset( |
| 59 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vector)); | 59 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vector)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void AuthenticatorTestBase::RunAuthExchange() { | 62 void AuthenticatorTestBase::RunAuthExchange() { |
| 63 do { | 63 ContinueAuthExchangeWith(client_.get(), host_.get()); |
| 64 scoped_ptr<buzz::XmlElement> message; | 64 } |
| 65 | 65 |
| 66 // Pass message from client to host. | 66 // static |
| 67 ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state()); | 67 void AuthenticatorTestBase::ContinueAuthExchangeWith(Authenticator* sender, |
| 68 message = client_->GetNextMessage(); | 68 Authenticator* receiver) { |
| 69 ASSERT_TRUE(message.get()); | 69 scoped_ptr<buzz::XmlElement> message; |
| 70 ASSERT_NE(Authenticator::MESSAGE_READY, client_->state()); | 70 ASSERT_NE(Authenticator::WAITING_MESSAGE, sender->state()); |
| 71 if (sender->state() == Authenticator::ACCEPTED || |
| 72 sender->state() == Authenticator::REJECTED) |
| 73 return; |
| 74 // Pass message from client to host. |
| 75 ASSERT_EQ(Authenticator::MESSAGE_READY, sender->state()); |
| 76 message = sender->GetNextMessage(); |
| 77 ASSERT_TRUE(message.get()); |
| 78 ASSERT_NE(Authenticator::MESSAGE_READY, sender->state()); |
| 71 | 79 |
| 72 ASSERT_EQ(Authenticator::WAITING_MESSAGE, host_->state()); | 80 ASSERT_EQ(Authenticator::WAITING_MESSAGE, receiver->state()); |
| 73 host_->ProcessMessage(message.get()); | 81 receiver->ProcessMessage(message.get(), base::Bind( |
| 74 ASSERT_NE(Authenticator::WAITING_MESSAGE, host_->state()); | 82 &AuthenticatorTestBase::ContinueAuthExchangeWith, |
| 75 | 83 base::Unretained(receiver), base::Unretained(sender))); |
| 76 // Are we done yet? | |
| 77 if (host_->state() == Authenticator::ACCEPTED || | |
| 78 host_->state() == Authenticator::REJECTED) { | |
| 79 break; | |
| 80 } | |
| 81 | |
| 82 // Pass message from host to client. | |
| 83 ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state()); | |
| 84 message = host_->GetNextMessage(); | |
| 85 ASSERT_TRUE(message.get()); | |
| 86 ASSERT_NE(Authenticator::MESSAGE_READY, host_->state()); | |
| 87 | |
| 88 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); | |
| 89 client_->ProcessMessage(message.get()); | |
| 90 ASSERT_NE(Authenticator::WAITING_MESSAGE, client_->state()); | |
| 91 } while (client_->state() != Authenticator::ACCEPTED && | |
| 92 client_->state() != Authenticator::REJECTED); | |
| 93 } | 84 } |
| 94 | 85 |
| 95 void AuthenticatorTestBase::RunChannelAuth(bool expected_fail) { | 86 void AuthenticatorTestBase::RunChannelAuth(bool expected_fail) { |
| 96 client_fake_socket_.reset(new FakeSocket()); | 87 client_fake_socket_.reset(new FakeSocket()); |
| 97 host_fake_socket_.reset(new FakeSocket()); | 88 host_fake_socket_.reset(new FakeSocket()); |
| 98 client_fake_socket_->PairWith(host_fake_socket_.get()); | 89 client_fake_socket_->PairWith(host_fake_socket_.get()); |
| 99 | 90 |
| 100 client_auth_->SecureAndAuthenticate( | 91 client_auth_->SecureAndAuthenticate( |
| 101 client_fake_socket_.PassAs<net::StreamSocket>(), | 92 client_fake_socket_.PassAs<net::StreamSocket>(), |
| 102 base::Bind(&AuthenticatorTestBase::OnClientConnected, | 93 base::Bind(&AuthenticatorTestBase::OnClientConnected, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 138 |
| 148 void AuthenticatorTestBase::OnClientConnected( | 139 void AuthenticatorTestBase::OnClientConnected( |
| 149 net::Error error, | 140 net::Error error, |
| 150 scoped_ptr<net::StreamSocket> socket) { | 141 scoped_ptr<net::StreamSocket> socket) { |
| 151 client_callback_.OnDone(error); | 142 client_callback_.OnDone(error); |
| 152 client_socket_ = socket.Pass(); | 143 client_socket_ = socket.Pass(); |
| 153 } | 144 } |
| 154 | 145 |
| 155 } // namespace protocol | 146 } // namespace protocol |
| 156 } // namespace remoting | 147 } // namespace remoting |
| OLD | NEW |