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

Side by Side Diff: chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_unittest.cc

Issue 143463009: Add policy that forces SAML users to log in online periodically (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Speculative fix for PolicyPrefIndicatorTest.CheckPolicyIndicators/3. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/test/simple_test_clock.h"
10 #include "base/test/test_simple_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "base/time/clock.h"
13 #include "chrome/browser/chromeos/login/mock_user_manager.h"
14 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory .h"
15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "components/user_prefs/pref_registry_syncable.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 using testing::Mock;
24 using testing::ReturnRef;
25 using testing::Sequence;
26
27 namespace chromeos {
28
29 namespace {
30 const char kTestUser[] = "user@example.com";
31 }
32
33 class SAMLOfflineSigninLimiterTest : public testing::Test {
34 protected:
35 SAMLOfflineSigninLimiterTest();
36 virtual ~SAMLOfflineSigninLimiterTest();
37
38 // testing::Test:
39 virtual void SetUp() OVERRIDE;
40 virtual void TearDown() OVERRIDE;
41
42 void DestroyLimiter();
43 void CreateLimiter();
44
45 scoped_refptr<base::TestSimpleTaskRunner> runner_;
46 base::ThreadTaskRunnerHandle runner_handle_;
47
48 MockUserManager* user_manager_; // Not owned.
49 ScopedUserManagerEnabler user_manager_enabler_;
50
51 scoped_ptr<TestingProfile> profile_;
52 base::SimpleTestClock clock_;
53
54 SAMLOfflineSigninLimiter* limiter_; // Owned.
55
56 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest);
57 };
58
59 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest()
60 : runner_(new base::TestSimpleTaskRunner),
61 runner_handle_(runner_),
62 user_manager_(new MockUserManager),
63 user_manager_enabler_(user_manager_),
64 limiter_(NULL) {
65 }
66
67 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() {
68 DestroyLimiter();
69 Mock::VerifyAndClearExpectations(user_manager_);
70 EXPECT_CALL(*user_manager_, Shutdown()).Times(1);
71 }
72
73 void SAMLOfflineSigninLimiterTest::DestroyLimiter() {
74 if (limiter_) {
75 limiter_->Shutdown();
76 delete limiter_;
77 limiter_ = NULL;
78 }
79 }
80
81 void SAMLOfflineSigninLimiterTest::CreateLimiter() {
82 DestroyLimiter();
83 limiter_ = new SAMLOfflineSigninLimiter(profile_.get(), &clock_);
84 }
85
86 void SAMLOfflineSigninLimiterTest::SetUp() {
87 const UserList user_list;
88 EXPECT_CALL(*user_manager_, GetLoggedInUsers())
89 .Times(1)
90 .WillOnce(ReturnRef(user_list));
91 profile_.reset(new TestingProfile);
92 Mock::VerifyAndClearExpectations(user_manager_);
93
94 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_);
95 user_manager_->AddUser(kTestUser);
96 profile_->set_profile_name(kTestUser);
97 clock_.Advance(base::TimeDelta::FromHours(1));
98 }
99
100 void SAMLOfflineSigninLimiterTest::TearDown() {
101 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL);
102 }
103
104 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) {
105 PrefService* prefs = profile_->GetPrefs();
106
107 // Set the time of last login with SAML.
108 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
109 clock_.Now().ToInternalValue());
110
111 // Authenticate against GAIA without SAML. Verify that the flag enforcing
112 // online login and the time of last login with SAML are cleared.
113 CreateLimiter();
114 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
115 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
116 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
117
118 const PrefService::Preference* pref =
119 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
120 ASSERT_TRUE(pref);
121 EXPECT_FALSE(pref->HasUserSetting());
122
123 // Verify that no timer is running.
124 EXPECT_FALSE(runner_->HasPendingTask());
125
126 // Log out. Verify that the flag enforcing online login is not set.
127 DestroyLimiter();
128
129 // Authenticate offline. Verify that the flag enforcing online login is not
130 // changed and the time of last login with SAML is not set.
131 CreateLimiter();
132 Mock::VerifyAndClearExpectations(user_manager_);
133 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
134 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
135 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
136
137 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
138 ASSERT_TRUE(pref);
139 EXPECT_FALSE(pref->HasUserSetting());
140
141 // Verify that no timer is running.
142 EXPECT_FALSE(runner_->HasPendingTask());
143 }
144
145 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLNoLimit) {
146 PrefService* prefs = profile_->GetPrefs();
147
148 // Remove the time limit.
149 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
150
151 // Set the time of last login with SAML.
152 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
153 clock_.Now().ToInternalValue());
154
155 // Authenticate against GAIA without SAML. Verify that the flag enforcing
156 // online login and the time of last login with SAML are cleared.
157 CreateLimiter();
158 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
159 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
160 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
161
162 const PrefService::Preference* pref =
163 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
164 ASSERT_TRUE(pref);
165 EXPECT_FALSE(pref->HasUserSetting());
166
167 // Verify that no timer is running.
168 EXPECT_FALSE(runner_->HasPendingTask());
169
170 // Log out. Verify that the flag enforcing online login is not set.
171 DestroyLimiter();
172
173 // Authenticate offline. Verify that the flag enforcing online login is not
174 // changed and the time of last login with SAML is not set.
175 CreateLimiter();
176 Mock::VerifyAndClearExpectations(user_manager_);
177 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
178 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
179 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
180
181 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
182 ASSERT_TRUE(pref);
183 EXPECT_FALSE(pref->HasUserSetting());
184
185 // Verify that no timer is running.
186 EXPECT_FALSE(runner_->HasPendingTask());
187 }
188
189 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLZeroLimit) {
190 PrefService* prefs = profile_->GetPrefs();
191
192 // Set a zero time limit.
193 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
194
195 // Set the time of last login with SAML.
196 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
197 clock_.Now().ToInternalValue());
198
199 // Authenticate against GAIA without SAML. Verify that the flag enforcing
200 // online login and the time of last login with SAML are cleared.
201 CreateLimiter();
202 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
203 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
204 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
205
206 const PrefService::Preference* pref =
207 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
208 ASSERT_TRUE(pref);
209 EXPECT_FALSE(pref->HasUserSetting());
210
211 // Verify that no timer is running.
212 EXPECT_FALSE(runner_->HasPendingTask());
213
214 // Log out. Verify that the flag enforcing online login is not set.
215 DestroyLimiter();
216
217 // Authenticate offline. Verify that the flag enforcing online login is not
218 // changed and the time of last login with SAML is not set.
219 CreateLimiter();
220 Mock::VerifyAndClearExpectations(user_manager_);
221 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
222 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
223 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
224
225 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
226 ASSERT_TRUE(pref);
227 EXPECT_FALSE(pref->HasUserSetting());
228
229 // Verify that no timer is running.
230 EXPECT_FALSE(runner_->HasPendingTask());
231 }
232
233 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLSetLimitWhileLoggedIn) {
234 PrefService* prefs = profile_->GetPrefs();
235
236 // Remove the time limit.
237 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
238
239 // Set the time of last login with SAML.
240 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
241 clock_.Now().ToInternalValue());
242
243 // Authenticate against GAIA without SAML. Verify that the flag enforcing
244 // online login and the time of last login with SAML are cleared.
245 CreateLimiter();
246 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
247 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
248 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
249
250 const PrefService::Preference* pref =
251 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
252 ASSERT_TRUE(pref);
253 EXPECT_FALSE(pref->HasUserSetting());
254
255 // Verify that no timer is running.
256 EXPECT_FALSE(runner_->HasPendingTask());
257
258 // Set a zero time limit.
259 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
260
261 // Verify that no timer is running.
262 EXPECT_FALSE(runner_->HasPendingTask());
263 }
264
265 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLRemoveLimitWhileLoggedIn) {
266 PrefService* prefs = profile_->GetPrefs();
267
268 // Set the time of last login with SAML.
269 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
270 clock_.Now().ToInternalValue());
271
272 // Authenticate against GAIA without SAML. Verify that the flag enforcing
273 // online login and the time of last login with SAML are cleared.
274 CreateLimiter();
275 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
276 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
277 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
278
279 const PrefService::Preference* pref =
280 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
281 ASSERT_TRUE(pref);
282 EXPECT_FALSE(pref->HasUserSetting());
283
284 // Verify that no timer is running.
285 EXPECT_FALSE(runner_->HasPendingTask());
286
287 // Remove the time limit.
288 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
289
290 // Verify that no timer is running.
291 EXPECT_FALSE(runner_->HasPendingTask());
292 }
293
294 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLLogInWithExpiredLimit) {
295 PrefService* prefs = profile_->GetPrefs();
296
297 // Set the time of last login with SAML.
298 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
299 clock_.Now().ToInternalValue());
300
301 // Advance time by four weeks.
302 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
303
304 // Authenticate against GAIA without SAML. Verify that the flag enforcing
305 // online login and the time of last login with SAML are cleared.
306 CreateLimiter();
307 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
308 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
309 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
310
311 const PrefService::Preference* pref =
312 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
313 ASSERT_TRUE(pref);
314 EXPECT_FALSE(pref->HasUserSetting());
315
316 // Verify that no timer is running.
317 EXPECT_FALSE(runner_->HasPendingTask());
318 }
319
320 TEST_F(SAMLOfflineSigninLimiterTest, SAMLDefaultLimit) {
321 PrefService* prefs = profile_->GetPrefs();
322
323 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
324 // login is cleared and the time of last login with SAML is set.
325 CreateLimiter();
326 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
327 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
328 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
329
330 base::Time last_gaia_signin_time = base::Time::FromInternalValue(
331 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
332 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
333
334 // Verify that the timer is running.
335 EXPECT_TRUE(runner_->HasPendingTask());
336
337 // Log out. Verify that the flag enforcing online login is not set.
338 DestroyLimiter();
339
340 // Advance time by an hour.
341 clock_.Advance(base::TimeDelta::FromHours(1));
342
343 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
344 // login is cleared and the time of last login with SAML is updated.
345 CreateLimiter();
346 Mock::VerifyAndClearExpectations(user_manager_);
347 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
348 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
349 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
350
351 last_gaia_signin_time = base::Time::FromInternalValue(
352 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
353 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
354
355 // Verify that the timer is running.
356 EXPECT_TRUE(runner_->HasPendingTask());
357
358 // Log out. Verify that the flag enforcing online login is not set.
359 DestroyLimiter();
360
361 // Advance time by an hour.
362 const base::Time gaia_signin_time = clock_.Now();
363 clock_.Advance(base::TimeDelta::FromHours(1));
364
365 // Authenticate offline. Verify that the flag enforcing online login and the
366 // time of last login with SAML are not changed.
367 CreateLimiter();
368 Mock::VerifyAndClearExpectations(user_manager_);
369 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
370 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
371 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
372
373 last_gaia_signin_time = base::Time::FromInternalValue(
374 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
375 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time);
376
377 // Verify that the timer is running.
378 EXPECT_TRUE(runner_->HasPendingTask());
379
380 // Advance time by four weeks.
381 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
382
383 // Allow the timer to fire. Verify that the flag enforcing online login is
384 // set.
385 Mock::VerifyAndClearExpectations(user_manager_);
386 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
387 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1);
388 runner_->RunPendingTasks();
389 }
390
391 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) {
392 PrefService* prefs = profile_->GetPrefs();
393
394 // Remove the time limit.
395 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
396
397 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
398 // login is cleared and the time of last login with SAML is set.
399 CreateLimiter();
400 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
401 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
402 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
403
404 base::Time last_gaia_signin_time = base::Time::FromInternalValue(
405 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
406 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
407
408 // Verify that no timer is running.
409 EXPECT_FALSE(runner_->HasPendingTask());
410
411 // Log out. Verify that the flag enforcing online login is not set.
412 DestroyLimiter();
413
414 // Advance time by an hour.
415 clock_.Advance(base::TimeDelta::FromHours(1));
416
417 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
418 // login is cleared and the time of last login with SAML is updated.
419 CreateLimiter();
420 Mock::VerifyAndClearExpectations(user_manager_);
421 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
422 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
423 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
424
425 last_gaia_signin_time = base::Time::FromInternalValue(
426 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
427 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
428
429 // Verify that no timer is running.
430 EXPECT_FALSE(runner_->HasPendingTask());
431
432 // Log out. Verify that the flag enforcing online login is not set.
433 DestroyLimiter();
434
435 // Advance time by an hour.
436 const base::Time gaia_signin_time = clock_.Now();
437 clock_.Advance(base::TimeDelta::FromHours(1));
438
439 // Authenticate offline. Verify that the flag enforcing online login and the
440 // time of last login with SAML are not changed.
441 CreateLimiter();
442 Mock::VerifyAndClearExpectations(user_manager_);
443 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
444 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
445 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
446
447 last_gaia_signin_time = base::Time::FromInternalValue(
448 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
449 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time);
450
451 // Verify that no timer is running.
452 EXPECT_FALSE(runner_->HasPendingTask());
453 }
454
455 TEST_F(SAMLOfflineSigninLimiterTest, SAMLZeroLimit) {
456 PrefService* prefs = profile_->GetPrefs();
457
458 // Set a zero time limit.
459 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
460
461 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
462 // login is cleared and then set immediately. Also verify that the time of
463 // last login with SAML is set.
464 CreateLimiter();
465 Sequence sequence;
466 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false))
467 .Times(1)
468 .InSequence(sequence);
469 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true))
470 .Times(1)
471 .InSequence(sequence);
472 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
473
474 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
475 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
476 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
477 }
478
479 TEST_F(SAMLOfflineSigninLimiterTest, SAMLSetLimitWhileLoggedIn) {
480 PrefService* prefs = profile_->GetPrefs();
481
482 // Remove the time limit.
483 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
484
485 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
486 // login is cleared and the time of last login with SAML is set.
487 CreateLimiter();
488 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
489 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
490 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
491
492 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
493 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
494 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
495
496 // Verify that no timer is running.
497 EXPECT_FALSE(runner_->HasPendingTask());
498
499 // Set a zero time limit. Verify that the flag enforcing online login is set.
500 Mock::VerifyAndClearExpectations(user_manager_);
501 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
502 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1);
503 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
504 }
505
506 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) {
507 PrefService* prefs = profile_->GetPrefs();
508
509 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
510 // login is cleared and the time of last login with SAML is set.
511 CreateLimiter();
512 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
513 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
514 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
515
516 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
517 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
518 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
519
520 // Verify that the timer is running.
521 EXPECT_TRUE(runner_->HasPendingTask());
522
523 // Remove the time limit.
524 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
525
526 // Allow the timer to fire. Verify that the flag enforcing online login is not
527 // changed.
528 Mock::VerifyAndClearExpectations(user_manager_);
529 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
530 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
531 runner_->RunUntilIdle();
532 }
533
534 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) {
535 PrefService* prefs = profile_->GetPrefs();
536
537 // Set the time of last login with SAML.
538 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
539 clock_.Now().ToInternalValue());
540
541 // Advance time by four weeks.
542 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
543
544 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
545 // login is cleared and the time of last login with SAML is updated.
546 CreateLimiter();
547 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
548 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
549 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
550
551 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
552 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
553 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
554
555 // Verify that the timer is running.
556 EXPECT_TRUE(runner_->HasPendingTask());
557 }
558
559 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInOfflineWithExpiredLimit) {
560 PrefService* prefs = profile_->GetPrefs();
561
562 // Set the time of last login with SAML.
563 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
564 clock_.Now().ToInternalValue());
565
566 // Advance time by four weeks.
567 const base::Time gaia_signin_time = clock_.Now();
568 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
569
570 // Authenticate offline. Verify that the flag enforcing online login is
571 // set and the time of last login with SAML is not changed.
572 CreateLimiter();
573 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
574 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1);
575 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
576
577 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
578 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
579 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time);
580 }
581
582 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698