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

Unified Diff: chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc

Issue 296773002: Add a Key class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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/auth/parallel_authenticator_unittest.cc
diff --git a/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc
index c3c7fff22e8f01783aa555facc16d7bf06d3ad89..0a7d37168df9a2cf8130c5f98c38708270047407 100644
--- a/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc
@@ -13,6 +13,7 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "chrome/browser/chromeos/login/auth/key.h"
#include "chrome/browser/chromeos/login/auth/mock_login_status_consumer.h"
#include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h"
#include "chrome/browser/chromeos/login/auth/test_attempt_state.h"
@@ -46,14 +47,14 @@ namespace chromeos {
class ParallelAuthenticatorTest : public testing::Test {
public:
ParallelAuthenticatorTest()
- : username_("me@nowhere.org"),
- password_("fakepass"),
- hash_ascii_(ParallelAuthenticator::HashPassword(
- password_,
- SystemSaltGetter::ConvertRawSaltToHexString(
- FakeCryptohomeClient::GetStubSystemSalt()))),
+ : user_context_("me@nowhere.org"),
user_manager_enabler_(new MockUserManager),
mock_caller_(NULL) {
+ user_context_.SetKey(Key("fakepass"));
+ transformed_key_ = *user_context_.GetKey();
+ transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF,
+ SystemSaltGetter::ConvertRawSaltToHexString(
+ FakeCryptohomeClient::GetStubSystemSalt()));
}
virtual ~ParallelAuthenticatorTest() {
@@ -75,9 +76,7 @@ class ParallelAuthenticatorTest : public testing::Test {
SystemSaltGetter::Initialize();
auth_ = new ParallelAuthenticator(&consumer_);
- UserContext user_context(username_);
- user_context.SetPassword(password_);
- state_.reset(new TestAttemptState(user_context, false));
+ state_.reset(new TestAttemptState(user_context_, false));
}
// Tears down the test fixture.
@@ -138,13 +137,7 @@ class ParallelAuthenticatorTest : public testing::Test {
.RetiresOnSaturation();
}
- void ExpectLoginSuccess(const std::string& username,
- const std::string& password,
- const std::string& username_hash,
- bool pending) {
- UserContext user_context(username);
- user_context.SetPassword(password);
- user_context.SetUserIDHash(username_hash);
+ void ExpectLoginSuccess(const UserContext& user_context) {
EXPECT_CALL(consumer_, OnLoginSuccess(user_context))
.WillOnce(Invoke(MockConsumer::OnSuccessQuit))
.RetiresOnSaturation();
@@ -183,10 +176,8 @@ class ParallelAuthenticatorTest : public testing::Test {
content::TestBrowserThreadBundle thread_bundle_;
- std::string username_;
- std::string password_;
- std::string username_hash_;
- std::string hash_ascii_;
+ UserContext user_context_;
+ Key transformed_key_;
ScopedDeviceSettingsTestHelper device_settings_test_helper_;
ScopedTestCrosSettings test_cros_settings_;
@@ -202,10 +193,7 @@ class ParallelAuthenticatorTest : public testing::Test {
};
TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) {
- UserContext user_context(username_);
- user_context.SetPassword(password_);
- user_context.SetUserIDHash(username_hash_);
- EXPECT_CALL(consumer_, OnLoginSuccess(user_context))
+ EXPECT_CALL(consumer_, OnLoginSuccess(user_context_))
.Times(1)
.RetiresOnSaturation();
@@ -268,10 +256,8 @@ TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) {
// the mount finish successfully.
state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
SetOwnerState(false, false);
- // and test that the mount has succeeded.
- UserContext user_context(username_);
- user_context.SetPassword(password_);
- state_.reset(new TestAttemptState(user_context, false));
+ // Test that the mount has succeeded.
+ state_.reset(new TestAttemptState(user_context_, false));
state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN,
SetAndResolveState(auth_.get(), state_.release()));
@@ -313,10 +299,8 @@ TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) {
// Flush all the pending operations. The operations should induce an owner
// verification.
device_settings_test_helper_.Flush();
- // and test that the mount has succeeded.
- UserContext user_context(username_);
- user_context.SetPassword(password_);
- state_.reset(new TestAttemptState(user_context, false));
+ // Test that the mount has succeeded.
+ state_.reset(new TestAttemptState(user_context_, false));
state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED,
SetAndResolveState(auth_.get(), state_.release()));
@@ -401,24 +385,27 @@ TEST_F(ParallelAuthenticatorTest, DriveRetailModeLoginButFail) {
}
TEST_F(ParallelAuthenticatorTest, DriveDataResync) {
- ExpectLoginSuccess(username_,
- password_,
- cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername,
- false);
+ UserContext expected_user_context(user_context_);
+ expected_user_context.SetUserIDHash(
+ cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
+ ExpectLoginSuccess(expected_user_context);
FailOnLoginFailure();
// Set up mock async method caller to respond successfully to a cryptohome
// remove attempt and a cryptohome create attempt (indicated by the
// |CREATE_IF_MISSING| flag to AsyncMount).
mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
- EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _))
+ EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_,
- cryptohome::CREATE_IF_MISSING, _))
+ EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(),
+ transformed_key_.GetSecret(),
+ cryptohome::CREATE_IF_MISSING,
+ _))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _))
+ EXPECT_CALL(*mock_caller_,
+ AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
.Times(1)
.RetiresOnSaturation();
@@ -435,7 +422,7 @@ TEST_F(ParallelAuthenticatorTest, DriveResyncFail) {
// Set up mock async method caller to fail a cryptohome remove attempt.
mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE);
- EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _))
+ EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
.Times(1)
.RetiresOnSaturation();
@@ -457,22 +444,28 @@ TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) {
}
TEST_F(ParallelAuthenticatorTest, DriveDataRecover) {
- ExpectLoginSuccess(username_,
- password_,
- cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername,
- false);
+ UserContext expected_user_context(user_context_);
+ expected_user_context.SetUserIDHash(
+ cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
+ ExpectLoginSuccess(expected_user_context);
FailOnLoginFailure();
// Set up mock async method caller to respond successfully to a key migration.
mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
- EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _))
+ EXPECT_CALL(*mock_caller_, AsyncMigrateKey(user_context_.GetUserID(),
+ _,
+ transformed_key_.GetSecret(),
+ _))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_,
- cryptohome::MOUNT_FLAGS_NONE, _))
+ EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(),
+ transformed_key_.GetSecret(),
+ cryptohome::MOUNT_FLAGS_NONE,
+ _))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _))
+ EXPECT_CALL(*mock_caller_,
+ AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
.Times(1)
.RetiresOnSaturation();
@@ -490,7 +483,10 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) {
// Set up mock async method caller to fail a key migration attempt,
// asserting that the wrong password was used.
mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
- EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _))
+ EXPECT_CALL(*mock_caller_, AsyncMigrateKey(user_context_.GetUserID(),
+ _,
+ transformed_key_.GetSecret(),
+ _))
.Times(1)
.RetiresOnSaturation();
@@ -525,20 +521,23 @@ TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) {
}
TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) {
- ExpectLoginSuccess(username_,
- password_,
- cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername,
- false);
+ UserContext expected_user_context(user_context_);
+ expected_user_context.SetUserIDHash(
+ cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
+ ExpectLoginSuccess(expected_user_context);
FailOnLoginFailure();
// Set up mock async method caller to respond successfully to a cryptohome
// create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount).
mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
- EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_,
- cryptohome::CREATE_IF_MISSING, _))
+ EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(),
+ transformed_key_.GetSecret(),
+ cryptohome::CREATE_IF_MISSING,
+ _))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _))
+ EXPECT_CALL(*mock_caller_,
+ AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
.Times(1)
.RetiresOnSaturation();
@@ -554,7 +553,7 @@ TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) {
}
TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) {
- ExpectLoginSuccess(username_, password_, username_hash_, false);
+ ExpectLoginSuccess(user_context_);
FailOnLoginFailure();
// Set up state as though a cryptohome mount attempt has occurred and
@@ -566,7 +565,7 @@ TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) {
}
TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) {
- ExpectLoginSuccess(username_, password_, username_hash_, false);
+ ExpectLoginSuccess(user_context_);
FailOnLoginFailure();
// Set up state as though a cryptohome mount attempt has occurred and
@@ -579,17 +578,17 @@ TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) {
}
TEST_F(ParallelAuthenticatorTest, DriveUnlock) {
- ExpectLoginSuccess(username_, std::string(), std::string(), false);
+ ExpectLoginSuccess(user_context_);
FailOnLoginFailure();
// Set up mock async method caller to respond successfully to a cryptohome
// key-check attempt.
mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
- EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _))
+ EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _))
.Times(1)
.RetiresOnSaturation();
- auth_->AuthenticateToUnlock(UserContext(username_));
+ auth_->AuthenticateToUnlock(user_context_);
base::MessageLoop::current()->Run();
}
« no previous file with comments | « chrome/browser/chromeos/login/auth/parallel_authenticator.cc ('k') | chrome/browser/chromeos/login/auth/user_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698