Chromium Code Reviews| OLD | NEW |
|---|---|
| 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::EnableQuickUnlockForTesting(); | |
| 25 | |
| 26 // Pin is not allowed by default so we need to update it for this test. | |
| 27 ListPrefUpdate update(profile_->GetPrefs(), prefs::kScreenUnlockWhitelist); | |
| 28 update->Append(base::MakeUnique<base::StringValue>("pin")); | |
|
jdufault
2016/10/04 17:55:06
If the device is *not* enterprise enrolled, PIN sh
| |
| 29 } | |
| 23 | 30 |
| 24 content::TestBrowserThreadBundle thread_bundle_; | 31 content::TestBrowserThreadBundle thread_bundle_; |
| 25 std::unique_ptr<TestingProfile> profile_; | 32 std::unique_ptr<TestingProfile> profile_; |
| 26 | 33 |
| 27 DISALLOW_COPY_AND_ASSIGN(PinStorageUnitTest); | 34 DISALLOW_COPY_AND_ASSIGN(PinStorageUnitTest); |
| 28 }; | 35 }; |
| 29 | 36 |
| 30 } // namespace | 37 } // namespace |
| 31 | 38 |
| 32 // Provides test-only PinStorage APIs. | 39 // Provides test-only PinStorage APIs. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 pin_storage->MarkStrongAuth(); | 118 pin_storage->MarkStrongAuth(); |
| 112 | 119 |
| 113 EXPECT_TRUE(pin_storage->HasStrongAuth()); | 120 EXPECT_TRUE(pin_storage->HasStrongAuth()); |
| 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 | |
|
jdufault
2016/10/04 17:55:06
Password => password
sammiequon
2016/10/18 22:47:49
Done.
| |
| 129 // results. | |
| 130 TEST_F(PinStorageUnitTest, PasswordConfirmationPreference) { | |
| 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_FALSE(pin_storage->NeedsStrongAuth()); | |
| 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_TRUE(pin_storage->NeedsStrongAuth()); | |
| 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( | |
| 155 prefs::kScreenUnlockPasswordConfirmationFrequency, | |
| 156 static_cast<int>(chromeos::PasswordConfirmation::SIX_HOURS)); | |
|
jdufault
2016/10/04 17:55:06
int{}
sammiequon
2016/10/18 22:47:49
int{} will cause a compiler error.
| |
| 157 pin_storage_test.ReduceRemainingStrongAuthTimeBy( | |
| 158 base::TimeDelta::FromHours(4)); | |
| 159 EXPECT_FALSE(pin_storage->NeedsStrongAuth()); | |
| 160 pin_storage_test.ReduceRemainingStrongAuthTimeBy( | |
| 161 base::TimeDelta::FromHours(4)); | |
| 162 EXPECT_TRUE(pin_storage->NeedsStrongAuth()); | |
| 163 | |
| 164 // Verify that by changing the frequency of required password confirmation to | |
| 165 // twelve hours, the current interval of 8 hours will not trigger a request | |
| 166 // for strong auth, but moving interval by an additional 5 hours will. | |
| 167 pref_service->SetInteger( | |
| 168 prefs::kScreenUnlockPasswordConfirmationFrequency, | |
| 169 static_cast<int>(chromeos::PasswordConfirmation::TWELVE_HOURS)); | |
| 170 EXPECT_FALSE(pin_storage->NeedsStrongAuth()); | |
| 171 pin_storage_test.ReduceRemainingStrongAuthTimeBy( | |
| 172 base::TimeDelta::FromHours(5)); | |
| 173 EXPECT_TRUE(pin_storage->NeedsStrongAuth()); | |
| 174 | |
| 175 pin_storage->MarkStrongAuth(); | |
| 176 // Verify that by changing the frequency of required password confirmation to | |
| 177 // one week, moving interval by 3 days will not trigger a request for strong | |
| 178 // auth, but moving interval by an addition 5 days will. | |
| 179 pref_service->SetInteger( | |
| 180 prefs::kScreenUnlockPasswordConfirmationFrequency, | |
| 181 static_cast<int>(chromeos::PasswordConfirmation::WEEK)); | |
| 182 pin_storage_test.ReduceRemainingStrongAuthTimeBy( | |
| 183 base::TimeDelta::FromDays(3)); | |
| 184 EXPECT_FALSE(pin_storage->NeedsStrongAuth()); | |
| 185 pin_storage_test.ReduceRemainingStrongAuthTimeBy( | |
| 186 base::TimeDelta::FromDays(5)); | |
| 187 EXPECT_TRUE(pin_storage->NeedsStrongAuth()); | |
| 188 } | |
| 189 | |
| 121 // Verifies that the correct pin can be used to authenticate. | 190 // Verifies that the correct pin can be used to authenticate. |
| 122 TEST_F(PinStorageUnitTest, AuthenticationSucceedsWithRightPin) { | 191 TEST_F(PinStorageUnitTest, AuthenticationSucceedsWithRightPin) { |
| 123 chromeos::PinStorage* pin_storage = | 192 chromeos::PinStorage* pin_storage = |
| 124 chromeos::PinStorageFactory::GetForProfile(profile_.get()); | 193 chromeos::PinStorageFactory::GetForProfile(profile_.get()); |
| 125 | 194 |
| 126 pin_storage->SetPin("1111"); | 195 pin_storage->SetPin("1111"); |
| 127 | 196 |
| 128 pin_storage->MarkStrongAuth(); | 197 pin_storage->MarkStrongAuth(); |
| 129 EXPECT_TRUE(pin_storage->TryAuthenticatePin("1111")); | 198 EXPECT_TRUE(pin_storage->TryAuthenticatePin("1111")); |
| 130 } | 199 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 154 chromeos::PinStorage* pin_storage = | 223 chromeos::PinStorage* pin_storage = |
| 155 chromeos::PinStorageFactory::GetForProfile(profile_.get()); | 224 chromeos::PinStorageFactory::GetForProfile(profile_.get()); |
| 156 PinStorageTestApi pin_storage_test(pin_storage); | 225 PinStorageTestApi pin_storage_test(pin_storage); |
| 157 | 226 |
| 158 pin_storage->SetPin("1111"); | 227 pin_storage->SetPin("1111"); |
| 159 pin_storage->MarkStrongAuth(); | 228 pin_storage->MarkStrongAuth(); |
| 160 EXPECT_TRUE(pin_storage->IsPinAuthenticationAvailable()); | 229 EXPECT_TRUE(pin_storage->IsPinAuthenticationAvailable()); |
| 161 | 230 |
| 162 // Remove all of the strong auth time so that we have a strong auth timeout. | 231 // Remove all of the strong auth time so that we have a strong auth timeout. |
| 163 pin_storage_test.ReduceRemainingStrongAuthTimeBy( | 232 pin_storage_test.ReduceRemainingStrongAuthTimeBy( |
| 164 chromeos::PinStorage::kStrongAuthTimeout + base::TimeDelta::FromHours(1)); | 233 base::TimeDelta::FromDays(10)); |
| 165 | 234 |
| 166 EXPECT_FALSE(pin_storage->IsPinAuthenticationAvailable()); | 235 EXPECT_FALSE(pin_storage->IsPinAuthenticationAvailable()); |
| 167 } | 236 } |
| 237 | |
| 238 TEST_F(PinStorageUnitTest, VerifyPinUnlockAgainstPolicy) { | |
| 239 chromeos::PinStorage* pin_storage = | |
| 240 chromeos::PinStorageFactory::GetForProfile(profile_.get()); | |
| 241 | |
| 242 ListPrefUpdate update(profile_->GetPrefs(), prefs::kScreenUnlockWhitelist); | |
| 243 // Verify that clearing the whitelist diables the pin. | |
| 244 update->Clear(); | |
| 245 EXPECT_FALSE(pin_storage->IsPinUnlockEnabled()); | |
| 246 | |
| 247 // Verify that by adding pin and another unlock mode, pin is enabled. | |
| 248 update->Append(base::MakeUnique<base::StringValue>("pin")); | |
| 249 EXPECT_TRUE(pin_storage->IsPinUnlockEnabled()); | |
| 250 update->Append(base::MakeUnique<base::StringValue>("password")); | |
| 251 EXPECT_TRUE(pin_storage->IsPinUnlockEnabled()); | |
| 252 | |
| 253 // Verify that adding all to the whitelist enables the pin. | |
| 254 update->Append(base::MakeUnique<base::StringValue>("all")); | |
| 255 EXPECT_TRUE(pin_storage->IsPinUnlockEnabled()); | |
| 256 } | |
| OLD | NEW |