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

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

Issue 398363002: Cleanup safe mode tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor corrections. Created 6 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 #include "chromeos/chromeos_switches.h" 31 #include "chromeos/chromeos_switches.h"
32 #include "chromeos/cryptohome/mock_async_method_caller.h" 32 #include "chromeos/cryptohome/mock_async_method_caller.h"
33 #include "chromeos/cryptohome/system_salt_getter.h" 33 #include "chromeos/cryptohome/system_salt_getter.h"
34 #include "chromeos/dbus/fake_cryptohome_client.h" 34 #include "chromeos/dbus/fake_cryptohome_client.h"
35 #include "chromeos/dbus/fake_dbus_thread_manager.h" 35 #include "chromeos/dbus/fake_dbus_thread_manager.h"
36 #include "chromeos/login/auth/key.h" 36 #include "chromeos/login/auth/key.h"
37 #include "chromeos/login/auth/mock_auth_status_consumer.h" 37 #include "chromeos/login/auth/mock_auth_status_consumer.h"
38 #include "chromeos/login/auth/user_context.h" 38 #include "chromeos/login/auth/user_context.h"
39 #include "content/public/test/test_browser_thread_bundle.h" 39 #include "content/public/test/test_browser_thread_bundle.h"
40 #include "crypto/nss_util.h" 40 #include "crypto/nss_util.h"
41 #include "crypto/nss_util_internal.h"
41 #include "google_apis/gaia/mock_url_fetcher_factory.h" 42 #include "google_apis/gaia/mock_url_fetcher_factory.h"
42 #include "net/base/net_errors.h" 43 #include "net/base/net_errors.h"
43 #include "net/url_request/url_request_status.h" 44 #include "net/url_request/url_request_status.h"
44 #include "testing/gmock/include/gmock/gmock.h" 45 #include "testing/gmock/include/gmock/gmock.h"
45 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
46 #include "third_party/cros_system_api/dbus/service_constants.h" 47 #include "third_party/cros_system_api/dbus/service_constants.h"
47 #include "url/gurl.h" 48 #include "url/gurl.h"
48 49
49 using ::testing::Invoke; 50 using ::testing::Invoke;
50 using ::testing::Return; 51 using ::testing::Return;
51 using ::testing::_; 52 using ::testing::_;
52 53
53 namespace chromeos { 54 namespace chromeos {
54 55
56 namespace {
57
58 // An owner key in PKCS#8 PrivateKeyInfo for testing owner checks.
59 const uint8 kOwnerPrivateKey[] = {
60 0x30, 0x82, 0x01, 0x53, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
61 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
62 0x01, 0x3d, 0x30, 0x82, 0x01, 0x39, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00,
63 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e, 0xdf,
64 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4, 0xf3,
65 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f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x09, 0x1c, 0xc1, 0x1c, 0xf2, 0x33, 0x9c, 0x1a,
81 0x72, 0xcc, 0xd4, 0xf3, 0x97, 0xc6, 0x44, 0x55, 0xf2, 0xe0, 0x94, 0x9c,
82 0x97, 0x75, 0x64, 0x34, 0x52, 0x4b, 0xc1, 0x53, 0xdd, 0x8f, 0x21, 0x02,
83 0x20, 0x0e, 0xef, 0x48, 0x92, 0x2d, 0x9c, 0xe8, 0xd3, 0x7e, 0x1e, 0x55,
84 0x0f, 0x23, 0x74, 0x76, 0x07, 0xec, 0x2c, 0x9e, 0xe4, 0x0e, 0xc0, 0x72,
85 0xeb, 0x70, 0xcb, 0x74, 0xef, 0xcc, 0x26, 0x50, 0xff, 0x02, 0x20, 0x29,
86 0x32, 0xd0, 0xbf, 0x11, 0xf2, 0xbf, 0x54, 0xfd, 0x6d, 0xf2, 0x1c, 0xbe,
87 0x50, 0x18, 0x62, 0x6d, 0x23, 0xe4, 0x26, 0x03, 0x8b, 0xb3, 0x42, 0x24,
88 0x7e, 0x68, 0x37, 0x26, 0xda, 0xb9, 0x87
89 };
90
91 // The public key alone matcing kOwnerPrivateKey.
92 const uint8 kOwnerPublicKey[] = {
93 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
94 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41,
95 0x00, 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e,
96 0xdf, 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4,
97 0xf3, 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc,
98 0xbb, 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0,
99 0x15, 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9,
100 0x3d, 0x3e, 0x2a, 0x68, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01
101 };
102
103 std::vector<uint8> GetOwnerPublicKey() {
104 return std::vector<uint8>(kOwnerPublicKey,
105 kOwnerPublicKey + arraysize(kOwnerPublicKey));
106 }
107
108 scoped_ptr<crypto::RSAPrivateKey> CreateOwnerKeyInSlot(PK11SlotInfo* slot) {
109 const std::vector<uint8> key(kOwnerPrivateKey,
110 kOwnerPrivateKey + arraysize(kOwnerPrivateKey));
111 return make_scoped_ptr(
112 crypto::RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo(slot, key));
113 }
114
115 } // namespace
116
55 class ParallelAuthenticatorTest : public testing::Test { 117 class ParallelAuthenticatorTest : public testing::Test {
56 public: 118 public:
57 ParallelAuthenticatorTest() 119 ParallelAuthenticatorTest()
58 : user_context_("me@nowhere.org"), 120 : user_context_("me@nowhere.org"),
59 user_manager_(new FakeUserManager()), 121 user_manager_(new FakeUserManager()),
60 user_manager_enabler_(user_manager_), 122 user_manager_enabler_(user_manager_),
61 mock_caller_(NULL), 123 mock_caller_(NULL),
62 owner_key_util_(new MockOwnerKeyUtil) { 124 owner_key_util_(new MockOwnerKeyUtil) {
63 user_context_.SetKey(Key("fakepass")); 125 user_context_.SetKey(Key("fakepass"));
64 user_context_.SetUserIDHash("me_nowhere_com_hash"); 126 user_context_.SetUserIDHash("me_nowhere_com_hash");
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ScopedTestCrosSettings test_cros_settings_; 262 ScopedTestCrosSettings test_cros_settings_;
201 263
202 TestingProfile profile_; 264 TestingProfile profile_;
203 scoped_ptr<TestingProfileManager> profile_manager_; 265 scoped_ptr<TestingProfileManager> profile_manager_;
204 FakeUserManager* user_manager_; 266 FakeUserManager* user_manager_;
205 ScopedUserManagerEnabler user_manager_enabler_; 267 ScopedUserManagerEnabler user_manager_enabler_;
206 268
207 cryptohome::MockAsyncMethodCaller* mock_caller_; 269 cryptohome::MockAsyncMethodCaller* mock_caller_;
208 270
209 MockAuthStatusConsumer consumer_; 271 MockAuthStatusConsumer consumer_;
210 crypto::ScopedTestNSSDB test_nssdb_;
211 272
212 scoped_refptr<ParallelAuthenticator> auth_; 273 scoped_refptr<ParallelAuthenticator> auth_;
213 scoped_ptr<TestAttemptState> state_; 274 scoped_ptr<TestAttemptState> state_;
214 FakeCryptohomeClient* fake_cryptohome_client_; 275 FakeCryptohomeClient* fake_cryptohome_client_;
215 276
216 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; 277 scoped_refptr<MockOwnerKeyUtil> owner_key_util_;
217 }; 278 };
218 279
219 TEST_F(ParallelAuthenticatorTest, OnAuthSuccess) { 280 TEST_F(ParallelAuthenticatorTest, OnAuthSuccess) {
220 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) 281 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_))
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 SetAndResolveState(auth_.get(), state_.release())); 334 SetAndResolveState(auth_.get(), state_.release()));
274 } 335 }
275 336
276 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) { 337 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) {
277 // Set up state as though a cryptohome mount attempt has occurred 338 // Set up state as though a cryptohome mount attempt has occurred
278 // and succeeded but we are in safe mode and the current user is not owner. 339 // and succeeded but we are in safe mode and the current user is not owner.
279 // This test will check that the "safe-mode" policy is not set and will let 340 // This test will check that the "safe-mode" policy is not set and will let
280 // the mount finish successfully. 341 // the mount finish successfully.
281 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 342 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
282 SetOwnerState(false, false); 343 SetOwnerState(false, false);
283 // Test that the mount has succeeded.
284 state_.reset(new TestAttemptState(user_context_, false));
285 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
286 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, 344 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN,
287 SetAndResolveState(auth_.get(), state_.release())); 345 SetAndResolveState(auth_.get(), state_.release()));
288 } 346 }
289 347
348 // Test the case that login switches to SafeMode and a User that is not the
349 // owner tries to log in. The login should fail because of the missing owner
350 // private key.
290 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { 351 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) {
352 crypto::ScopedTestNSSChromeOSUser user_slot(user_context_.GetUserIDHash());
353 owner_key_util_->SetPublicKey(GetOwnerPublicKey());
354
291 profile_manager_.reset( 355 profile_manager_.reset(
292 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 356 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
293 ASSERT_TRUE(profile_manager_->SetUp()); 357 ASSERT_TRUE(profile_manager_->SetUp());
294 358
295 FailOnLoginSuccess(); // Set failing on success as the default... 359 FailOnLoginSuccess(); // Set failing on success as the default...
296 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED); 360 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED);
297 ExpectLoginFailure(failure); 361 ExpectLoginFailure(failure);
298 362
299 fake_cryptohome_client_->set_unmount_result(true);
300
301 CrosSettingsProvider* device_settings_provider; 363 CrosSettingsProvider* device_settings_provider;
302 StubCrosSettingsProvider stub_settings_provider; 364 StubCrosSettingsProvider stub_settings_provider;
303 // Set up state as though a cryptohome mount attempt has occurred 365 // Set up state as though a cryptohome mount attempt has occurred
304 // and succeeded but we are in safe mode and the current user is not owner. 366 // and succeeded but we are in safe mode and the current user is not owner.
305 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 367 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
306 SetOwnerState(false, false); 368 SetOwnerState(false, false);
307 // Remove the real DeviceSettingsProvider and replace it with a stub. 369 // Remove the real DeviceSettingsProvider and replace it with a stub.
308 device_settings_provider = 370 device_settings_provider =
309 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); 371 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo);
310 EXPECT_TRUE(device_settings_provider != NULL); 372 EXPECT_TRUE(device_settings_provider != NULL);
(...skipping 17 matching lines...) Expand all
328 state_.reset(new TestAttemptState(user_context_, false)); 390 state_.reset(new TestAttemptState(user_context_, false));
329 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 391 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
330 392
331 // The owner key util should not have found the owner key, so login should 393 // The owner key util should not have found the owner key, so login should
332 // not be allowed. 394 // not be allowed.
333 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, 395 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED,
334 SetAndResolveState(auth_.get(), state_.release())); 396 SetAndResolveState(auth_.get(), state_.release()));
335 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 397 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
336 398
337 // Unset global objects used by this test. 399 // Unset global objects used by this test.
400 fake_cryptohome_client_->set_unmount_result(true);
338 LoginState::Shutdown(); 401 LoginState::Shutdown();
339 EXPECT_TRUE( 402 EXPECT_TRUE(
340 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); 403 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
404 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
405 }
406
407 // Test the case that login switches to SafeMode and the Owner logs in, which
408 // should lead to a successful login.
409 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededSuccess) {
410 crypto::ScopedTestNSSChromeOSUser test_user_db(user_context_.GetUserIDHash());
411 owner_key_util_->SetPublicKey(GetOwnerPublicKey());
412
413 crypto::ScopedPK11Slot user_slot(
414 crypto::GetPublicSlotForChromeOSUser(user_context_.GetUserIDHash()));
415 CreateOwnerKeyInSlot(user_slot.get());
416
417 profile_manager_.reset(
418 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
419 ASSERT_TRUE(profile_manager_->SetUp());
420
421 ExpectLoginSuccess(user_context_);
422
423 CrosSettingsProvider* device_settings_provider;
424 StubCrosSettingsProvider stub_settings_provider;
425 // Set up state as though a cryptohome mount attempt has occurred
426 // and succeeded but we are in safe mode and the current user is not owner.
427 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
428 SetOwnerState(false, false);
429 // Remove the real DeviceSettingsProvider and replace it with a stub.
430 device_settings_provider =
ygorshenin1 2014/07/18 10:27:46 nit: move device_settings_provider declaration her
pneubeck (no reviews) 2014/07/18 12:20:29 Done.
431 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo);
432 EXPECT_TRUE(device_settings_provider != NULL);
433 EXPECT_TRUE(
434 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
435 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
ygorshenin1 2014/07/18 10:27:46 nit: move stub_settings_provider declaration here.
pneubeck (no reviews) 2014/07/18 12:20:29 Done.
436 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
437
438 // Initialize login state for this test to verify the login state is changed
439 // to SAFE_MODE.
440 LoginState::Initialize();
441
442 EXPECT_EQ(ParallelAuthenticator::CONTINUE,
443 SetAndResolveState(auth_.get(), state_.release()));
444 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
445
446 // Flush all the pending operations. The operations should induce an owner
447 // verification.
448 device_settings_test_helper_.Flush();
449
450 state_.reset(new TestAttemptState(user_context_, false));
451 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
452
453 // The owner key util should find the owner key, so login should succeed.
454 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN,
455 SetAndResolveState(auth_.get(), state_.release()));
456 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
457
458 // Unset global objects used by this test.
459 fake_cryptohome_client_->set_unmount_result(true);
460 LoginState::Shutdown();
461 EXPECT_TRUE(
462 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
341 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); 463 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
342 } 464 }
343 465
344 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) { 466 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) {
345 FailOnLoginSuccess(); 467 FailOnLoginSuccess();
346 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME)); 468 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME));
347 469
348 // Set up state as though a cryptohome mount attempt has occurred 470 // Set up state as though a cryptohome mount attempt has occurred
349 // and failed. 471 // and failed.
350 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE); 472 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 737 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
616 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) 738 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _))
617 .Times(1) 739 .Times(1)
618 .RetiresOnSaturation(); 740 .RetiresOnSaturation();
619 741
620 auth_->AuthenticateToUnlock(user_context_); 742 auth_->AuthenticateToUnlock(user_context_);
621 base::MessageLoop::current()->Run(); 743 base::MessageLoop::current()->Run();
622 } 744 }
623 745
624 } // namespace chromeos 746 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698