Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: remoting/protocol/v1_authenticator_unittest.cc

Issue 9240033: Use scoped_ptr<>.Pass() to pass ownership in the remoting protocol code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/v1_authenticator.h" 5 #include "remoting/protocol/v1_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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 host_cert_, *private_key_, host_secret, kClientJid)); 80 host_cert_, *private_key_, host_secret, kClientJid));
81 client_.reset(new V1ClientAuthenticator(kClientJid, client_secret)); 81 client_.reset(new V1ClientAuthenticator(kClientJid, client_secret));
82 } 82 }
83 83
84 void RunAuthExchange() { 84 void RunAuthExchange() {
85 do { 85 do {
86 scoped_ptr<buzz::XmlElement> message; 86 scoped_ptr<buzz::XmlElement> message;
87 87
88 // Pass message from client to host. 88 // Pass message from client to host.
89 ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state()); 89 ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state());
90 message.reset(client_->GetNextMessage()); 90 message = client_->GetNextMessage();
91 ASSERT_TRUE(message.get()); 91 ASSERT_TRUE(message.get());
92 ASSERT_NE(Authenticator::MESSAGE_READY, client_->state()); 92 ASSERT_NE(Authenticator::MESSAGE_READY, client_->state());
93 93
94 ASSERT_EQ(Authenticator::WAITING_MESSAGE, host_->state()); 94 ASSERT_EQ(Authenticator::WAITING_MESSAGE, host_->state());
95 host_->ProcessMessage(message.get()); 95 host_->ProcessMessage(message.get());
96 ASSERT_NE(Authenticator::WAITING_MESSAGE, host_->state()); 96 ASSERT_NE(Authenticator::WAITING_MESSAGE, host_->state());
97 97
98 // Are we done yet? 98 // Are we done yet?
99 if (host_->state() == Authenticator::ACCEPTED || 99 if (host_->state() == Authenticator::ACCEPTED ||
100 host_->state() == Authenticator::REJECTED) { 100 host_->state() == Authenticator::REJECTED) {
101 break; 101 break;
102 } 102 }
103 103
104 // Pass message from host to client. 104 // Pass message from host to client.
105 ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state()); 105 ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state());
106 message.reset(host_->GetNextMessage()); 106 message = host_->GetNextMessage();
107 ASSERT_TRUE(message.get()); 107 ASSERT_TRUE(message.get());
108 ASSERT_NE(Authenticator::MESSAGE_READY, host_->state()); 108 ASSERT_NE(Authenticator::MESSAGE_READY, host_->state());
109 109
110 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); 110 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state());
111 client_->ProcessMessage(message.get()); 111 client_->ProcessMessage(message.get());
112 ASSERT_NE(Authenticator::WAITING_MESSAGE, client_->state()); 112 ASSERT_NE(Authenticator::WAITING_MESSAGE, client_->state());
113 } while (host_->state() != Authenticator::ACCEPTED && 113 } while (host_->state() != Authenticator::ACCEPTED &&
114 host_->state() != Authenticator::REJECTED); 114 host_->state() != Authenticator::REJECTED);
115 } 115 }
116 116
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 TEST_F(V1AuthenticatorTest, SuccessfulAuth) { 171 TEST_F(V1AuthenticatorTest, SuccessfulAuth) {
172 { 172 {
173 SCOPED_TRACE("RunAuthExchange"); 173 SCOPED_TRACE("RunAuthExchange");
174 InitAuthenticators(kTestSharedSecret, kTestSharedSecret); 174 InitAuthenticators(kTestSharedSecret, kTestSharedSecret);
175 RunAuthExchange(); 175 RunAuthExchange();
176 } 176 }
177 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); 177 ASSERT_EQ(Authenticator::ACCEPTED, host_->state());
178 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); 178 ASSERT_EQ(Authenticator::ACCEPTED, client_->state());
179 179
180 client_auth_.reset(client_->CreateChannelAuthenticator()); 180 client_auth_ = client_->CreateChannelAuthenticator();
181 host_auth_.reset(host_->CreateChannelAuthenticator()); 181 host_auth_ = host_->CreateChannelAuthenticator();
182 RunChannelAuth(false); 182 RunChannelAuth(false);
183 183
184 EXPECT_TRUE(client_socket_.get() != NULL); 184 EXPECT_TRUE(client_socket_.get() != NULL);
185 EXPECT_TRUE(host_socket_.get() != NULL); 185 EXPECT_TRUE(host_socket_.get() != NULL);
186 186
187 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 187 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
188 kMessageSize, kMessages); 188 kMessageSize, kMessages);
189 189
190 tester.Start(); 190 tester.Start();
191 message_loop_.Run(); 191 message_loop_.Run();
192 tester.CheckResults(); 192 tester.CheckResults();
193 } 193 }
194 194
195 // Verify that connection is rejected when secrets don't match. 195 // Verify that connection is rejected when secrets don't match.
196 TEST_F(V1AuthenticatorTest, InvalidSecret) { 196 TEST_F(V1AuthenticatorTest, InvalidSecret) {
197 { 197 {
198 SCOPED_TRACE("RunAuthExchange"); 198 SCOPED_TRACE("RunAuthExchange");
199 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret); 199 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret);
200 RunAuthExchange(); 200 RunAuthExchange();
201 } 201 }
202 ASSERT_EQ(Authenticator::REJECTED, host_->state()); 202 ASSERT_EQ(Authenticator::REJECTED, host_->state());
203 } 203 }
204 204
205 } // namespace protocol 205 } // namespace protocol
206 } // namespace remoting 206 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698