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

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

Issue 143463009: Add policy that forces SAML users to log in online periodically (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits addressed. Created 6 years, 11 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 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 208 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
197 host_resolver()->AddRule("*", "127.0.0.1"); 209 host_resolver()->AddRule("*", "127.0.0.1");
198 } 210 }
199 211
200 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 212 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
201 command_line->AppendSwitch(switches::kLoginManager); 213 command_line->AppendSwitch(switches::kLoginManager);
202 command_line->AppendSwitch(switches::kForceLoginManagerInTests); 214 command_line->AppendSwitch(switches::kForceLoginManagerInTests);
203 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); 215 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking);
204 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 216 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
205 command_line->AppendSwitch(switches::kEnableSamlSignin); 217 command_line->AppendSwitch(switches::kEnableSamlSignin);
218 command_line->AppendSwitchASCII("remote-debugging-port", "9999");
Nikita (slow) 2014/01/23 17:50:09 nit: Debug change?
bartfab (slow) 2014/01/24 12:56:07 Oops. Thanks for the catch. Removed.
206 219
207 const GURL& server_url = embedded_test_server()->base_url(); 220 const GURL& server_url = embedded_test_server()->base_url();
208 221
209 std::string gaia_host("gaia"); 222 std::string gaia_host("gaia");
210 GURL::Replacements replace_gaia_host; 223 GURL::Replacements replace_gaia_host;
211 replace_gaia_host.SetHostStr(gaia_host); 224 replace_gaia_host.SetHostStr(gaia_host);
212 gaia_url_ = server_url.ReplaceComponents(replace_gaia_host); 225 gaia_url_ = server_url.ReplaceComponents(replace_gaia_host);
213 226
214 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url_.spec()); 227 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url_.spec());
215 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url_.spec()); 228 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url_.spec());
216 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, 229 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl,
217 gaia_url_.spec()); 230 gaia_url_.spec());
218 fake_gaia_.Initialize(); 231 fake_gaia_.Initialize();
219 232
220 std::string saml_idp_host("saml.idp"); 233 std::string saml_idp_host("saml.idp");
221 GURL::Replacements replace_saml_idp_host; 234 GURL::Replacements replace_saml_idp_host;
222 replace_saml_idp_host.SetHostStr(saml_idp_host); 235 replace_saml_idp_host.SetHostStr(saml_idp_host);
223 GURL saml_idp_url = server_url.ReplaceComponents(replace_saml_idp_host); 236 GURL saml_idp_url = server_url.ReplaceComponents(replace_saml_idp_host);
224 saml_idp_url = saml_idp_url.Resolve("/SAML/SSO"); 237 saml_idp_url = saml_idp_url.Resolve("/SAML/SSO");
225 238
226 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url_); 239 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url_);
227 fake_gaia_.RegisterSamlUser(kAnotherUserEmail, saml_idp_url); 240 fake_gaia_.RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url);
228 fake_gaia_.RegisterSamlUser(kUserEmail, saml_idp_url); 241 fake_gaia_.RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url);
229 } 242 }
230 243
231 virtual void SetUpOnMainThread() OVERRIDE { 244 virtual void SetUpOnMainThread() OVERRIDE {
232 FakeGaia::MergeSessionParams params; 245 FakeGaia::MergeSessionParams params;
233 params.auth_sid_cookie = kTestAuthSIDCookie; 246 params.auth_sid_cookie = kTestAuthSIDCookie;
234 params.auth_lsid_cookie = kTestAuthLSIDCookie; 247 params.auth_lsid_cookie = kTestAuthLSIDCookie;
235 params.auth_code = kTestAuthCode; 248 params.auth_code = kTestAuthCode;
236 params.refresh_token = kTestRefreshToken; 249 params.refresh_token = kTestRefreshToken;
237 params.access_token = kTestAuthLoginAccessToken; 250 params.access_token = kTestAuthLoginAccessToken;
238 params.gaia_uber_token = kTestGaiaUberToken; 251 params.gaia_uber_token = kTestGaiaUberToken;
239 params.session_sid_cookie = kTestSessionSIDCookie; 252 params.session_sid_cookie = kTestSessionSIDCookie;
240 params.session_lsid_cookie = kTestSessionLSIDCookie; 253 params.session_lsid_cookie = kTestSessionLSIDCookie;
241 params.email = kUserEmail; 254 params.email = kFirstSAMLUserEmail;
242 fake_gaia_.SetMergeSessionParams(params); 255 fake_gaia_.SetMergeSessionParams(params);
243 256
244 embedded_test_server()->RegisterRequestHandler( 257 embedded_test_server()->RegisterRequestHandler(
245 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); 258 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
246 embedded_test_server()->RegisterRequestHandler(base::Bind( 259 embedded_test_server()->RegisterRequestHandler(base::Bind(
247 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); 260 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_)));
248 261
249 // Restart the thread as the sandbox host process has already been spawned. 262 // Restart the thread as the sandbox host process has already been spawned.
250 embedded_test_server()->RestartThreadAndListen(); 263 embedded_test_server()->RestartThreadAndListen();
264
265 login_screen_load_observer_.reset(new content::WindowedNotificationObserver(
266 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
267 content::NotificationService::AllSources()));
251 } 268 }
252 269
253 virtual void CleanUpOnMainThread() OVERRIDE { 270 virtual void CleanUpOnMainThread() OVERRIDE {
254 // If the login display is still showing, exit gracefully. 271 // If the login display is still showing, exit gracefully.
255 if (LoginDisplayHostImpl::default_host()) { 272 if (LoginDisplayHostImpl::default_host()) {
256 base::MessageLoop::current()->PostTask(FROM_HERE, 273 base::MessageLoop::current()->PostTask(FROM_HERE,
257 base::Bind(&chrome::AttemptExit)); 274 base::Bind(&chrome::AttemptExit));
258 content::RunMessageLoop(); 275 content::RunMessageLoop();
259 } 276 }
260 } 277 }
261 278
262 WebUILoginDisplay* GetLoginDisplay() { 279 WebUILoginDisplay* GetLoginDisplay() {
263 ExistingUserController* controller = 280 ExistingUserController* controller =
264 ExistingUserController::current_controller(); 281 ExistingUserController::current_controller();
265 CHECK(controller); 282 CHECK(controller);
266 return static_cast<WebUILoginDisplay*>(controller->login_display()); 283 return static_cast<WebUILoginDisplay*>(controller->login_display());
267 } 284 }
268 285
269 void WaitForSigninScreen() { 286 void WaitForSigninScreen() {
270 WizardController::SkipPostLoginScreensForTesting(); 287 WizardController::SkipPostLoginScreensForTesting();
271 WizardController* wizard_controller = 288 WizardController* wizard_controller =
272 chromeos::WizardController::default_controller(); 289 chromeos::WizardController::default_controller();
273 CHECK(wizard_controller); 290 CHECK(wizard_controller);
274 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); 291 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
275 292
276 content::WindowedNotificationObserver( 293 login_screen_load_observer_->Wait();
277 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
278 content::NotificationService::AllSources()).Wait();
279 } 294 }
280 295
281 void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) { 296 void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) {
282 WaitForSigninScreen(); 297 WaitForSigninScreen();
283 298
284 if (!saml_load_injected_) { 299 if (!saml_load_injected_) {
285 saml_load_injected_ = true; 300 saml_load_injected_ = true;
286 301
287 ASSERT_TRUE(content::ExecuteScript( 302 ASSERT_TRUE(content::ExecuteScript(
288 GetLoginUI()->GetWebContents(), 303 GetLoginUI()->GetWebContents(),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Executes Js code in the auth iframe hosted by gaia_auth extension. 355 // Executes Js code in the auth iframe hosted by gaia_auth extension.
341 void ExecuteJsInSigninFrame(const std::string& js) { 356 void ExecuteJsInSigninFrame(const std::string& js) {
342 ASSERT_TRUE(content::ExecuteScriptInFrame( 357 ASSERT_TRUE(content::ExecuteScriptInFrame(
343 GetLoginUI()->GetWebContents(), 358 GetLoginUI()->GetWebContents(),
344 "//iframe[@id='signin-frame']\n//iframe", 359 "//iframe[@id='signin-frame']\n//iframe",
345 js)); 360 js));
346 } 361 }
347 362
348 FakeSamlIdp* fake_saml_idp() { return &fake_saml_idp_; } 363 FakeSamlIdp* fake_saml_idp() { return &fake_saml_idp_; }
349 364
365 protected:
366 scoped_ptr<content::WindowedNotificationObserver> login_screen_load_observer_;
367
350 private: 368 private:
351 GURL gaia_url_; 369 GURL gaia_url_;
352 FakeGaia fake_gaia_; 370 FakeGaia fake_gaia_;
353 FakeSamlIdp fake_saml_idp_; 371 FakeSamlIdp fake_saml_idp_;
354 372
355 bool saml_load_injected_; 373 bool saml_load_injected_;
356 374
357 DISALLOW_COPY_AND_ASSIGN(SamlTest); 375 DISALLOW_COPY_AND_ASSIGN(SamlTest);
358 }; 376 };
359 377
360 // Tests that signin frame should have 'saml' class and 'cancel' button is 378 // Tests that signin frame should have 'saml' class and 'cancel' button is
361 // visible when SAML IdP page is loaded. And 'cancel' button goes back to 379 // visible when SAML IdP page is loaded. And 'cancel' button goes back to
362 // gaia on clicking. 380 // gaia on clicking.
363 IN_PROC_BROWSER_TEST_F(SamlTest, SamlUI) { 381 IN_PROC_BROWSER_TEST_F(SamlTest, SamlUI) {
364 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 382 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
365 StartSamlAndWaitForIdpPageLoad(kUserEmail); 383 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
366 384
367 // Saml flow UI expectations. 385 // Saml flow UI expectations.
368 JsExpect("$('gaia-signin').classList.contains('saml')"); 386 JsExpect("$('gaia-signin').classList.contains('saml')");
369 JsExpect("!$('cancel-add-user-button').hidden"); 387 JsExpect("!$('cancel-add-user-button').hidden");
370 388
371 // Click on 'cancel'. 389 // Click on 'cancel'.
372 content::DOMMessageQueue message_queue; // Observe before 'cancel'. 390 content::DOMMessageQueue message_queue; // Observe before 'cancel'.
373 ASSERT_TRUE(content::ExecuteScript( 391 ASSERT_TRUE(content::ExecuteScript(
374 GetLoginUI()->GetWebContents(), 392 GetLoginUI()->GetWebContents(),
375 "$('cancel-add-user-button').click();")); 393 "$('cancel-add-user-button').click();"));
376 394
377 // Auth flow should change back to Gaia. 395 // Auth flow should change back to Gaia.
378 std::string message; 396 std::string message;
379 do { 397 do {
380 ASSERT_TRUE(message_queue.WaitForMessage(&message)); 398 ASSERT_TRUE(message_queue.WaitForMessage(&message));
381 } while (message != "\"GaiaLoaded\""); 399 } while (message != "\"GaiaLoaded\"");
382 400
383 // Saml flow is gone. 401 // Saml flow is gone.
384 JsExpect("!$('gaia-signin').classList.contains('saml')"); 402 JsExpect("!$('gaia-signin').classList.contains('saml')");
385 } 403 }
386 404
387 // Tests the sign-in flow when the credentials passing API is used. 405 // Tests the sign-in flow when the credentials passing API is used.
388 IN_PROC_BROWSER_TEST_F(SamlTest, CredentialPassingAPI) { 406 IN_PROC_BROWSER_TEST_F(SamlTest, CredentialPassingAPI) {
389 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); 407 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html");
390 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); 408 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html");
391 StartSamlAndWaitForIdpPageLoad(kUserEmail); 409 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
392 410
393 // Fill-in the SAML IdP form and submit. 411 // Fill-in the SAML IdP form and submit.
394 SetSignFormField("Email", "fake_user"); 412 SetSignFormField("Email", "fake_user");
395 SetSignFormField("Password", "fake_password"); 413 SetSignFormField("Password", "fake_password");
396 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 414 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
397 415
398 // Login should finish login and a session should start. 416 // Login should finish login and a session should start.
399 content::WindowedNotificationObserver( 417 content::WindowedNotificationObserver(
400 chrome::NOTIFICATION_SESSION_STARTED, 418 chrome::NOTIFICATION_SESSION_STARTED,
401 content::NotificationService::AllSources()).Wait(); 419 content::NotificationService::AllSources()).Wait();
402 } 420 }
403 421
404 // Tests the single password scraped flow. 422 // Tests the single password scraped flow.
405 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedSingle) { 423 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedSingle) {
406 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 424 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
407 StartSamlAndWaitForIdpPageLoad(kUserEmail); 425 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
408 426
409 // Fill-in the SAML IdP form and submit. 427 // Fill-in the SAML IdP form and submit.
410 SetSignFormField("Email", "fake_user"); 428 SetSignFormField("Email", "fake_user");
411 SetSignFormField("Password", "fake_password"); 429 SetSignFormField("Password", "fake_password");
412 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 430 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
413 431
414 // Lands on confirm password screen. 432 // Lands on confirm password screen.
415 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 433 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
416 434
417 // Enter an unknown password should go back to confirm password screen. 435 // Enter an unknown password should go back to confirm password screen.
418 SendConfirmPassword("wrong_password"); 436 SendConfirmPassword("wrong_password");
419 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 437 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
420 438
421 // Enter a known password should finish login and start session. 439 // Enter a known password should finish login and start session.
422 SendConfirmPassword("fake_password"); 440 SendConfirmPassword("fake_password");
423 content::WindowedNotificationObserver( 441 content::WindowedNotificationObserver(
424 chrome::NOTIFICATION_SESSION_STARTED, 442 chrome::NOTIFICATION_SESSION_STARTED,
425 content::NotificationService::AllSources()).Wait(); 443 content::NotificationService::AllSources()).Wait();
426 } 444 }
427 445
428 // Tests the multiple password scraped flow. 446 // Tests the multiple password scraped flow.
429 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedMultiple) { 447 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedMultiple) {
430 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_two_passwords.html"); 448 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_two_passwords.html");
431 449
432 StartSamlAndWaitForIdpPageLoad(kUserEmail); 450 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
433 451
434 SetSignFormField("Email", "fake_user"); 452 SetSignFormField("Email", "fake_user");
435 SetSignFormField("Password", "fake_password"); 453 SetSignFormField("Password", "fake_password");
436 SetSignFormField("Password1", "password1"); 454 SetSignFormField("Password1", "password1");
437 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 455 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
438 456
439 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 457 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
440 458
441 // Either scraped password should be able to sign-in. 459 // Either scraped password should be able to sign-in.
442 SendConfirmPassword("password1"); 460 SendConfirmPassword("password1");
443 content::WindowedNotificationObserver( 461 content::WindowedNotificationObserver(
444 chrome::NOTIFICATION_SESSION_STARTED, 462 chrome::NOTIFICATION_SESSION_STARTED,
445 content::NotificationService::AllSources()).Wait(); 463 content::NotificationService::AllSources()).Wait();
446 } 464 }
447 465
448 // Tests the no password scraped flow. 466 // Tests the no password scraped flow.
449 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedNone) { 467 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedNone) {
450 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_no_passwords.html"); 468 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_no_passwords.html");
451 469
452 StartSamlAndWaitForIdpPageLoad(kUserEmail); 470 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
453 471
454 SetSignFormField("Email", "fake_user"); 472 SetSignFormField("Email", "fake_user");
455 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 473 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
456 474
457 OobeScreenWaiter(OobeDisplay::SCREEN_MESSAGE_BOX).Wait(); 475 OobeScreenWaiter(OobeDisplay::SCREEN_MESSAGE_BOX).Wait();
458 JsExpect( 476 JsExpect(
459 "$('message-box-title').textContent == " 477 "$('message-box-title').textContent == "
460 "loadTimeData.getString('noPasswordWarningTitle')"); 478 "loadTimeData.getString('noPasswordWarningTitle')");
461 } 479 }
462 480
463 // Types |alice@example.com| into the GAIA login form but then authenticates as 481 // Types |bob@example.com| into the GAIA login form but then authenticates as
464 // |bob@example.com| via SAML. Verifies that the logged-in user is correctly 482 // |alice@example.com| via SAML. Verifies that the logged-in user is correctly
465 // identified as Bob. 483 // identified as Alice.
466 IN_PROC_BROWSER_TEST_F(SamlTest, UseAutenticatedUserEmailAddress) { 484 IN_PROC_BROWSER_TEST_F(SamlTest, UseAutenticatedUserEmailAddress) {
467 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 485 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
468 // Type |alice@example.com| into the GAIA login form. 486 // Type |bob@example.com| into the GAIA login form.
469 StartSamlAndWaitForIdpPageLoad(kAnotherUserEmail); 487 StartSamlAndWaitForIdpPageLoad(kSecondSAMLUserEmail);
470 488
471 // Authenticate as bob@example.com via SAML (the |Email| provided here is 489 // Authenticate as alice@example.com via SAML (the |Email| provided here is
472 // irrelevant - the authenticated user's e-mail address that FakeGAIA 490 // irrelevant - the authenticated user's e-mail address that FakeGAIA
473 // reports was set via SetMergeSessionParams()). 491 // reports was set via SetMergeSessionParams()).
474 SetSignFormField("Email", "fake_user"); 492 SetSignFormField("Email", "fake_user");
475 SetSignFormField("Password", "fake_password"); 493 SetSignFormField("Password", "fake_password");
476 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 494 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
477 495
478 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 496 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
479 497
480 SendConfirmPassword("fake_password"); 498 SendConfirmPassword("fake_password");
481 content::WindowedNotificationObserver( 499 content::WindowedNotificationObserver(
482 chrome::NOTIFICATION_SESSION_STARTED, 500 chrome::NOTIFICATION_SESSION_STARTED,
483 content::NotificationService::AllSources()).Wait(); 501 content::NotificationService::AllSources()).Wait();
484 const User* user = UserManager::Get()->GetActiveUser(); 502 const User* user = UserManager::Get()->GetActiveUser();
485 ASSERT_TRUE(user); 503 ASSERT_TRUE(user);
486 EXPECT_EQ(kUserEmail, user->email()); 504 EXPECT_EQ(kFirstSAMLUserEmail, user->email());
487 } 505 }
488 506
507 class SAMLPolicyTest : public SamlTest {
508 public:
509 SAMLPolicyTest();
510 virtual ~SAMLPolicyTest();
511
512 // SamlTest:
513 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
514 virtual void SetUpOnMainThread() OVERRIDE;
515
516 void SetSAMLOfflineSigninTimeLimitPolicy(int limit);
517
518 protected:
519 policy::MockConfigurationPolicyProvider provider_;
520
521 private:
522 DISALLOW_COPY_AND_ASSIGN(SAMLPolicyTest);
523 };
524
525 SAMLPolicyTest::SAMLPolicyTest() {
526 }
527
528 SAMLPolicyTest::~SAMLPolicyTest() {
529 }
530
531 void SAMLPolicyTest::SetUpInProcessBrowserTestFixture() {
532 SamlTest::SetUpInProcessBrowserTestFixture();
533
534 EXPECT_CALL(provider_, IsInitializationComplete(_))
535 .WillRepeatedly(Return(true));
536 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
537 }
538
539 void SAMLPolicyTest::SetUpOnMainThread() {
540 SamlTest::SetUpOnMainThread();
541
542 // Pretend that the test users' OAuth tokens are valid.
543 UserManager::Get()->SaveUserOAuthStatus(kFirstSAMLUserEmail,
544 User::OAUTH2_TOKEN_STATUS_VALID);
545 UserManager::Get()->SaveUserOAuthStatus(kNonSAMLUserEmail,
Nikita (slow) 2014/01/23 17:50:09 nit: Indent
bartfab (slow) 2014/01/24 12:56:07 Done.
546 User::OAUTH2_TOKEN_STATUS_VALID);
547 }
548
549 void SAMLPolicyTest::SetSAMLOfflineSigninTimeLimitPolicy(int limit) {
550 policy::PolicyMap policy;
551 policy.Set(policy::key::kSAMLOfflineSigninTimeLimit,
552 policy::POLICY_LEVEL_MANDATORY,
553 policy::POLICY_SCOPE_USER,
554 new base::FundamentalValue(limit),
555 NULL);
556 provider_.UpdateChromePolicy(policy);
557 base::RunLoop().RunUntilIdle();
558 }
559
560 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_NoSAML) {
561 // Set the offline login time limit for SAML users to zero.
562 SetSAMLOfflineSigninTimeLimitPolicy(0);
563
564 WaitForSigninScreen();
565
566 // Log in without SAML.
567 GetLoginDisplay()->ShowSigninScreenForCreds(kNonSAMLUserEmail, "password");
568
569 content::WindowedNotificationObserver(
570 chrome::NOTIFICATION_SESSION_STARTED,
571 content::NotificationService::AllSources()).Wait();
572 }
573
574 // Verifies that the offline login time limit does not affect a user who
575 // authenticated without SAML.
576 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, NoSAML) {
577 login_screen_load_observer_->Wait();
578 // Verify that offline login is allowed.
579 JsExpect("document.querySelector('#pod-row .signin-button').hidden");
580 }
581
582 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_SAMLNoLimit) {
583 // Remove the offline login time limit for SAML users.
584 SetSAMLOfflineSigninTimeLimitPolicy(-1);
585
586 // Log in with SAML.
587 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
588 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
589
590 SetSignFormField("Email", "fake_user");
591 SetSignFormField("Password", "fake_password");
592 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
593
594 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
595
596 SendConfirmPassword("fake_password");
597 content::WindowedNotificationObserver(
598 chrome::NOTIFICATION_SESSION_STARTED,
599 content::NotificationService::AllSources()).Wait();
600 }
601
602 // Verifies that when no offline login time limit is set, a user who
603 // authenticated with SAML is allowed to log in offline.
604 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLNoLimit) {
605 login_screen_load_observer_->Wait();
606 // Verify that offline login is allowed.
607 JsExpect("document.querySelector('#pod-row .signin-button').hidden");
608 }
609
610 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_SAMLZeroLimit) {
611 // Set the offline login time limit for SAML users to zero.
612 SetSAMLOfflineSigninTimeLimitPolicy(0);
613
614 // Log in with SAML.
615 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
616 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
617
618 SetSignFormField("Email", "fake_user");
619 SetSignFormField("Password", "fake_password");
620 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
621
622 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
623
624 SendConfirmPassword("fake_password");
625 content::WindowedNotificationObserver(
626 chrome::NOTIFICATION_SESSION_STARTED,
627 content::NotificationService::AllSources()).Wait();
628 }
629
630 // Verifies that when the offline login time limit is exceeded for a user who
631 // authenticated via SAML, that user is forced to log in online the next time.
632 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLZeroLimit) {
633 login_screen_load_observer_->Wait();
634 // Verify that offline login is not allowed.
635 JsExpect("!document.querySelector('#pod-row .signin-button').hidden");
636 }
489 637
490 } // namespace chromeos 638 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698