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