| OLD | NEW |
| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 using net::test_server::BasicHttpResponse; | 51 using net::test_server::BasicHttpResponse; |
| 52 using net::test_server::HttpRequest; | 52 using net::test_server::HttpRequest; |
| 53 using net::test_server::HttpResponse; | 53 using net::test_server::HttpResponse; |
| 54 using testing::_; | 54 using testing::_; |
| 55 using testing::Return; | 55 using testing::Return; |
| 56 | 56 |
| 57 namespace chromeos { | 57 namespace chromeos { |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 | 60 |
| 61 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie"; | |
| 62 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie"; | |
| 63 const char kTestAuthCode[] = "fake-auth-code"; | |
| 64 const char kTestGaiaUberToken[] = "fake-uber-token"; | |
| 65 const char kTestAuthLoginAccessToken[] = "fake-access-token"; | |
| 66 const char kTestRefreshToken[] = "fake-refresh-token"; | |
| 67 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; | |
| 68 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; | |
| 69 | |
| 70 const char kFirstSAMLUserEmail[] = "bob@example.com"; | 61 const char kFirstSAMLUserEmail[] = "bob@example.com"; |
| 71 const char kSecondSAMLUserEmail[] = "alice@example.com"; | 62 const char kSecondSAMLUserEmail[] = "alice@example.com"; |
| 72 const char kHTTPSAMLUserEmail[] = "carol@example.com"; | 63 const char kHTTPSAMLUserEmail[] = "carol@example.com"; |
| 73 const char kNonSAMLUserEmail[] = "dan@example.com"; | 64 const char kNonSAMLUserEmail[] = "dan@example.com"; |
| 74 | 65 |
| 75 const char kRelayState[] = "RelayState"; | 66 const char kRelayState[] = "RelayState"; |
| 76 | 67 |
| 77 // FakeSamlIdp serves IdP auth form and the form submission. The form is | 68 // FakeSamlIdp serves IdP auth form and the form submission. The form is |
| 78 // served with the template's RelayState placeholder expanded to the real | 69 // served with the template's RelayState placeholder expanded to the real |
| 79 // RelayState parameter from request. The form submission redirects back to | 70 // RelayState parameter from request. The form submission redirects back to |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 fake_gaia_.RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url); | 241 fake_gaia_.RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url); |
| 251 fake_gaia_.RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url); | 242 fake_gaia_.RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url); |
| 252 fake_gaia_.RegisterSamlUser( | 243 fake_gaia_.RegisterSamlUser( |
| 253 kHTTPSAMLUserEmail, | 244 kHTTPSAMLUserEmail, |
| 254 embedded_test_server()->base_url().Resolve("/SAML")); | 245 embedded_test_server()->base_url().Resolve("/SAML")); |
| 255 | 246 |
| 256 fake_gaia_.Initialize(); | 247 fake_gaia_.Initialize(); |
| 257 } | 248 } |
| 258 | 249 |
| 259 virtual void SetUpOnMainThread() OVERRIDE { | 250 virtual void SetUpOnMainThread() OVERRIDE { |
| 260 SetMergeSessionParams(kFirstSAMLUserEmail); | 251 fake_gaia_.SetFakeMergeSessionParamsForEmail(kFirstSAMLUserEmail); |
| 261 | 252 |
| 262 embedded_test_server()->RegisterRequestHandler( | 253 embedded_test_server()->RegisterRequestHandler( |
| 263 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); | 254 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); |
| 264 embedded_test_server()->RegisterRequestHandler(base::Bind( | 255 embedded_test_server()->RegisterRequestHandler(base::Bind( |
| 265 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); | 256 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); |
| 266 | 257 |
| 267 // Restart the thread as the sandbox host process has already been spawned. | 258 // Restart the thread as the sandbox host process has already been spawned. |
| 268 embedded_test_server()->RestartThreadAndListen(); | 259 embedded_test_server()->RestartThreadAndListen(); |
| 269 | 260 |
| 270 login_screen_load_observer_.reset(new content::WindowedNotificationObserver( | 261 login_screen_load_observer_.reset(new content::WindowedNotificationObserver( |
| 271 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 262 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 272 content::NotificationService::AllSources())); | 263 content::NotificationService::AllSources())); |
| 273 } | 264 } |
| 274 | 265 |
| 275 virtual void CleanUpOnMainThread() OVERRIDE { | 266 virtual void CleanUpOnMainThread() OVERRIDE { |
| 276 // If the login display is still showing, exit gracefully. | 267 // If the login display is still showing, exit gracefully. |
| 277 if (LoginDisplayHostImpl::default_host()) { | 268 if (LoginDisplayHostImpl::default_host()) { |
| 278 base::MessageLoop::current()->PostTask(FROM_HERE, | 269 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 279 base::Bind(&chrome::AttemptExit)); | 270 base::Bind(&chrome::AttemptExit)); |
| 280 content::RunMessageLoop(); | 271 content::RunMessageLoop(); |
| 281 } | 272 } |
| 282 } | 273 } |
| 283 | 274 |
| 284 void SetMergeSessionParams(const std::string& email) { | |
| 285 FakeGaia::MergeSessionParams params; | |
| 286 params.auth_sid_cookie = kTestAuthSIDCookie; | |
| 287 params.auth_lsid_cookie = kTestAuthLSIDCookie; | |
| 288 params.auth_code = kTestAuthCode; | |
| 289 params.refresh_token = kTestRefreshToken; | |
| 290 params.access_token = kTestAuthLoginAccessToken; | |
| 291 params.gaia_uber_token = kTestGaiaUberToken; | |
| 292 params.session_sid_cookie = kTestSessionSIDCookie; | |
| 293 params.session_lsid_cookie = kTestSessionLSIDCookie; | |
| 294 params.email = email; | |
| 295 fake_gaia_.SetMergeSessionParams(params); | |
| 296 } | |
| 297 | |
| 298 WebUILoginDisplay* GetLoginDisplay() { | 275 WebUILoginDisplay* GetLoginDisplay() { |
| 299 ExistingUserController* controller = | 276 ExistingUserController* controller = |
| 300 ExistingUserController::current_controller(); | 277 ExistingUserController::current_controller(); |
| 301 CHECK(controller); | 278 CHECK(controller); |
| 302 return static_cast<WebUILoginDisplay*>(controller->login_display()); | 279 return static_cast<WebUILoginDisplay*>(controller->login_display()); |
| 303 } | 280 } |
| 304 | 281 |
| 305 void WaitForSigninScreen() { | 282 void WaitForSigninScreen() { |
| 306 WizardController::SkipPostLoginScreensForTesting(); | 283 WizardController::SkipPostLoginScreensForTesting(); |
| 307 WizardController* wizard_controller = | 284 WizardController* wizard_controller = |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 void ExecuteJsInSigninFrame(const std::string& js) { | 365 void ExecuteJsInSigninFrame(const std::string& js) { |
| 389 content::RenderFrameHost* frame = InlineLoginUI::GetAuthIframe( | 366 content::RenderFrameHost* frame = InlineLoginUI::GetAuthIframe( |
| 390 GetLoginUI()->GetWebContents(), GURL(), "signin-frame"); | 367 GetLoginUI()->GetWebContents(), GURL(), "signin-frame"); |
| 391 ASSERT_TRUE(content::ExecuteScript(frame, js)); | 368 ASSERT_TRUE(content::ExecuteScript(frame, js)); |
| 392 } | 369 } |
| 393 | 370 |
| 394 FakeSamlIdp* fake_saml_idp() { return &fake_saml_idp_; } | 371 FakeSamlIdp* fake_saml_idp() { return &fake_saml_idp_; } |
| 395 | 372 |
| 396 protected: | 373 protected: |
| 397 scoped_ptr<content::WindowedNotificationObserver> login_screen_load_observer_; | 374 scoped_ptr<content::WindowedNotificationObserver> login_screen_load_observer_; |
| 375 FakeGaia fake_gaia_; |
| 398 | 376 |
| 399 private: | 377 private: |
| 400 FakeGaia fake_gaia_; | |
| 401 FakeSamlIdp fake_saml_idp_; | 378 FakeSamlIdp fake_saml_idp_; |
| 402 scoped_ptr<HTTPSForwarder> gaia_https_forwarder_; | 379 scoped_ptr<HTTPSForwarder> gaia_https_forwarder_; |
| 403 scoped_ptr<HTTPSForwarder> saml_https_forwarder_; | 380 scoped_ptr<HTTPSForwarder> saml_https_forwarder_; |
| 404 | 381 |
| 405 bool saml_load_injected_; | 382 bool saml_load_injected_; |
| 406 | 383 |
| 407 DISALLOW_COPY_AND_ASSIGN(SamlTest); | 384 DISALLOW_COPY_AND_ASSIGN(SamlTest); |
| 408 }; | 385 }; |
| 409 | 386 |
| 410 // Tests that signin frame should have 'saml' class and 'cancel' button is | 387 // Tests that signin frame should have 'saml' class and 'cancel' button is |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 // Types |bob@example.com| into the GAIA login form but then authenticates as | 488 // Types |bob@example.com| into the GAIA login form but then authenticates as |
| 512 // |alice@example.com| via SAML. Verifies that the logged-in user is correctly | 489 // |alice@example.com| via SAML. Verifies that the logged-in user is correctly |
| 513 // identified as Alice. | 490 // identified as Alice. |
| 514 IN_PROC_BROWSER_TEST_F(SamlTest, UseAutenticatedUserEmailAddress) { | 491 IN_PROC_BROWSER_TEST_F(SamlTest, UseAutenticatedUserEmailAddress) { |
| 515 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); | 492 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
| 516 // Type |bob@example.com| into the GAIA login form. | 493 // Type |bob@example.com| into the GAIA login form. |
| 517 StartSamlAndWaitForIdpPageLoad(kSecondSAMLUserEmail); | 494 StartSamlAndWaitForIdpPageLoad(kSecondSAMLUserEmail); |
| 518 | 495 |
| 519 // Authenticate as alice@example.com via SAML (the |Email| provided here is | 496 // Authenticate as alice@example.com via SAML (the |Email| provided here is |
| 520 // irrelevant - the authenticated user's e-mail address that FakeGAIA | 497 // irrelevant - the authenticated user's e-mail address that FakeGAIA |
| 521 // reports was set via SetMergeSessionParams()). | 498 // reports was set via |SetFakeMergeSessionParamsForEmail|. |
| 522 SetSignFormField("Email", "fake_user"); | 499 SetSignFormField("Email", "fake_user"); |
| 523 SetSignFormField("Password", "fake_password"); | 500 SetSignFormField("Password", "fake_password"); |
| 524 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); | 501 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
| 525 | 502 |
| 526 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); | 503 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); |
| 527 | 504 |
| 528 SendConfirmPassword("fake_password"); | 505 SendConfirmPassword("fake_password"); |
| 529 content::WindowedNotificationObserver( | 506 content::WindowedNotificationObserver( |
| 530 chrome::NOTIFICATION_SESSION_STARTED, | 507 chrome::NOTIFICATION_SESSION_STARTED, |
| 531 content::NotificationService::AllSources()).Wait(); | 508 content::NotificationService::AllSources()).Wait(); |
| 532 const user_manager::User* user = UserManager::Get()->GetActiveUser(); | 509 const user_manager::User* user = UserManager::Get()->GetActiveUser(); |
| 533 ASSERT_TRUE(user); | 510 ASSERT_TRUE(user); |
| 534 EXPECT_EQ(kFirstSAMLUserEmail, user->email()); | 511 EXPECT_EQ(kFirstSAMLUserEmail, user->email()); |
| 535 } | 512 } |
| 536 | 513 |
| 537 // Verifies that if the authenticated user's e-mail address cannot be retrieved, | 514 // Verifies that if the authenticated user's e-mail address cannot be retrieved, |
| 538 // an error message is shown. | 515 // an error message is shown. |
| 539 IN_PROC_BROWSER_TEST_F(SamlTest, FailToRetrieveAutenticatedUserEmailAddress) { | 516 IN_PROC_BROWSER_TEST_F(SamlTest, FailToRetrieveAutenticatedUserEmailAddress) { |
| 540 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); | 517 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
| 541 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); | 518 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
| 542 | 519 |
| 543 SetMergeSessionParams(""); | 520 fake_gaia_.SetFakeMergeSessionParamsForEmail(""); |
| 544 SetSignFormField("Email", "fake_user"); | 521 SetSignFormField("Email", "fake_user"); |
| 545 SetSignFormField("Password", "fake_password"); | 522 SetSignFormField("Password", "fake_password"); |
| 546 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); | 523 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
| 547 | 524 |
| 548 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_NO_EMAIL), | 525 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_NO_EMAIL), |
| 549 WaitForAndGetFatalErrorMessage()); | 526 WaitForAndGetFatalErrorMessage()); |
| 550 } | 527 } |
| 551 | 528 |
| 552 // Tests the password confirm flow: show error on the first failure and | 529 // Tests the password confirm flow: show error on the first failure and |
| 553 // fatal error on the second failure. | 530 // fatal error on the second failure. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 // Verifies that when the offline login time limit is exceeded for a user who | 714 // Verifies that when the offline login time limit is exceeded for a user who |
| 738 // authenticated via SAML, that user is forced to log in online the next time. | 715 // authenticated via SAML, that user is forced to log in online the next time. |
| 739 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLZeroLimit) { | 716 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLZeroLimit) { |
| 740 login_screen_load_observer_->Wait(); | 717 login_screen_load_observer_->Wait(); |
| 741 // Verify that offline login is not allowed. | 718 // Verify that offline login is not allowed. |
| 742 JsExpect("window.getComputedStyle(document.querySelector(" | 719 JsExpect("window.getComputedStyle(document.querySelector(" |
| 743 " '#pod-row .signin-button-container')).display != 'none'"); | 720 " '#pod-row .signin-button-container')).display != 'none'"); |
| 744 } | 721 } |
| 745 | 722 |
| 746 } // namespace chromeos | 723 } // namespace chromeos |
| OLD | NEW |