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

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller_browsertest.cc

Issue 696263003: Prevent login while cros settings are untrusted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_2_425574_add_protos_for_device_disabling_in_steady_state
Patch Set: Fix multi-login. Fix style guide violation: no else after return. Created 6 years, 1 month 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
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 <string>
5 #include <vector> 6 #include <vector>
6 7
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
9 #include "base/callback.h" 10 #include "base/callback.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/location.h" 12 #include "base/location.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/login/existing_user_controller.h" 16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
17 #include "chrome/browser/chromeos/login/help_app_launcher.h"
16 #include "chrome/browser/chromeos/login/helper.h" 18 #include "chrome/browser/chromeos/login/helper.h"
17 #include "chrome/browser/chromeos/login/mock_login_utils.h" 19 #include "chrome/browser/chromeos/login/mock_login_utils.h"
20 #include "chrome/browser/chromeos/login/screens/mock_base_screen_delegate.h"
21 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_scre en.h"
18 #include "chrome/browser/chromeos/login/ui/mock_login_display.h" 22 #include "chrome/browser/chromeos/login/ui/mock_login_display.h"
19 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h" 23 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h"
20 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 24 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
21 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 25 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
22 #include "chrome/browser/chromeos/login/wizard_controller.h" 26 #include "chrome/browser/chromeos/login/wizard_controller.h"
23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 27 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
24 #include "chrome/browser/chromeos/policy/device_local_account.h" 28 #include "chrome/browser/chromeos/policy/device_local_account.h"
25 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" 29 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
26 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" 30 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
27 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 31 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
28 #include "chrome/browser/chromeos/settings/cros_settings.h" 32 #include "chrome/browser/chromeos/settings/cros_settings.h"
33 #include "chrome/browser/ui/webui/chromeos/login/supervised_user_creation_screen _handler.h"
34 #include "chrome/grit/generated_resources.h"
29 #include "chrome/test/base/testing_browser_process.h" 35 #include "chrome/test/base/testing_browser_process.h"
30 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
31 #include "chromeos/chromeos_switches.h" 37 #include "chromeos/chromeos_switches.h"
32 #include "chromeos/dbus/fake_session_manager_client.h" 38 #include "chromeos/dbus/fake_session_manager_client.h"
33 #include "chromeos/login/auth/authenticator.h" 39 #include "chromeos/login/auth/authenticator.h"
34 #include "chromeos/login/auth/key.h" 40 #include "chromeos/login/auth/key.h"
35 #include "chromeos/login/auth/mock_authenticator.h" 41 #include "chromeos/login/auth/mock_authenticator.h"
36 #include "chromeos/login/auth/mock_url_fetchers.h" 42 #include "chromeos/login/auth/mock_url_fetchers.h"
37 #include "chromeos/login/auth/user_context.h" 43 #include "chromeos/login/auth/user_context.h"
44 #include "chromeos/login/user_names.h"
38 #include "chromeos/settings/cros_settings_names.h" 45 #include "chromeos/settings/cros_settings_names.h"
46 #include "chromeos/settings/cros_settings_provider.h"
39 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 47 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
40 #include "components/policy/core/common/cloud/cloud_policy_core.h" 48 #include "components/policy/core/common/cloud/cloud_policy_core.h"
41 #include "components/policy/core/common/cloud/cloud_policy_store.h" 49 #include "components/policy/core/common/cloud/cloud_policy_store.h"
42 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 50 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
43 #include "components/policy/core/common/cloud/policy_builder.h" 51 #include "components/policy/core/common/cloud/policy_builder.h"
44 #include "components/user_manager/user.h" 52 #include "components/user_manager/user.h"
45 #include "components/user_manager/user_manager.h" 53 #include "components/user_manager/user_manager.h"
46 #include "components/user_manager/user_type.h" 54 #include "components/user_manager/user_type.h"
47 #include "content/public/test/mock_notification_observer.h" 55 #include "content/public/test/mock_notification_observer.h"
48 #include "content/public/test/test_utils.h" 56 #include "content/public/test/test_utils.h"
49 #include "google_apis/gaia/mock_url_fetcher_factory.h" 57 #include "google_apis/gaia/mock_url_fetcher_factory.h"
58 #include "policy/proto/device_management_backend.pb.h"
50 #include "testing/gmock/include/gmock/gmock.h" 59 #include "testing/gmock/include/gmock/gmock.h"
51 #include "testing/gtest/include/gtest/gtest.h" 60 #include "testing/gtest/include/gtest/gtest.h"
52 61
53 using ::testing::AnyNumber; 62 using ::testing::AnyNumber;
54 using ::testing::Invoke; 63 using ::testing::Invoke;
55 using ::testing::InvokeWithoutArgs; 64 using ::testing::InvokeWithoutArgs;
56 using ::testing::Return; 65 using ::testing::Return;
57 using ::testing::ReturnNull; 66 using ::testing::ReturnNull;
58 using ::testing::Sequence; 67 using ::testing::Sequence;
59 using ::testing::WithArg; 68 using ::testing::WithArg;
60 using ::testing::_; 69 using ::testing::_;
61 70
62 namespace em = enterprise_management; 71 namespace em = enterprise_management;
63 72
64 namespace chromeos { 73 namespace chromeos {
65 74
66 namespace { 75 namespace {
67 76
68 const char kUsername[] = "test_user@gmail.com"; 77 const char kUsername[] = "test_user@gmail.com";
69 const char kNewUsername[] = "test_new_user@gmail.com"; 78 const char kNewUsername[] = "test_new_user@gmail.com";
79 const char kSupervisedUserID[] = "supervised_user@locally-managed.localhost";
70 const char kPassword[] = "test_password"; 80 const char kPassword[] = "test_password";
71 81
72 const char kPublicSessionAccountId[] = "public_session_user@localhost"; 82 const char kPublicSessionAccountId[] = "public_session_user@localhost";
73 const int kAutoLoginNoDelay = 0; 83 const int kAutoLoginNoDelay = 0;
74 const int kAutoLoginShortDelay = 1; 84 const int kAutoLoginShortDelay = 1;
75 const int kAutoLoginLongDelay = 10000; 85 const int kAutoLoginLongDelay = 10000;
76 86
77 ACTION_P(CreateAuthenticator, user_context) { 87 ACTION_P(CreateAuthenticator, user_context) {
78 return new MockAuthenticator(arg0, user_context); 88 return new MockAuthenticator(arg0, user_context);
79 } 89 }
80 90
91 // Wait for cros settings to become permanently untrusted and run |callback|.
92 void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure& callback) {
93 while (true) {
94 const CrosSettingsProvider::TrustedStatus status =
95 CrosSettings::Get()->PrepareTrustedValues(base::Bind(
96 &WaitForPermanentlyUntrustedStatusAndRun,
97 callback));
98 switch (status) {
99 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED:
100 callback.Run();
101 return;
102 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED:
103 return;
104 case CrosSettingsProvider::TRUSTED:
105 content::RunAllPendingInMessageLoop();
106 break;
107 }
108 }
109 }
110
81 } // namespace 111 } // namespace
82 112
83 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { 113 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest {
84 protected: 114 protected:
85 ExistingUserControllerTest() 115 ExistingUserControllerTest()
86 : mock_login_display_(NULL), mock_user_manager_(NULL) {} 116 : mock_login_display_(NULL), mock_user_manager_(NULL) {}
87 117
88 ExistingUserController* existing_user_controller() { 118 ExistingUserController* existing_user_controller() {
89 return ExistingUserController::current_controller(); 119 return ExistingUserController::current_controller();
90 } 120 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // If there is an outstanding login attempt when ExistingUserController is 216 // If there is an outstanding login attempt when ExistingUserController is
187 // deleted, its LoginPerformer instance will be deleted, which in turn 217 // deleted, its LoginPerformer instance will be deleted, which in turn
188 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must 218 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
189 // be deleted on the UI thread. 219 // be deleted on the UI thread.
190 existing_user_controller_.reset(); 220 existing_user_controller_.reset();
191 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread(); 221 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread();
192 testing_profile_.reset(NULL); 222 testing_profile_.reset(NULL);
193 user_manager_enabler_.reset(); 223 user_manager_enabler_.reset();
194 } 224 }
195 225
226 void ExpectLoginFailure() {
227 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
228 .Times(1);
229 EXPECT_CALL(*mock_login_display_,
230 ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST,
231 1,
232 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT))
233 .Times(1);
234 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
235 .Times(1);
236 }
237
196 // ExistingUserController private member accessors. 238 // ExistingUserController private member accessors.
197 base::OneShotTimer<ExistingUserController>* auto_login_timer() { 239 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
198 return existing_user_controller()->auto_login_timer_.get(); 240 return existing_user_controller()->auto_login_timer_.get();
199 } 241 }
200 242
201 const std::string& auto_login_username() const { 243 const std::string& auto_login_username() const {
202 return existing_user_controller()->public_session_auto_login_username_; 244 return existing_user_controller()->public_session_auto_login_username_;
203 } 245 }
204 246
205 int auto_login_delay() const { 247 int auto_login_delay() const {
(...skipping 23 matching lines...) Expand all
229 MockURLFetcherFactory<SuccessFetcher> factory_; 271 MockURLFetcherFactory<SuccessFetcher> factory_;
230 272
231 base::Callback<void(void)> profile_prepared_cb_; 273 base::Callback<void(void)> profile_prepared_cb_;
232 274
233 private: 275 private:
234 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); 276 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest);
235 }; 277 };
236 278
237 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { 279 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) {
238 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 280 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
239 .Times(1); 281 .Times(2);
240 UserContext user_context(kUsername); 282 UserContext user_context(kUsername);
241 user_context.SetKey(Key(kPassword)); 283 user_context.SetKey(Key(kPassword));
242 user_context.SetUserIDHash(kUsername); 284 user_context.SetUserIDHash(kUsername);
243 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) 285 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
244 .Times(1) 286 .Times(1)
245 .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); 287 .WillOnce(WithArg<0>(CreateAuthenticator(user_context)));
246 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _)) 288 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _))
247 .Times(1) 289 .Times(1)
248 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 290 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
249 &base::Callback<void(void)>::Run)); 291 &base::Callback<void(void)>::Run));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 .Times(1) 365 .Times(1)
324 .InSequence(uiEnabledSequence); 366 .InSequence(uiEnabledSequence);
325 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 367 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
326 .Times(1) 368 .Times(1)
327 .InSequence(uiEnabledSequence); 369 .InSequence(uiEnabledSequence);
328 370
329 existing_user_controller()->CompleteLogin(user_context); 371 existing_user_controller()->CompleteLogin(user_context);
330 content::RunAllPendingInMessageLoop(); 372 content::RunAllPendingInMessageLoop();
331 } 373 }
332 374
375 // Verifies that when the cros settings are untrusted, no new session can be
376 // started.
377 class ExistingUserControllerUntrustedTest : public ExistingUserControllerTest {
378 public:
379 ExistingUserControllerUntrustedTest();
380
381 void SetUpInProcessBrowserTestFixture() override;
382
383 void SetUpSessionManager() override;
384
385 private:
386 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerUntrustedTest);
387 };
388
389 ExistingUserControllerUntrustedTest::ExistingUserControllerUntrustedTest() {
390 }
391
392 void ExistingUserControllerUntrustedTest::SetUpInProcessBrowserTestFixture() {
393 ExistingUserControllerTest::SetUpInProcessBrowserTestFixture();
394
395 ExpectLoginFailure();
396 }
397
398 void ExistingUserControllerUntrustedTest::SetUpSessionManager() {
399 InstallOwnerKey();
400 }
401
402 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest,
403 UserLoginForbidden) {
404 UserContext user_context(kUsername);
405 user_context.SetKey(Key(kPassword));
406 user_context.SetUserIDHash(kUsername);
407 existing_user_controller()->Login(user_context, SigninSpecifics());
408 }
409
410 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest,
411 CreateAccountForbidden) {
412 existing_user_controller()->CreateAccount();
413 }
414
415 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest,
416 GuestLoginForbidden) {
417 existing_user_controller()->Login(
418 UserContext(user_manager::USER_TYPE_GUEST, std::string()),
419 SigninSpecifics());
420 }
421
422 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest,
423 RetailModeLoginForbidden) {
424 existing_user_controller()->Login(
425 UserContext(user_manager::USER_TYPE_RETAIL_MODE,
426 chromeos::login::kRetailModeUserName),
427 SigninSpecifics());
428 }
429
430 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest,
431 SupervisedUserLoginForbidden) {
432 UserContext user_context(kSupervisedUserID);
433 user_context.SetKey(Key(kPassword));
434 user_context.SetUserIDHash(kUsername);
435 existing_user_controller()->Login(user_context, SigninSpecifics());
436 }
437
438 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest,
439 SupervisedUserCreationForbidden) {
440 MockBaseScreenDelegate mock_base_screen_delegate;
441 SupervisedUserCreationScreenHandler supervised_user_creation_screen_handler;
442 SupervisedUserCreationScreen supervised_user_creation_screen(
443 &mock_base_screen_delegate,
444 &supervised_user_creation_screen_handler);
445
446 EXPECT_CALL(*mock_user_manager_, SetUserFlow(kUsername, _)).Times(1);
447 supervised_user_creation_screen.AuthenticateManager(kUsername, kPassword);
448 }
449
333 MATCHER_P(HasDetails, expected, "") { 450 MATCHER_P(HasDetails, expected, "") {
334 return expected == *content::Details<const std::string>(arg).ptr(); 451 return expected == *content::Details<const std::string>(arg).ptr();
335 } 452 }
336 453
337 class ExistingUserControllerPublicSessionTest 454 class ExistingUserControllerPublicSessionTest
338 : public ExistingUserControllerTest { 455 : public ExistingUserControllerTest {
339 protected: 456 protected:
340 ExistingUserControllerPublicSessionTest() 457 ExistingUserControllerPublicSessionTest()
341 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId( 458 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
342 kPublicSessionAccountId, 459 kPublicSessionAccountId,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 598 }
482 599
483 void ConfigureAutoLogin() { 600 void ConfigureAutoLogin() {
484 existing_user_controller()->ConfigurePublicSessionAutoLogin(); 601 existing_user_controller()->ConfigurePublicSessionAutoLogin();
485 } 602 }
486 603
487 void FireAutoLogin() { 604 void FireAutoLogin() {
488 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); 605 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
489 } 606 }
490 607
608 void MakeCrosSettingsPermanentlyUntrusted() {
609 device_policy()->policy().set_policy_data_signature("bad signature");
610 session_manager_client()->set_device_policy(device_policy()->GetBlob());
611 session_manager_client()->OnPropertyChangeComplete(true);
612
613 base::RunLoop run_loop;
614 WaitForPermanentlyUntrustedStatusAndRun(run_loop.QuitClosure());
615 run_loop.Run();
616 }
617
491 const std::string public_session_user_id_; 618 const std::string public_session_user_id_;
492 619
493 private: 620 private:
494 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); 621 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
495 }; 622 };
496 623
497 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 624 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
498 ConfigureAutoLoginUsingPolicy) { 625 ConfigureAutoLoginUsingPolicy) {
499 existing_user_controller()->OnSigninScreenReady(); 626 existing_user_controller()->OnSigninScreenReady();
500 EXPECT_EQ("", auto_login_username()); 627 EXPECT_EQ("", auto_login_username());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 686 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
560 LoginStopsAutoLogin) { 687 LoginStopsAutoLogin) {
561 // Set up mocks to check login success. 688 // Set up mocks to check login success.
562 UserContext user_context(kUsername); 689 UserContext user_context(kUsername);
563 user_context.SetKey(Key(kPassword)); 690 user_context.SetKey(Key(kPassword));
564 user_context.SetUserIDHash(user_context.GetUserID()); 691 user_context.SetUserIDHash(user_context.GetUserID());
565 ExpectSuccessfulLogin(user_context); 692 ExpectSuccessfulLogin(user_context);
566 693
567 existing_user_controller()->OnSigninScreenReady(); 694 existing_user_controller()->OnSigninScreenReady();
568 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); 695 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
569 ASSERT_TRUE(auto_login_timer()); 696 EXPECT_TRUE(auto_login_timer());
570 697
571 // Log in and check that it stopped the timer. 698 // Log in and check that it stopped the timer.
572 existing_user_controller()->Login(user_context, SigninSpecifics()); 699 existing_user_controller()->Login(user_context, SigninSpecifics());
573 EXPECT_TRUE(is_login_in_progress()); 700 EXPECT_TRUE(is_login_in_progress());
574 ASSERT_TRUE(auto_login_timer()); 701 ASSERT_TRUE(auto_login_timer());
575 EXPECT_FALSE(auto_login_timer()->IsRunning()); 702 EXPECT_FALSE(auto_login_timer()->IsRunning());
576 703
577 // Wait for login tasks to complete. 704 // Wait for login tasks to complete.
578 content::RunAllPendingInMessageLoop(); 705 content::RunAllPendingInMessageLoop();
579 706
580 // Timer should still be stopped after login completes. 707 // Timer should still be stopped after login completes.
581 ASSERT_TRUE(auto_login_timer()); 708 ASSERT_TRUE(auto_login_timer());
582 EXPECT_FALSE(auto_login_timer()->IsRunning()); 709 EXPECT_FALSE(auto_login_timer()->IsRunning());
583 } 710 }
584 711
585 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 712 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
586 GuestModeLoginStopsAutoLogin) { 713 GuestModeLoginStopsAutoLogin) {
587 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 714 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
588 .Times(1); 715 .Times(2);
589 UserContext user_context(kUsername); 716 UserContext user_context(kUsername);
590 user_context.SetKey(Key(kPassword)); 717 user_context.SetKey(Key(kPassword));
591 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) 718 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
592 .Times(1) 719 .Times(1)
593 .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); 720 .WillOnce(WithArg<0>(CreateAuthenticator(user_context)));
594 721
595 existing_user_controller()->OnSigninScreenReady(); 722 existing_user_controller()->OnSigninScreenReady();
596 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); 723 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
597 ASSERT_TRUE(auto_login_timer()); 724 EXPECT_TRUE(auto_login_timer());
598 725
599 // Login and check that it stopped the timer. 726 // Login and check that it stopped the timer.
600 existing_user_controller()->LoginAsGuest(); 727 existing_user_controller()->Login(UserContext(user_manager::USER_TYPE_GUEST,
728 std::string()),
729 SigninSpecifics());
601 EXPECT_TRUE(is_login_in_progress()); 730 EXPECT_TRUE(is_login_in_progress());
602 ASSERT_TRUE(auto_login_timer()); 731 ASSERT_TRUE(auto_login_timer());
603 EXPECT_FALSE(auto_login_timer()->IsRunning()); 732 EXPECT_FALSE(auto_login_timer()->IsRunning());
604 733
605 // Wait for login tasks to complete. 734 // Wait for login tasks to complete.
606 content::RunAllPendingInMessageLoop(); 735 content::RunAllPendingInMessageLoop();
607 736
608 // Timer should still be stopped after login completes. 737 // Timer should still be stopped after login completes.
609 ASSERT_TRUE(auto_login_timer()); 738 ASSERT_TRUE(auto_login_timer());
610 EXPECT_FALSE(auto_login_timer()->IsRunning()); 739 EXPECT_FALSE(auto_login_timer()->IsRunning());
611 } 740 }
612 741
613 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 742 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
614 CompleteLoginStopsAutoLogin) { 743 CompleteLoginStopsAutoLogin) {
615 // Set up mocks to check login success. 744 // Set up mocks to check login success.
616 UserContext user_context(kUsername); 745 UserContext user_context(kUsername);
617 user_context.SetKey(Key(kPassword)); 746 user_context.SetKey(Key(kPassword));
618 user_context.SetUserIDHash(user_context.GetUserID()); 747 user_context.SetUserIDHash(user_context.GetUserID());
619 ExpectSuccessfulLogin(user_context); 748 ExpectSuccessfulLogin(user_context);
620 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) 749 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
621 .Times(1); 750 .Times(1);
622 751
623 existing_user_controller()->OnSigninScreenReady(); 752 existing_user_controller()->OnSigninScreenReady();
624 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); 753 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
625 ASSERT_TRUE(auto_login_timer()); 754 EXPECT_TRUE(auto_login_timer());
626 755
627 // Check that login completes and stops the timer. 756 // Check that login completes and stops the timer.
628 existing_user_controller()->CompleteLogin(user_context); 757 existing_user_controller()->CompleteLogin(user_context);
629 ASSERT_TRUE(auto_login_timer()); 758 ASSERT_TRUE(auto_login_timer());
630 EXPECT_FALSE(auto_login_timer()->IsRunning()); 759 EXPECT_FALSE(auto_login_timer()->IsRunning());
631 760
632 // Wait for login tasks to complete. 761 // Wait for login tasks to complete.
633 content::RunAllPendingInMessageLoop(); 762 content::RunAllPendingInMessageLoop();
634 763
635 // Timer should still be stopped after login completes. 764 // Timer should still be stopped after login completes.
636 ASSERT_TRUE(auto_login_timer()); 765 ASSERT_TRUE(auto_login_timer());
637 EXPECT_FALSE(auto_login_timer()->IsRunning()); 766 EXPECT_FALSE(auto_login_timer()->IsRunning());
638 } 767 }
639 768
640 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 769 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
641 PublicSessionLoginStopsAutoLogin) { 770 PublicSessionLoginStopsAutoLogin) {
642 // Set up mocks to check login success. 771 // Set up mocks to check login success.
643 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, 772 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT,
644 public_session_user_id_); 773 public_session_user_id_);
645 user_context.SetUserIDHash(user_context.GetUserID()); 774 user_context.SetUserIDHash(user_context.GetUserID());
646 ExpectSuccessfulLogin(user_context); 775 ExpectSuccessfulLogin(user_context);
647 existing_user_controller()->OnSigninScreenReady(); 776 existing_user_controller()->OnSigninScreenReady();
648 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); 777 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
649 ASSERT_TRUE(auto_login_timer()); 778 EXPECT_TRUE(auto_login_timer());
650 779
651 // Login and check that it stopped the timer. 780 // Login and check that it stopped the timer.
652 existing_user_controller()->LoginAsPublicSession(UserContext( 781 existing_user_controller()->Login(
653 user_manager::USER_TYPE_PUBLIC_ACCOUNT, 782 UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT,
654 public_session_user_id_)); 783 public_session_user_id_),
784 SigninSpecifics());
655 785
656 EXPECT_TRUE(is_login_in_progress()); 786 EXPECT_TRUE(is_login_in_progress());
657 ASSERT_TRUE(auto_login_timer()); 787 ASSERT_TRUE(auto_login_timer());
658 EXPECT_FALSE(auto_login_timer()->IsRunning()); 788 EXPECT_FALSE(auto_login_timer()->IsRunning());
659 789
660 // Wait for login tasks to complete. 790 // Wait for login tasks to complete.
661 content::RunAllPendingInMessageLoop(); 791 content::RunAllPendingInMessageLoop();
662 792
663 // Timer should still be stopped after login completes. 793 // Timer should still be stopped after login completes.
664 ASSERT_TRUE(auto_login_timer()); 794 ASSERT_TRUE(auto_login_timer());
665 EXPECT_FALSE(auto_login_timer()->IsRunning()); 795 EXPECT_FALSE(auto_login_timer()->IsRunning());
666 } 796 }
667 797
668 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 798 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
799 LoginForbiddenWhenUntrusted) {
800 // Make cros settings untrusted.
801 MakeCrosSettingsPermanentlyUntrusted();
802
803 // Check that the attempt to start a public session fails with an error.
804 ExpectLoginFailure();
805 UserContext user_context(kUsername);
806 user_context.SetKey(Key(kPassword));
807 user_context.SetUserIDHash(user_context.GetUserID());
808 existing_user_controller()->Login(user_context, SigninSpecifics());
809 }
810
811 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
812 NoAutoLoginWhenUntrusted) {
813 // Start the public session timer.
814 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
815 existing_user_controller()->OnSigninScreenReady();
816 EXPECT_TRUE(auto_login_timer());
817
818 // Make cros settings untrusted.
819 MakeCrosSettingsPermanentlyUntrusted();
820
821 // Check that when the timer fires, auto-login fails with an error.
822 ExpectLoginFailure();
823 FireAutoLogin();
824 }
825
826 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
669 PRE_TestLoadingPublicUsersFromLocalState) { 827 PRE_TestLoadingPublicUsersFromLocalState) {
670 // First run propagates public accounts and stores them in Local State. 828 // First run propagates public accounts and stores them in Local State.
671 } 829 }
672 830
673 // See http://crbug.com/393704; flaky. 831 // See http://crbug.com/393704; flaky.
674 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 832 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
675 DISABLED_TestLoadingPublicUsersFromLocalState) { 833 DISABLED_TestLoadingPublicUsersFromLocalState) {
676 // Second run loads list of public accounts from Local State. 834 // Second run loads list of public accounts from Local State.
677 } 835 }
678 836
679 } // namespace chromeos 837 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/existing_user_controller.cc ('k') | chrome/browser/chromeos/login/kiosk_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698