| Index: chrome/browser/signin/local_auth_unittest.cc
|
| diff --git a/chrome/browser/signin/local_auth_unittest.cc b/chrome/browser/signin/local_auth_unittest.cc
|
| index 68ee397043ad9c9614b444ad6611043eda24453d..bf47094a16dee4d38e3417c65a7fb7a3234e1f1b 100644
|
| --- a/chrome/browser/signin/local_auth_unittest.cc
|
| +++ b/chrome/browser/signin/local_auth_unittest.cc
|
| @@ -42,7 +42,7 @@ TEST(LocalAuthTest, SetAndCheckCredentials) {
|
| // - The encoding exists (we can guarantee future backward compatibility).
|
| // - The plaintext version of the password is not mistakenly stored anywhere.
|
| EXPECT_FALSE(passhash.empty());
|
| - EXPECT_EQ('1', passhash[0]);
|
| + EXPECT_EQ('2', passhash[0]);
|
| EXPECT_EQ(passhash.find(password), std::string::npos);
|
|
|
| std::string decodedhash;
|
| @@ -56,3 +56,58 @@ TEST(LocalAuthTest, SetAndCheckCredentials) {
|
| SetLocalAuthCredentials(prof, password); // makes different salt
|
| EXPECT_NE(passhash, cache.GetLocalAuthCredentialsOfProfileAtIndex(0));
|
| }
|
| +
|
| +
|
| +TEST(LocalAuthTest, SetUpgradeAndCheckCredentials) {
|
| + TestingProfileManager testing_profile_manager(
|
| + TestingBrowserProcess::GetGlobal());
|
| + ASSERT_TRUE(testing_profile_manager.SetUp());
|
| + Profile* prof = testing_profile_manager.CreateTestingProfile("p1");
|
| + ProfileInfoCache& cache =
|
| + testing_profile_manager.profile_manager()->GetProfileInfoCache();
|
| +
|
| + std::string password("Some Password");
|
| + size_t profile_index = cache.GetIndexOfProfileWithPath(prof->GetPath());
|
| + SetLocalAuthCredentialsWithEncoding(profile_index, password, '1');
|
| +
|
| + // Ensure we indeed persisted the correct encoding.
|
| + std::string oldpasshash = cache.GetLocalAuthCredentialsOfProfileAtIndex(
|
| + profile_index);
|
| + EXPECT_EQ('1', oldpasshash[0]);
|
| +
|
| + // Validate, ensure we can validate against the old encoding.
|
| + EXPECT_TRUE(ValidateLocalAuthCredentials(prof, password));
|
| +
|
| + // Ensure we updated the encoding.
|
| + std::string newpasshash = cache.GetLocalAuthCredentialsOfProfileAtIndex(
|
| + profile_index);
|
| + EXPECT_EQ('2', newpasshash[0]);
|
| + // Encoding '2' writes fewer bytes than encoding '1'.
|
| + EXPECT_LE(newpasshash.length(), oldpasshash.length());
|
| +
|
| + // Validate, ensure we validate against the new encoding.
|
| + EXPECT_TRUE(ValidateLocalAuthCredentials(prof, password));
|
| +}
|
| +
|
| +TEST(LocalAuthTest, TruncateStringTo16Bits) {
|
| + std::string two_chars = "AB";
|
| + std::string three_chars = "ABC";
|
| + EXPECT_EQ(two_chars, TruncateStringByBits(two_chars, 16));
|
| + EXPECT_EQ(two_chars, TruncateStringByBits(three_chars, 16));
|
| +}
|
| +
|
| +TEST(LocalAuthTest, TruncateStringTo14BitsLowBitsOnly) {
|
| + std::string two_chars = "A6";
|
| + std::string three_chars = "A6C";
|
| + EXPECT_EQ(two_chars, TruncateStringByBits(two_chars, 14));
|
| + EXPECT_EQ(two_chars, TruncateStringByBits(three_chars, 14));
|
| +}
|
| +
|
| +TEST(LocalAuthTest, TruncateStringTo14BitsLowAndHighBits) {
|
| + std::string two_chars = "Az";
|
| + std::string three_chars = "AzC";
|
| + // 'z' = 0x7A, ':' = 0x3A.
|
| + std::string two_chars_truncated = "A:";
|
| + EXPECT_EQ(two_chars_truncated, TruncateStringByBits(two_chars, 14));
|
| + EXPECT_EQ(two_chars_truncated, TruncateStringByBits(three_chars, 14));
|
| +}
|
|
|