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/v2_authenticator.h" | 5 #include "remoting/protocol/v2_authenticator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.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/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 host_cert_, *private_key_, host_secret)); | 79 host_cert_, *private_key_, host_secret)); |
80 client_.reset(V2Authenticator::CreateForClient(client_secret)); | 80 client_.reset(V2Authenticator::CreateForClient(client_secret)); |
81 } | 81 } |
82 | 82 |
83 void RunAuthExchange() { | 83 void RunAuthExchange() { |
84 do { | 84 do { |
85 scoped_ptr<buzz::XmlElement> message; | 85 scoped_ptr<buzz::XmlElement> message; |
86 | 86 |
87 // Pass message from client to host. | 87 // Pass message from client to host. |
88 ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state()); | 88 ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state()); |
89 message.reset(client_->GetNextMessage()); | 89 message = client_->GetNextMessage(); |
90 ASSERT_TRUE(message.get()); | 90 ASSERT_TRUE(message.get()); |
91 ASSERT_NE(Authenticator::MESSAGE_READY, client_->state()); | 91 ASSERT_NE(Authenticator::MESSAGE_READY, client_->state()); |
92 | 92 |
93 ASSERT_EQ(Authenticator::WAITING_MESSAGE, host_->state()); | 93 ASSERT_EQ(Authenticator::WAITING_MESSAGE, host_->state()); |
94 host_->ProcessMessage(message.get()); | 94 host_->ProcessMessage(message.get()); |
95 ASSERT_NE(Authenticator::WAITING_MESSAGE, host_->state()); | 95 ASSERT_NE(Authenticator::WAITING_MESSAGE, host_->state()); |
96 | 96 |
97 // Are we done yet? | 97 // Are we done yet? |
98 if (host_->state() == Authenticator::ACCEPTED || | 98 if (host_->state() == Authenticator::ACCEPTED || |
99 host_->state() == Authenticator::REJECTED) { | 99 host_->state() == Authenticator::REJECTED) { |
100 break; | 100 break; |
101 } | 101 } |
102 | 102 |
103 // Pass message from host to client. | 103 // Pass message from host to client. |
104 ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state()); | 104 ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state()); |
105 message.reset(host_->GetNextMessage()); | 105 message = host_->GetNextMessage(); |
106 ASSERT_TRUE(message.get()); | 106 ASSERT_TRUE(message.get()); |
107 ASSERT_NE(Authenticator::MESSAGE_READY, host_->state()); | 107 ASSERT_NE(Authenticator::MESSAGE_READY, host_->state()); |
108 | 108 |
109 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); | 109 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); |
110 client_->ProcessMessage(message.get()); | 110 client_->ProcessMessage(message.get()); |
111 ASSERT_NE(Authenticator::WAITING_MESSAGE, client_->state()); | 111 ASSERT_NE(Authenticator::WAITING_MESSAGE, client_->state()); |
112 } while (client_->state() != Authenticator::ACCEPTED && | 112 } while (client_->state() != Authenticator::ACCEPTED && |
113 client_->state() != Authenticator::REJECTED); | 113 client_->state() != Authenticator::REJECTED); |
114 } | 114 } |
115 | 115 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 }; | 165 }; |
166 | 166 |
167 TEST_F(V2AuthenticatorTest, SuccessfulAuth) { | 167 TEST_F(V2AuthenticatorTest, SuccessfulAuth) { |
168 ASSERT_NO_FATAL_FAILURE( | 168 ASSERT_NO_FATAL_FAILURE( |
169 InitAuthenticators(kTestSharedSecret, kTestSharedSecret)); | 169 InitAuthenticators(kTestSharedSecret, kTestSharedSecret)); |
170 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 170 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
171 | 171 |
172 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); | 172 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); |
173 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); | 173 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); |
174 | 174 |
175 client_auth_.reset(client_->CreateChannelAuthenticator()); | 175 client_auth_ = client_->CreateChannelAuthenticator(); |
176 host_auth_.reset(host_->CreateChannelAuthenticator()); | 176 host_auth_ = host_->CreateChannelAuthenticator(); |
177 RunChannelAuth(false); | 177 RunChannelAuth(false); |
178 | 178 |
179 EXPECT_TRUE(client_socket_.get() != NULL); | 179 EXPECT_TRUE(client_socket_.get() != NULL); |
180 EXPECT_TRUE(host_socket_.get() != NULL); | 180 EXPECT_TRUE(host_socket_.get() != NULL); |
181 | 181 |
182 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 182 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
183 kMessageSize, kMessages); | 183 kMessageSize, kMessages); |
184 | 184 |
185 tester.Start(); | 185 tester.Start(); |
186 message_loop_.Run(); | 186 message_loop_.Run(); |
(...skipping 14 matching lines...) Expand all Loading... |
201 scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage()); | 201 scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage()); |
202 ASSERT_TRUE(message.get()); | 202 ASSERT_TRUE(message.get()); |
203 | 203 |
204 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); | 204 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); |
205 host_->ProcessMessage(message.get()); | 205 host_->ProcessMessage(message.get()); |
206 ASSERT_EQ(Authenticator::REJECTED, host_->state()); | 206 ASSERT_EQ(Authenticator::REJECTED, host_->state()); |
207 } | 207 } |
208 | 208 |
209 } // namespace protocol | 209 } // namespace protocol |
210 } // namespace remoting | 210 } // namespace remoting |
OLD | NEW |