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

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

Issue 21128006: Refactored PairingRegistry::Delegate such that it can retrieve/modify for a single client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "net/base/net_errors.h" 6 #include "net/base/net_errors.h"
7 #include "remoting/base/rsa_key_pair.h" 7 #include "remoting/base/rsa_key_pair.h"
8 #include "remoting/protocol/authenticator_test_base.h" 8 #include "remoting/protocol/authenticator_test_base.h"
9 #include "remoting/protocol/channel_authenticator.h" 9 #include "remoting/protocol/channel_authenticator.h"
10 #include "remoting/protocol/connection_tester.h" 10 #include "remoting/protocol/connection_tester.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 85
86 void CreatePairingRegistry(bool with_paired_client) { 86 void CreatePairingRegistry(bool with_paired_client) {
87 mock_delegate_ = new MockPairingRegistryDelegate; 87 mock_delegate_ = new MockPairingRegistryDelegate;
88 pairing_registry_ = new PairingRegistry( 88 pairing_registry_ = new PairingRegistry(
89 scoped_ptr<PairingRegistry::Delegate>(mock_delegate_)); 89 scoped_ptr<PairingRegistry::Delegate>(mock_delegate_));
90 if (with_paired_client) { 90 if (with_paired_client) {
91 PairingRegistry::Pairing pairing( 91 PairingRegistry::Pairing pairing(
92 base::Time(), kTestClientName, kTestClientId, kTestPairedSecret); 92 base::Time(), kTestClientName, kTestClientId, kTestPairedSecret);
93 pairing_registry_->AddPairing(pairing); 93 pairing_registry_->AddPairing(pairing);
94 mock_delegate_->RunCallback(); 94 mock_delegate_->DrainCallbacks();
95 } 95 }
96 } 96 }
97 97
98 static void FetchSecret( 98 static void FetchSecret(
99 const std::string& client_secret, 99 const std::string& client_secret,
100 bool pairing_supported, 100 bool pairing_supported,
101 bool pairing_expected, 101 bool pairing_expected,
102 const protocol::SecretFetchedCallback& secret_fetched_callback) { 102 const protocol::SecretFetchedCallback& secret_fetched_callback) {
103 secret_fetched_callback.Run(client_secret); 103 secret_fetched_callback.Run(client_secret);
104 ASSERT_EQ(pairing_supported, pairing_expected); 104 ASSERT_EQ(pairing_supported, pairing_expected);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 210 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
211 VerifyAccepted(AuthenticationMethod::Spake2Pair()); 211 VerifyAccepted(AuthenticationMethod::Spake2Pair());
212 } 212 }
213 213
214 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinOkay) { 214 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinOkay) {
215 CreatePairingRegistry(false); 215 CreatePairingRegistry(false);
216 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 216 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
217 kTestClientId, kTestPairedSecret, kTestPin, kTestPin, 217 kTestClientId, kTestPairedSecret, kTestPin, kTestPin,
218 AuthenticationMethod::HMAC_SHA256, false)); 218 AuthenticationMethod::HMAC_SHA256, false));
219 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 219 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
220 mock_delegate_->RunCallback(); 220 mock_delegate_->DrainCallbacks();
221 VerifyAccepted(AuthenticationMethod::Spake2Pair()); 221 VerifyAccepted(AuthenticationMethod::Spake2Pair());
222 } 222 }
223 223
224 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinBad) { 224 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinBad) {
225 CreatePairingRegistry(false); 225 CreatePairingRegistry(false);
226 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 226 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
227 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin, 227 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin,
228 AuthenticationMethod::HMAC_SHA256, false)); 228 AuthenticationMethod::HMAC_SHA256, false));
229 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 229 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
230 mock_delegate_->RunCallback(); 230 mock_delegate_->DrainCallbacks();
231 VerifyRejected(Authenticator::INVALID_CREDENTIALS); 231 VerifyRejected(Authenticator::INVALID_CREDENTIALS);
232 } 232 }
233 233
234 TEST_F(NegotiatingAuthenticatorTest, PairingSucceeded) { 234 TEST_F(NegotiatingAuthenticatorTest, PairingSucceeded) {
235 CreatePairingRegistry(true); 235 CreatePairingRegistry(true);
236 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 236 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
237 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin, 237 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin,
238 AuthenticationMethod::HMAC_SHA256, false)); 238 AuthenticationMethod::HMAC_SHA256, false));
239 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 239 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
240 mock_delegate_->RunCallback(); 240 mock_delegate_->DrainCallbacks();
241 VerifyAccepted(AuthenticationMethod::Spake2Pair()); 241 VerifyAccepted(AuthenticationMethod::Spake2Pair());
242 } 242 }
243 243
244 TEST_F(NegotiatingAuthenticatorTest, PairingSucceededInvalidSecretButPinOkay) { 244 TEST_F(NegotiatingAuthenticatorTest, PairingSucceededInvalidSecretButPinOkay) {
245 CreatePairingRegistry(true); 245 CreatePairingRegistry(true);
246 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 246 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
247 kTestClientId, kTestPairedSecretBad, kTestPin, kTestPin, 247 kTestClientId, kTestPairedSecretBad, kTestPin, kTestPin,
248 AuthenticationMethod::HMAC_SHA256, false)); 248 AuthenticationMethod::HMAC_SHA256, false));
249 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 249 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
250 mock_delegate_->RunCallback(); 250 mock_delegate_->DrainCallbacks();
251 VerifyAccepted(AuthenticationMethod::Spake2Pair()); 251 VerifyAccepted(AuthenticationMethod::Spake2Pair());
252 } 252 }
253 253
254 TEST_F(NegotiatingAuthenticatorTest, PairingFailedInvalidSecretAndPin) { 254 TEST_F(NegotiatingAuthenticatorTest, PairingFailedInvalidSecretAndPin) {
255 CreatePairingRegistry(true); 255 CreatePairingRegistry(true);
256 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 256 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
257 kTestClientId, kTestPairedSecretBad, kTestPinBad, kTestPin, 257 kTestClientId, kTestPairedSecretBad, kTestPinBad, kTestPin,
258 AuthenticationMethod::HMAC_SHA256, false)); 258 AuthenticationMethod::HMAC_SHA256, false));
259 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 259 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
260 mock_delegate_->RunCallback(); 260 mock_delegate_->DrainCallbacks();
261 VerifyRejected(Authenticator::INVALID_CREDENTIALS); 261 VerifyRejected(Authenticator::INVALID_CREDENTIALS);
262 } 262 }
263 263
264 } // namespace protocol 264 } // namespace protocol
265 } // namespace remoting 265 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698