| OLD | NEW |
| 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 "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" | 5 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
| 10 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 ~SAMLOfflineSigninLimiterTest() override; | 39 ~SAMLOfflineSigninLimiterTest() override; |
| 40 | 40 |
| 41 // testing::Test: | 41 // testing::Test: |
| 42 void SetUp() override; | 42 void SetUp() override; |
| 43 void TearDown() override; | 43 void TearDown() override; |
| 44 | 44 |
| 45 void DestroyLimiter(); | 45 void DestroyLimiter(); |
| 46 void CreateLimiter(); | 46 void CreateLimiter(); |
| 47 | 47 |
| 48 void SetUpUserManager(); | 48 void SetUpUserManager(); |
| 49 | |
| 50 const AccountId test_account_id_ = AccountId::FromUserEmail(kTestUser); | |
| 51 | |
| 52 TestingPrefServiceSimple* GetTestingLocalState(); | 49 TestingPrefServiceSimple* GetTestingLocalState(); |
| 53 | 50 |
| 54 scoped_refptr<base::TestSimpleTaskRunner> runner_; | 51 scoped_refptr<base::TestSimpleTaskRunner> runner_; |
| 55 base::ThreadTaskRunnerHandle runner_handle_; | 52 base::ThreadTaskRunnerHandle runner_handle_; |
| 56 | 53 |
| 57 MockUserManager* user_manager_; // Not owned. | 54 MockUserManager* user_manager_; // Not owned. |
| 58 ScopedUserManagerEnabler user_manager_enabler_; | 55 ScopedUserManagerEnabler user_manager_enabler_; |
| 59 | 56 |
| 60 scoped_ptr<TestingProfile> profile_; | 57 scoped_ptr<TestingProfile> profile_; |
| 61 base::SimpleTestClock clock_; | 58 base::SimpleTestClock clock_; |
| 62 | 59 |
| 63 SAMLOfflineSigninLimiter* limiter_; // Owned. | 60 SAMLOfflineSigninLimiter* limiter_; // Owned. |
| 64 | 61 |
| 65 TestingPrefServiceSimple testing_local_state_; | 62 TestingPrefServiceSimple testing_local_state_; |
| 66 | 63 |
| 67 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); | 64 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); |
| 68 }; | 65 }; |
| 69 | 66 |
| 70 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() | 67 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() |
| 71 : runner_(new base::TestSimpleTaskRunner), | 68 : runner_(new base::TestSimpleTaskRunner), |
| 72 runner_handle_(runner_), | 69 runner_handle_(runner_), |
| 73 user_manager_(new MockUserManager), | 70 user_manager_(new MockUserManager), |
| 74 user_manager_enabler_(user_manager_), | 71 user_manager_enabler_(user_manager_), |
| 75 limiter_(NULL) {} | 72 limiter_(NULL) { |
| 73 } |
| 76 | 74 |
| 77 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() { | 75 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() { |
| 78 DestroyLimiter(); | 76 DestroyLimiter(); |
| 79 Mock::VerifyAndClearExpectations(user_manager_); | 77 Mock::VerifyAndClearExpectations(user_manager_); |
| 80 EXPECT_CALL(*user_manager_, Shutdown()).Times(1); | 78 EXPECT_CALL(*user_manager_, Shutdown()).Times(1); |
| 81 EXPECT_CALL(*user_manager_, RemoveSessionStateObserver(_)).Times(1); | 79 EXPECT_CALL(*user_manager_, RemoveSessionStateObserver(_)).Times(1); |
| 82 profile_.reset(); | 80 profile_.reset(); |
| 83 TestingBrowserProcess::DeleteInstance(); | 81 TestingBrowserProcess::DeleteInstance(); |
| 84 } | 82 } |
| 85 | 83 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 | 96 |
| 99 void SAMLOfflineSigninLimiterTest::SetUpUserManager() { | 97 void SAMLOfflineSigninLimiterTest::SetUpUserManager() { |
| 100 EXPECT_CALL(*user_manager_, GetLocalState()) | 98 EXPECT_CALL(*user_manager_, GetLocalState()) |
| 101 .WillRepeatedly(Return(GetTestingLocalState())); | 99 .WillRepeatedly(Return(GetTestingLocalState())); |
| 102 } | 100 } |
| 103 | 101 |
| 104 void SAMLOfflineSigninLimiterTest::SetUp() { | 102 void SAMLOfflineSigninLimiterTest::SetUp() { |
| 105 profile_.reset(new TestingProfile); | 103 profile_.reset(new TestingProfile); |
| 106 | 104 |
| 107 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); | 105 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); |
| 108 user_manager_->AddUser(test_account_id_); | 106 user_manager_->AddUser(kTestUser); |
| 109 profile_->set_profile_name(kTestUser); | 107 profile_->set_profile_name(kTestUser); |
| 110 clock_.Advance(base::TimeDelta::FromHours(1)); | 108 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 111 | 109 |
| 112 user_manager_->RegisterPrefs(GetTestingLocalState()->registry()); | 110 user_manager_->RegisterPrefs(GetTestingLocalState()->registry()); |
| 113 SetUpUserManager(); | 111 SetUpUserManager(); |
| 114 } | 112 } |
| 115 | 113 |
| 116 TestingPrefServiceSimple* SAMLOfflineSigninLimiterTest::GetTestingLocalState() { | 114 TestingPrefServiceSimple* SAMLOfflineSigninLimiterTest::GetTestingLocalState() { |
| 117 return &testing_local_state_; | 115 return &testing_local_state_; |
| 118 } | 116 } |
| 119 | 117 |
| 120 void SAMLOfflineSigninLimiterTest::TearDown() { | 118 void SAMLOfflineSigninLimiterTest::TearDown() { |
| 121 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL); | 119 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL); |
| 122 } | 120 } |
| 123 | 121 |
| 124 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) { | 122 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) { |
| 125 PrefService* prefs = profile_->GetPrefs(); | 123 PrefService* prefs = profile_->GetPrefs(); |
| 126 | 124 |
| 127 // Set the time of last login with SAML. | 125 // Set the time of last login with SAML. |
| 128 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 126 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 129 clock_.Now().ToInternalValue()); | 127 clock_.Now().ToInternalValue()); |
| 130 | 128 |
| 131 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 129 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 132 // online login and the time of last login with SAML are cleared. | 130 // online login and the time of last login with SAML are cleared. |
| 133 CreateLimiter(); | 131 CreateLimiter(); |
| 134 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 132 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 135 .Times(1); | 133 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 136 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 137 .Times(0); | |
| 138 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 134 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 139 | 135 |
| 140 const PrefService::Preference* pref = | 136 const PrefService::Preference* pref = |
| 141 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 137 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 142 ASSERT_TRUE(pref); | 138 ASSERT_TRUE(pref); |
| 143 EXPECT_FALSE(pref->HasUserSetting()); | 139 EXPECT_FALSE(pref->HasUserSetting()); |
| 144 | 140 |
| 145 // Verify that no timer is running. | 141 // Verify that no timer is running. |
| 146 EXPECT_FALSE(runner_->HasPendingTask()); | 142 EXPECT_FALSE(runner_->HasPendingTask()); |
| 147 | 143 |
| 148 // Log out. Verify that the flag enforcing online login is not set. | 144 // Log out. Verify that the flag enforcing online login is not set. |
| 149 DestroyLimiter(); | 145 DestroyLimiter(); |
| 150 | 146 |
| 151 // Authenticate offline. Verify that the flag enforcing online login is not | 147 // Authenticate offline. Verify that the flag enforcing online login is not |
| 152 // changed and the time of last login with SAML is not set. | 148 // changed and the time of last login with SAML is not set. |
| 153 CreateLimiter(); | 149 CreateLimiter(); |
| 154 Mock::VerifyAndClearExpectations(user_manager_); | 150 Mock::VerifyAndClearExpectations(user_manager_); |
| 155 SetUpUserManager(); | 151 SetUpUserManager(); |
| 156 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 152 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 157 .Times(0); | 153 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 158 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 159 .Times(0); | |
| 160 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 154 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 161 | 155 |
| 162 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 156 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 163 ASSERT_TRUE(pref); | 157 ASSERT_TRUE(pref); |
| 164 EXPECT_FALSE(pref->HasUserSetting()); | 158 EXPECT_FALSE(pref->HasUserSetting()); |
| 165 | 159 |
| 166 // Verify that no timer is running. | 160 // Verify that no timer is running. |
| 167 EXPECT_FALSE(runner_->HasPendingTask()); | 161 EXPECT_FALSE(runner_->HasPendingTask()); |
| 168 } | 162 } |
| 169 | 163 |
| 170 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLNoLimit) { | 164 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLNoLimit) { |
| 171 PrefService* prefs = profile_->GetPrefs(); | 165 PrefService* prefs = profile_->GetPrefs(); |
| 172 | 166 |
| 173 // Remove the time limit. | 167 // Remove the time limit. |
| 174 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 168 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 175 | 169 |
| 176 // Set the time of last login with SAML. | 170 // Set the time of last login with SAML. |
| 177 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 171 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 178 clock_.Now().ToInternalValue()); | 172 clock_.Now().ToInternalValue()); |
| 179 | 173 |
| 180 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 174 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 181 // online login and the time of last login with SAML are cleared. | 175 // online login and the time of last login with SAML are cleared. |
| 182 CreateLimiter(); | 176 CreateLimiter(); |
| 183 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 177 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 184 .Times(1); | 178 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 185 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 186 .Times(0); | |
| 187 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 179 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 188 | 180 |
| 189 const PrefService::Preference* pref = | 181 const PrefService::Preference* pref = |
| 190 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 182 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 191 ASSERT_TRUE(pref); | 183 ASSERT_TRUE(pref); |
| 192 EXPECT_FALSE(pref->HasUserSetting()); | 184 EXPECT_FALSE(pref->HasUserSetting()); |
| 193 | 185 |
| 194 // Verify that no timer is running. | 186 // Verify that no timer is running. |
| 195 EXPECT_FALSE(runner_->HasPendingTask()); | 187 EXPECT_FALSE(runner_->HasPendingTask()); |
| 196 | 188 |
| 197 // Log out. Verify that the flag enforcing online login is not set. | 189 // Log out. Verify that the flag enforcing online login is not set. |
| 198 DestroyLimiter(); | 190 DestroyLimiter(); |
| 199 | 191 |
| 200 // Authenticate offline. Verify that the flag enforcing online login is not | 192 // Authenticate offline. Verify that the flag enforcing online login is not |
| 201 // changed and the time of last login with SAML is not set. | 193 // changed and the time of last login with SAML is not set. |
| 202 CreateLimiter(); | 194 CreateLimiter(); |
| 203 Mock::VerifyAndClearExpectations(user_manager_); | 195 Mock::VerifyAndClearExpectations(user_manager_); |
| 204 SetUpUserManager(); | 196 SetUpUserManager(); |
| 205 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 197 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 206 .Times(0); | 198 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 207 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 208 .Times(0); | |
| 209 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 199 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 210 | 200 |
| 211 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 201 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 212 ASSERT_TRUE(pref); | 202 ASSERT_TRUE(pref); |
| 213 EXPECT_FALSE(pref->HasUserSetting()); | 203 EXPECT_FALSE(pref->HasUserSetting()); |
| 214 | 204 |
| 215 // Verify that no timer is running. | 205 // Verify that no timer is running. |
| 216 EXPECT_FALSE(runner_->HasPendingTask()); | 206 EXPECT_FALSE(runner_->HasPendingTask()); |
| 217 } | 207 } |
| 218 | 208 |
| 219 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLZeroLimit) { | 209 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLZeroLimit) { |
| 220 PrefService* prefs = profile_->GetPrefs(); | 210 PrefService* prefs = profile_->GetPrefs(); |
| 221 | 211 |
| 222 // Set a zero time limit. | 212 // Set a zero time limit. |
| 223 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 213 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 224 | 214 |
| 225 // Set the time of last login with SAML. | 215 // Set the time of last login with SAML. |
| 226 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 216 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 227 clock_.Now().ToInternalValue()); | 217 clock_.Now().ToInternalValue()); |
| 228 | 218 |
| 229 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 219 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 230 // online login and the time of last login with SAML are cleared. | 220 // online login and the time of last login with SAML are cleared. |
| 231 CreateLimiter(); | 221 CreateLimiter(); |
| 232 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 222 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 233 .Times(1); | 223 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 234 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 235 .Times(0); | |
| 236 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 224 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 237 | 225 |
| 238 const PrefService::Preference* pref = | 226 const PrefService::Preference* pref = |
| 239 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 227 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 240 ASSERT_TRUE(pref); | 228 ASSERT_TRUE(pref); |
| 241 EXPECT_FALSE(pref->HasUserSetting()); | 229 EXPECT_FALSE(pref->HasUserSetting()); |
| 242 | 230 |
| 243 // Verify that no timer is running. | 231 // Verify that no timer is running. |
| 244 EXPECT_FALSE(runner_->HasPendingTask()); | 232 EXPECT_FALSE(runner_->HasPendingTask()); |
| 245 | 233 |
| 246 // Log out. Verify that the flag enforcing online login is not set. | 234 // Log out. Verify that the flag enforcing online login is not set. |
| 247 DestroyLimiter(); | 235 DestroyLimiter(); |
| 248 | 236 |
| 249 // Authenticate offline. Verify that the flag enforcing online login is not | 237 // Authenticate offline. Verify that the flag enforcing online login is not |
| 250 // changed and the time of last login with SAML is not set. | 238 // changed and the time of last login with SAML is not set. |
| 251 CreateLimiter(); | 239 CreateLimiter(); |
| 252 Mock::VerifyAndClearExpectations(user_manager_); | 240 Mock::VerifyAndClearExpectations(user_manager_); |
| 253 SetUpUserManager(); | 241 SetUpUserManager(); |
| 254 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 242 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 255 .Times(0); | 243 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 256 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 257 .Times(0); | |
| 258 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 244 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 259 | 245 |
| 260 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 246 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 261 ASSERT_TRUE(pref); | 247 ASSERT_TRUE(pref); |
| 262 EXPECT_FALSE(pref->HasUserSetting()); | 248 EXPECT_FALSE(pref->HasUserSetting()); |
| 263 | 249 |
| 264 // Verify that no timer is running. | 250 // Verify that no timer is running. |
| 265 EXPECT_FALSE(runner_->HasPendingTask()); | 251 EXPECT_FALSE(runner_->HasPendingTask()); |
| 266 } | 252 } |
| 267 | 253 |
| 268 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLSetLimitWhileLoggedIn) { | 254 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLSetLimitWhileLoggedIn) { |
| 269 PrefService* prefs = profile_->GetPrefs(); | 255 PrefService* prefs = profile_->GetPrefs(); |
| 270 | 256 |
| 271 // Remove the time limit. | 257 // Remove the time limit. |
| 272 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 258 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 273 | 259 |
| 274 // Set the time of last login with SAML. | 260 // Set the time of last login with SAML. |
| 275 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 261 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 276 clock_.Now().ToInternalValue()); | 262 clock_.Now().ToInternalValue()); |
| 277 | 263 |
| 278 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 264 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 279 // online login and the time of last login with SAML are cleared. | 265 // online login and the time of last login with SAML are cleared. |
| 280 CreateLimiter(); | 266 CreateLimiter(); |
| 281 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 267 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 282 .Times(1); | 268 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 283 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 284 .Times(0); | |
| 285 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 269 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 286 | 270 |
| 287 const PrefService::Preference* pref = | 271 const PrefService::Preference* pref = |
| 288 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 272 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 289 ASSERT_TRUE(pref); | 273 ASSERT_TRUE(pref); |
| 290 EXPECT_FALSE(pref->HasUserSetting()); | 274 EXPECT_FALSE(pref->HasUserSetting()); |
| 291 | 275 |
| 292 // Verify that no timer is running. | 276 // Verify that no timer is running. |
| 293 EXPECT_FALSE(runner_->HasPendingTask()); | 277 EXPECT_FALSE(runner_->HasPendingTask()); |
| 294 | 278 |
| 295 // Set a zero time limit. | 279 // Set a zero time limit. |
| 296 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 280 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 297 | 281 |
| 298 // Verify that no timer is running. | 282 // Verify that no timer is running. |
| 299 EXPECT_FALSE(runner_->HasPendingTask()); | 283 EXPECT_FALSE(runner_->HasPendingTask()); |
| 300 } | 284 } |
| 301 | 285 |
| 302 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLRemoveLimitWhileLoggedIn) { | 286 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLRemoveLimitWhileLoggedIn) { |
| 303 PrefService* prefs = profile_->GetPrefs(); | 287 PrefService* prefs = profile_->GetPrefs(); |
| 304 | 288 |
| 305 // Set the time of last login with SAML. | 289 // Set the time of last login with SAML. |
| 306 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 290 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 307 clock_.Now().ToInternalValue()); | 291 clock_.Now().ToInternalValue()); |
| 308 | 292 |
| 309 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 293 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 310 // online login and the time of last login with SAML are cleared. | 294 // online login and the time of last login with SAML are cleared. |
| 311 CreateLimiter(); | 295 CreateLimiter(); |
| 312 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 296 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 313 .Times(1); | 297 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 314 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 315 .Times(0); | |
| 316 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 298 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 317 | 299 |
| 318 const PrefService::Preference* pref = | 300 const PrefService::Preference* pref = |
| 319 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 301 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 320 ASSERT_TRUE(pref); | 302 ASSERT_TRUE(pref); |
| 321 EXPECT_FALSE(pref->HasUserSetting()); | 303 EXPECT_FALSE(pref->HasUserSetting()); |
| 322 | 304 |
| 323 // Verify that no timer is running. | 305 // Verify that no timer is running. |
| 324 EXPECT_FALSE(runner_->HasPendingTask()); | 306 EXPECT_FALSE(runner_->HasPendingTask()); |
| 325 | 307 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 336 // Set the time of last login with SAML. | 318 // Set the time of last login with SAML. |
| 337 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 319 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 338 clock_.Now().ToInternalValue()); | 320 clock_.Now().ToInternalValue()); |
| 339 | 321 |
| 340 // Advance time by four weeks. | 322 // Advance time by four weeks. |
| 341 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 323 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 342 | 324 |
| 343 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 325 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 344 // online login and the time of last login with SAML are cleared. | 326 // online login and the time of last login with SAML are cleared. |
| 345 CreateLimiter(); | 327 CreateLimiter(); |
| 346 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 328 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 347 .Times(1); | 329 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 348 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 349 .Times(0); | |
| 350 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 330 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 351 | 331 |
| 352 const PrefService::Preference* pref = | 332 const PrefService::Preference* pref = |
| 353 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 333 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 354 ASSERT_TRUE(pref); | 334 ASSERT_TRUE(pref); |
| 355 EXPECT_FALSE(pref->HasUserSetting()); | 335 EXPECT_FALSE(pref->HasUserSetting()); |
| 356 | 336 |
| 357 // Verify that no timer is running. | 337 // Verify that no timer is running. |
| 358 EXPECT_FALSE(runner_->HasPendingTask()); | 338 EXPECT_FALSE(runner_->HasPendingTask()); |
| 359 } | 339 } |
| 360 | 340 |
| 361 TEST_F(SAMLOfflineSigninLimiterTest, SAMLDefaultLimit) { | 341 TEST_F(SAMLOfflineSigninLimiterTest, SAMLDefaultLimit) { |
| 362 PrefService* prefs = profile_->GetPrefs(); | 342 PrefService* prefs = profile_->GetPrefs(); |
| 363 | 343 |
| 364 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 344 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 365 // login is cleared and the time of last login with SAML is set. | 345 // login is cleared and the time of last login with SAML is set. |
| 366 CreateLimiter(); | 346 CreateLimiter(); |
| 367 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 347 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 368 .Times(1); | 348 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 369 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 370 .Times(0); | |
| 371 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 349 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 372 | 350 |
| 373 base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 351 base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 374 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 352 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 375 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 353 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 376 | 354 |
| 377 // Verify that the timer is running. | 355 // Verify that the timer is running. |
| 378 EXPECT_TRUE(runner_->HasPendingTask()); | 356 EXPECT_TRUE(runner_->HasPendingTask()); |
| 379 | 357 |
| 380 // Log out. Verify that the flag enforcing online login is not set. | 358 // Log out. Verify that the flag enforcing online login is not set. |
| 381 DestroyLimiter(); | 359 DestroyLimiter(); |
| 382 | 360 |
| 383 // Advance time by an hour. | 361 // Advance time by an hour. |
| 384 clock_.Advance(base::TimeDelta::FromHours(1)); | 362 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 385 | 363 |
| 386 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 364 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 387 // login is cleared and the time of last login with SAML is updated. | 365 // login is cleared and the time of last login with SAML is updated. |
| 388 CreateLimiter(); | 366 CreateLimiter(); |
| 389 Mock::VerifyAndClearExpectations(user_manager_); | 367 Mock::VerifyAndClearExpectations(user_manager_); |
| 390 SetUpUserManager(); | 368 SetUpUserManager(); |
| 391 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 369 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 392 .Times(1); | 370 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 393 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 394 .Times(0); | |
| 395 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 371 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 396 | 372 |
| 397 last_gaia_signin_time = base::Time::FromInternalValue( | 373 last_gaia_signin_time = base::Time::FromInternalValue( |
| 398 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 374 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 399 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 375 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 400 | 376 |
| 401 // Verify that the timer is running. | 377 // Verify that the timer is running. |
| 402 EXPECT_TRUE(runner_->HasPendingTask()); | 378 EXPECT_TRUE(runner_->HasPendingTask()); |
| 403 | 379 |
| 404 // Log out. Verify that the flag enforcing online login is not set. | 380 // Log out. Verify that the flag enforcing online login is not set. |
| 405 DestroyLimiter(); | 381 DestroyLimiter(); |
| 406 | 382 |
| 407 // Advance time by an hour. | 383 // Advance time by an hour. |
| 408 const base::Time gaia_signin_time = clock_.Now(); | 384 const base::Time gaia_signin_time = clock_.Now(); |
| 409 clock_.Advance(base::TimeDelta::FromHours(1)); | 385 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 410 | 386 |
| 411 // Authenticate offline. Verify that the flag enforcing online login and the | 387 // Authenticate offline. Verify that the flag enforcing online login and the |
| 412 // time of last login with SAML are not changed. | 388 // time of last login with SAML are not changed. |
| 413 CreateLimiter(); | 389 CreateLimiter(); |
| 414 Mock::VerifyAndClearExpectations(user_manager_); | 390 Mock::VerifyAndClearExpectations(user_manager_); |
| 415 SetUpUserManager(); | 391 SetUpUserManager(); |
| 416 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 392 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 417 .Times(0); | 393 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 418 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 419 .Times(0); | |
| 420 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 394 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 421 | 395 |
| 422 last_gaia_signin_time = base::Time::FromInternalValue( | 396 last_gaia_signin_time = base::Time::FromInternalValue( |
| 423 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 397 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 424 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 398 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 425 | 399 |
| 426 // Verify that the timer is running. | 400 // Verify that the timer is running. |
| 427 EXPECT_TRUE(runner_->HasPendingTask()); | 401 EXPECT_TRUE(runner_->HasPendingTask()); |
| 428 | 402 |
| 429 // Advance time by four weeks. | 403 // Advance time by four weeks. |
| 430 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 404 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 431 | 405 |
| 432 // Allow the timer to fire. Verify that the flag enforcing online login is | 406 // Allow the timer to fire. Verify that the flag enforcing online login is |
| 433 // set. | 407 // set. |
| 434 Mock::VerifyAndClearExpectations(user_manager_); | 408 Mock::VerifyAndClearExpectations(user_manager_); |
| 435 SetUpUserManager(); | 409 SetUpUserManager(); |
| 436 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 410 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 437 .Times(0); | 411 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); |
| 438 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 439 .Times(1); | |
| 440 runner_->RunPendingTasks(); | 412 runner_->RunPendingTasks(); |
| 441 } | 413 } |
| 442 | 414 |
| 443 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) { | 415 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) { |
| 444 PrefService* prefs = profile_->GetPrefs(); | 416 PrefService* prefs = profile_->GetPrefs(); |
| 445 | 417 |
| 446 // Remove the time limit. | 418 // Remove the time limit. |
| 447 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 419 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 448 | 420 |
| 449 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 421 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 450 // login is cleared and the time of last login with SAML is set. | 422 // login is cleared and the time of last login with SAML is set. |
| 451 CreateLimiter(); | 423 CreateLimiter(); |
| 452 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 424 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 453 .Times(1); | 425 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 454 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 455 .Times(0); | |
| 456 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 426 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 457 | 427 |
| 458 base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 428 base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 459 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 429 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 460 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 430 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 461 | 431 |
| 462 // Verify that no timer is running. | 432 // Verify that no timer is running. |
| 463 EXPECT_FALSE(runner_->HasPendingTask()); | 433 EXPECT_FALSE(runner_->HasPendingTask()); |
| 464 | 434 |
| 465 // Log out. Verify that the flag enforcing online login is not set. | 435 // Log out. Verify that the flag enforcing online login is not set. |
| 466 DestroyLimiter(); | 436 DestroyLimiter(); |
| 467 | 437 |
| 468 // Advance time by an hour. | 438 // Advance time by an hour. |
| 469 clock_.Advance(base::TimeDelta::FromHours(1)); | 439 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 470 | 440 |
| 471 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 441 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 472 // login is cleared and the time of last login with SAML is updated. | 442 // login is cleared and the time of last login with SAML is updated. |
| 473 CreateLimiter(); | 443 CreateLimiter(); |
| 474 Mock::VerifyAndClearExpectations(user_manager_); | 444 Mock::VerifyAndClearExpectations(user_manager_); |
| 475 SetUpUserManager(); | 445 SetUpUserManager(); |
| 476 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 446 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 477 .Times(1); | 447 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 478 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 479 .Times(0); | |
| 480 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 448 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 481 | 449 |
| 482 last_gaia_signin_time = base::Time::FromInternalValue( | 450 last_gaia_signin_time = base::Time::FromInternalValue( |
| 483 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 451 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 484 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 452 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 485 | 453 |
| 486 // Verify that no timer is running. | 454 // Verify that no timer is running. |
| 487 EXPECT_FALSE(runner_->HasPendingTask()); | 455 EXPECT_FALSE(runner_->HasPendingTask()); |
| 488 | 456 |
| 489 // Log out. Verify that the flag enforcing online login is not set. | 457 // Log out. Verify that the flag enforcing online login is not set. |
| 490 DestroyLimiter(); | 458 DestroyLimiter(); |
| 491 | 459 |
| 492 // Advance time by an hour. | 460 // Advance time by an hour. |
| 493 const base::Time gaia_signin_time = clock_.Now(); | 461 const base::Time gaia_signin_time = clock_.Now(); |
| 494 clock_.Advance(base::TimeDelta::FromHours(1)); | 462 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 495 | 463 |
| 496 // Authenticate offline. Verify that the flag enforcing online login and the | 464 // Authenticate offline. Verify that the flag enforcing online login and the |
| 497 // time of last login with SAML are not changed. | 465 // time of last login with SAML are not changed. |
| 498 CreateLimiter(); | 466 CreateLimiter(); |
| 499 Mock::VerifyAndClearExpectations(user_manager_); | 467 Mock::VerifyAndClearExpectations(user_manager_); |
| 500 SetUpUserManager(); | 468 SetUpUserManager(); |
| 501 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 469 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 502 .Times(0); | 470 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 503 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 504 .Times(0); | |
| 505 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 471 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 506 | 472 |
| 507 last_gaia_signin_time = base::Time::FromInternalValue( | 473 last_gaia_signin_time = base::Time::FromInternalValue( |
| 508 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 474 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 509 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 475 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 510 | 476 |
| 511 // Verify that no timer is running. | 477 // Verify that no timer is running. |
| 512 EXPECT_FALSE(runner_->HasPendingTask()); | 478 EXPECT_FALSE(runner_->HasPendingTask()); |
| 513 } | 479 } |
| 514 | 480 |
| 515 TEST_F(SAMLOfflineSigninLimiterTest, SAMLZeroLimit) { | 481 TEST_F(SAMLOfflineSigninLimiterTest, SAMLZeroLimit) { |
| 516 PrefService* prefs = profile_->GetPrefs(); | 482 PrefService* prefs = profile_->GetPrefs(); |
| 517 | 483 |
| 518 // Set a zero time limit. | 484 // Set a zero time limit. |
| 519 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 485 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 520 | 486 |
| 521 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 487 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 522 // login is cleared and then set immediately. Also verify that the time of | 488 // login is cleared and then set immediately. Also verify that the time of |
| 523 // last login with SAML is set. | 489 // last login with SAML is set. |
| 524 CreateLimiter(); | 490 CreateLimiter(); |
| 525 Sequence sequence; | 491 Sequence sequence; |
| 526 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 492 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)) |
| 527 .Times(1) | 493 .Times(1) |
| 528 .InSequence(sequence); | 494 .InSequence(sequence); |
| 529 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | 495 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)) |
| 530 .Times(1) | 496 .Times(1) |
| 531 .InSequence(sequence); | 497 .InSequence(sequence); |
| 532 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 498 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 533 | 499 |
| 534 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 500 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 535 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 501 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 536 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 502 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 537 } | 503 } |
| 538 | 504 |
| 539 TEST_F(SAMLOfflineSigninLimiterTest, SAMLSetLimitWhileLoggedIn) { | 505 TEST_F(SAMLOfflineSigninLimiterTest, SAMLSetLimitWhileLoggedIn) { |
| 540 PrefService* prefs = profile_->GetPrefs(); | 506 PrefService* prefs = profile_->GetPrefs(); |
| 541 | 507 |
| 542 // Remove the time limit. | 508 // Remove the time limit. |
| 543 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 509 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 544 | 510 |
| 545 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 511 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 546 // login is cleared and the time of last login with SAML is set. | 512 // login is cleared and the time of last login with SAML is set. |
| 547 CreateLimiter(); | 513 CreateLimiter(); |
| 548 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 514 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 549 .Times(1); | 515 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 550 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 551 .Times(0); | |
| 552 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 516 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 553 | 517 |
| 554 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 518 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 555 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 519 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 556 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 520 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 557 | 521 |
| 558 // Verify that no timer is running. | 522 // Verify that no timer is running. |
| 559 EXPECT_FALSE(runner_->HasPendingTask()); | 523 EXPECT_FALSE(runner_->HasPendingTask()); |
| 560 | 524 |
| 561 // Set a zero time limit. Verify that the flag enforcing online login is set. | 525 // Set a zero time limit. Verify that the flag enforcing online login is set. |
| 562 Mock::VerifyAndClearExpectations(user_manager_); | 526 Mock::VerifyAndClearExpectations(user_manager_); |
| 563 SetUpUserManager(); | 527 SetUpUserManager(); |
| 564 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 528 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 565 .Times(0); | 529 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); |
| 566 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 567 .Times(1); | |
| 568 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 530 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 569 } | 531 } |
| 570 | 532 |
| 571 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) { | 533 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) { |
| 572 PrefService* prefs = profile_->GetPrefs(); | 534 PrefService* prefs = profile_->GetPrefs(); |
| 573 | 535 |
| 574 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 536 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 575 // login is cleared and the time of last login with SAML is set. | 537 // login is cleared and the time of last login with SAML is set. |
| 576 CreateLimiter(); | 538 CreateLimiter(); |
| 577 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 539 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 578 .Times(1); | 540 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 579 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 580 .Times(0); | |
| 581 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 541 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 582 | 542 |
| 583 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 543 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 584 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 544 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 585 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 545 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 586 | 546 |
| 587 // Verify that the timer is running. | 547 // Verify that the timer is running. |
| 588 EXPECT_TRUE(runner_->HasPendingTask()); | 548 EXPECT_TRUE(runner_->HasPendingTask()); |
| 589 | 549 |
| 590 // Remove the time limit. | 550 // Remove the time limit. |
| 591 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 551 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 592 | 552 |
| 593 // Allow the timer to fire. Verify that the flag enforcing online login is not | 553 // Allow the timer to fire. Verify that the flag enforcing online login is not |
| 594 // changed. | 554 // changed. |
| 595 Mock::VerifyAndClearExpectations(user_manager_); | 555 Mock::VerifyAndClearExpectations(user_manager_); |
| 596 SetUpUserManager(); | 556 SetUpUserManager(); |
| 597 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 557 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 598 .Times(0); | 558 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 599 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 600 .Times(0); | |
| 601 runner_->RunUntilIdle(); | 559 runner_->RunUntilIdle(); |
| 602 } | 560 } |
| 603 | 561 |
| 604 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) { | 562 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) { |
| 605 PrefService* prefs = profile_->GetPrefs(); | 563 PrefService* prefs = profile_->GetPrefs(); |
| 606 | 564 |
| 607 // Set the time of last login with SAML. | 565 // Set the time of last login with SAML. |
| 608 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 566 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 609 clock_.Now().ToInternalValue()); | 567 clock_.Now().ToInternalValue()); |
| 610 | 568 |
| 611 // Advance time by four weeks. | 569 // Advance time by four weeks. |
| 612 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 570 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 613 | 571 |
| 614 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 572 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 615 // login is cleared and the time of last login with SAML is updated. | 573 // login is cleared and the time of last login with SAML is updated. |
| 616 CreateLimiter(); | 574 CreateLimiter(); |
| 617 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 575 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 618 .Times(1); | 576 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 619 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 620 .Times(0); | |
| 621 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 577 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 622 | 578 |
| 623 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 579 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 624 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 580 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 625 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 581 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 626 | 582 |
| 627 // Verify that the timer is running. | 583 // Verify that the timer is running. |
| 628 EXPECT_TRUE(runner_->HasPendingTask()); | 584 EXPECT_TRUE(runner_->HasPendingTask()); |
| 629 } | 585 } |
| 630 | 586 |
| 631 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInOfflineWithExpiredLimit) { | 587 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInOfflineWithExpiredLimit) { |
| 632 PrefService* prefs = profile_->GetPrefs(); | 588 PrefService* prefs = profile_->GetPrefs(); |
| 633 | 589 |
| 634 // Set the time of last login with SAML. | 590 // Set the time of last login with SAML. |
| 635 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 591 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 636 clock_.Now().ToInternalValue()); | 592 clock_.Now().ToInternalValue()); |
| 637 | 593 |
| 638 // Advance time by four weeks. | 594 // Advance time by four weeks. |
| 639 const base::Time gaia_signin_time = clock_.Now(); | 595 const base::Time gaia_signin_time = clock_.Now(); |
| 640 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 596 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 641 | 597 |
| 642 // Authenticate offline. Verify that the flag enforcing online login is | 598 // Authenticate offline. Verify that the flag enforcing online login is |
| 643 // set and the time of last login with SAML is not changed. | 599 // set and the time of last login with SAML is not changed. |
| 644 CreateLimiter(); | 600 CreateLimiter(); |
| 645 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) | 601 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 646 .Times(0); | 602 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); |
| 647 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 648 .Times(1); | |
| 649 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 603 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 650 | 604 |
| 651 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 605 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 652 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 606 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 653 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 607 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 654 } | 608 } |
| 655 | 609 |
| 656 } // namespace chromeos | 610 } // namespace chromeos |
| OLD | NEW |