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

Unified Diff: chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc

Issue 2715823004: Add FingerprintUnlock KeyedService for each profile (Closed)
Patch Set: rebase Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc
diff --git a/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc b/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc
index 37ce31a3ffcb9f18835bba8db54bfdd1b337e5b3..039d6d5b190eafd0f7dac8e7ade916ac7ee8f9e4 100644
--- a/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc
+++ b/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h"
-#include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h"
+#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h"
+#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h"
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
@@ -15,13 +15,6 @@
namespace chromeos {
namespace {
-void SetConfirmationFrequency(
- PrefService* pref_service,
- quick_unlock::PasswordConfirmationFrequency frequency) {
- pref_service->SetInteger(prefs::kQuickUnlockTimeout,
- static_cast<int>(frequency));
-}
-
class PinStorageUnitTest : public testing::Test {
protected:
PinStorageUnitTest() : profile_(new TestingProfile()) {}
@@ -45,19 +38,17 @@ class PinStorageTestApi {
explicit PinStorageTestApi(quick_unlock::PinStorage* pin_storage)
: pin_storage_(pin_storage) {}
- // Reduces the amount of strong auth time available by |time_delta|.
- void ReduceRemainingStrongAuthTimeBy(const base::TimeDelta& time_delta) {
- pin_storage_->last_strong_auth_ -= time_delta;
- }
-
- bool HasStrongAuthInfo() {
- return !pin_storage_->last_strong_auth_.is_null();
- }
-
std::string PinSalt() const { return pin_storage_->PinSalt(); }
std::string PinSecret() const { return pin_storage_->PinSecret(); }
+ bool IsPinAuthenticationAvailable() const {
+ return pin_storage_->IsPinAuthenticationAvailable();
+ }
+ bool TryAuthenticatePin(const std::string& pin) {
+ return pin_storage_->TryAuthenticatePin(pin);
+ }
+
private:
quick_unlock::PinStorage* pin_storage_;
@@ -75,7 +66,8 @@ TEST_F(PinStorageUnitTest, PinStorageWritesToPrefs) {
EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret));
quick_unlock::PinStorage* pin_storage =
- quick_unlock::PinStorageFactory::GetForProfile(profile_.get());
+ quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
+ ->pin_storage();
PinStorageTestApi pin_storage_test(pin_storage);
pin_storage->SetPin("1111");
@@ -99,7 +91,8 @@ TEST_F(PinStorageUnitTest, PinStorageWritesToPrefs) {
// 3. Resetting unlock attempt count correctly sets attempt count to 0.
TEST_F(PinStorageUnitTest, UnlockAttemptCount) {
quick_unlock::PinStorage* pin_storage =
- quick_unlock::PinStorageFactory::GetForProfile(profile_.get());
+ quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
+ ->pin_storage();
EXPECT_EQ(0, pin_storage->unlock_attempt_count());
@@ -112,126 +105,36 @@ TEST_F(PinStorageUnitTest, UnlockAttemptCount) {
EXPECT_EQ(0, pin_storage->unlock_attempt_count());
}
-// Verifies that marking the strong auth makes TimeSinceLastStrongAuth a > zero
-// value.
-TEST_F(PinStorageUnitTest, TimeSinceLastStrongAuthReturnsPositiveValue) {
- quick_unlock::PinStorage* pin_storage =
- quick_unlock::PinStorageFactory::GetForProfile(profile_.get());
- PinStorageTestApi pin_storage_test(pin_storage);
-
- EXPECT_FALSE(pin_storage_test.HasStrongAuthInfo());
-
- pin_storage->MarkStrongAuth();
-
- EXPECT_TRUE(pin_storage_test.HasStrongAuthInfo());
- pin_storage_test.ReduceRemainingStrongAuthTimeBy(
- base::TimeDelta::FromSeconds(60));
-
- EXPECT_TRUE(pin_storage->TimeSinceLastStrongAuth() >=
- base::TimeDelta::FromSeconds(30));
-}
-
-// Verifies that by altering the password confirmation preference, the pin
-// storage will request password reconfirmation as expected.
-TEST_F(PinStorageUnitTest, QuickUnlockPasswordConfirmationFrequencyPreference) {
- quick_unlock::PinStorage* pin_storage =
- quick_unlock::PinStorageFactory::GetForProfile(profile_.get());
- PrefService* pref_service = profile_->GetPrefs();
- PinStorageTestApi test_api(pin_storage);
-
- // The default is one day, so verify moving the last strong auth time back 13
- // hours should not request strong auth.
- pin_storage->MarkStrongAuth();
- test_api.ReduceRemainingStrongAuthTimeBy(base::TimeDelta::FromHours(13));
- EXPECT_TRUE(pin_storage->HasStrongAuth());
-
- // Verify moving the last strong auth time back another 13 hours should
- // request strong auth.
- test_api.ReduceRemainingStrongAuthTimeBy(base::TimeDelta::FromHours(13));
- EXPECT_FALSE(pin_storage->HasStrongAuth());
-
- // Verify that by changing the frequency of required password confirmation to
- // six hours, moving the last strong auth interval back by 4 hours will not
- // trigger a request for strong auth, but moving it by an additional 4 hours
- // will.
- pin_storage->MarkStrongAuth();
- SetConfirmationFrequency(
- pref_service, quick_unlock::PasswordConfirmationFrequency::SIX_HOURS);
- test_api.ReduceRemainingStrongAuthTimeBy(base::TimeDelta::FromHours(4));
- EXPECT_TRUE(pin_storage->HasStrongAuth());
- test_api.ReduceRemainingStrongAuthTimeBy(base::TimeDelta::FromHours(4));
- EXPECT_FALSE(pin_storage->HasStrongAuth());
-
- // A valid strong auth becomes invalid if the confirmation frequency is
- // shortened to less than the expiration time.
- pin_storage->MarkStrongAuth();
- SetConfirmationFrequency(
- pref_service, quick_unlock::PasswordConfirmationFrequency::TWELVE_HOURS);
- EXPECT_TRUE(pin_storage->HasStrongAuth());
- test_api.ReduceRemainingStrongAuthTimeBy(base::TimeDelta::FromHours(8));
- EXPECT_TRUE(pin_storage->HasStrongAuth());
- SetConfirmationFrequency(
- pref_service, quick_unlock::PasswordConfirmationFrequency::SIX_HOURS);
- EXPECT_FALSE(pin_storage->HasStrongAuth());
-
- // An expired strong auth becomes usable if the confirmation frequency gets
- // extended past the expiration time.
- pin_storage->MarkStrongAuth();
- SetConfirmationFrequency(
- pref_service, quick_unlock::PasswordConfirmationFrequency::SIX_HOURS);
- EXPECT_TRUE(pin_storage->HasStrongAuth());
- test_api.ReduceRemainingStrongAuthTimeBy(base::TimeDelta::FromHours(8));
- EXPECT_FALSE(pin_storage->HasStrongAuth());
- SetConfirmationFrequency(
- pref_service, quick_unlock::PasswordConfirmationFrequency::TWELVE_HOURS);
- EXPECT_TRUE(pin_storage->HasStrongAuth());
-}
-
// Verifies that the correct pin can be used to authenticate.
TEST_F(PinStorageUnitTest, AuthenticationSucceedsWithRightPin) {
quick_unlock::PinStorage* pin_storage =
- quick_unlock::PinStorageFactory::GetForProfile(profile_.get());
+ quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
+ ->pin_storage();
+ PinStorageTestApi pin_storage_test(pin_storage);
pin_storage->SetPin("1111");
- pin_storage->MarkStrongAuth();
- EXPECT_TRUE(pin_storage->TryAuthenticatePin("1111"));
+ EXPECT_TRUE(pin_storage_test.TryAuthenticatePin("1111"));
}
// Verifies that the correct pin will fail to authenticate if too many
// authentication attempts have been made.
TEST_F(PinStorageUnitTest, AuthenticationFailsFromTooManyAttempts) {
quick_unlock::PinStorage* pin_storage =
- quick_unlock::PinStorageFactory::GetForProfile(profile_.get());
+ quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
+ ->pin_storage();
+ PinStorageTestApi pin_storage_test(pin_storage);
pin_storage->SetPin("1111");
// Use up all of the authentication attempts so authentication fails.
- pin_storage->MarkStrongAuth();
- EXPECT_TRUE(pin_storage->IsPinAuthenticationAvailable());
+ EXPECT_TRUE(pin_storage_test.IsPinAuthenticationAvailable());
for (int i = 0; i < quick_unlock::PinStorage::kMaximumUnlockAttempts; ++i)
- EXPECT_FALSE(pin_storage->TryAuthenticatePin("foobar"));
+ EXPECT_FALSE(pin_storage_test.TryAuthenticatePin("foobar"));
// We used up all of the attempts, so entering the right PIN will still fail.
- EXPECT_FALSE(pin_storage->IsPinAuthenticationAvailable());
- EXPECT_FALSE(pin_storage->TryAuthenticatePin("1111"));
+ EXPECT_FALSE(pin_storage_test.IsPinAuthenticationAvailable());
+ EXPECT_FALSE(pin_storage_test.TryAuthenticatePin("1111"));
}
-// Verifies that the correct pin will fail to authenticate if it has been too
-// long since a strong-auth/password authentication.
-TEST_F(PinStorageUnitTest, AuthenticationFailsFromTimeout) {
- quick_unlock::PinStorage* pin_storage =
- quick_unlock::PinStorageFactory::GetForProfile(profile_.get());
- PinStorageTestApi pin_storage_test(pin_storage);
-
- pin_storage->SetPin("1111");
- pin_storage->MarkStrongAuth();
- EXPECT_TRUE(pin_storage->IsPinAuthenticationAvailable());
-
- // Remove all of the strong auth time so that we have a strong auth timeout.
- pin_storage_test.ReduceRemainingStrongAuthTimeBy(
- base::TimeDelta::FromDays(10));
-
- EXPECT_FALSE(pin_storage->IsPinAuthenticationAvailable());
-}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698