OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 15 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
13 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 16 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
14 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 17 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
15 #include "chrome/browser/chromeos/login/user.h" | 18 #include "chrome/browser/chromeos/login/user.h" |
16 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
17 #include "chrome/browser/chromeos/login/webui_login_display.h" | 20 #include "chrome/browser/chromeos/login/webui_login_display.h" |
18 #include "chrome/browser/chromeos/login/wizard_controller.h" | 21 #include "chrome/browser/chromeos/login/wizard_controller.h" |
19 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
20 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chromeos/chromeos_switches.h" | 26 #include "chromeos/chromeos_switches.h" |
| 27 #include "components/policy/core/browser/browser_policy_connector.h" |
| 28 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 29 #include "components/policy/core/common/policy_map.h" |
| 30 #include "components/policy/core/common/policy_types.h" |
24 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
26 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
27 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
28 #include "google_apis/gaia/fake_gaia.h" | 35 #include "google_apis/gaia/fake_gaia.h" |
29 #include "google_apis/gaia/gaia_switches.h" | 36 #include "google_apis/gaia/gaia_switches.h" |
30 #include "net/base/url_util.h" | 37 #include "net/base/url_util.h" |
31 #include "net/dns/mock_host_resolver.h" | 38 #include "net/dns/mock_host_resolver.h" |
32 #include "net/test/embedded_test_server/embedded_test_server.h" | 39 #include "net/test/embedded_test_server/embedded_test_server.h" |
33 #include "net/test/embedded_test_server/http_request.h" | 40 #include "net/test/embedded_test_server/http_request.h" |
34 #include "net/test/embedded_test_server/http_response.h" | 41 #include "net/test/embedded_test_server/http_response.h" |
| 42 #include "policy/policy_constants.h" |
| 43 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
36 | 45 |
37 using net::test_server::BasicHttpResponse; | 46 using net::test_server::BasicHttpResponse; |
38 using net::test_server::HttpRequest; | 47 using net::test_server::HttpRequest; |
39 using net::test_server::HttpResponse; | 48 using net::test_server::HttpResponse; |
| 49 using testing::_; |
| 50 using testing::Return; |
40 | 51 |
41 namespace chromeos { | 52 namespace chromeos { |
42 | 53 |
43 namespace { | 54 namespace { |
44 | 55 |
45 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie"; | 56 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie"; |
46 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie"; | 57 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie"; |
47 const char kTestAuthCode[] = "fake-auth-code"; | 58 const char kTestAuthCode[] = "fake-auth-code"; |
48 const char kTestGaiaUberToken[] = "fake-uber-token"; | 59 const char kTestGaiaUberToken[] = "fake-uber-token"; |
49 const char kTestAuthLoginAccessToken[] = "fake-access-token"; | 60 const char kTestAuthLoginAccessToken[] = "fake-access-token"; |
50 const char kTestRefreshToken[] = "fake-refresh-token"; | 61 const char kTestRefreshToken[] = "fake-refresh-token"; |
51 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; | 62 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; |
52 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; | 63 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; |
53 | 64 |
54 const char kAnotherUserEmail[] = "alice@example.com"; | 65 const char kFirstSAMLUserEmail[] = "bob@example.com"; |
55 const char kUserEmail[] = "bob@example.com"; | 66 const char kSecondSAMLUserEmail[] = "alice@example.com"; |
| 67 const char kNonSAMLUserEmail[] = "carol@example.com"; |
56 | 68 |
57 const char kRelayState[] = "RelayState"; | 69 const char kRelayState[] = "RelayState"; |
58 | 70 |
59 // FakeSamlIdp serves IdP auth form and the form submission. The form is | 71 // FakeSamlIdp serves IdP auth form and the form submission. The form is |
60 // served with the template's RelayState placeholder expanded to the real | 72 // served with the template's RelayState placeholder expanded to the real |
61 // RelayState parameter from request. The form submission redirects back to | 73 // RelayState parameter from request. The form submission redirects back to |
62 // FakeGaia with the same RelayState. | 74 // FakeGaia with the same RelayState. |
63 class FakeSamlIdp { | 75 class FakeSamlIdp { |
64 public: | 76 public: |
65 FakeSamlIdp(); | 77 FakeSamlIdp(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 gaia_url_.spec()); | 228 gaia_url_.spec()); |
217 fake_gaia_.Initialize(); | 229 fake_gaia_.Initialize(); |
218 | 230 |
219 std::string saml_idp_host("saml.idp"); | 231 std::string saml_idp_host("saml.idp"); |
220 GURL::Replacements replace_saml_idp_host; | 232 GURL::Replacements replace_saml_idp_host; |
221 replace_saml_idp_host.SetHostStr(saml_idp_host); | 233 replace_saml_idp_host.SetHostStr(saml_idp_host); |
222 GURL saml_idp_url = server_url.ReplaceComponents(replace_saml_idp_host); | 234 GURL saml_idp_url = server_url.ReplaceComponents(replace_saml_idp_host); |
223 saml_idp_url = saml_idp_url.Resolve("/SAML/SSO"); | 235 saml_idp_url = saml_idp_url.Resolve("/SAML/SSO"); |
224 | 236 |
225 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url_); | 237 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url_); |
226 fake_gaia_.RegisterSamlUser(kAnotherUserEmail, saml_idp_url); | 238 fake_gaia_.RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url); |
227 fake_gaia_.RegisterSamlUser(kUserEmail, saml_idp_url); | 239 fake_gaia_.RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url); |
228 } | 240 } |
229 | 241 |
230 virtual void SetUpOnMainThread() OVERRIDE { | 242 virtual void SetUpOnMainThread() OVERRIDE { |
231 FakeGaia::MergeSessionParams params; | 243 FakeGaia::MergeSessionParams params; |
232 params.auth_sid_cookie = kTestAuthSIDCookie; | 244 params.auth_sid_cookie = kTestAuthSIDCookie; |
233 params.auth_lsid_cookie = kTestAuthLSIDCookie; | 245 params.auth_lsid_cookie = kTestAuthLSIDCookie; |
234 params.auth_code = kTestAuthCode; | 246 params.auth_code = kTestAuthCode; |
235 params.refresh_token = kTestRefreshToken; | 247 params.refresh_token = kTestRefreshToken; |
236 params.access_token = kTestAuthLoginAccessToken; | 248 params.access_token = kTestAuthLoginAccessToken; |
237 params.gaia_uber_token = kTestGaiaUberToken; | 249 params.gaia_uber_token = kTestGaiaUberToken; |
238 params.session_sid_cookie = kTestSessionSIDCookie; | 250 params.session_sid_cookie = kTestSessionSIDCookie; |
239 params.session_lsid_cookie = kTestSessionLSIDCookie; | 251 params.session_lsid_cookie = kTestSessionLSIDCookie; |
240 params.email = kUserEmail; | 252 params.email = kFirstSAMLUserEmail; |
241 fake_gaia_.SetMergeSessionParams(params); | 253 fake_gaia_.SetMergeSessionParams(params); |
242 | 254 |
243 embedded_test_server()->RegisterRequestHandler( | 255 embedded_test_server()->RegisterRequestHandler( |
244 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); | 256 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); |
245 embedded_test_server()->RegisterRequestHandler(base::Bind( | 257 embedded_test_server()->RegisterRequestHandler(base::Bind( |
246 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); | 258 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); |
247 | 259 |
248 // Restart the thread as the sandbox host process has already been spawned. | 260 // Restart the thread as the sandbox host process has already been spawned. |
249 embedded_test_server()->RestartThreadAndListen(); | 261 embedded_test_server()->RestartThreadAndListen(); |
| 262 |
| 263 login_screen_load_observer_.reset(new content::WindowedNotificationObserver( |
| 264 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 265 content::NotificationService::AllSources())); |
250 } | 266 } |
251 | 267 |
252 virtual void CleanUpOnMainThread() OVERRIDE { | 268 virtual void CleanUpOnMainThread() OVERRIDE { |
253 // If the login display is still showing, exit gracefully. | 269 // If the login display is still showing, exit gracefully. |
254 if (LoginDisplayHostImpl::default_host()) { | 270 if (LoginDisplayHostImpl::default_host()) { |
255 base::MessageLoop::current()->PostTask(FROM_HERE, | 271 base::MessageLoop::current()->PostTask(FROM_HERE, |
256 base::Bind(&chrome::AttemptExit)); | 272 base::Bind(&chrome::AttemptExit)); |
257 content::RunMessageLoop(); | 273 content::RunMessageLoop(); |
258 } | 274 } |
259 } | 275 } |
260 | 276 |
261 WebUILoginDisplay* GetLoginDisplay() { | 277 WebUILoginDisplay* GetLoginDisplay() { |
262 ExistingUserController* controller = | 278 ExistingUserController* controller = |
263 ExistingUserController::current_controller(); | 279 ExistingUserController::current_controller(); |
264 CHECK(controller); | 280 CHECK(controller); |
265 return static_cast<WebUILoginDisplay*>(controller->login_display()); | 281 return static_cast<WebUILoginDisplay*>(controller->login_display()); |
266 } | 282 } |
267 | 283 |
268 void WaitForSigninScreen() { | 284 void WaitForSigninScreen() { |
269 WizardController::SkipPostLoginScreensForTesting(); | 285 WizardController::SkipPostLoginScreensForTesting(); |
270 WizardController* wizard_controller = | 286 WizardController* wizard_controller = |
271 chromeos::WizardController::default_controller(); | 287 chromeos::WizardController::default_controller(); |
272 CHECK(wizard_controller); | 288 CHECK(wizard_controller); |
273 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); | 289 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
274 | 290 |
275 content::WindowedNotificationObserver( | 291 login_screen_load_observer_->Wait(); |
276 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | |
277 content::NotificationService::AllSources()).Wait(); | |
278 } | 292 } |
279 | 293 |
280 void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) { | 294 void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) { |
281 WaitForSigninScreen(); | 295 WaitForSigninScreen(); |
282 | 296 |
283 if (!saml_load_injected_) { | 297 if (!saml_load_injected_) { |
284 saml_load_injected_ = true; | 298 saml_load_injected_ = true; |
285 | 299 |
286 ASSERT_TRUE(content::ExecuteScript( | 300 ASSERT_TRUE(content::ExecuteScript( |
287 GetLoginUI()->GetWebContents(), | 301 GetLoginUI()->GetWebContents(), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // Executes Js code in the auth iframe hosted by gaia_auth extension. | 353 // Executes Js code in the auth iframe hosted by gaia_auth extension. |
340 void ExecuteJsInSigninFrame(const std::string& js) { | 354 void ExecuteJsInSigninFrame(const std::string& js) { |
341 ASSERT_TRUE(content::ExecuteScriptInFrame( | 355 ASSERT_TRUE(content::ExecuteScriptInFrame( |
342 GetLoginUI()->GetWebContents(), | 356 GetLoginUI()->GetWebContents(), |
343 "//iframe[@id='signin-frame']\n//iframe", | 357 "//iframe[@id='signin-frame']\n//iframe", |
344 js)); | 358 js)); |
345 } | 359 } |
346 | 360 |
347 FakeSamlIdp* fake_saml_idp() { return &fake_saml_idp_; } | 361 FakeSamlIdp* fake_saml_idp() { return &fake_saml_idp_; } |
348 | 362 |
| 363 protected: |
| 364 scoped_ptr<content::WindowedNotificationObserver> login_screen_load_observer_; |
| 365 |
349 private: | 366 private: |
350 GURL gaia_url_; | 367 GURL gaia_url_; |
351 FakeGaia fake_gaia_; | 368 FakeGaia fake_gaia_; |
352 FakeSamlIdp fake_saml_idp_; | 369 FakeSamlIdp fake_saml_idp_; |
353 | 370 |
354 bool saml_load_injected_; | 371 bool saml_load_injected_; |
355 | 372 |
356 DISALLOW_COPY_AND_ASSIGN(SamlTest); | 373 DISALLOW_COPY_AND_ASSIGN(SamlTest); |
357 }; | 374 }; |
358 | 375 |
359 // Tests that signin frame should have 'saml' class and 'cancel' button is | 376 // Tests that signin frame should have 'saml' class and 'cancel' button is |
360 // visible when SAML IdP page is loaded. And 'cancel' button goes back to | 377 // visible when SAML IdP page is loaded. And 'cancel' button goes back to |
361 // gaia on clicking. | 378 // gaia on clicking. |
362 IN_PROC_BROWSER_TEST_F(SamlTest, SamlUI) { | 379 IN_PROC_BROWSER_TEST_F(SamlTest, SamlUI) { |
363 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); | 380 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
364 StartSamlAndWaitForIdpPageLoad(kUserEmail); | 381 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
365 | 382 |
366 // Saml flow UI expectations. | 383 // Saml flow UI expectations. |
367 JsExpect("$('gaia-signin').classList.contains('saml')"); | 384 JsExpect("$('gaia-signin').classList.contains('saml')"); |
368 JsExpect("!$('cancel-add-user-button').hidden"); | 385 JsExpect("!$('cancel-add-user-button').hidden"); |
369 | 386 |
370 // Click on 'cancel'. | 387 // Click on 'cancel'. |
371 content::DOMMessageQueue message_queue; // Observe before 'cancel'. | 388 content::DOMMessageQueue message_queue; // Observe before 'cancel'. |
372 ASSERT_TRUE(content::ExecuteScript( | 389 ASSERT_TRUE(content::ExecuteScript( |
373 GetLoginUI()->GetWebContents(), | 390 GetLoginUI()->GetWebContents(), |
374 "$('cancel-add-user-button').click();")); | 391 "$('cancel-add-user-button').click();")); |
375 | 392 |
376 // Auth flow should change back to Gaia. | 393 // Auth flow should change back to Gaia. |
377 std::string message; | 394 std::string message; |
378 do { | 395 do { |
379 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 396 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
380 } while (message != "\"GaiaLoaded\""); | 397 } while (message != "\"GaiaLoaded\""); |
381 | 398 |
382 // Saml flow is gone. | 399 // Saml flow is gone. |
383 JsExpect("!$('gaia-signin').classList.contains('saml')"); | 400 JsExpect("!$('gaia-signin').classList.contains('saml')"); |
384 } | 401 } |
385 | 402 |
386 // Tests the sign-in flow when the credentials passing API is used. | 403 // Tests the sign-in flow when the credentials passing API is used. |
387 IN_PROC_BROWSER_TEST_F(SamlTest, CredentialPassingAPI) { | 404 IN_PROC_BROWSER_TEST_F(SamlTest, CredentialPassingAPI) { |
388 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); | 405 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); |
389 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); | 406 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); |
390 StartSamlAndWaitForIdpPageLoad(kUserEmail); | 407 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
391 | 408 |
392 // Fill-in the SAML IdP form and submit. | 409 // Fill-in the SAML IdP form and submit. |
393 SetSignFormField("Email", "fake_user"); | 410 SetSignFormField("Email", "fake_user"); |
394 SetSignFormField("Password", "fake_password"); | 411 SetSignFormField("Password", "fake_password"); |
395 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); | 412 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
396 | 413 |
397 // Login should finish login and a session should start. | 414 // Login should finish login and a session should start. |
398 content::WindowedNotificationObserver( | 415 content::WindowedNotificationObserver( |
399 chrome::NOTIFICATION_SESSION_STARTED, | 416 chrome::NOTIFICATION_SESSION_STARTED, |
400 content::NotificationService::AllSources()).Wait(); | 417 content::NotificationService::AllSources()).Wait(); |
401 } | 418 } |
402 | 419 |
403 // Tests the single password scraped flow. | 420 // Tests the single password scraped flow. |
404 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedSingle) { | 421 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedSingle) { |
405 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); | 422 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
406 StartSamlAndWaitForIdpPageLoad(kUserEmail); | 423 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
407 | 424 |
408 // Fill-in the SAML IdP form and submit. | 425 // Fill-in the SAML IdP form and submit. |
409 SetSignFormField("Email", "fake_user"); | 426 SetSignFormField("Email", "fake_user"); |
410 SetSignFormField("Password", "fake_password"); | 427 SetSignFormField("Password", "fake_password"); |
411 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); | 428 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
412 | 429 |
413 // Lands on confirm password screen. | 430 // Lands on confirm password screen. |
414 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); | 431 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); |
415 | 432 |
416 // Enter an unknown password should go back to confirm password screen. | 433 // Enter an unknown password should go back to confirm password screen. |
417 SendConfirmPassword("wrong_password"); | 434 SendConfirmPassword("wrong_password"); |
418 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); | 435 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); |
419 | 436 |
420 // Enter a known password should finish login and start session. | 437 // Enter a known password should finish login and start session. |
421 SendConfirmPassword("fake_password"); | 438 SendConfirmPassword("fake_password"); |
422 content::WindowedNotificationObserver( | 439 content::WindowedNotificationObserver( |
423 chrome::NOTIFICATION_SESSION_STARTED, | 440 chrome::NOTIFICATION_SESSION_STARTED, |
424 content::NotificationService::AllSources()).Wait(); | 441 content::NotificationService::AllSources()).Wait(); |
425 } | 442 } |
426 | 443 |
427 // Tests the multiple password scraped flow. | 444 // Tests the multiple password scraped flow. |
428 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedMultiple) { | 445 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedMultiple) { |
429 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_two_passwords.html"); | 446 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_two_passwords.html"); |
430 | 447 |
431 StartSamlAndWaitForIdpPageLoad(kUserEmail); | 448 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
432 | 449 |
433 SetSignFormField("Email", "fake_user"); | 450 SetSignFormField("Email", "fake_user"); |
434 SetSignFormField("Password", "fake_password"); | 451 SetSignFormField("Password", "fake_password"); |
435 SetSignFormField("Password1", "password1"); | 452 SetSignFormField("Password1", "password1"); |
436 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); | 453 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
437 | 454 |
438 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); | 455 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); |
439 | 456 |
440 // Either scraped password should be able to sign-in. | 457 // Either scraped password should be able to sign-in. |
441 SendConfirmPassword("password1"); | 458 SendConfirmPassword("password1"); |
442 content::WindowedNotificationObserver( | 459 content::WindowedNotificationObserver( |
443 chrome::NOTIFICATION_SESSION_STARTED, | 460 chrome::NOTIFICATION_SESSION_STARTED, |
444 content::NotificationService::AllSources()).Wait(); | 461 content::NotificationService::AllSources()).Wait(); |
445 } | 462 } |
446 | 463 |
447 // Tests the no password scraped flow. | 464 // Tests the no password scraped flow. |
448 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedNone) { | 465 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedNone) { |
449 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_no_passwords.html"); | 466 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_no_passwords.html"); |
450 | 467 |
451 StartSamlAndWaitForIdpPageLoad(kUserEmail); | 468 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
452 | 469 |
453 SetSignFormField("Email", "fake_user"); | 470 SetSignFormField("Email", "fake_user"); |
454 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); | 471 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
455 | 472 |
456 OobeScreenWaiter(OobeDisplay::SCREEN_MESSAGE_BOX).Wait(); | 473 OobeScreenWaiter(OobeDisplay::SCREEN_MESSAGE_BOX).Wait(); |
457 JsExpect( | 474 JsExpect( |
458 "$('message-box-title').textContent == " | 475 "$('message-box-title').textContent == " |
459 "loadTimeData.getString('noPasswordWarningTitle')"); | 476 "loadTimeData.getString('noPasswordWarningTitle')"); |
460 } | 477 } |
461 | 478 |
462 // Types |alice@example.com| into the GAIA login form but then authenticates as | 479 // Types |bob@example.com| into the GAIA login form but then authenticates as |
463 // |bob@example.com| via SAML. Verifies that the logged-in user is correctly | 480 // |alice@example.com| via SAML. Verifies that the logged-in user is correctly |
464 // identified as Bob. | 481 // identified as Alice. |
465 IN_PROC_BROWSER_TEST_F(SamlTest, UseAutenticatedUserEmailAddress) { | 482 IN_PROC_BROWSER_TEST_F(SamlTest, UseAutenticatedUserEmailAddress) { |
466 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); | 483 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
467 // Type |alice@example.com| into the GAIA login form. | 484 // Type |bob@example.com| into the GAIA login form. |
468 StartSamlAndWaitForIdpPageLoad(kAnotherUserEmail); | 485 StartSamlAndWaitForIdpPageLoad(kSecondSAMLUserEmail); |
469 | 486 |
470 // Authenticate as bob@example.com via SAML (the |Email| provided here is | 487 // Authenticate as alice@example.com via SAML (the |Email| provided here is |
471 // irrelevant - the authenticated user's e-mail address that FakeGAIA | 488 // irrelevant - the authenticated user's e-mail address that FakeGAIA |
472 // reports was set via SetMergeSessionParams()). | 489 // reports was set via SetMergeSessionParams()). |
473 SetSignFormField("Email", "fake_user"); | 490 SetSignFormField("Email", "fake_user"); |
474 SetSignFormField("Password", "fake_password"); | 491 SetSignFormField("Password", "fake_password"); |
475 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); | 492 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
476 | 493 |
477 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); | 494 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); |
478 | 495 |
479 SendConfirmPassword("fake_password"); | 496 SendConfirmPassword("fake_password"); |
480 content::WindowedNotificationObserver( | 497 content::WindowedNotificationObserver( |
481 chrome::NOTIFICATION_SESSION_STARTED, | 498 chrome::NOTIFICATION_SESSION_STARTED, |
482 content::NotificationService::AllSources()).Wait(); | 499 content::NotificationService::AllSources()).Wait(); |
483 const User* user = UserManager::Get()->GetActiveUser(); | 500 const User* user = UserManager::Get()->GetActiveUser(); |
484 ASSERT_TRUE(user); | 501 ASSERT_TRUE(user); |
485 EXPECT_EQ(kUserEmail, user->email()); | 502 EXPECT_EQ(kFirstSAMLUserEmail, user->email()); |
486 } | 503 } |
487 | 504 |
| 505 class SAMLPolicyTest : public SamlTest { |
| 506 public: |
| 507 SAMLPolicyTest(); |
| 508 virtual ~SAMLPolicyTest(); |
| 509 |
| 510 // SamlTest: |
| 511 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; |
| 512 virtual void SetUpOnMainThread() OVERRIDE; |
| 513 |
| 514 void SetSAMLOfflineSigninTimeLimitPolicy(int limit); |
| 515 |
| 516 protected: |
| 517 policy::MockConfigurationPolicyProvider provider_; |
| 518 |
| 519 private: |
| 520 DISALLOW_COPY_AND_ASSIGN(SAMLPolicyTest); |
| 521 }; |
| 522 |
| 523 SAMLPolicyTest::SAMLPolicyTest() { |
| 524 } |
| 525 |
| 526 SAMLPolicyTest::~SAMLPolicyTest() { |
| 527 } |
| 528 |
| 529 void SAMLPolicyTest::SetUpInProcessBrowserTestFixture() { |
| 530 SamlTest::SetUpInProcessBrowserTestFixture(); |
| 531 |
| 532 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 533 .WillRepeatedly(Return(true)); |
| 534 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 535 } |
| 536 |
| 537 void SAMLPolicyTest::SetUpOnMainThread() { |
| 538 SamlTest::SetUpOnMainThread(); |
| 539 |
| 540 // Pretend that the test users' OAuth tokens are valid. |
| 541 UserManager::Get()->SaveUserOAuthStatus(kFirstSAMLUserEmail, |
| 542 User::OAUTH2_TOKEN_STATUS_VALID); |
| 543 UserManager::Get()->SaveUserOAuthStatus(kNonSAMLUserEmail, |
| 544 User::OAUTH2_TOKEN_STATUS_VALID); |
| 545 } |
| 546 |
| 547 void SAMLPolicyTest::SetSAMLOfflineSigninTimeLimitPolicy(int limit) { |
| 548 policy::PolicyMap policy; |
| 549 policy.Set(policy::key::kSAMLOfflineSigninTimeLimit, |
| 550 policy::POLICY_LEVEL_MANDATORY, |
| 551 policy::POLICY_SCOPE_USER, |
| 552 new base::FundamentalValue(limit), |
| 553 NULL); |
| 554 provider_.UpdateChromePolicy(policy); |
| 555 base::RunLoop().RunUntilIdle(); |
| 556 } |
| 557 |
| 558 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_NoSAML) { |
| 559 // Set the offline login time limit for SAML users to zero. |
| 560 SetSAMLOfflineSigninTimeLimitPolicy(0); |
| 561 |
| 562 WaitForSigninScreen(); |
| 563 |
| 564 // Log in without SAML. |
| 565 GetLoginDisplay()->ShowSigninScreenForCreds(kNonSAMLUserEmail, "password"); |
| 566 |
| 567 content::WindowedNotificationObserver( |
| 568 chrome::NOTIFICATION_SESSION_STARTED, |
| 569 content::NotificationService::AllSources()).Wait(); |
| 570 } |
| 571 |
| 572 // Verifies that the offline login time limit does not affect a user who |
| 573 // authenticated without SAML. |
| 574 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, NoSAML) { |
| 575 login_screen_load_observer_->Wait(); |
| 576 // Verify that offline login is allowed. |
| 577 JsExpect("document.querySelector('#pod-row .signin-button').hidden"); |
| 578 } |
| 579 |
| 580 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_SAMLNoLimit) { |
| 581 // Remove the offline login time limit for SAML users. |
| 582 SetSAMLOfflineSigninTimeLimitPolicy(-1); |
| 583 |
| 584 // Log in with SAML. |
| 585 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
| 586 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
| 587 |
| 588 SetSignFormField("Email", "fake_user"); |
| 589 SetSignFormField("Password", "fake_password"); |
| 590 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
| 591 |
| 592 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); |
| 593 |
| 594 SendConfirmPassword("fake_password"); |
| 595 content::WindowedNotificationObserver( |
| 596 chrome::NOTIFICATION_SESSION_STARTED, |
| 597 content::NotificationService::AllSources()).Wait(); |
| 598 } |
| 599 |
| 600 // Verifies that when no offline login time limit is set, a user who |
| 601 // authenticated with SAML is allowed to log in offline. |
| 602 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLNoLimit) { |
| 603 login_screen_load_observer_->Wait(); |
| 604 // Verify that offline login is allowed. |
| 605 JsExpect("document.querySelector('#pod-row .signin-button').hidden"); |
| 606 } |
| 607 |
| 608 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_SAMLZeroLimit) { |
| 609 // Set the offline login time limit for SAML users to zero. |
| 610 SetSAMLOfflineSigninTimeLimitPolicy(0); |
| 611 |
| 612 // Log in with SAML. |
| 613 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
| 614 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
| 615 |
| 616 SetSignFormField("Email", "fake_user"); |
| 617 SetSignFormField("Password", "fake_password"); |
| 618 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); |
| 619 |
| 620 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); |
| 621 |
| 622 SendConfirmPassword("fake_password"); |
| 623 content::WindowedNotificationObserver( |
| 624 chrome::NOTIFICATION_SESSION_STARTED, |
| 625 content::NotificationService::AllSources()).Wait(); |
| 626 } |
| 627 |
| 628 // Verifies that when the offline login time limit is exceeded for a user who |
| 629 // authenticated via SAML, that user is forced to log in online the next time. |
| 630 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLZeroLimit) { |
| 631 login_screen_load_observer_->Wait(); |
| 632 // Verify that offline login is not allowed. |
| 633 JsExpect("!document.querySelector('#pod-row .signin-button').hidden"); |
| 634 } |
488 | 635 |
489 } // namespace chromeos | 636 } // namespace chromeos |
OLD | NEW |