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

Side by Side Diff: chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc

Issue 2387253002: cros: Added policies for screen unlock. (Closed)
Patch Set: Fixed rebase error. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/quick_unlock/pin_storage.h" 5 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h"
6 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h" 6 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h"
7 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" 7 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h"
8 #include "chrome/common/pref_names.h" 8 #include "chrome/common/pref_names.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "components/prefs/pref_service.h" 10 #include "components/prefs/pref_service.h"
11 #include "components/prefs/scoped_user_pref_update.h"
11 #include "content/public/test/test_browser_thread_bundle.h" 12 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace { 15 namespace {
15 16
16 class PinStorageUnitTest : public testing::Test { 17 class PinStorageUnitTest : public testing::Test {
17 protected: 18 protected:
18 PinStorageUnitTest() : profile_(new TestingProfile()) {} 19 PinStorageUnitTest() : profile_(new TestingProfile()) {}
19 ~PinStorageUnitTest() override {} 20 ~PinStorageUnitTest() override {}
20 21
21 // testing::Test: 22 // testing::Test:
22 void SetUp() override { chromeos::EnableQuickUnlockForTesting(); } 23 void SetUp() override {
24 chromeos::quick_unlock::EnableQuickUnlockForTesting();
25 }
23 26
24 content::TestBrowserThreadBundle thread_bundle_; 27 content::TestBrowserThreadBundle thread_bundle_;
25 std::unique_ptr<TestingProfile> profile_; 28 std::unique_ptr<TestingProfile> profile_;
26 29
27 DISALLOW_COPY_AND_ASSIGN(PinStorageUnitTest); 30 DISALLOW_COPY_AND_ASSIGN(PinStorageUnitTest);
28 }; 31 };
29 32
30 } // namespace 33 } // namespace
31 34
32 // Provides test-only PinStorage APIs. 35 // Provides test-only PinStorage APIs.
33 class PinStorageTestApi { 36 class PinStorageTestApi {
34 public: 37 public:
35 // Does *not* take ownership over |pin_storage|. 38 // Does *not* take ownership over |pin_storage|.
36 explicit PinStorageTestApi(chromeos::PinStorage* pin_storage) 39 explicit PinStorageTestApi(chromeos::PinStorage* pin_storage)
37 : pin_storage_(pin_storage) {} 40 : pin_storage_(pin_storage) {}
38 41
39 // Reduces the amount of strong auth time available by |time_delta|. 42 // Reduces the amount of strong auth time available by |time_delta|.
40 void ReduceRemainingStrongAuthTimeBy(const base::TimeDelta& time_delta) { 43 void ReduceRemainingStrongAuthTimeBy(const base::TimeDelta& time_delta) {
41 pin_storage_->last_strong_auth_ -= time_delta; 44 pin_storage_->last_strong_auth_ -= time_delta;
42 } 45 }
43 46
47 bool HasStrongAuthInfo() {
48 return !pin_storage_->last_strong_auth_.is_null();
49 }
50
44 std::string PinSalt() const { return pin_storage_->PinSalt(); } 51 std::string PinSalt() const { return pin_storage_->PinSalt(); }
45 52
46 std::string PinSecret() const { return pin_storage_->PinSecret(); } 53 std::string PinSecret() const { return pin_storage_->PinSecret(); }
47 54
48 private: 55 private:
49 chromeos::PinStorage* pin_storage_; 56 chromeos::PinStorage* pin_storage_;
50 57
51 DISALLOW_COPY_AND_ASSIGN(PinStorageTestApi); 58 DISALLOW_COPY_AND_ASSIGN(PinStorageTestApi);
52 }; 59 };
53 60
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 EXPECT_EQ(0, pin_storage->unlock_attempt_count()); 106 EXPECT_EQ(0, pin_storage->unlock_attempt_count());
100 } 107 }
101 108
102 // Verifies that marking the strong auth makes TimeSinceLastStrongAuth a > zero 109 // Verifies that marking the strong auth makes TimeSinceLastStrongAuth a > zero
103 // value. 110 // value.
104 TEST_F(PinStorageUnitTest, TimeSinceLastStrongAuthReturnsPositiveValue) { 111 TEST_F(PinStorageUnitTest, TimeSinceLastStrongAuthReturnsPositiveValue) {
105 chromeos::PinStorage* pin_storage = 112 chromeos::PinStorage* pin_storage =
106 chromeos::PinStorageFactory::GetForProfile(profile_.get()); 113 chromeos::PinStorageFactory::GetForProfile(profile_.get());
107 PinStorageTestApi pin_storage_test(pin_storage); 114 PinStorageTestApi pin_storage_test(pin_storage);
108 115
109 EXPECT_FALSE(pin_storage->HasStrongAuth()); 116 EXPECT_FALSE(pin_storage_test.HasStrongAuthInfo());
110 117
111 pin_storage->MarkStrongAuth(); 118 pin_storage->MarkStrongAuth();
112 119
113 EXPECT_TRUE(pin_storage->HasStrongAuth()); 120 EXPECT_TRUE(pin_storage_test.HasStrongAuthInfo());
114 pin_storage_test.ReduceRemainingStrongAuthTimeBy( 121 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
115 base::TimeDelta::FromSeconds(60)); 122 base::TimeDelta::FromSeconds(60));
116 123
117 EXPECT_TRUE(pin_storage->TimeSinceLastStrongAuth() >= 124 EXPECT_TRUE(pin_storage->TimeSinceLastStrongAuth() >=
118 base::TimeDelta::FromSeconds(30)); 125 base::TimeDelta::FromSeconds(30));
119 } 126 }
120 127
128 // Verifies altering the password confirmation preference produces the expected
129 // results.
jdufault 2016/10/31 22:22:01 What are the expected results?
sammiequon 2016/11/01 04:33:17 Done.
130 TEST_F(PinStorageUnitTest, PasswordConfirmationFrequencyPreference) {
131 chromeos::PinStorage* pin_storage =
132 chromeos::PinStorageFactory::GetForProfile(profile_.get());
133 PrefService* pref_service = profile_->GetPrefs();
134 PinStorageTestApi pin_storage_test(pin_storage);
135
136 // The default is one day, so verify moving time back 13 hours should not
137 // request strong auth.
138 pin_storage->MarkStrongAuth();
139 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
140 base::TimeDelta::FromHours(13));
141 EXPECT_TRUE(pin_storage->HasStrongAuth());
142
143 // Verify moving time back another 13 hours should request strong auth.
144 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
145 base::TimeDelta::FromHours(13));
146 EXPECT_FALSE(pin_storage->HasStrongAuth());
147
148 // Reset the time since last strong auth.
149 pin_storage->MarkStrongAuth();
150
151 // Verify that by changing the frequency of required password confirmation to
152 // six hours, moving interval by 4 hours will not trigger a request for strong
153 // auth, but moving interval by an additional 4 hours will.
154 pref_service->SetInteger(
jdufault 2016/10/31 22:22:02 Write a helper method to do this. SetConfirmation
sammiequon 2016/11/01 04:33:17 Done.
155 prefs::kQuickUnlockTimeout,
156 static_cast<int>(
157 chromeos::quick_unlock::PasswordConfirmationFrequency::SIX_HOURS));
158 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
159 base::TimeDelta::FromHours(4));
160 EXPECT_TRUE(pin_storage->HasStrongAuth());
161 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
162 base::TimeDelta::FromHours(4));
163 EXPECT_FALSE(pin_storage->HasStrongAuth());
164
165 // Verify that by changing the frequency of required password confirmation to
166 // twelve hours, the current interval of 8 hours will not trigger a request
167 // for strong auth, but moving interval by an additional 5 hours will.
168 pref_service->SetInteger(
169 prefs::kQuickUnlockTimeout,
170 static_cast<int>(
171 chromeos::quick_unlock::PasswordConfirmationFrequency::TWELVE_HOURS));
172 EXPECT_TRUE(pin_storage->HasStrongAuth());
173 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
jdufault 2016/10/31 22:22:01 What about renaming pin_storage_test to test_api?
sammiequon 2016/11/01 04:33:17 Done.
174 base::TimeDelta::FromHours(5));
175 EXPECT_FALSE(pin_storage->HasStrongAuth());
176
177 pin_storage->MarkStrongAuth();
178 // Verify that by changing the frequency of required password confirmation to
179 // one week, moving interval by 3 days will not trigger a request for strong
jdufault 2016/10/31 22:22:01 This is the same test four times over. I would eli
sammiequon 2016/11/01 04:33:17 Done.
180 // auth, but moving interval by an addition 5 days will.
181 pref_service->SetInteger(
182 prefs::kQuickUnlockTimeout,
183 static_cast<int>(
184 chromeos::quick_unlock::PasswordConfirmationFrequency::WEEK));
185 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
186 base::TimeDelta::FromDays(3));
187 EXPECT_TRUE(pin_storage->HasStrongAuth());
188 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
189 base::TimeDelta::FromDays(5));
190 EXPECT_FALSE(pin_storage->HasStrongAuth());
191 }
192
121 // Verifies that the correct pin can be used to authenticate. 193 // Verifies that the correct pin can be used to authenticate.
122 TEST_F(PinStorageUnitTest, AuthenticationSucceedsWithRightPin) { 194 TEST_F(PinStorageUnitTest, AuthenticationSucceedsWithRightPin) {
123 chromeos::PinStorage* pin_storage = 195 chromeos::PinStorage* pin_storage =
124 chromeos::PinStorageFactory::GetForProfile(profile_.get()); 196 chromeos::PinStorageFactory::GetForProfile(profile_.get());
125 197
126 pin_storage->SetPin("1111"); 198 pin_storage->SetPin("1111");
127 199
128 pin_storage->MarkStrongAuth(); 200 pin_storage->MarkStrongAuth();
129 EXPECT_TRUE(pin_storage->TryAuthenticatePin("1111")); 201 EXPECT_TRUE(pin_storage->TryAuthenticatePin("1111"));
130 } 202 }
(...skipping 23 matching lines...) Expand all
154 chromeos::PinStorage* pin_storage = 226 chromeos::PinStorage* pin_storage =
155 chromeos::PinStorageFactory::GetForProfile(profile_.get()); 227 chromeos::PinStorageFactory::GetForProfile(profile_.get());
156 PinStorageTestApi pin_storage_test(pin_storage); 228 PinStorageTestApi pin_storage_test(pin_storage);
157 229
158 pin_storage->SetPin("1111"); 230 pin_storage->SetPin("1111");
159 pin_storage->MarkStrongAuth(); 231 pin_storage->MarkStrongAuth();
160 EXPECT_TRUE(pin_storage->IsPinAuthenticationAvailable()); 232 EXPECT_TRUE(pin_storage->IsPinAuthenticationAvailable());
161 233
162 // Remove all of the strong auth time so that we have a strong auth timeout. 234 // Remove all of the strong auth time so that we have a strong auth timeout.
163 pin_storage_test.ReduceRemainingStrongAuthTimeBy( 235 pin_storage_test.ReduceRemainingStrongAuthTimeBy(
164 chromeos::PinStorage::kStrongAuthTimeout + base::TimeDelta::FromHours(1)); 236 base::TimeDelta::FromDays(10));
165 237
166 EXPECT_FALSE(pin_storage->IsPinAuthenticationAvailable()); 238 EXPECT_FALSE(pin_storage->IsPinAuthenticationAvailable());
167 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698