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

Side by Side Diff: chrome/browser/chromeos/login/saml/saml_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698