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