summaryrefslogtreecommitdiffstats
path: root/chromeos/login/auth/fake_extended_authenticator.cc
blob: e57755b99fe938b21b68b57b8a8ff7e7bc093ee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/login/auth/fake_extended_authenticator.h"

#include "base/logging.h"
#include "chromeos/login/auth/auth_status_consumer.h"
#include "components/signin/core/account_id/account_id.h"

namespace chromeos {

FakeExtendedAuthenticator::FakeExtendedAuthenticator(
    NewAuthStatusConsumer* consumer,
    const UserContext& expected_user_context)
    : consumer_(consumer),
      old_consumer_(NULL),
      expected_user_context_(expected_user_context) {
}

FakeExtendedAuthenticator::FakeExtendedAuthenticator(
    AuthStatusConsumer* consumer,
    const UserContext& expected_user_context)
    : consumer_(NULL),
      old_consumer_(consumer),
      expected_user_context_(expected_user_context) {
}

FakeExtendedAuthenticator::~FakeExtendedAuthenticator() {
}

void FakeExtendedAuthenticator::SetConsumer(AuthStatusConsumer* consumer) {
  old_consumer_ = consumer;
}

void FakeExtendedAuthenticator::AuthenticateToMount(
    const UserContext& context,
    const ResultCallback& success_callback) {
  if (expected_user_context_ == context) {
    UserContext reported_user_context(context);
    const std::string mount_hash =
        reported_user_context.GetAccountId().GetUserEmail() + "-hash";
    reported_user_context.SetUserIDHash(mount_hash);
    if (!success_callback.is_null())
      success_callback.Run(mount_hash);
    OnAuthSuccess(reported_user_context);
    return;
  }

  OnAuthFailure(FAILED_MOUNT,
                AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME));
}

void FakeExtendedAuthenticator::AuthenticateToCheck(
    const UserContext& context,
    const base::Closure& success_callback) {
  if (expected_user_context_ == context) {
    if (!success_callback.is_null())
      success_callback.Run();
    OnAuthSuccess(context);
    return;
  }

  OnAuthFailure(FAILED_MOUNT,
                AuthFailure(AuthFailure::UNLOCK_FAILED));
}

void FakeExtendedAuthenticator::CreateMount(const std::string& user_id,
                         const std::vector<cryptohome::KeyDefinition>& keys,
                         const ResultCallback& success_callback) {
  NOTREACHED();
}

void FakeExtendedAuthenticator::AddKey(const UserContext& context,
                    const cryptohome::KeyDefinition& key,
                    bool replace_existing,
                    const base::Closure& success_callback) {
  NOTREACHED();
}

void FakeExtendedAuthenticator::UpdateKeyAuthorized(
    const UserContext& context,
    const cryptohome::KeyDefinition& key,
    const std::string& signature,
    const base::Closure& success_callback) {
  NOTREACHED();
}

void FakeExtendedAuthenticator::RemoveKey(const UserContext& context,
                       const std::string& key_to_remove,
                       const base::Closure& success_callback) {
  NOTREACHED();
}

void FakeExtendedAuthenticator::TransformKeyIfNeeded(
    const UserContext& user_context,
    const ContextCallback& callback) {
  if (!callback.is_null())
    callback.Run(user_context);
}

void FakeExtendedAuthenticator::OnAuthSuccess(const UserContext& context) {
  if (old_consumer_)
    old_consumer_->OnAuthSuccess(context);
}

void FakeExtendedAuthenticator::OnAuthFailure(AuthState state,
                                              const AuthFailure& error) {
  if (consumer_)
    consumer_->OnAuthenticationFailure(state);
  if (old_consumer_)
    old_consumer_->OnAuthFailure(error);
}

}  // namespace chromeos