OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/login/auth/mock_authenticator.h" | 5 #include "chromeos/login/auth/stub_authenticator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 namespace chromeos { | 11 namespace chromeos { |
12 | 12 |
13 MockAuthenticator::MockAuthenticator(AuthStatusConsumer* consumer, | 13 namespace { |
| 14 |
| 15 // As defined in /chromeos/dbus/cryptohome_client.cc. |
| 16 static const char kUserIdHashSuffix[] = "-hash"; |
| 17 |
| 18 } // anonymous namespace |
| 19 |
| 20 StubAuthenticator::StubAuthenticator(AuthStatusConsumer* consumer, |
14 const UserContext& expected_user_context) | 21 const UserContext& expected_user_context) |
15 : Authenticator(consumer), | 22 : Authenticator(consumer), |
16 expected_user_context_(expected_user_context), | 23 expected_user_context_(expected_user_context), |
17 message_loop_(base::MessageLoopProxy::current()) { | 24 message_loop_(base::MessageLoopProxy::current()) { |
18 } | 25 } |
19 | 26 |
20 void MockAuthenticator::CompleteLogin(content::BrowserContext* ignored, | 27 void StubAuthenticator::CompleteLogin(content::BrowserContext* context, |
21 const UserContext& user_context) { | 28 const UserContext& user_context) { |
| 29 authentication_context_ = context; |
22 if (expected_user_context_ != user_context) | 30 if (expected_user_context_ != user_context) |
23 NOTREACHED(); | 31 NOTREACHED(); |
24 OnAuthSuccess(); | 32 OnAuthSuccess(); |
25 } | 33 } |
26 | 34 |
27 void MockAuthenticator::AuthenticateToLogin(content::BrowserContext* ignored, | 35 void StubAuthenticator::AuthenticateToLogin(content::BrowserContext* context, |
28 const UserContext& user_context) { | 36 const UserContext& user_context) { |
| 37 authentication_context_ = context; |
29 if (user_context == expected_user_context_) { | 38 if (user_context == expected_user_context_) { |
30 message_loop_->PostTask( | 39 message_loop_->PostTask( |
31 FROM_HERE, base::Bind(&MockAuthenticator::OnAuthSuccess, this)); | 40 FROM_HERE, base::Bind(&StubAuthenticator::OnAuthSuccess, this)); |
32 return; | 41 return; |
33 } | 42 } |
34 GoogleServiceAuthError error( | 43 GoogleServiceAuthError error( |
35 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 44 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
36 message_loop_->PostTask( | 45 message_loop_->PostTask( |
37 FROM_HERE, | 46 FROM_HERE, base::Bind(&StubAuthenticator::OnAuthFailure, this, |
38 base::Bind(&MockAuthenticator::OnAuthFailure, | 47 AuthFailure::FromNetworkAuthFailure(error))); |
39 this, | |
40 AuthFailure::FromNetworkAuthFailure(error))); | |
41 } | 48 } |
42 | 49 |
43 void MockAuthenticator::AuthenticateToUnlock(const UserContext& user_context) { | 50 void StubAuthenticator::AuthenticateToUnlock(const UserContext& user_context) { |
44 AuthenticateToLogin(NULL /* not used */, user_context); | 51 AuthenticateToLogin(NULL /* not used */, user_context); |
45 } | 52 } |
46 | 53 |
47 void MockAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { | 54 void StubAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { |
48 UserContext new_user_context = user_context; | 55 UserContext new_user_context = user_context; |
49 new_user_context.SetUserIDHash(user_context.GetUserID()); | 56 new_user_context.SetUserIDHash(user_context.GetUserID() + kUserIdHashSuffix); |
50 consumer_->OnAuthSuccess(new_user_context); | 57 consumer_->OnAuthSuccess(new_user_context); |
51 } | 58 } |
52 | 59 |
53 void MockAuthenticator::LoginOffTheRecord() { | 60 void StubAuthenticator::LoginOffTheRecord() { |
54 consumer_->OnOffTheRecordAuthSuccess(); | 61 consumer_->OnOffTheRecordAuthSuccess(); |
55 } | 62 } |
56 | 63 |
57 void MockAuthenticator::LoginAsPublicSession(const UserContext& user_context) { | 64 void StubAuthenticator::LoginAsPublicSession(const UserContext& user_context) { |
58 UserContext logged_in_user_context = user_context; | 65 UserContext logged_in_user_context = user_context; |
59 logged_in_user_context.SetUserIDHash(logged_in_user_context.GetUserID()); | 66 logged_in_user_context.SetIsUsingOAuth(false); |
| 67 logged_in_user_context.SetUserIDHash(logged_in_user_context.GetUserID() + |
| 68 kUserIdHashSuffix); |
60 consumer_->OnAuthSuccess(logged_in_user_context); | 69 consumer_->OnAuthSuccess(logged_in_user_context); |
61 } | 70 } |
62 | 71 |
63 void MockAuthenticator::LoginAsKioskAccount(const std::string& app_user_id, | 72 void StubAuthenticator::LoginAsKioskAccount(const std::string& app_user_id, |
64 bool use_guest_mount) { | 73 bool use_guest_mount) { |
65 UserContext user_context(expected_user_context_.GetUserID()); | 74 UserContext user_context(expected_user_context_.GetUserID()); |
66 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | 75 user_context.SetIsUsingOAuth(false); |
| 76 user_context.SetUserIDHash(expected_user_context_.GetUserID() + |
| 77 kUserIdHashSuffix); |
67 consumer_->OnAuthSuccess(user_context); | 78 consumer_->OnAuthSuccess(user_context); |
68 } | 79 } |
69 | 80 |
70 void MockAuthenticator::OnAuthSuccess() { | 81 void StubAuthenticator::OnAuthSuccess() { |
71 // If we want to be more like the real thing, we could save the user ID | 82 // If we want to be more like the real thing, we could save the user ID |
72 // in AuthenticateToLogin, but there's not much of a point. | 83 // in AuthenticateToLogin, but there's not much of a point. |
73 UserContext user_context(expected_user_context_); | 84 UserContext user_context(expected_user_context_); |
74 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | 85 user_context.SetUserIDHash(expected_user_context_.GetUserID() + |
| 86 kUserIdHashSuffix); |
75 consumer_->OnAuthSuccess(user_context); | 87 consumer_->OnAuthSuccess(user_context); |
76 } | 88 } |
77 | 89 |
78 void MockAuthenticator::OnAuthFailure(const AuthFailure& failure) { | 90 void StubAuthenticator::OnAuthFailure(const AuthFailure& failure) { |
79 consumer_->OnAuthFailure(failure); | 91 consumer_->OnAuthFailure(failure); |
80 } | 92 } |
81 | 93 |
82 void MockAuthenticator::RecoverEncryptedData(const std::string& old_password) { | 94 void StubAuthenticator::RecoverEncryptedData(const std::string& old_password) { |
83 } | 95 } |
84 | 96 |
85 void MockAuthenticator::ResyncEncryptedData() { | 97 void StubAuthenticator::ResyncEncryptedData() { |
86 } | 98 } |
87 | 99 |
88 void MockAuthenticator::SetExpectedCredentials( | 100 void StubAuthenticator::SetExpectedCredentials( |
89 const UserContext& user_context) { | 101 const UserContext& user_context) { |
90 expected_user_context_ = user_context; | 102 expected_user_context_ = user_context; |
91 } | 103 } |
92 | 104 |
93 MockAuthenticator::~MockAuthenticator() { | 105 StubAuthenticator::~StubAuthenticator() { |
94 } | 106 } |
95 | 107 |
96 } // namespace chromeos | 108 } // namespace chromeos |
OLD | NEW |