1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/login/auth/fake_extended_authenticator.h"
7 #include "base/logging.h"
8 #include "chromeos/login/auth/auth_status_consumer.h"
12 FakeExtendedAuthenticator::FakeExtendedAuthenticator(
13 NewAuthStatusConsumer
* consumer
,
14 const UserContext
& expected_user_context
)
15 : consumer_(consumer
),
17 expected_user_context_(expected_user_context
) {
20 FakeExtendedAuthenticator::FakeExtendedAuthenticator(
21 AuthStatusConsumer
* consumer
,
22 const UserContext
& expected_user_context
)
24 old_consumer_(consumer
),
25 expected_user_context_(expected_user_context
) {
28 FakeExtendedAuthenticator::~FakeExtendedAuthenticator() {
31 void FakeExtendedAuthenticator::SetConsumer(AuthStatusConsumer
* consumer
) {
32 old_consumer_
= consumer
;
35 void FakeExtendedAuthenticator::AuthenticateToMount(
36 const UserContext
& context
,
37 const ResultCallback
& success_callback
) {
38 if (expected_user_context_
== context
) {
39 UserContext
reported_user_context(context
);
40 const std::string mount_hash
= reported_user_context
.GetUserID() + "-hash";
41 reported_user_context
.SetUserIDHash(mount_hash
);
42 if (!success_callback
.is_null())
43 success_callback
.Run(mount_hash
);
44 OnAuthSuccess(reported_user_context
);
48 OnAuthFailure(FAILED_MOUNT
,
49 AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME
));
52 void FakeExtendedAuthenticator::AuthenticateToCheck(
53 const UserContext
& context
,
54 const base::Closure
& success_callback
) {
55 if (expected_user_context_
== context
) {
56 if (!success_callback
.is_null())
57 success_callback
.Run();
58 OnAuthSuccess(context
);
62 OnAuthFailure(FAILED_MOUNT
,
63 AuthFailure(AuthFailure::UNLOCK_FAILED
));
66 void FakeExtendedAuthenticator::CreateMount(const std::string
& user_id
,
67 const std::vector
<cryptohome::KeyDefinition
>& keys
,
68 const ResultCallback
& success_callback
) {
72 void FakeExtendedAuthenticator::AddKey(const UserContext
& context
,
73 const cryptohome::KeyDefinition
& key
,
74 bool replace_existing
,
75 const base::Closure
& success_callback
) {
79 void FakeExtendedAuthenticator::UpdateKeyAuthorized(
80 const UserContext
& context
,
81 const cryptohome::KeyDefinition
& key
,
82 const std::string
& signature
,
83 const base::Closure
& success_callback
) {
87 void FakeExtendedAuthenticator::RemoveKey(const UserContext
& context
,
88 const std::string
& key_to_remove
,
89 const base::Closure
& success_callback
) {
93 void FakeExtendedAuthenticator::TransformKeyIfNeeded(
94 const UserContext
& user_context
,
95 const ContextCallback
& callback
) {
96 if (!callback
.is_null())
97 callback
.Run(user_context
);
100 void FakeExtendedAuthenticator::OnAuthSuccess(const UserContext
& context
) {
102 old_consumer_
->OnAuthSuccess(context
);
105 void FakeExtendedAuthenticator::OnAuthFailure(AuthState state
,
106 const AuthFailure
& error
) {
108 consumer_
->OnAuthenticationFailure(state
);
110 old_consumer_
->OnAuthFailure(error
);
113 } // namespace chromeos