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

Side by Side Diff: chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc

Issue 290483003: Tame the proliferation of UserContext constructors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/login/auth/parallel_authenticator.h" 5 #include "chrome/browser/chromeos/login/auth/parallel_authenticator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; 69 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
70 fake_cryptohome_client_ = new FakeCryptohomeClient; 70 fake_cryptohome_client_ = new FakeCryptohomeClient;
71 fake_dbus_thread_manager->SetCryptohomeClient( 71 fake_dbus_thread_manager->SetCryptohomeClient(
72 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); 72 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_));
73 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager); 73 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager);
74 74
75 SystemSaltGetter::Initialize(); 75 SystemSaltGetter::Initialize();
76 76
77 auth_ = new ParallelAuthenticator(&consumer_); 77 auth_ = new ParallelAuthenticator(&consumer_);
78 state_.reset(new TestAttemptState(UserContext(username_, 78 UserContext user_context(username_);
79 password_, 79 user_context.SetPassword(password_);
80 std::string()), 80 state_.reset(new TestAttemptState(user_context, false));
81 "",
82 "",
83 User::USER_TYPE_REGULAR,
84 false));
85 } 81 }
86 82
87 // Tears down the test fixture. 83 // Tears down the test fixture.
88 virtual void TearDown() { 84 virtual void TearDown() {
89 SystemSaltGetter::Shutdown(); 85 SystemSaltGetter::Shutdown();
90 DBusThreadManager::Shutdown(); 86 DBusThreadManager::Shutdown();
91 87
92 cryptohome::AsyncMethodCaller::Shutdown(); 88 cryptohome::AsyncMethodCaller::Shutdown();
93 mock_caller_ = NULL; 89 mock_caller_ = NULL;
94 } 90 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 133 }
138 134
139 void ExpectRetailModeLoginSuccess() { 135 void ExpectRetailModeLoginSuccess() {
140 EXPECT_CALL(consumer_, OnRetailModeLoginSuccess(_)) 136 EXPECT_CALL(consumer_, OnRetailModeLoginSuccess(_))
141 .WillOnce(Invoke(MockConsumer::OnRetailModeSuccessQuit)) 137 .WillOnce(Invoke(MockConsumer::OnRetailModeSuccessQuit))
142 .RetiresOnSaturation(); 138 .RetiresOnSaturation();
143 } 139 }
144 140
145 void ExpectLoginSuccess(const std::string& username, 141 void ExpectLoginSuccess(const std::string& username,
146 const std::string& password, 142 const std::string& password,
147 const std::string& username_hash_, 143 const std::string& username_hash,
148 bool pending) { 144 bool pending) {
149 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext( 145 UserContext user_context(username);
150 username, 146 user_context.SetPassword(password);
151 password, 147 user_context.SetUserIDHash(username_hash);
152 std::string(), 148 EXPECT_CALL(consumer_, OnLoginSuccess(user_context))
153 username_hash_,
154 true, // using_oauth
155 UserContext::AUTH_FLOW_OFFLINE)))
156 .WillOnce(Invoke(MockConsumer::OnSuccessQuit)) 149 .WillOnce(Invoke(MockConsumer::OnSuccessQuit))
157 .RetiresOnSaturation(); 150 .RetiresOnSaturation();
158 } 151 }
159 152
160 void ExpectGuestLoginSuccess() { 153 void ExpectGuestLoginSuccess() {
161 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess()) 154 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess())
162 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit)) 155 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit))
163 .RetiresOnSaturation(); 156 .RetiresOnSaturation();
164 } 157 }
165 158
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 195
203 cryptohome::MockAsyncMethodCaller* mock_caller_; 196 cryptohome::MockAsyncMethodCaller* mock_caller_;
204 197
205 MockConsumer consumer_; 198 MockConsumer consumer_;
206 scoped_refptr<ParallelAuthenticator> auth_; 199 scoped_refptr<ParallelAuthenticator> auth_;
207 scoped_ptr<TestAttemptState> state_; 200 scoped_ptr<TestAttemptState> state_;
208 FakeCryptohomeClient* fake_cryptohome_client_; 201 FakeCryptohomeClient* fake_cryptohome_client_;
209 }; 202 };
210 203
211 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { 204 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) {
212 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext( 205 UserContext user_context(username_);
213 username_, 206 user_context.SetPassword(password_);
214 password_, 207 user_context.SetUserIDHash(username_hash_);
215 std::string(), 208 EXPECT_CALL(consumer_, OnLoginSuccess(user_context))
216 username_hash_,
217 true, // using oauth
218 UserContext::AUTH_FLOW_OFFLINE)))
219 .Times(1) 209 .Times(1)
220 .RetiresOnSaturation(); 210 .RetiresOnSaturation();
221 211
222 SetAttemptState(auth_.get(), state_.release()); 212 SetAttemptState(auth_.get(), state_.release());
223 auth_->OnLoginSuccess(); 213 auth_->OnLoginSuccess();
224 } 214 }
225 215
226 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) { 216 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) {
227 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) 217 EXPECT_CALL(consumer_, OnPasswordChangeDetected())
228 .Times(1) 218 .Times(1)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 262 }
273 263
274 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) { 264 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) {
275 // Set up state as though a cryptohome mount attempt has occurred 265 // Set up state as though a cryptohome mount attempt has occurred
276 // and succeeded but we are in safe mode and the current user is not owner. 266 // and succeeded but we are in safe mode and the current user is not owner.
277 // This test will check that the "safe-mode" policy is not set and will let 267 // This test will check that the "safe-mode" policy is not set and will let
278 // the mount finish successfully. 268 // the mount finish successfully.
279 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 269 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
280 SetOwnerState(false, false); 270 SetOwnerState(false, false);
281 // and test that the mount has succeeded. 271 // and test that the mount has succeeded.
282 state_.reset(new TestAttemptState(UserContext(username_, 272 UserContext user_context(username_);
283 password_, 273 user_context.SetPassword(password_);
284 std::string()), 274 state_.reset(new TestAttemptState(user_context, false));
285 "",
286 "",
287 User::USER_TYPE_REGULAR,
288 false));
289 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 275 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
290 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, 276 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN,
291 SetAndResolveState(auth_.get(), state_.release())); 277 SetAndResolveState(auth_.get(), state_.release()));
292 } 278 }
293 279
294 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { 280 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) {
295 FailOnLoginSuccess(); // Set failing on success as the default... 281 FailOnLoginSuccess(); // Set failing on success as the default...
296 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED); 282 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED);
297 ExpectLoginFailure(failure); 283 ExpectLoginFailure(failure);
298 284
(...skipping 22 matching lines...) Expand all
321 SetAndResolveState(auth_.get(), state_.release())); 307 SetAndResolveState(auth_.get(), state_.release()));
322 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 308 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
323 309
324 // Simulate TPM token ready event. 310 // Simulate TPM token ready event.
325 DeviceSettingsService::Get()->OnTPMTokenReady(); 311 DeviceSettingsService::Get()->OnTPMTokenReady();
326 312
327 // Flush all the pending operations. The operations should induce an owner 313 // Flush all the pending operations. The operations should induce an owner
328 // verification. 314 // verification.
329 device_settings_test_helper_.Flush(); 315 device_settings_test_helper_.Flush();
330 // and test that the mount has succeeded. 316 // and test that the mount has succeeded.
331 state_.reset(new TestAttemptState(UserContext(username_, 317 UserContext user_context(username_);
332 password_, 318 user_context.SetPassword(password_);
333 std::string()), 319 state_.reset(new TestAttemptState(user_context, false));
334 "",
335 "",
336 User::USER_TYPE_REGULAR,
337 false));
338 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 320 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
339 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, 321 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED,
340 SetAndResolveState(auth_.get(), state_.release())); 322 SetAndResolveState(auth_.get(), state_.release()));
341 323
342 // Unset global objects used by this test. 324 // Unset global objects used by this test.
343 LoginState::Shutdown(); 325 LoginState::Shutdown();
344 EXPECT_TRUE( 326 EXPECT_TRUE(
345 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); 327 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
346 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); 328 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
347 } 329 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 ExpectLoginSuccess(username_, std::string(), std::string(), false); 582 ExpectLoginSuccess(username_, std::string(), std::string(), false);
601 FailOnLoginFailure(); 583 FailOnLoginFailure();
602 584
603 // Set up mock async method caller to respond successfully to a cryptohome 585 // Set up mock async method caller to respond successfully to a cryptohome
604 // key-check attempt. 586 // key-check attempt.
605 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 587 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
606 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _)) 588 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _))
607 .Times(1) 589 .Times(1)
608 .RetiresOnSaturation(); 590 .RetiresOnSaturation();
609 591
610 auth_->AuthenticateToUnlock(UserContext(username_, 592 auth_->AuthenticateToUnlock(UserContext(username_));
611 std::string(),
612 std::string()));
613 base::MessageLoop::current()->Run(); 593 base::MessageLoop::current()->Run();
614 } 594 }
615 595
616 } // namespace chromeos 596 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/auth/parallel_authenticator.cc ('k') | chrome/browser/chromeos/login/auth/test_attempt_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698