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 "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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 client_interactive_pin, | 77 client_interactive_pin, |
78 pairing_expected); | 78 pairing_expected); |
79 client_as_negotiating_authenticator_ = new NegotiatingClientAuthenticator( | 79 client_as_negotiating_authenticator_ = new NegotiatingClientAuthenticator( |
80 client_id, client_paired_secret, | 80 client_id, client_paired_secret, |
81 kTestHostId, fetch_secret_callback, | 81 kTestHostId, fetch_secret_callback, |
82 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher>(), methods); | 82 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher>(), methods); |
83 client_.reset(client_as_negotiating_authenticator_); | 83 client_.reset(client_as_negotiating_authenticator_); |
84 } | 84 } |
85 | 85 |
86 void CreatePairingRegistry(bool with_paired_client) { | 86 void CreatePairingRegistry(bool with_paired_client) { |
87 mock_delegate_ = new MockPairingRegistryDelegate; | 87 pairing_registry_ = new SynchronousPairingRegistry( |
88 pairing_registry_ = new PairingRegistry( | 88 scoped_ptr<PairingRegistry::Delegate>( |
89 scoped_ptr<PairingRegistry::Delegate>(mock_delegate_)); | 89 new MockPairingRegistryDelegate())); |
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(); | |
95 } | 94 } |
96 } | 95 } |
97 | 96 |
98 static void FetchSecret( | 97 static void FetchSecret( |
99 const std::string& client_secret, | 98 const std::string& client_secret, |
100 bool pairing_supported, | 99 bool pairing_supported, |
101 bool pairing_expected, | 100 bool pairing_expected, |
102 const protocol::SecretFetchedCallback& secret_fetched_callback) { | 101 const protocol::SecretFetchedCallback& secret_fetched_callback) { |
103 secret_fetched_callback.Run(client_secret); | 102 secret_fetched_callback.Run(client_secret); |
104 ASSERT_EQ(pairing_supported, pairing_expected); | 103 ASSERT_EQ(pairing_supported, pairing_expected); |
(...skipping 30 matching lines...) Expand all Loading... |
135 message_loop_.Run(); | 134 message_loop_.Run(); |
136 tester.CheckResults(); | 135 tester.CheckResults(); |
137 EXPECT_EQ( | 136 EXPECT_EQ( |
138 expected_method, | 137 expected_method, |
139 client_as_negotiating_authenticator_->current_method_for_testing()); | 138 client_as_negotiating_authenticator_->current_method_for_testing()); |
140 } | 139 } |
141 | 140 |
142 // Use a bare pointer because the storage is managed by the base class. | 141 // Use a bare pointer because the storage is managed by the base class. |
143 NegotiatingClientAuthenticator* client_as_negotiating_authenticator_; | 142 NegotiatingClientAuthenticator* client_as_negotiating_authenticator_; |
144 | 143 |
145 protected: | |
146 MockPairingRegistryDelegate* mock_delegate_; | |
147 | |
148 private: | 144 private: |
149 scoped_refptr<PairingRegistry> pairing_registry_; | 145 scoped_refptr<PairingRegistry> pairing_registry_; |
150 | 146 |
151 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); | 147 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); |
152 }; | 148 }; |
153 | 149 |
154 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) { | 150 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) { |
155 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 151 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
156 kNoClientId, kNoPairedSecret, kTestPin, kTestPin, | 152 kNoClientId, kNoPairedSecret, kTestPin, kTestPin, |
157 AuthenticationMethod::HMAC_SHA256, false)); | 153 AuthenticationMethod::HMAC_SHA256, false)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 206 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
211 VerifyAccepted(AuthenticationMethod::Spake2Pair()); | 207 VerifyAccepted(AuthenticationMethod::Spake2Pair()); |
212 } | 208 } |
213 | 209 |
214 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinOkay) { | 210 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinOkay) { |
215 CreatePairingRegistry(false); | 211 CreatePairingRegistry(false); |
216 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 212 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
217 kTestClientId, kTestPairedSecret, kTestPin, kTestPin, | 213 kTestClientId, kTestPairedSecret, kTestPin, kTestPin, |
218 AuthenticationMethod::HMAC_SHA256, false)); | 214 AuthenticationMethod::HMAC_SHA256, false)); |
219 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 215 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
220 mock_delegate_->RunCallback(); | |
221 VerifyAccepted(AuthenticationMethod::Spake2Pair()); | 216 VerifyAccepted(AuthenticationMethod::Spake2Pair()); |
222 } | 217 } |
223 | 218 |
224 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinBad) { | 219 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinBad) { |
225 CreatePairingRegistry(false); | 220 CreatePairingRegistry(false); |
226 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 221 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
227 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin, | 222 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin, |
228 AuthenticationMethod::HMAC_SHA256, false)); | 223 AuthenticationMethod::HMAC_SHA256, false)); |
229 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 224 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
230 mock_delegate_->RunCallback(); | |
231 VerifyRejected(Authenticator::INVALID_CREDENTIALS); | 225 VerifyRejected(Authenticator::INVALID_CREDENTIALS); |
232 } | 226 } |
233 | 227 |
234 TEST_F(NegotiatingAuthenticatorTest, PairingSucceeded) { | 228 TEST_F(NegotiatingAuthenticatorTest, PairingSucceeded) { |
235 CreatePairingRegistry(true); | 229 CreatePairingRegistry(true); |
236 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 230 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
237 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin, | 231 kTestClientId, kTestPairedSecret, kTestPinBad, kTestPin, |
238 AuthenticationMethod::HMAC_SHA256, false)); | 232 AuthenticationMethod::HMAC_SHA256, false)); |
239 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 233 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
240 mock_delegate_->RunCallback(); | |
241 VerifyAccepted(AuthenticationMethod::Spake2Pair()); | 234 VerifyAccepted(AuthenticationMethod::Spake2Pair()); |
242 } | 235 } |
243 | 236 |
244 TEST_F(NegotiatingAuthenticatorTest, PairingSucceededInvalidSecretButPinOkay) { | 237 TEST_F(NegotiatingAuthenticatorTest, PairingSucceededInvalidSecretButPinOkay) { |
245 CreatePairingRegistry(true); | 238 CreatePairingRegistry(true); |
246 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 239 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
247 kTestClientId, kTestPairedSecretBad, kTestPin, kTestPin, | 240 kTestClientId, kTestPairedSecretBad, kTestPin, kTestPin, |
248 AuthenticationMethod::HMAC_SHA256, false)); | 241 AuthenticationMethod::HMAC_SHA256, false)); |
249 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 242 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
250 mock_delegate_->RunCallback(); | |
251 VerifyAccepted(AuthenticationMethod::Spake2Pair()); | 243 VerifyAccepted(AuthenticationMethod::Spake2Pair()); |
252 } | 244 } |
253 | 245 |
254 TEST_F(NegotiatingAuthenticatorTest, PairingFailedInvalidSecretAndPin) { | 246 TEST_F(NegotiatingAuthenticatorTest, PairingFailedInvalidSecretAndPin) { |
255 CreatePairingRegistry(true); | 247 CreatePairingRegistry(true); |
256 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 248 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
257 kTestClientId, kTestPairedSecretBad, kTestPinBad, kTestPin, | 249 kTestClientId, kTestPairedSecretBad, kTestPinBad, kTestPin, |
258 AuthenticationMethod::HMAC_SHA256, false)); | 250 AuthenticationMethod::HMAC_SHA256, false)); |
259 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 251 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
260 mock_delegate_->RunCallback(); | |
261 VerifyRejected(Authenticator::INVALID_CREDENTIALS); | 252 VerifyRejected(Authenticator::INVALID_CREDENTIALS); |
262 } | 253 } |
263 | 254 |
264 } // namespace protocol | 255 } // namespace protocol |
265 } // namespace remoting | 256 } // namespace remoting |
OLD | NEW |