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