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_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 std::string key_string; | 53 std::string key_string; |
54 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); | 54 ASSERT_TRUE(base::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_ = RsaKeyPair::FromString(key_base64); | 57 key_pair_ = RsaKeyPair::FromString(key_base64); |
58 ASSERT_TRUE(key_pair_.get()); | 58 ASSERT_TRUE(key_pair_.get()); |
59 host_public_key_ = key_pair_->GetPublicKey(); | 59 host_public_key_ = key_pair_->GetPublicKey(); |
60 } | 60 } |
61 | 61 |
62 void AuthenticatorTestBase::RunAuthExchange() { | 62 void AuthenticatorTestBase::RunAuthExchange() { |
63 ContinueAuthExchangeWith(client_.get(), host_.get()); | 63 ContinueAuthExchangeWith(client_.get(), |
| 64 host_.get(), |
| 65 client_->started(), |
| 66 host_->started()); |
64 } | 67 } |
65 | 68 |
66 void AuthenticatorTestBase::RunHostInitiatedAuthExchange() { | 69 void AuthenticatorTestBase::RunHostInitiatedAuthExchange() { |
67 ContinueAuthExchangeWith(host_.get(), client_.get()); | 70 ContinueAuthExchangeWith(host_.get(), |
| 71 client_.get(), |
| 72 host_->started(), |
| 73 client_->started()); |
68 } | 74 } |
69 | 75 |
70 // static | 76 // static |
| 77 // This function sends a message from the sender and receiver and recursively |
| 78 // calls itself to the send the next message from the receiver to the sender |
| 79 // untils the authentication completes. |
71 void AuthenticatorTestBase::ContinueAuthExchangeWith(Authenticator* sender, | 80 void AuthenticatorTestBase::ContinueAuthExchangeWith(Authenticator* sender, |
72 Authenticator* receiver) { | 81 Authenticator* receiver, |
| 82 bool sender_started, |
| 83 bool receiver_started) { |
73 scoped_ptr<buzz::XmlElement> message; | 84 scoped_ptr<buzz::XmlElement> message; |
74 ASSERT_NE(Authenticator::WAITING_MESSAGE, sender->state()); | 85 ASSERT_NE(Authenticator::WAITING_MESSAGE, sender->state()); |
75 if (sender->state() == Authenticator::ACCEPTED || | 86 if (sender->state() == Authenticator::ACCEPTED || |
76 sender->state() == Authenticator::REJECTED) | 87 sender->state() == Authenticator::REJECTED) |
77 return; | 88 return; |
78 // Pass message from client to host. | 89 |
| 90 // Verify that once the started flag for either party is set to true, |
| 91 // it should always stay true. |
| 92 if (receiver_started) { |
| 93 ASSERT_TRUE(receiver->started()); |
| 94 } |
| 95 |
| 96 if (sender_started) { |
| 97 ASSERT_TRUE(sender->started()); |
| 98 } |
| 99 |
79 ASSERT_EQ(Authenticator::MESSAGE_READY, sender->state()); | 100 ASSERT_EQ(Authenticator::MESSAGE_READY, sender->state()); |
80 message = sender->GetNextMessage(); | 101 message = sender->GetNextMessage(); |
81 ASSERT_TRUE(message.get()); | 102 ASSERT_TRUE(message.get()); |
82 ASSERT_NE(Authenticator::MESSAGE_READY, sender->state()); | 103 ASSERT_NE(Authenticator::MESSAGE_READY, sender->state()); |
83 | 104 |
84 ASSERT_EQ(Authenticator::WAITING_MESSAGE, receiver->state()); | 105 ASSERT_EQ(Authenticator::WAITING_MESSAGE, receiver->state()); |
85 receiver->ProcessMessage(message.get(), base::Bind( | 106 receiver->ProcessMessage(message.get(), base::Bind( |
86 &AuthenticatorTestBase::ContinueAuthExchangeWith, | 107 &AuthenticatorTestBase::ContinueAuthExchangeWith, |
87 base::Unretained(receiver), base::Unretained(sender))); | 108 base::Unretained(receiver), base::Unretained(sender), |
| 109 receiver->started(), sender->started())); |
88 } | 110 } |
89 | 111 |
90 void AuthenticatorTestBase::RunChannelAuth(bool expected_fail) { | 112 void AuthenticatorTestBase::RunChannelAuth(bool expected_fail) { |
91 client_fake_socket_.reset(new FakeSocket()); | 113 client_fake_socket_.reset(new FakeSocket()); |
92 host_fake_socket_.reset(new FakeSocket()); | 114 host_fake_socket_.reset(new FakeSocket()); |
93 client_fake_socket_->PairWith(host_fake_socket_.get()); | 115 client_fake_socket_->PairWith(host_fake_socket_.get()); |
94 | 116 |
95 client_auth_->SecureAndAuthenticate( | 117 client_auth_->SecureAndAuthenticate( |
96 client_fake_socket_.PassAs<net::StreamSocket>(), | 118 client_fake_socket_.PassAs<net::StreamSocket>(), |
97 base::Bind(&AuthenticatorTestBase::OnClientConnected, | 119 base::Bind(&AuthenticatorTestBase::OnClientConnected, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 165 |
144 void AuthenticatorTestBase::OnClientConnected( | 166 void AuthenticatorTestBase::OnClientConnected( |
145 net::Error error, | 167 net::Error error, |
146 scoped_ptr<net::StreamSocket> socket) { | 168 scoped_ptr<net::StreamSocket> socket) { |
147 client_callback_.OnDone(error); | 169 client_callback_.OnDone(error); |
148 client_socket_ = socket.Pass(); | 170 client_socket_ = socket.Pass(); |
149 } | 171 } |
150 | 172 |
151 } // namespace protocol | 173 } // namespace protocol |
152 } // namespace remoting | 174 } // namespace remoting |
OLD | NEW |