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

Side by Side Diff: chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc

Issue 495563003: Move ParallelAuthnticator to chromeos and rename it to CryptohomeAuthenticator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/chromeos/login/auth/parallel_authenticator.h" 5 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 using ::testing::Invoke; 49 using ::testing::Invoke;
50 using ::testing::Return; 50 using ::testing::Return;
51 using ::testing::_; 51 using ::testing::_;
52 52
53 namespace chromeos { 53 namespace chromeos {
54 54
55 namespace { 55 namespace {
56 56
57 // An owner key in PKCS#8 PrivateKeyInfo for testing owner checks. 57 // An owner key in PKCS#8 PrivateKeyInfo for testing owner checks.
58 const uint8 kOwnerPrivateKey[] = { 58 const uint8 kOwnerPrivateKey[] = {
59 0x30, 0x82, 0x01, 0x53, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 59 0x30, 0x82, 0x01, 0x53, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
60 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 60 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
61 0x01, 0x3d, 0x30, 0x82, 0x01, 0x39, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 61 0x01, 0x3d, 0x30, 0x82, 0x01, 0x39, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00,
62 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e, 0xdf, 62 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e, 0xdf,
63 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4, 0xf3, 63 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4, 0xf3,
64 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc, 0xbb, 64 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc, 0xbb,
65 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0, 0x15, 65 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0, 0x15,
66 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9, 0x3d, 66 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9, 0x3d,
67 0x3e, 0x2a, 0x68, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x40, 67 0x3e, 0x2a, 0x68, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x40,
68 0xc7, 0xb5, 0xb3, 0xbc, 0xac, 0x0a, 0x77, 0x02, 0x0f, 0x05, 0xda, 0xdb, 68 0xc7, 0xb5, 0xb3, 0xbc, 0xac, 0x0a, 0x77, 0x02, 0x0f, 0x05, 0xda, 0xdb,
69 0xfc, 0x48, 0xf6, 0x0a, 0xb5, 0xf2, 0xef, 0x31, 0x1c, 0x36, 0xb1, 0x0f, 69 0xfc, 0x48, 0xf6, 0x0a, 0xb5, 0xf2, 0xef, 0x31, 0x1c, 0x36, 0xb1, 0x0f,
70 0xa7, 0x5a, 0xf3, 0xb9, 0xa3, 0x4e, 0xb8, 0xf6, 0x10, 0xfe, 0x25, 0x7b, 70 0xa7, 0x5a, 0xf3, 0xb9, 0xa3, 0x4e, 0xb8, 0xf6, 0x10, 0xfe, 0x25, 0x7b,
71 0x36, 0xb4, 0x1b, 0x80, 0xe3, 0x92, 0x37, 0x83, 0xf0, 0x43, 0xb3, 0x00, 71 0x36, 0xb4, 0x1b, 0x80, 0xe3, 0x92, 0x37, 0x83, 0xf0, 0x43, 0xb3, 0x00,
72 0xa6, 0x53, 0xc6, 0x1b, 0x7e, 0x4b, 0xb0, 0x33, 0xd4, 0xe1, 0x03, 0xc4, 72 0xa6, 0x53, 0xc6, 0x1b, 0x7e, 0x4b, 0xb0, 0x33, 0xd4, 0xe1, 0x03, 0xc4,
73 0xaa, 0xbc, 0x89, 0x02, 0x21, 0x00, 0xde, 0xc8, 0x8d, 0x10, 0xbc, 0xf3, 73 0xaa, 0xbc, 0x89, 0x02, 0x21, 0x00, 0xde, 0xc8, 0x8d, 0x10, 0xbc, 0xf3,
74 0x43, 0x49, 0x1f, 0x07, 0xf7, 0x12, 0xeb, 0x0a, 0x90, 0xab, 0xb9, 0xaa, 74 0x43, 0x49, 0x1f, 0x07, 0xf7, 0x12, 0xeb, 0x0a, 0x90, 0xab, 0xb9, 0xaa,
75 0x81, 0xb5, 0x54, 0x71, 0xf4, 0x2e, 0xc4, 0x44, 0xec, 0xff, 0x7d, 0xff, 75 0x81, 0xb5, 0x54, 0x71, 0xf4, 0x2e, 0xc4, 0x44, 0xec, 0xff, 0x7d, 0xff,
76 0xe8, 0xa5, 0x02, 0x21, 0x00, 0xcf, 0xf0, 0xbe, 0xa6, 0xde, 0x9c, 0x70, 76 0xe8, 0xa5, 0x02, 0x21, 0x00, 0xcf, 0xf0, 0xbe, 0xa6, 0xde, 0x9c, 0x70,
77 0xed, 0xf0, 0xc3, 0x18, 0x9b, 0xca, 0xe5, 0x7c, 0x4b, 0x9b, 0xf5, 0x12, 77 0xed, 0xf0, 0xc3, 0x18, 0x9b, 0xca, 0xe5, 0x7c, 0x4b, 0x9b, 0xf5, 0x12,
78 0x5d, 0x86, 0xbe, 0x8d, 0xf1, 0xbc, 0x2c, 0x79, 0x59, 0xf5, 0xff, 0xbc, 78 0x5d, 0x86, 0xbe, 0x8d, 0xf1, 0xbc, 0x2c, 0x79, 0x59, 0xf5, 0xff, 0xbc,
79 0x6b, 0x02, 0x20, 0x7c, 0x09, 0x1c, 0xc1, 0x1c, 0xf2, 0x33, 0x9c, 0x1a, 79 0x6b, 0x02, 0x20, 0x7c, 0x09, 0x1c, 0xc1, 0x1c, 0xf2, 0x33, 0x9c, 0x1a,
80 0x72, 0xcc, 0xd4, 0xf3, 0x97, 0xc6, 0x44, 0x55, 0xf2, 0xe0, 0x94, 0x9c, 80 0x72, 0xcc, 0xd4, 0xf3, 0x97, 0xc6, 0x44, 0x55, 0xf2, 0xe0, 0x94, 0x9c,
81 0x97, 0x75, 0x64, 0x34, 0x52, 0x4b, 0xc1, 0x53, 0xdd, 0x8f, 0x21, 0x02, 81 0x97, 0x75, 0x64, 0x34, 0x52, 0x4b, 0xc1, 0x53, 0xdd, 0x8f, 0x21, 0x02,
82 0x20, 0x0e, 0xef, 0x48, 0x92, 0x2d, 0x9c, 0xe8, 0xd3, 0x7e, 0x1e, 0x55, 82 0x20, 0x0e, 0xef, 0x48, 0x92, 0x2d, 0x9c, 0xe8, 0xd3, 0x7e, 0x1e, 0x55,
83 0x0f, 0x23, 0x74, 0x76, 0x07, 0xec, 0x2c, 0x9e, 0xe4, 0x0e, 0xc0, 0x72, 83 0x0f, 0x23, 0x74, 0x76, 0x07, 0xec, 0x2c, 0x9e, 0xe4, 0x0e, 0xc0, 0x72,
84 0xeb, 0x70, 0xcb, 0x74, 0xef, 0xcc, 0x26, 0x50, 0xff, 0x02, 0x20, 0x29, 84 0xeb, 0x70, 0xcb, 0x74, 0xef, 0xcc, 0x26, 0x50, 0xff, 0x02, 0x20, 0x29,
85 0x32, 0xd0, 0xbf, 0x11, 0xf2, 0xbf, 0x54, 0xfd, 0x6d, 0xf2, 0x1c, 0xbe, 85 0x32, 0xd0, 0xbf, 0x11, 0xf2, 0xbf, 0x54, 0xfd, 0x6d, 0xf2, 0x1c, 0xbe,
86 0x50, 0x18, 0x62, 0x6d, 0x23, 0xe4, 0x26, 0x03, 0x8b, 0xb3, 0x42, 0x24, 86 0x50, 0x18, 0x62, 0x6d, 0x23, 0xe4, 0x26, 0x03, 0x8b, 0xb3, 0x42, 0x24,
87 0x7e, 0x68, 0x37, 0x26, 0xda, 0xb9, 0x87 87 0x7e, 0x68, 0x37, 0x26, 0xda, 0xb9, 0x87};
88 };
89 88
90 // The public key alone matcing kOwnerPrivateKey. 89 // The public key alone matcing kOwnerPrivateKey.
91 const uint8 kOwnerPublicKey[] = { 90 const uint8 kOwnerPublicKey[] = {
92 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 91 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
93 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 92 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41,
94 0x00, 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e, 93 0x00, 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e,
95 0xdf, 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4, 94 0xdf, 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4,
96 0xf3, 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc, 95 0xf3, 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc,
97 0xbb, 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0, 96 0xbb, 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0,
98 0x15, 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9, 97 0x15, 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9,
99 0x3d, 0x3e, 0x2a, 0x68, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01 98 0x3d, 0x3e, 0x2a, 0x68, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01};
100 };
101 99
102 std::vector<uint8> GetOwnerPublicKey() { 100 std::vector<uint8> GetOwnerPublicKey() {
103 return std::vector<uint8>(kOwnerPublicKey, 101 return std::vector<uint8>(kOwnerPublicKey,
104 kOwnerPublicKey + arraysize(kOwnerPublicKey)); 102 kOwnerPublicKey + arraysize(kOwnerPublicKey));
105 } 103 }
106 104
107 scoped_ptr<crypto::RSAPrivateKey> CreateOwnerKeyInSlot(PK11SlotInfo* slot) { 105 scoped_ptr<crypto::RSAPrivateKey> CreateOwnerKeyInSlot(PK11SlotInfo* slot) {
108 const std::vector<uint8> key(kOwnerPrivateKey, 106 const std::vector<uint8> key(kOwnerPrivateKey,
109 kOwnerPrivateKey + arraysize(kOwnerPrivateKey)); 107 kOwnerPrivateKey + arraysize(kOwnerPrivateKey));
110 return make_scoped_ptr( 108 return make_scoped_ptr(
111 crypto::RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo(slot, key)); 109 crypto::RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo(slot, key));
112 } 110 }
113 111
114 } // namespace 112 } // namespace
115 113
116 class ParallelAuthenticatorTest : public testing::Test { 114 class CryptohomeAuthenticatorTest : public testing::Test {
117 public: 115 public:
118 ParallelAuthenticatorTest() 116 CryptohomeAuthenticatorTest()
119 : user_context_("me@nowhere.org"), 117 : user_context_("me@nowhere.org"),
120 user_manager_(new FakeUserManager()), 118 user_manager_(new FakeUserManager()),
121 user_manager_enabler_(user_manager_), 119 user_manager_enabler_(user_manager_),
122 mock_caller_(NULL), 120 mock_caller_(NULL),
123 owner_key_util_(new MockOwnerKeyUtil) { 121 owner_key_util_(new MockOwnerKeyUtil) {
124 user_context_.SetKey(Key("fakepass")); 122 user_context_.SetKey(Key("fakepass"));
125 user_context_.SetUserIDHash("me_nowhere_com_hash"); 123 user_context_.SetUserIDHash("me_nowhere_com_hash");
126 const user_manager::User* user = 124 const user_manager::User* user =
127 user_manager_->AddUser(user_context_.GetUserID()); 125 user_manager_->AddUser(user_context_.GetUserID());
128 profile_.set_profile_name(user_context_.GetUserID()); 126 profile_.set_profile_name(user_context_.GetUserID());
129 127
130 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); 128 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_);
131 129
132 transformed_key_ = *user_context_.GetKey(); 130 transformed_key_ = *user_context_.GetKey();
133 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, 131 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF,
134 SystemSaltGetter::ConvertRawSaltToHexString( 132 SystemSaltGetter::ConvertRawSaltToHexString(
135 FakeCryptohomeClient::GetStubSystemSalt())); 133 FakeCryptohomeClient::GetStubSystemSalt()));
136 } 134 }
137 135
138 virtual ~ParallelAuthenticatorTest() {} 136 virtual ~CryptohomeAuthenticatorTest() {}
139 137
140 virtual void SetUp() { 138 virtual void SetUp() {
141 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager); 139 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager);
142 140
143 mock_caller_ = new cryptohome::MockAsyncMethodCaller; 141 mock_caller_ = new cryptohome::MockAsyncMethodCaller;
144 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); 142 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_);
145 143
146 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; 144 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
147 fake_cryptohome_client_ = new FakeCryptohomeClient; 145 fake_cryptohome_client_ = new FakeCryptohomeClient;
148 fake_dbus_thread_manager->SetCryptohomeClient( 146 fake_dbus_thread_manager->SetCryptohomeClient(
149 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); 147 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_));
150 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager); 148 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager);
151 149
152 SystemSaltGetter::Initialize(); 150 SystemSaltGetter::Initialize();
153 151
154 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_); 152 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_);
155 153
156 auth_ = new ParallelAuthenticator(&consumer_); 154 auth_ = new ChromeCryptohomeAuthenticator(&consumer_);
157 state_.reset(new TestAttemptState(user_context_, false)); 155 state_.reset(new TestAttemptState(user_context_, false));
158 } 156 }
159 157
160 // Tears down the test fixture. 158 // Tears down the test fixture.
161 virtual void TearDown() { 159 virtual void TearDown() {
162 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL); 160 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL);
163 SystemSaltGetter::Shutdown(); 161 SystemSaltGetter::Shutdown();
164 DBusThreadManager::Shutdown(); 162 DBusThreadManager::Shutdown();
165 163
166 cryptohome::AsyncMethodCaller::Shutdown(); 164 cryptohome::AsyncMethodCaller::Shutdown();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 .WillOnce(Invoke(MockAuthStatusConsumer::OnGuestSuccessQuit)) 225 .WillOnce(Invoke(MockAuthStatusConsumer::OnGuestSuccessQuit))
228 .RetiresOnSaturation(); 226 .RetiresOnSaturation();
229 } 227 }
230 228
231 void ExpectPasswordChange() { 229 void ExpectPasswordChange() {
232 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) 230 EXPECT_CALL(consumer_, OnPasswordChangeDetected())
233 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit)) 231 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit))
234 .RetiresOnSaturation(); 232 .RetiresOnSaturation();
235 } 233 }
236 234
237 void RunResolve(ParallelAuthenticator* auth) { 235 void RunResolve(CryptohomeAuthenticator* auth) {
238 auth->Resolve(); 236 auth->Resolve();
239 base::MessageLoop::current()->RunUntilIdle(); 237 base::MessageLoop::current()->RunUntilIdle();
240 } 238 }
241 239
242 void SetAttemptState(ParallelAuthenticator* auth, TestAttemptState* state) { 240 void SetAttemptState(CryptohomeAuthenticator* auth, TestAttemptState* state) {
243 auth->set_attempt_state(state); 241 auth->set_attempt_state(state);
244 } 242 }
245 243
246 ParallelAuthenticator::AuthState SetAndResolveState( 244 CryptohomeAuthenticator::AuthState SetAndResolveState(
247 ParallelAuthenticator* auth, TestAttemptState* state) { 245 CryptohomeAuthenticator* auth,
246 TestAttemptState* state) {
248 auth->set_attempt_state(state); 247 auth->set_attempt_state(state);
249 return auth->ResolveState(); 248 return auth->ResolveState();
250 } 249 }
251 250
252 void SetOwnerState(bool owner_check_finished, bool check_result) { 251 void SetOwnerState(bool owner_check_finished, bool check_result) {
253 auth_->SetOwnerState(owner_check_finished, check_result); 252 auth_->SetOwnerState(owner_check_finished, check_result);
254 } 253 }
255 254
256 content::TestBrowserThreadBundle thread_bundle_; 255 content::TestBrowserThreadBundle thread_bundle_;
257 256
258 UserContext user_context_; 257 UserContext user_context_;
259 Key transformed_key_; 258 Key transformed_key_;
260 259
261 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 260 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
262 ScopedTestCrosSettings test_cros_settings_; 261 ScopedTestCrosSettings test_cros_settings_;
263 262
264 TestingProfile profile_; 263 TestingProfile profile_;
265 scoped_ptr<TestingProfileManager> profile_manager_; 264 scoped_ptr<TestingProfileManager> profile_manager_;
266 FakeUserManager* user_manager_; 265 FakeUserManager* user_manager_;
267 ScopedUserManagerEnabler user_manager_enabler_; 266 ScopedUserManagerEnabler user_manager_enabler_;
268 267
269 cryptohome::MockAsyncMethodCaller* mock_caller_; 268 cryptohome::MockAsyncMethodCaller* mock_caller_;
270 269
271 MockAuthStatusConsumer consumer_; 270 MockAuthStatusConsumer consumer_;
272 271
273 scoped_refptr<ParallelAuthenticator> auth_; 272 scoped_refptr<CryptohomeAuthenticator> auth_;
274 scoped_ptr<TestAttemptState> state_; 273 scoped_ptr<TestAttemptState> state_;
275 FakeCryptohomeClient* fake_cryptohome_client_; 274 FakeCryptohomeClient* fake_cryptohome_client_;
276 275
277 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; 276 scoped_refptr<MockOwnerKeyUtil> owner_key_util_;
278 }; 277 };
279 278
280 TEST_F(ParallelAuthenticatorTest, OnAuthSuccess) { 279 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) {
281 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) 280 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_))
282 .Times(1) 281 .Times(1)
283 .RetiresOnSaturation(); 282 .RetiresOnSaturation();
284 283
285 SetAttemptState(auth_.get(), state_.release()); 284 SetAttemptState(auth_.get(), state_.release());
286 auth_->OnAuthSuccess(); 285 auth_->OnAuthSuccess();
287 } 286 }
288 287
289 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) { 288 TEST_F(CryptohomeAuthenticatorTest, OnPasswordChangeDetected) {
290 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) 289 EXPECT_CALL(consumer_, OnPasswordChangeDetected())
291 .Times(1) 290 .Times(1)
292 .RetiresOnSaturation(); 291 .RetiresOnSaturation();
293 SetAttemptState(auth_.get(), state_.release()); 292 SetAttemptState(auth_.get(), state_.release());
294 auth_->OnPasswordChangeDetected(); 293 auth_->OnPasswordChangeDetected();
295 } 294 }
296 295
297 TEST_F(ParallelAuthenticatorTest, ResolveNothingDone) { 296 TEST_F(CryptohomeAuthenticatorTest, ResolveNothingDone) {
298 EXPECT_EQ(ParallelAuthenticator::CONTINUE, 297 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE,
299 SetAndResolveState(auth_.get(), state_.release())); 298 SetAndResolveState(auth_.get(), state_.release()));
300 } 299 }
301 300
302 301 TEST_F(CryptohomeAuthenticatorTest, ResolvePossiblePwChangeToFailedMount) {
303 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChangeToFailedMount) {
304 // Set up state as though a cryptohome mount attempt has occurred 302 // Set up state as though a cryptohome mount attempt has occurred
305 // and been rejected. 303 // and been rejected.
306 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); 304 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
307 305
308 // When there is no online attempt and online results, POSSIBLE_PW_CHANGE 306 // When there is no online attempt and online results, POSSIBLE_PW_CHANGE
309 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, 307 EXPECT_EQ(CryptohomeAuthenticator::FAILED_MOUNT,
310 SetAndResolveState(auth_.get(), state_.release())); 308 SetAndResolveState(auth_.get(), state_.release()));
311 } 309 }
312 310
313 TEST_F(ParallelAuthenticatorTest, ResolveNeedOldPw) { 311 TEST_F(CryptohomeAuthenticatorTest, ResolveNeedOldPw) {
314 // Set up state as though a cryptohome mount attempt has occurred 312 // Set up state as though a cryptohome mount attempt has occurred
315 // and been rejected because of unmatched key; additionally, 313 // and been rejected because of unmatched key; additionally,
316 // an online auth attempt has completed successfully. 314 // an online auth attempt has completed successfully.
317 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); 315 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
318 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 316 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
319 317
320 EXPECT_EQ(ParallelAuthenticator::NEED_OLD_PW, 318 EXPECT_EQ(CryptohomeAuthenticator::NEED_OLD_PW,
321 SetAndResolveState(auth_.get(), state_.release())); 319 SetAndResolveState(auth_.get(), state_.release()));
322 } 320 }
323 321
324 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededDirectFailedMount) { 322 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededDirectFailedMount) {
325 // Set up state as though a cryptohome mount attempt has occurred 323 // Set up state as though a cryptohome mount attempt has occurred
326 // and succeeded but we are in safe mode and the current user is not owner. 324 // and succeeded but we are in safe mode and the current user is not owner.
327 // This is a high level test to verify the proper transitioning in this mode 325 // This is a high level test to verify the proper transitioning in this mode
328 // only. It is not testing that we properly verify that the user is an owner 326 // only. It is not testing that we properly verify that the user is an owner
329 // or that we really are in "safe-mode". 327 // or that we really are in "safe-mode".
330 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 328 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
331 SetOwnerState(true, false); 329 SetOwnerState(true, false);
332 330
333 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, 331 EXPECT_EQ(CryptohomeAuthenticator::OWNER_REQUIRED,
334 SetAndResolveState(auth_.get(), state_.release())); 332 SetAndResolveState(auth_.get(), state_.release()));
335 } 333 }
336 334
337 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) { 335 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededMount) {
338 // Set up state as though a cryptohome mount attempt has occurred 336 // Set up state as though a cryptohome mount attempt has occurred
339 // and succeeded but we are in safe mode and the current user is not owner. 337 // and succeeded but we are in safe mode and the current user is not owner.
340 // This test will check that the "safe-mode" policy is not set and will let 338 // This test will check that the "safe-mode" policy is not set and will let
341 // the mount finish successfully. 339 // the mount finish successfully.
342 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 340 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
343 SetOwnerState(false, false); 341 SetOwnerState(false, false);
344 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, 342 EXPECT_EQ(CryptohomeAuthenticator::OFFLINE_LOGIN,
345 SetAndResolveState(auth_.get(), state_.release())); 343 SetAndResolveState(auth_.get(), state_.release()));
346 } 344 }
347 345
348 // Test the case that login switches to SafeMode and a User that is not the 346 // Test the case that login switches to SafeMode and a User that is not the
349 // owner tries to log in. The login should fail because of the missing owner 347 // owner tries to log in. The login should fail because of the missing owner
350 // private key. 348 // private key.
351 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { 349 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededFailedMount) {
352 crypto::ScopedTestNSSChromeOSUser user_slot(user_context_.GetUserIDHash()); 350 crypto::ScopedTestNSSChromeOSUser user_slot(user_context_.GetUserIDHash());
353 owner_key_util_->SetPublicKey(GetOwnerPublicKey()); 351 owner_key_util_->SetPublicKey(GetOwnerPublicKey());
354 352
355 profile_manager_.reset( 353 profile_manager_.reset(
356 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 354 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
357 ASSERT_TRUE(profile_manager_->SetUp()); 355 ASSERT_TRUE(profile_manager_->SetUp());
358 356
359 FailOnLoginSuccess(); // Set failing on success as the default... 357 FailOnLoginSuccess(); // Set failing on success as the default...
360 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED); 358 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED);
361 ExpectLoginFailure(failure); 359 ExpectLoginFailure(failure);
362 360
363 // Set up state as though a cryptohome mount attempt has occurred 361 // Set up state as though a cryptohome mount attempt has occurred
364 // and succeeded but we are in safe mode and the current user is not owner. 362 // and succeeded but we are in safe mode and the current user is not owner.
365 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 363 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
366 SetOwnerState(false, false); 364 SetOwnerState(false, false);
367 // Remove the real DeviceSettingsProvider and replace it with a stub. 365 // Remove the real DeviceSettingsProvider and replace it with a stub.
368 CrosSettingsProvider* device_settings_provider = 366 CrosSettingsProvider* device_settings_provider =
369 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); 367 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo);
370 EXPECT_TRUE(device_settings_provider != NULL); 368 EXPECT_TRUE(device_settings_provider != NULL);
371 EXPECT_TRUE( 369 EXPECT_TRUE(
372 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); 370 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
373 StubCrosSettingsProvider stub_settings_provider; 371 StubCrosSettingsProvider stub_settings_provider;
374 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); 372 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
375 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); 373 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
376 374
377 // Initialize login state for this test to verify the login state is changed 375 // Initialize login state for this test to verify the login state is changed
378 // to SAFE_MODE. 376 // to SAFE_MODE.
379 LoginState::Initialize(); 377 LoginState::Initialize();
380 378
381 EXPECT_EQ(ParallelAuthenticator::CONTINUE, 379 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE,
382 SetAndResolveState(auth_.get(), state_.release())); 380 SetAndResolveState(auth_.get(), state_.release()));
383 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 381 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
384 382
385 // Flush all the pending operations. The operations should induce an owner 383 // Flush all the pending operations. The operations should induce an owner
386 // verification. 384 // verification.
387 device_settings_test_helper_.Flush(); 385 device_settings_test_helper_.Flush();
388 386
389 state_.reset(new TestAttemptState(user_context_, false)); 387 state_.reset(new TestAttemptState(user_context_, false));
390 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 388 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
391 389
392 // The owner key util should not have found the owner key, so login should 390 // The owner key util should not have found the owner key, so login should
393 // not be allowed. 391 // not be allowed.
394 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, 392 EXPECT_EQ(CryptohomeAuthenticator::OWNER_REQUIRED,
395 SetAndResolveState(auth_.get(), state_.release())); 393 SetAndResolveState(auth_.get(), state_.release()));
396 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 394 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
397 395
398 // Unset global objects used by this test. 396 // Unset global objects used by this test.
399 fake_cryptohome_client_->set_unmount_result(true); 397 fake_cryptohome_client_->set_unmount_result(true);
400 LoginState::Shutdown(); 398 LoginState::Shutdown();
401 EXPECT_TRUE( 399 EXPECT_TRUE(
402 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); 400 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
403 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); 401 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
404 } 402 }
405 403
406 // Test the case that login switches to SafeMode and the Owner logs in, which 404 // Test the case that login switches to SafeMode and the Owner logs in, which
407 // should lead to a successful login. 405 // should lead to a successful login.
408 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededSuccess) { 406 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededSuccess) {
409 crypto::ScopedTestNSSChromeOSUser test_user_db(user_context_.GetUserIDHash()); 407 crypto::ScopedTestNSSChromeOSUser test_user_db(user_context_.GetUserIDHash());
410 owner_key_util_->SetPublicKey(GetOwnerPublicKey()); 408 owner_key_util_->SetPublicKey(GetOwnerPublicKey());
411 409
412 crypto::ScopedPK11Slot user_slot( 410 crypto::ScopedPK11Slot user_slot(
413 crypto::GetPublicSlotForChromeOSUser(user_context_.GetUserIDHash())); 411 crypto::GetPublicSlotForChromeOSUser(user_context_.GetUserIDHash()));
414 CreateOwnerKeyInSlot(user_slot.get()); 412 CreateOwnerKeyInSlot(user_slot.get());
415 413
416 profile_manager_.reset( 414 profile_manager_.reset(
417 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 415 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
418 ASSERT_TRUE(profile_manager_->SetUp()); 416 ASSERT_TRUE(profile_manager_->SetUp());
(...skipping 11 matching lines...) Expand all
430 EXPECT_TRUE( 428 EXPECT_TRUE(
431 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); 429 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
432 StubCrosSettingsProvider stub_settings_provider; 430 StubCrosSettingsProvider stub_settings_provider;
433 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); 431 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
434 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); 432 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
435 433
436 // Initialize login state for this test to verify the login state is changed 434 // Initialize login state for this test to verify the login state is changed
437 // to SAFE_MODE. 435 // to SAFE_MODE.
438 LoginState::Initialize(); 436 LoginState::Initialize();
439 437
440 EXPECT_EQ(ParallelAuthenticator::CONTINUE, 438 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE,
441 SetAndResolveState(auth_.get(), state_.release())); 439 SetAndResolveState(auth_.get(), state_.release()));
442 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 440 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
443 441
444 // Flush all the pending operations. The operations should induce an owner 442 // Flush all the pending operations. The operations should induce an owner
445 // verification. 443 // verification.
446 device_settings_test_helper_.Flush(); 444 device_settings_test_helper_.Flush();
447 445
448 state_.reset(new TestAttemptState(user_context_, false)); 446 state_.reset(new TestAttemptState(user_context_, false));
449 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 447 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
450 448
451 // The owner key util should find the owner key, so login should succeed. 449 // The owner key util should find the owner key, so login should succeed.
452 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, 450 EXPECT_EQ(CryptohomeAuthenticator::OFFLINE_LOGIN,
453 SetAndResolveState(auth_.get(), state_.release())); 451 SetAndResolveState(auth_.get(), state_.release()));
454 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 452 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
455 453
456 // Unset global objects used by this test. 454 // Unset global objects used by this test.
457 fake_cryptohome_client_->set_unmount_result(true); 455 fake_cryptohome_client_->set_unmount_result(true);
458 LoginState::Shutdown(); 456 LoginState::Shutdown();
459 EXPECT_TRUE( 457 EXPECT_TRUE(
460 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); 458 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
461 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); 459 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
462 } 460 }
463 461
464 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) { 462 TEST_F(CryptohomeAuthenticatorTest, DriveFailedMount) {
465 FailOnLoginSuccess(); 463 FailOnLoginSuccess();
466 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME)); 464 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME));
467 465
468 // Set up state as though a cryptohome mount attempt has occurred 466 // Set up state as though a cryptohome mount attempt has occurred
469 // and failed. 467 // and failed.
470 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE); 468 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE);
471 SetAttemptState(auth_.get(), state_.release()); 469 SetAttemptState(auth_.get(), state_.release());
472 470
473 RunResolve(auth_.get()); 471 RunResolve(auth_.get());
474 } 472 }
475 473
476 TEST_F(ParallelAuthenticatorTest, DriveGuestLogin) { 474 TEST_F(CryptohomeAuthenticatorTest, DriveGuestLogin) {
477 ExpectGuestLoginSuccess(); 475 ExpectGuestLoginSuccess();
478 FailOnLoginFailure(); 476 FailOnLoginFailure();
479 477
480 // Set up mock async method caller to respond as though a tmpfs mount 478 // Set up mock async method caller to respond as though a tmpfs mount
481 // attempt has occurred and succeeded. 479 // attempt has occurred and succeeded.
482 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 480 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
483 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)) 481 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation();
484 .Times(1)
485 .RetiresOnSaturation();
486 482
487 auth_->LoginOffTheRecord(); 483 auth_->LoginOffTheRecord();
488 base::MessageLoop::current()->Run(); 484 base::MessageLoop::current()->Run();
489 } 485 }
490 486
491 TEST_F(ParallelAuthenticatorTest, DriveGuestLoginButFail) { 487 TEST_F(CryptohomeAuthenticatorTest, DriveGuestLoginButFail) {
492 FailOnGuestLoginSuccess(); 488 FailOnGuestLoginSuccess();
493 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_TMPFS)); 489 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_TMPFS));
494 490
495 // Set up mock async method caller to respond as though a tmpfs mount 491 // Set up mock async method caller to respond as though a tmpfs mount
496 // attempt has occurred and failed. 492 // attempt has occurred and failed.
497 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); 493 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE);
498 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)) 494 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation();
499 .Times(1)
500 .RetiresOnSaturation();
501 495
502 auth_->LoginOffTheRecord(); 496 auth_->LoginOffTheRecord();
503 base::MessageLoop::current()->Run(); 497 base::MessageLoop::current()->Run();
504 } 498 }
505 499
506 TEST_F(ParallelAuthenticatorTest, DriveRetailModeUserLogin) { 500 TEST_F(CryptohomeAuthenticatorTest, DriveRetailModeUserLogin) {
507 ExpectRetailModeLoginSuccess(); 501 ExpectRetailModeLoginSuccess();
508 FailOnLoginFailure(); 502 FailOnLoginFailure();
509 503
510 // Set up mock async method caller to respond as though a tmpfs mount 504 // Set up mock async method caller to respond as though a tmpfs mount
511 // attempt has occurred and succeeded. 505 // attempt has occurred and succeeded.
512 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 506 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
513 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)) 507 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation();
514 .Times(1)
515 .RetiresOnSaturation();
516 508
517 auth_->LoginRetailMode(); 509 auth_->LoginRetailMode();
518 base::MessageLoop::current()->Run(); 510 base::MessageLoop::current()->Run();
519 } 511 }
520 512
521 TEST_F(ParallelAuthenticatorTest, DriveRetailModeLoginButFail) { 513 TEST_F(CryptohomeAuthenticatorTest, DriveRetailModeLoginButFail) {
522 FailOnRetailModeLoginSuccess(); 514 FailOnRetailModeLoginSuccess();
523 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_TMPFS)); 515 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_TMPFS));
524 516
525 // Set up mock async method caller to respond as though a tmpfs mount 517 // Set up mock async method caller to respond as though a tmpfs mount
526 // attempt has occurred and failed. 518 // attempt has occurred and failed.
527 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); 519 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE);
528 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)) 520 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation();
529 .Times(1)
530 .RetiresOnSaturation();
531 521
532 auth_->LoginRetailMode(); 522 auth_->LoginRetailMode();
533 base::MessageLoop::current()->Run(); 523 base::MessageLoop::current()->Run();
534 } 524 }
535 525
536 TEST_F(ParallelAuthenticatorTest, DriveDataResync) { 526 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) {
537 UserContext expected_user_context(user_context_); 527 UserContext expected_user_context(user_context_);
538 expected_user_context.SetUserIDHash( 528 expected_user_context.SetUserIDHash(
539 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 529 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
540 ExpectLoginSuccess(expected_user_context); 530 ExpectLoginSuccess(expected_user_context);
541 FailOnLoginFailure(); 531 FailOnLoginFailure();
542 532
543 // Set up mock async method caller to respond successfully to a cryptohome 533 // Set up mock async method caller to respond successfully to a cryptohome
544 // remove attempt and a cryptohome create attempt (indicated by the 534 // remove attempt and a cryptohome create attempt (indicated by the
545 // |CREATE_IF_MISSING| flag to AsyncMount). 535 // |CREATE_IF_MISSING| flag to AsyncMount).
546 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 536 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
547 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) 537 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
548 .Times(1) 538 .Times(1)
549 .RetiresOnSaturation(); 539 .RetiresOnSaturation();
550 EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(), 540 EXPECT_CALL(*mock_caller_,
551 transformed_key_.GetSecret(), 541 AsyncMount(user_context_.GetUserID(),
552 cryptohome::CREATE_IF_MISSING, 542 transformed_key_.GetSecret(),
553 _)) 543 cryptohome::CREATE_IF_MISSING,
544 _))
554 .Times(1) 545 .Times(1)
555 .RetiresOnSaturation(); 546 .RetiresOnSaturation();
556 EXPECT_CALL(*mock_caller_, 547 EXPECT_CALL(*mock_caller_,
557 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 548 AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
558 .Times(1) 549 .Times(1)
559 .RetiresOnSaturation(); 550 .RetiresOnSaturation();
560 551
561 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 552 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
562 SetAttemptState(auth_.get(), state_.release()); 553 SetAttemptState(auth_.get(), state_.release());
563 554
564 auth_->ResyncEncryptedData(); 555 auth_->ResyncEncryptedData();
565 base::MessageLoop::current()->Run(); 556 base::MessageLoop::current()->Run();
566 } 557 }
567 558
568 TEST_F(ParallelAuthenticatorTest, DriveResyncFail) { 559 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) {
569 FailOnLoginSuccess(); 560 FailOnLoginSuccess();
570 ExpectLoginFailure(AuthFailure(AuthFailure::DATA_REMOVAL_FAILED)); 561 ExpectLoginFailure(AuthFailure(AuthFailure::DATA_REMOVAL_FAILED));
571 562
572 // Set up mock async method caller to fail a cryptohome remove attempt. 563 // Set up mock async method caller to fail a cryptohome remove attempt.
573 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); 564 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE);
574 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) 565 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
575 .Times(1) 566 .Times(1)
576 .RetiresOnSaturation(); 567 .RetiresOnSaturation();
577 568
578 SetAttemptState(auth_.get(), state_.release()); 569 SetAttemptState(auth_.get(), state_.release());
579 570
580 auth_->ResyncEncryptedData(); 571 auth_->ResyncEncryptedData();
581 base::MessageLoop::current()->Run(); 572 base::MessageLoop::current()->Run();
582 } 573 }
583 574
584 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) { 575 TEST_F(CryptohomeAuthenticatorTest, DriveRequestOldPassword) {
585 FailOnLoginSuccess(); 576 FailOnLoginSuccess();
586 ExpectPasswordChange(); 577 ExpectPasswordChange();
587 578
588 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); 579 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
589 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 580 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
590 SetAttemptState(auth_.get(), state_.release()); 581 SetAttemptState(auth_.get(), state_.release());
591 582
592 RunResolve(auth_.get()); 583 RunResolve(auth_.get());
593 } 584 }
594 585
595 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { 586 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecover) {
596 UserContext expected_user_context(user_context_); 587 UserContext expected_user_context(user_context_);
597 expected_user_context.SetUserIDHash( 588 expected_user_context.SetUserIDHash(
598 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 589 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
599 ExpectLoginSuccess(expected_user_context); 590 ExpectLoginSuccess(expected_user_context);
600 FailOnLoginFailure(); 591 FailOnLoginFailure();
601 592
602 // Set up mock async method caller to respond successfully to a key migration. 593 // Set up mock async method caller to respond successfully to a key migration.
603 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 594 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
604 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(user_context_.GetUserID(), 595 EXPECT_CALL(
605 _, 596 *mock_caller_,
606 transformed_key_.GetSecret(), 597 AsyncMigrateKey(
607 _)) 598 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _))
608 .Times(1) 599 .Times(1)
609 .RetiresOnSaturation(); 600 .RetiresOnSaturation();
610 EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(), 601 EXPECT_CALL(*mock_caller_,
611 transformed_key_.GetSecret(), 602 AsyncMount(user_context_.GetUserID(),
612 cryptohome::MOUNT_FLAGS_NONE, 603 transformed_key_.GetSecret(),
613 _)) 604 cryptohome::MOUNT_FLAGS_NONE,
605 _))
614 .Times(1) 606 .Times(1)
615 .RetiresOnSaturation(); 607 .RetiresOnSaturation();
616 EXPECT_CALL(*mock_caller_, 608 EXPECT_CALL(*mock_caller_,
617 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 609 AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
618 .Times(1) 610 .Times(1)
619 .RetiresOnSaturation(); 611 .RetiresOnSaturation();
620 612
621 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 613 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
622 SetAttemptState(auth_.get(), state_.release()); 614 SetAttemptState(auth_.get(), state_.release());
623 615
624 auth_->RecoverEncryptedData(std::string()); 616 auth_->RecoverEncryptedData(std::string());
625 base::MessageLoop::current()->Run(); 617 base::MessageLoop::current()->Run();
626 } 618 }
627 619
628 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { 620 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) {
629 FailOnLoginSuccess(); 621 FailOnLoginSuccess();
630 ExpectPasswordChange(); 622 ExpectPasswordChange();
631 623
632 // Set up mock async method caller to fail a key migration attempt, 624 // Set up mock async method caller to fail a key migration attempt,
633 // asserting that the wrong password was used. 625 // asserting that the wrong password was used.
634 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); 626 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
635 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(user_context_.GetUserID(), 627 EXPECT_CALL(
636 _, 628 *mock_caller_,
637 transformed_key_.GetSecret(), 629 AsyncMigrateKey(
638 _)) 630 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _))
639 .Times(1) 631 .Times(1)
640 .RetiresOnSaturation(); 632 .RetiresOnSaturation();
641 633
642 SetAttemptState(auth_.get(), state_.release()); 634 SetAttemptState(auth_.get(), state_.release());
643 635
644 auth_->RecoverEncryptedData(std::string()); 636 auth_->RecoverEncryptedData(std::string());
645 base::MessageLoop::current()->Run(); 637 base::MessageLoop::current()->Run();
646 } 638 }
647 639
648 TEST_F(ParallelAuthenticatorTest, ResolveNoMountToFailedMount) { 640 TEST_F(CryptohomeAuthenticatorTest, ResolveNoMountToFailedMount) {
649 // Set up state as though a cryptohome mount attempt has occurred 641 // Set up state as though a cryptohome mount attempt has occurred
650 // and been rejected because the user doesn't exist. 642 // and been rejected because the user doesn't exist.
651 state_->PresetCryptohomeStatus(false, 643 state_->PresetCryptohomeStatus(false,
652 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 644 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
653 645
654 // When there is no online attempt and online results, NO_MOUNT will be 646 // When there is no online attempt and online results, NO_MOUNT will be
655 // resolved to FAILED_MOUNT. 647 // resolved to FAILED_MOUNT.
656 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, 648 EXPECT_EQ(CryptohomeAuthenticator::FAILED_MOUNT,
657 SetAndResolveState(auth_.get(), state_.release())); 649 SetAndResolveState(auth_.get(), state_.release()));
658 } 650 }
659 651
660 TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) { 652 TEST_F(CryptohomeAuthenticatorTest, ResolveCreateNew) {
661 // Set up state as though a cryptohome mount attempt has occurred 653 // Set up state as though a cryptohome mount attempt has occurred
662 // and been rejected because the user doesn't exist; additionally, 654 // and been rejected because the user doesn't exist; additionally,
663 // an online auth attempt has completed successfully. 655 // an online auth attempt has completed successfully.
664 state_->PresetCryptohomeStatus(false, 656 state_->PresetCryptohomeStatus(false,
665 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 657 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
666 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 658 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
667 659
668 EXPECT_EQ(ParallelAuthenticator::CREATE_NEW, 660 EXPECT_EQ(CryptohomeAuthenticator::CREATE_NEW,
669 SetAndResolveState(auth_.get(), state_.release())); 661 SetAndResolveState(auth_.get(), state_.release()));
670 } 662 }
671 663
672 TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) { 664 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) {
673 UserContext expected_user_context(user_context_); 665 UserContext expected_user_context(user_context_);
674 expected_user_context.SetUserIDHash( 666 expected_user_context.SetUserIDHash(
675 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 667 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
676 ExpectLoginSuccess(expected_user_context); 668 ExpectLoginSuccess(expected_user_context);
677 FailOnLoginFailure(); 669 FailOnLoginFailure();
678 670
679 // Set up mock async method caller to respond successfully to a cryptohome 671 // Set up mock async method caller to respond successfully to a cryptohome
680 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). 672 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount).
681 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 673 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
682 EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(), 674 EXPECT_CALL(*mock_caller_,
683 transformed_key_.GetSecret(), 675 AsyncMount(user_context_.GetUserID(),
684 cryptohome::CREATE_IF_MISSING, 676 transformed_key_.GetSecret(),
685 _)) 677 cryptohome::CREATE_IF_MISSING,
678 _))
686 .Times(1) 679 .Times(1)
687 .RetiresOnSaturation(); 680 .RetiresOnSaturation();
688 EXPECT_CALL(*mock_caller_, 681 EXPECT_CALL(*mock_caller_,
689 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 682 AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
690 .Times(1) 683 .Times(1)
691 .RetiresOnSaturation(); 684 .RetiresOnSaturation();
692 685
693 // Set up state as though a cryptohome mount attempt has occurred 686 // Set up state as though a cryptohome mount attempt has occurred
694 // and been rejected because the user doesn't exist; additionally, 687 // and been rejected because the user doesn't exist; additionally,
695 // an online auth attempt has completed successfully. 688 // an online auth attempt has completed successfully.
696 state_->PresetCryptohomeStatus(false, 689 state_->PresetCryptohomeStatus(false,
697 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 690 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
698 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 691 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
699 SetAttemptState(auth_.get(), state_.release()); 692 SetAttemptState(auth_.get(), state_.release());
700 693
701 RunResolve(auth_.get()); 694 RunResolve(auth_.get());
702 } 695 }
703 696
704 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) { 697 TEST_F(CryptohomeAuthenticatorTest, DriveOfflineLogin) {
705 ExpectLoginSuccess(user_context_); 698 ExpectLoginSuccess(user_context_);
706 FailOnLoginFailure(); 699 FailOnLoginFailure();
707 700
708 // Set up state as though a cryptohome mount attempt has occurred and 701 // Set up state as though a cryptohome mount attempt has occurred and
709 // succeeded. 702 // succeeded.
710 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 703 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
711 SetAttemptState(auth_.get(), state_.release()); 704 SetAttemptState(auth_.get(), state_.release());
712 705
713 RunResolve(auth_.get()); 706 RunResolve(auth_.get());
714 } 707 }
715 708
716 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { 709 TEST_F(CryptohomeAuthenticatorTest, DriveOnlineLogin) {
717 ExpectLoginSuccess(user_context_); 710 ExpectLoginSuccess(user_context_);
718 FailOnLoginFailure(); 711 FailOnLoginFailure();
719 712
720 // Set up state as though a cryptohome mount attempt has occurred and 713 // Set up state as though a cryptohome mount attempt has occurred and
721 // succeeded. 714 // succeeded.
722 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 715 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
723 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 716 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
724 SetAttemptState(auth_.get(), state_.release()); 717 SetAttemptState(auth_.get(), state_.release());
725 718
726 RunResolve(auth_.get()); 719 RunResolve(auth_.get());
727 } 720 }
728 721
729 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { 722 TEST_F(CryptohomeAuthenticatorTest, DriveUnlock) {
730 ExpectLoginSuccess(user_context_); 723 ExpectLoginSuccess(user_context_);
731 FailOnLoginFailure(); 724 FailOnLoginFailure();
732 725
733 // Set up mock async method caller to respond successfully to a cryptohome 726 // Set up mock async method caller to respond successfully to a cryptohome
734 // key-check attempt. 727 // key-check attempt.
735 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 728 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
736 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) 729 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _))
737 .Times(1) 730 .Times(1)
738 .RetiresOnSaturation(); 731 .RetiresOnSaturation();
739 732
740 auth_->AuthenticateToUnlock(user_context_); 733 auth_->AuthenticateToUnlock(user_context_);
741 base::MessageLoop::current()->Run(); 734 base::MessageLoop::current()->Run();
742 } 735 }
743 736
744 } // namespace chromeos 737 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698