| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/signin/signin_manager.h" | 5 #include "chrome/browser/signin/signin_manager.h" |
| 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 ASSERT_NE(std::find(cookies_.begin(), cookies_.end(), "checkCookie = true"), | 325 ASSERT_NE(std::find(cookies_.begin(), cookies_.end(), "checkCookie = true"), |
| 326 cookies_.end()); | 326 cookies_.end()); |
| 327 | 327 |
| 328 // Should persist across resets. | 328 // Should persist across resets. |
| 329 manager_->Shutdown(); | 329 manager_->Shutdown(); |
| 330 manager_.reset(new SigninManager()); | 330 manager_.reset(new SigninManager()); |
| 331 manager_->Initialize(profile_.get()); | 331 manager_->Initialize(profile_.get()); |
| 332 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); | 332 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); |
| 333 } | 333 } |
| 334 | 334 |
| 335 TEST_F(SigninManagerTest, Prohibited) { | |
| 336 g_browser_process->local_state()->SetString( | |
| 337 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); | |
| 338 manager_->Initialize(profile_.get()); | |
| 339 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); | |
| 340 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com")); | |
| 341 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com")); | |
| 342 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com")); | |
| 343 EXPECT_FALSE(manager_->IsAllowedUsername("")); | |
| 344 } | |
| 345 | |
| 346 TEST_F(SigninManagerTest, TestAlternateWildcard) { | |
| 347 // Test to make sure we accept "*@google.com" as a pattern (treat it as if | |
| 348 // the admin entered ".*@google.com"). | |
| 349 g_browser_process->local_state()->SetString( | |
| 350 prefs::kGoogleServicesUsernamePattern, "*@google.com"); | |
| 351 manager_->Initialize(profile_.get()); | |
| 352 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); | |
| 353 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com")); | |
| 354 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com")); | |
| 355 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com")); | |
| 356 EXPECT_FALSE(manager_->IsAllowedUsername("")); | |
| 357 } | |
| 358 | |
| 359 TEST_F(SigninManagerTest, ProhibitedAtStartup) { | |
| 360 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | |
| 361 "monkey@invalid.com"); | |
| 362 g_browser_process->local_state()->SetString( | |
| 363 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); | |
| 364 manager_->Initialize(profile_.get()); | |
| 365 // Currently signed in user is prohibited by policy, so should be signed out. | |
| 366 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); | |
| 367 } | |
| 368 | |
| 369 TEST_F(SigninManagerTest, ProhibitedAfterStartup) { | |
| 370 std::string user("monkey@invalid.com"); | |
| 371 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); | |
| 372 manager_->Initialize(profile_.get()); | |
| 373 EXPECT_EQ(user, manager_->GetAuthenticatedUsername()); | |
| 374 // Update the profile - user should be signed out. | |
| 375 g_browser_process->local_state()->SetString( | |
| 376 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); | |
| 377 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); | |
| 378 } | |
| 379 | |
| 380 TEST_F(SigninManagerTest, SignInWithCredentials) { | 335 TEST_F(SigninManagerTest, SignInWithCredentials) { |
| 381 manager_->Initialize(profile_.get()); | 336 manager_->Initialize(profile_.get()); |
| 382 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); | 337 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); |
| 383 | 338 |
| 384 manager_->StartSignInWithCredentials("0", "user@gmail.com", "password"); | 339 manager_->StartSignInWithCredentials("0", "user@gmail.com", "password"); |
| 385 | 340 |
| 386 ExpectSignInWithCredentialsSuccess(); | 341 ExpectSignInWithCredentialsSuccess(); |
| 387 } | 342 } |
| 388 | 343 |
| 389 TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) { | 344 TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 GURL("http://accounts.google.com/ServiceLogin?service=chromiumsync"))); | 631 GURL("http://accounts.google.com/ServiceLogin?service=chromiumsync"))); |
| 677 // http, not https, should not be treated as web based signin. | 632 // http, not https, should not be treated as web based signin. |
| 678 EXPECT_FALSE(SigninManager::IsWebBasedSigninFlowURL( | 633 EXPECT_FALSE(SigninManager::IsWebBasedSigninFlowURL( |
| 679 GURL("http://accounts.google.com/ServiceLogin?service=googlemail"))); | 634 GURL("http://accounts.google.com/ServiceLogin?service=googlemail"))); |
| 680 // chromiumsync is double-embedded in a continue query param. | 635 // chromiumsync is double-embedded in a continue query param. |
| 681 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL( | 636 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL( |
| 682 GURL("https://accounts.google.com/CheckCookie?" | 637 GURL("https://accounts.google.com/CheckCookie?" |
| 683 "continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen-US%2Fchrome" | 638 "continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen-US%2Fchrome" |
| 684 "%2Fblank.html%3Fsource%3D3%26nonadv%3D1&service=chromiumsync"))); | 639 "%2Fblank.html%3Fsource%3D3%26nonadv%3D1&service=chromiumsync"))); |
| 685 } | 640 } |
| OLD | NEW |