| 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 <cstring> | 5 #include <cstring> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 260 |
| 261 return http_response.Pass(); | 261 return http_response.Pass(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace | 264 } // namespace |
| 265 | 265 |
| 266 // Boolean parameter is used to run this test for webview (true) and for | 266 // Boolean parameter is used to run this test for webview (true) and for |
| 267 // iframe (false) GAIA sign in. | 267 // iframe (false) GAIA sign in. |
| 268 class SamlTest : public OobeBaseTest, public testing::WithParamInterface<bool> { | 268 class SamlTest : public OobeBaseTest, public testing::WithParamInterface<bool> { |
| 269 public: | 269 public: |
| 270 SamlTest() : saml_load_injected_(false) { | 270 SamlTest() { |
| 271 set_use_webview(GetParam()); | 271 set_use_webview(GetParam()); |
| 272 set_initialize_fake_merge_session(false); | 272 set_initialize_fake_merge_session(false); |
| 273 } | 273 } |
| 274 ~SamlTest() override {} | 274 ~SamlTest() override {} |
| 275 | 275 |
| 276 void SetUpCommandLine(base::CommandLine* command_line) override { | 276 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 277 command_line->AppendSwitch(switches::kOobeSkipPostLogin); | 277 command_line->AppendSwitch(switches::kOobeSkipPostLogin); |
| 278 | 278 |
| 279 const GURL gaia_url = gaia_https_forwarder_.GetURLForSSLHost(""); | 279 const GURL gaia_url = gaia_https_forwarder_.GetURLForSSLHost(""); |
| 280 const GURL saml_idp_url = saml_https_forwarder_.GetURLForSSLHost("SAML"); | 280 const GURL saml_idp_url = saml_https_forwarder_.GetURLForSSLHost("SAML"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 292 void SetUpOnMainThread() override { | 292 void SetUpOnMainThread() override { |
| 293 fake_gaia_->SetFakeMergeSessionParams( | 293 fake_gaia_->SetFakeMergeSessionParams( |
| 294 kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1); | 294 kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1); |
| 295 | 295 |
| 296 embedded_test_server()->RegisterRequestHandler(base::Bind( | 296 embedded_test_server()->RegisterRequestHandler(base::Bind( |
| 297 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); | 297 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); |
| 298 | 298 |
| 299 OobeBaseTest::SetUpOnMainThread(); | 299 OobeBaseTest::SetUpOnMainThread(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void SetupAuthFlowChangeListener() { |
| 303 ASSERT_TRUE(content::ExecuteScript( |
| 304 GetLoginUI()->GetWebContents(), |
| 305 "$('gaia-signin').gaiaAuthHost_.addEventListener('authFlowChange'," |
| 306 "function f() {" |
| 307 "$('gaia-signin').gaiaAuthHost_.removeEventListener(" |
| 308 "'authFlowChange', f);" |
| 309 "window.domAutomationController.setAutomationId(0);" |
| 310 "window.domAutomationController.send(" |
| 311 "$('gaia-signin').isSAML() ? 'SamlLoaded' : 'GaiaLoaded');" |
| 312 "});")); |
| 313 } |
| 314 |
| 302 virtual void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) { | 315 virtual void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) { |
| 303 WaitForSigninScreen(); | 316 WaitForSigninScreen(); |
| 304 | 317 |
| 305 if (!saml_load_injected_) { | 318 SetupAuthFlowChangeListener(); |
| 306 saml_load_injected_ = true; | |
| 307 | |
| 308 ASSERT_TRUE(content::ExecuteScript( | |
| 309 GetLoginUI()->GetWebContents(), | |
| 310 "$('gaia-signin').gaiaAuthHost_.addEventListener('authFlowChange'," | |
| 311 "function() {" | |
| 312 "window.domAutomationController.setAutomationId(0);" | |
| 313 "window.domAutomationController.send(" | |
| 314 "$('gaia-signin').isSAML() ? 'SamlLoaded' : 'GaiaLoaded');" | |
| 315 "});")); | |
| 316 } | |
| 317 | 319 |
| 318 content::DOMMessageQueue message_queue; // Start observe before SAML. | 320 content::DOMMessageQueue message_queue; // Start observe before SAML. |
| 319 GetLoginDisplay()->ShowSigninScreenForCreds(gaia_email, ""); | 321 GetLoginDisplay()->ShowSigninScreenForCreds(gaia_email, ""); |
| 320 | 322 |
| 321 std::string message; | 323 std::string message; |
| 322 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 324 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 323 EXPECT_EQ("\"SamlLoaded\"", message); | 325 EXPECT_EQ("\"SamlLoaded\"", message); |
| 324 } | 326 } |
| 325 | 327 |
| 326 void SendConfirmPassword(const std::string& password_to_confirm) { | 328 void SendConfirmPassword(const std::string& password_to_confirm) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 351 ASSERT_TRUE(saml_https_forwarder_.Initialize( | 353 ASSERT_TRUE(saml_https_forwarder_.Initialize( |
| 352 kIdPHost, embedded_test_server()->base_url())); | 354 kIdPHost, embedded_test_server()->base_url())); |
| 353 OobeBaseTest::InitHttpsForwarders(); | 355 OobeBaseTest::InitHttpsForwarders(); |
| 354 } | 356 } |
| 355 | 357 |
| 356 HTTPSForwarder saml_https_forwarder_; | 358 HTTPSForwarder saml_https_forwarder_; |
| 357 | 359 |
| 358 private: | 360 private: |
| 359 FakeSamlIdp fake_saml_idp_; | 361 FakeSamlIdp fake_saml_idp_; |
| 360 | 362 |
| 361 bool saml_load_injected_; | |
| 362 | |
| 363 DISALLOW_COPY_AND_ASSIGN(SamlTest); | 363 DISALLOW_COPY_AND_ASSIGN(SamlTest); |
| 364 }; | 364 }; |
| 365 | 365 |
| 366 // Tests that signin frame should have 'saml' class and 'cancel' button is | 366 // Tests that signin frame should have 'saml' class and 'cancel' button is |
| 367 // visible when SAML IdP page is loaded. And 'cancel' button goes back to | 367 // visible when SAML IdP page is loaded. And 'cancel' button goes back to |
| 368 // gaia on clicking. | 368 // gaia on clicking. |
| 369 IN_PROC_BROWSER_TEST_P(SamlTest, SamlUI) { | 369 IN_PROC_BROWSER_TEST_P(SamlTest, SamlUI) { |
| 370 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); | 370 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
| 371 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); | 371 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
| 372 | 372 |
| 373 // Saml flow UI expectations. | 373 // Saml flow UI expectations. |
| 374 JsExpect("$('gaia-signin').classList.contains('full-width')"); | 374 JsExpect("$('gaia-signin').classList.contains('full-width')"); |
| 375 JsExpect("!$('saml-notice-container').hidden"); | 375 JsExpect("!$('saml-notice-container').hidden"); |
| 376 std::string js = "$('saml-notice-message').textContent.indexOf('$Host') > -1"; | 376 std::string js = "$('saml-notice-message').textContent.indexOf('$Host') > -1"; |
| 377 ReplaceSubstringsAfterOffset(&js, 0, "$Host", kIdPHost); | 377 ReplaceSubstringsAfterOffset(&js, 0, "$Host", kIdPHost); |
| 378 JsExpect(js); | 378 JsExpect(js); |
| 379 if (!use_webview()) { | 379 if (!use_webview()) { |
| 380 JsExpect("!$('cancel-add-user-button').hidden"); | 380 JsExpect("!$('cancel-add-user-button').hidden"); |
| 381 } | 381 } |
| 382 | 382 |
| 383 SetupAuthFlowChangeListener(); |
| 384 |
| 383 // Click on 'cancel'. | 385 // Click on 'cancel'. |
| 384 content::DOMMessageQueue message_queue; // Observe before 'cancel'. | 386 content::DOMMessageQueue message_queue; // Observe before 'cancel'. |
| 385 if (use_webview()) { | 387 if (use_webview()) { |
| 386 ASSERT_TRUE(content::ExecuteScript( | 388 ASSERT_TRUE(content::ExecuteScript( |
| 387 GetLoginUI()->GetWebContents(), | 389 GetLoginUI()->GetWebContents(), |
| 388 "$('close-button-item').click();")); | 390 "$('close-button-item').click();")); |
| 389 } else { | 391 } else { |
| 390 ASSERT_TRUE(content::ExecuteScript( | 392 ASSERT_TRUE(content::ExecuteScript( |
| 391 GetLoginUI()->GetWebContents(), | 393 GetLoginUI()->GetWebContents(), |
| 392 "$('cancel-add-user-button').click();")); | 394 "$('cancel-add-user-button').click();")); |
| 393 } | 395 } |
| 394 | 396 |
| 395 // Auth flow should change back to Gaia. | 397 // Auth flow should change back to Gaia. |
| 396 std::string message; | 398 std::string message; |
| 397 do { | 399 do { |
| 398 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 400 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 399 } while (message != "\"GaiaLoaded\""); | 401 } while (message != "\"GaiaLoaded\""); |
| 400 | 402 |
| 401 // Saml flow is gone. | 403 // Saml flow is gone. |
| 402 JsExpect("!$('gaia-signin').classList.contains('full-width')"); | 404 JsExpect("!$('gaia-signin').classList.contains('full-width')"); |
| 403 } | 405 } |
| 404 | 406 |
| 405 // Tests the sign-in flow when the credentials passing API is used. | 407 // Tests the sign-in flow when the credentials passing API is used. |
| 406 IN_PROC_BROWSER_TEST_P(SamlTest, CredentialPassingAPI) { | 408 IN_PROC_BROWSER_TEST_P(SamlTest, CredentialPassingAPI) { |
| 407 // Disabled for webview because the script is injected using | |
| 408 // webview.executeScript and there is no way to control the injection time. | |
| 409 // As a result, this test is flaky and fails about 20% of the time. | |
| 410 // TODO(xiyuan): Re-enable when webview.addContentScript API is ready. | |
| 411 if (use_webview()) | |
| 412 return; | |
| 413 | |
| 414 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); | 409 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); |
| 415 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); | 410 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); |
| 416 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); | 411 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
| 417 | 412 |
| 418 content::WindowedNotificationObserver session_start_waiter( | 413 content::WindowedNotificationObserver session_start_waiter( |
| 419 chrome::NOTIFICATION_SESSION_STARTED, | 414 chrome::NOTIFICATION_SESSION_STARTED, |
| 420 content::NotificationService::AllSources()); | 415 content::NotificationService::AllSources()); |
| 421 | 416 |
| 422 // Fill-in the SAML IdP form and submit. | 417 // Fill-in the SAML IdP form and submit. |
| 423 SetSignFormField("Email", "fake_user"); | 418 SetSignFormField("Email", "fake_user"); |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); | 1166 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); |
| 1172 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); | 1167 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); |
| 1173 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); | 1168 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); |
| 1174 } | 1169 } |
| 1175 | 1170 |
| 1176 INSTANTIATE_TEST_CASE_P(SamlSuite, | 1171 INSTANTIATE_TEST_CASE_P(SamlSuite, |
| 1177 SAMLPolicyTest, | 1172 SAMLPolicyTest, |
| 1178 testing::Bool()); | 1173 testing::Bool()); |
| 1179 | 1174 |
| 1180 } // namespace chromeos | 1175 } // namespace chromeos |
| OLD | NEW |