OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/owner_manager_unittest.h" |
5 #include "chrome/browser/chromeos/login/owner_manager.h" | 6 #include "chrome/browser/chromeos/login/owner_manager.h" |
6 | 7 |
7 #include <cert.h> | |
8 #include <keyhi.h> | |
9 #include <keythi.h> // KeyType enum | |
10 #include <pk11pub.h> | |
11 #include <stdlib.h> | |
12 | |
13 #include <string> | 8 #include <string> |
14 | 9 |
15 #include "base/crypto/rsa_private_key.h" | 10 #include "base/crypto/rsa_private_key.h" |
16 #include "base/file_path.h" | 11 #include "base/file_path.h" |
17 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/nss_util.h" |
18 #include "base/logging.h" | 14 #include "base/logging.h" |
19 #include "base/nss_util_internal.h" | |
20 #include "base/nss_util.h" | |
21 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
22 #include "chrome/browser/chrome_thread.h" | 16 #include "chrome/browser/chrome_thread.h" |
23 #include "chrome/common/notification_observer.h" | 17 #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" |
24 #include "chrome/common/notification_registrar.h" | |
25 #include "chrome/common/notification_service.h" | |
26 #include "chrome/common/notification_type.h" | |
27 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
29 | 20 |
30 using ::base::RSAPrivateKey; | 21 using ::base::RSAPrivateKey; |
31 using ::testing::DoAll; | 22 using ::testing::DoAll; |
32 using ::testing::Invoke; | 23 using ::testing::Invoke; |
33 using ::testing::Return; | 24 using ::testing::Return; |
34 using ::testing::SetArgumentPointee; | 25 using ::testing::SetArgumentPointee; |
35 using ::testing::_; | 26 using ::testing::_; |
36 | 27 |
37 namespace chromeos { | 28 namespace chromeos { |
38 | 29 |
39 namespace { | 30 class OwnerManagerTest : public ::testing::Test { |
40 | |
41 class MockKeyUtils : public OwnerKeyUtils { | |
42 public: | |
43 MockKeyUtils() {} | |
44 ~MockKeyUtils() {} | |
45 MOCK_METHOD0(GenerateKeyPair, RSAPrivateKey*()); | |
46 MOCK_METHOD1(ExportPublicKeyViaDbus, bool(RSAPrivateKey* pair)); | |
47 MOCK_METHOD2(ExportPublicKeyToFile, bool(RSAPrivateKey* pair, | |
48 const FilePath& key_file)); | |
49 MOCK_METHOD2(ImportPublicKey, bool(const FilePath& key_file, | |
50 std::vector<uint8>* output)); | |
51 MOCK_METHOD1(FindPrivateKey, RSAPrivateKey*(const std::vector<uint8>& key)); | |
52 MOCK_METHOD0(GetOwnerKeyFilePath, FilePath()); | |
53 private: | |
54 DISALLOW_COPY_AND_ASSIGN(MockKeyUtils); | |
55 }; | |
56 | |
57 class MockInjector : public OwnerKeyUtils::Factory { | |
58 public: | |
59 // Takes ownership of |mock|. | |
60 explicit MockInjector(MockKeyUtils* mock) : | |
61 transient_(mock), | |
62 delete_transient_(true) { | |
63 } | |
64 | |
65 virtual ~MockInjector() { | |
66 if (delete_transient_) | |
67 delete transient_; | |
68 } | |
69 | |
70 // If this is called, its caller takes ownership of |transient_|. | |
71 // If it's never called, |transient_| remains our problem. | |
72 OwnerKeyUtils* CreateOwnerKeyUtils() { | |
73 delete_transient_ = false; | |
74 return transient_; | |
75 } | |
76 | |
77 private: | |
78 MockKeyUtils* transient_; | |
79 bool delete_transient_; | |
80 DISALLOW_COPY_AND_ASSIGN(MockInjector); | |
81 }; | |
82 | |
83 class KeyUser : public OwnerManager::Delegate { | |
84 public: | |
85 explicit KeyUser(const OwnerManager::KeyOpCode expected) | |
86 : expected_(expected) { | |
87 } | |
88 | |
89 virtual ~KeyUser() {} | |
90 | |
91 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | |
92 const std::string& payload) { | |
93 MessageLoop::current()->Quit(); | |
94 EXPECT_EQ(expected_, return_code); | |
95 } | |
96 | |
97 const OwnerManager::KeyOpCode expected_; | |
98 private: | |
99 DISALLOW_COPY_AND_ASSIGN(KeyUser); | |
100 }; | |
101 | |
102 static bool Win(RSAPrivateKey* key) { | |
103 MessageLoop::current()->Quit(); | |
104 return true; | |
105 } | |
106 | |
107 static bool Fail(RSAPrivateKey* key) { | |
108 MessageLoop::current()->Quit(); | |
109 return false; | |
110 } | |
111 | |
112 } // anonymous namespace | |
113 | |
114 class OwnerManagerTest : public ::testing::Test, | |
115 public NotificationObserver { | |
116 public: | 31 public: |
117 OwnerManagerTest() | 32 OwnerManagerTest() |
118 : message_loop_(MessageLoop::TYPE_UI), | 33 : message_loop_(MessageLoop::TYPE_UI), |
119 ui_thread_(ChromeThread::UI, &message_loop_), | 34 ui_thread_(ChromeThread::UI, &message_loop_), |
120 file_thread_(ChromeThread::FILE), | 35 file_thread_(ChromeThread::FILE), |
121 success_expected_(false), | |
122 quit_on_observe_(true), | |
123 mock_(new MockKeyUtils), | 36 mock_(new MockKeyUtils), |
124 injector_(mock_) /* injector_ takes ownership of mock_ */ { | 37 injector_(mock_) /* injector_ takes ownership of mock_ */ { |
125 registrar_.Add( | |
126 this, | |
127 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, | |
128 NotificationService::AllSources()); | |
129 registrar_.Add( | |
130 this, | |
131 NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, | |
132 NotificationService::AllSources()); | |
133 } | 38 } |
134 virtual ~OwnerManagerTest() {} | 39 virtual ~OwnerManagerTest() {} |
135 | 40 |
136 virtual void SetUp() { | 41 virtual void SetUp() { |
137 base::OpenPersistentNSSDB(); // TODO(cmasone): use test DB instead | 42 base::OpenPersistentNSSDB(); // TODO(cmasone): use test DB instead |
138 fake_private_key_.reset(RSAPrivateKey::Create(256)); | 43 fake_private_key_.reset(RSAPrivateKey::Create(256)); |
139 ASSERT_TRUE(fake_private_key_->ExportPublicKey(&fake_public_key_)); | 44 ASSERT_TRUE(fake_private_key_->ExportPublicKey(&fake_public_key_)); |
140 | 45 |
141 // Mimic ownership. | 46 // Mimic ownership. |
142 ASSERT_TRUE(tmpdir_.CreateUniqueTempDir()); | 47 ASSERT_TRUE(tmpdir_.CreateUniqueTempDir()); |
143 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir_.path(), &tmpfile_)); | 48 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir_.path(), &tmpfile_)); |
144 | 49 |
145 file_thread_.Start(); | 50 file_thread_.Start(); |
146 OwnerKeyUtils::set_factory(&injector_); | 51 OwnerKeyUtils::set_factory(&injector_); |
147 } | 52 } |
148 | 53 |
149 virtual void TearDown() { | 54 virtual void TearDown() { |
150 OwnerKeyUtils::set_factory(NULL); | 55 OwnerKeyUtils::set_factory(NULL); |
151 } | 56 } |
152 | 57 |
153 void StartUnowned() { | 58 void StartUnowned() { |
154 file_util::Delete(tmpfile_, false); | 59 file_util::Delete(tmpfile_, false); |
155 } | 60 } |
156 | 61 |
157 void InjectKeys(OwnerManager* manager) { | 62 void InjectKeys(OwnerManager* manager) { |
158 manager->public_key_ = fake_public_key_; | 63 manager->public_key_ = fake_public_key_; |
159 manager->private_key_.reset(fake_private_key_.release()); | 64 manager->private_key_.reset(fake_private_key_.release()); |
160 } | 65 } |
161 | 66 |
162 // NotificationObserver implementation. | |
163 virtual void Observe(NotificationType type, | |
164 const NotificationSource& source, | |
165 const NotificationDetails& details) { | |
166 if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { | |
167 EXPECT_TRUE(success_expected_); | |
168 if (quit_on_observe_) | |
169 MessageLoop::current()->Quit(); | |
170 } else if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED) { | |
171 EXPECT_FALSE(success_expected_); | |
172 if (quit_on_observe_) | |
173 MessageLoop::current()->Quit(); | |
174 } | |
175 } | |
176 | |
177 void ExpectKeyFetchSuccess(bool should_succeed) { | |
178 success_expected_ = should_succeed; | |
179 } | |
180 | |
181 void SetQuitOnKeyFetch(bool should_quit) { quit_on_observe_ = should_quit; } | |
182 | |
183 ScopedTempDir tmpdir_; | 67 ScopedTempDir tmpdir_; |
184 FilePath tmpfile_; | 68 FilePath tmpfile_; |
185 | 69 |
186 MessageLoop message_loop_; | 70 MessageLoop message_loop_; |
187 ChromeThread ui_thread_; | 71 ChromeThread ui_thread_; |
188 ChromeThread file_thread_; | 72 ChromeThread file_thread_; |
189 | 73 |
190 std::vector<uint8> fake_public_key_; | 74 std::vector<uint8> fake_public_key_; |
191 scoped_ptr<RSAPrivateKey> fake_private_key_; | 75 scoped_ptr<RSAPrivateKey> fake_private_key_; |
192 | 76 |
193 NotificationRegistrar registrar_; | |
194 bool success_expected_; | |
195 bool quit_on_observe_; | |
196 | |
197 MockKeyUtils* mock_; | 77 MockKeyUtils* mock_; |
198 MockInjector injector_; | 78 MockInjector injector_; |
| 79 |
199 }; | 80 }; |
200 | 81 |
201 TEST_F(OwnerManagerTest, LoadKeyUnowned) { | 82 TEST_F(OwnerManagerTest, LoadOwnerKeyFail) { |
202 StartUnowned(); | 83 StartUnowned(); |
| 84 MockKeyLoadObserver loader; |
| 85 scoped_refptr<OwnerManager> manager(new OwnerManager); |
203 | 86 |
204 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | 87 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
205 .WillRepeatedly(Return(tmpfile_)); | 88 .WillRepeatedly(Return(tmpfile_)); |
206 | |
207 scoped_refptr<OwnerManager> manager(new OwnerManager); | |
208 EXPECT_FALSE(manager->StartLoadOwnerKeyAttempt()); | |
209 } | |
210 | |
211 TEST_F(OwnerManagerTest, LoadOwnerKeyFail) { | |
212 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | |
213 .WillRepeatedly(Return(tmpfile_)); | |
214 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) | 89 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) |
215 .WillOnce(Return(false)) | 90 .WillOnce(Return(false)) |
216 .RetiresOnSaturation(); | 91 .RetiresOnSaturation(); |
217 | 92 |
218 scoped_refptr<OwnerManager> manager(new OwnerManager); | 93 ChromeThread::PostTask( |
219 EXPECT_TRUE(manager->StartLoadOwnerKeyAttempt()); | 94 ChromeThread::FILE, FROM_HERE, |
220 | 95 NewRunnableMethod(manager.get(), |
221 // Run remaining events, until ExportPublicKeyViaDbus(). | 96 &OwnerManager::LoadOwnerKey)); |
222 message_loop_.Run(); | 97 message_loop_.Run(); |
223 } | 98 } |
224 | 99 |
225 TEST_F(OwnerManagerTest, LoadOwnerKey) { | 100 TEST_F(OwnerManagerTest, LoadOwnerKey) { |
226 ExpectKeyFetchSuccess(true); | 101 MockKeyLoadObserver loader; |
| 102 loader.ExpectKeyFetchSuccess(true); |
| 103 scoped_refptr<OwnerManager> manager(new OwnerManager); |
227 | 104 |
228 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | 105 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
229 .WillRepeatedly(Return(tmpfile_)); | 106 .WillRepeatedly(Return(tmpfile_)); |
230 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) | 107 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) |
231 .WillOnce(DoAll(SetArgumentPointee<1>(fake_public_key_), | 108 .WillOnce(DoAll(SetArgumentPointee<1>(fake_public_key_), |
232 Return(true))) | 109 Return(true))) |
233 .RetiresOnSaturation(); | 110 .RetiresOnSaturation(); |
234 | 111 |
235 scoped_refptr<OwnerManager> manager(new OwnerManager); | 112 ChromeThread::PostTask( |
236 EXPECT_TRUE(manager->StartLoadOwnerKeyAttempt()); | 113 ChromeThread::FILE, FROM_HERE, |
| 114 NewRunnableMethod(manager.get(), |
| 115 &OwnerManager::LoadOwnerKey)); |
237 | 116 |
238 // Run remaining events, until ExportPublicKeyViaDbus(). | |
239 message_loop_.Run(); | 117 message_loop_.Run(); |
240 } | 118 } |
241 | 119 |
242 TEST_F(OwnerManagerTest, TakeOwnershipAlreadyOwned) { | |
243 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | |
244 .WillRepeatedly(Return(tmpfile_)); | |
245 | |
246 scoped_refptr<OwnerManager> manager(new OwnerManager); | |
247 EXPECT_FALSE(manager->StartTakeOwnershipAttempt()); | |
248 } | |
249 | |
250 TEST_F(OwnerManagerTest, KeyGenerationFail) { | 120 TEST_F(OwnerManagerTest, KeyGenerationFail) { |
251 StartUnowned(); | 121 StartUnowned(); |
| 122 MockKeyLoadObserver loader; |
| 123 loader.ExpectKeyFetchSuccess(false); |
| 124 scoped_refptr<OwnerManager> manager(new OwnerManager); |
252 | 125 |
253 EXPECT_CALL(*mock_, GenerateKeyPair()) | 126 EXPECT_CALL(*mock_, GenerateKeyPair()) |
254 .WillOnce(Return(reinterpret_cast<RSAPrivateKey*>(NULL))) | 127 .WillOnce(Return(reinterpret_cast<RSAPrivateKey*>(NULL))) |
255 .RetiresOnSaturation(); | 128 .RetiresOnSaturation(); |
256 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | 129 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
257 .WillRepeatedly(Return(tmpfile_)); | 130 .WillRepeatedly(Return(tmpfile_)); |
258 | 131 |
259 scoped_refptr<OwnerManager> manager(new OwnerManager); | 132 ChromeThread::PostTask( |
260 EXPECT_TRUE(manager->StartTakeOwnershipAttempt()); | 133 ChromeThread::FILE, FROM_HERE, |
| 134 NewRunnableMethod(manager.get(), |
| 135 &OwnerManager::GenerateKeysAndExportPublic)); |
261 | 136 |
262 message_loop_.Run(); | 137 message_loop_.Run(); |
263 } | 138 } |
264 | 139 |
265 TEST_F(OwnerManagerTest, KeyExportFail) { | 140 TEST_F(OwnerManagerTest, KeyExportFail) { |
266 StartUnowned(); | 141 StartUnowned(); |
| 142 MockKeyLoadObserver loader; |
| 143 loader.ExpectKeyFetchSuccess(false); |
| 144 scoped_refptr<OwnerManager> manager(new OwnerManager); |
267 | 145 |
268 EXPECT_CALL(*mock_, ExportPublicKeyViaDbus(fake_private_key_.get())) | 146 EXPECT_CALL(*mock_, ExportPublicKeyViaDbus(fake_private_key_.get(), |
269 .WillOnce(Invoke(Fail)) | 147 manager.get())) |
| 148 .WillOnce(Invoke(MockKeyUtils::ExportPublicKeyViaDbusFail)) |
270 .RetiresOnSaturation(); | 149 .RetiresOnSaturation(); |
271 EXPECT_CALL(*mock_, GenerateKeyPair()) | 150 EXPECT_CALL(*mock_, GenerateKeyPair()) |
272 .WillOnce(Return(fake_private_key_.release())) | 151 .WillOnce(Return(fake_private_key_.release())) |
273 .RetiresOnSaturation(); | 152 .RetiresOnSaturation(); |
274 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | 153 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
275 .WillRepeatedly(Return(tmpfile_)); | 154 .WillRepeatedly(Return(tmpfile_)); |
276 | 155 |
277 scoped_refptr<OwnerManager> manager(new OwnerManager); | 156 ChromeThread::PostTask( |
278 EXPECT_TRUE(manager->StartTakeOwnershipAttempt()); | 157 ChromeThread::FILE, FROM_HERE, |
| 158 NewRunnableMethod(manager.get(), |
| 159 &OwnerManager::GenerateKeysAndExportPublic)); |
279 | 160 |
280 message_loop_.Run(); | 161 message_loop_.Run(); |
281 } | 162 } |
282 | 163 |
283 TEST_F(OwnerManagerTest, TakeOwnership) { | 164 TEST_F(OwnerManagerTest, TakeOwnership) { |
284 StartUnowned(); | 165 StartUnowned(); |
285 ExpectKeyFetchSuccess(true); | 166 MockKeyLoadObserver loader; |
| 167 loader.ExpectKeyFetchSuccess(true); |
| 168 scoped_refptr<OwnerManager> manager(new OwnerManager); |
286 | 169 |
287 EXPECT_CALL(*mock_, ExportPublicKeyViaDbus(fake_private_key_.get())) | 170 EXPECT_CALL(*mock_, ExportPublicKeyViaDbus(fake_private_key_.get(), |
288 .WillOnce(Invoke(Win)) | 171 manager.get())) |
| 172 .WillOnce(Invoke(MockKeyUtils::ExportPublicKeyViaDbusWin)) |
289 .RetiresOnSaturation(); | 173 .RetiresOnSaturation(); |
290 EXPECT_CALL(*mock_, GenerateKeyPair()) | 174 EXPECT_CALL(*mock_, GenerateKeyPair()) |
291 .WillOnce(Return(fake_private_key_.release())) | 175 .WillOnce(Return(fake_private_key_.release())) |
292 .RetiresOnSaturation(); | 176 .RetiresOnSaturation(); |
293 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | 177 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
294 .WillRepeatedly(Return(tmpfile_)); | 178 .WillRepeatedly(Return(tmpfile_)); |
295 | 179 |
296 scoped_refptr<OwnerManager> manager(new OwnerManager); | 180 ChromeThread::PostTask( |
297 EXPECT_TRUE(manager->StartTakeOwnershipAttempt()); | 181 ChromeThread::FILE, FROM_HERE, |
298 | 182 NewRunnableMethod(manager.get(), |
299 message_loop_.Run(); | 183 &OwnerManager::GenerateKeysAndExportPublic)); |
300 } | |
301 | |
302 TEST_F(OwnerManagerTest, NotYetOwnedVerify) { | |
303 StartUnowned(); | |
304 | |
305 // Since this shouldn't happen, don't want it to end the test if it does. | |
306 SetQuitOnKeyFetch(false); | |
307 | |
308 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | |
309 .WillRepeatedly(Return(tmpfile_)); | |
310 | |
311 scoped_refptr<OwnerManager> manager(new OwnerManager); | |
312 KeyUser delegate(OwnerManager::KEY_UNAVAILABLE); | |
313 EXPECT_FALSE(manager->StartVerifyAttempt("", "", &delegate)); | |
314 } | |
315 | |
316 TEST_F(OwnerManagerTest, AlreadyHaveKeysVerify) { | |
317 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | |
318 .WillRepeatedly(Return(tmpfile_)); | |
319 | |
320 scoped_refptr<OwnerManager> manager(new OwnerManager); | |
321 InjectKeys(manager.get()); | |
322 KeyUser delegate(OwnerManager::SUCCESS); | |
323 EXPECT_TRUE(manager->StartVerifyAttempt("", "", &delegate)); | |
324 | 184 |
325 message_loop_.Run(); | 185 message_loop_.Run(); |
326 } | 186 } |
327 | 187 |
328 TEST_F(OwnerManagerTest, GetKeyFailDuringVerify) { | 188 TEST_F(OwnerManagerTest, GetKeyFailDuringVerify) { |
329 ExpectKeyFetchSuccess(false); | 189 StartUnowned(); |
| 190 MockKeyLoadObserver loader; |
| 191 loader.ExpectKeyFetchSuccess(false); |
| 192 scoped_refptr<OwnerManager> manager(new OwnerManager); |
330 | 193 |
331 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | 194 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
332 .WillRepeatedly(Return(tmpfile_)); | 195 .WillRepeatedly(Return(tmpfile_)); |
333 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) | 196 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) |
334 .WillOnce(Return(false)) | 197 .WillOnce(Return(false)) |
335 .RetiresOnSaturation(); | 198 .RetiresOnSaturation(); |
336 | 199 |
| 200 MockKeyUser delegate(OwnerManager::KEY_UNAVAILABLE); |
| 201 |
| 202 ChromeThread::PostTask( |
| 203 ChromeThread::FILE, FROM_HERE, |
| 204 NewRunnableMethod(manager.get(), |
| 205 &OwnerManager::Verify, |
| 206 ChromeThread::UI, |
| 207 std::string(), |
| 208 std::string(), |
| 209 &delegate)); |
| 210 message_loop_.Run(); |
| 211 } |
| 212 |
| 213 TEST_F(OwnerManagerTest, AlreadyHaveKeysVerify) { |
337 scoped_refptr<OwnerManager> manager(new OwnerManager); | 214 scoped_refptr<OwnerManager> manager(new OwnerManager); |
338 KeyUser delegate(OwnerManager::KEY_UNAVAILABLE); | |
339 EXPECT_TRUE(manager->StartVerifyAttempt("", "", &delegate)); | |
340 | 215 |
| 216 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
| 217 .WillRepeatedly(Return(tmpfile_)); |
| 218 |
| 219 InjectKeys(manager.get()); |
| 220 MockKeyUser delegate(OwnerManager::SUCCESS); |
| 221 |
| 222 ChromeThread::PostTask( |
| 223 ChromeThread::FILE, FROM_HERE, |
| 224 NewRunnableMethod(manager.get(), |
| 225 &OwnerManager::Verify, |
| 226 ChromeThread::UI, |
| 227 std::string(), |
| 228 std::string(), |
| 229 &delegate)); |
341 message_loop_.Run(); | 230 message_loop_.Run(); |
342 } | 231 } |
343 | 232 |
344 TEST_F(OwnerManagerTest, GetKeyAndVerify) { | 233 TEST_F(OwnerManagerTest, GetKeyAndVerify) { |
345 ExpectKeyFetchSuccess(true); | 234 MockKeyLoadObserver loader; |
346 SetQuitOnKeyFetch(false); | 235 loader.ExpectKeyFetchSuccess(true); |
| 236 loader.SetQuitOnKeyFetch(false); |
| 237 scoped_refptr<OwnerManager> manager(new OwnerManager); |
347 | 238 |
348 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) | 239 EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) |
349 .WillRepeatedly(Return(tmpfile_)); | 240 .WillRepeatedly(Return(tmpfile_)); |
350 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) | 241 EXPECT_CALL(*mock_, ImportPublicKey(tmpfile_, _)) |
351 .WillOnce(DoAll(SetArgumentPointee<1>(fake_public_key_), | 242 .WillOnce(DoAll(SetArgumentPointee<1>(fake_public_key_), |
352 Return(true))) | 243 Return(true))) |
353 .RetiresOnSaturation(); | 244 .RetiresOnSaturation(); |
354 | 245 |
355 scoped_refptr<OwnerManager> manager(new OwnerManager); | 246 MockKeyUser delegate(OwnerManager::SUCCESS); |
356 KeyUser delegate(OwnerManager::SUCCESS); | 247 ChromeThread::PostTask( |
357 EXPECT_TRUE(manager->StartVerifyAttempt("", "", &delegate)); | 248 ChromeThread::FILE, FROM_HERE, |
358 | 249 NewRunnableMethod(manager.get(), |
| 250 &OwnerManager::Verify, |
| 251 ChromeThread::UI, |
| 252 std::string(), |
| 253 std::string(), |
| 254 &delegate)); |
359 message_loop_.Run(); | 255 message_loop_.Run(); |
360 } | 256 } |
361 | 257 |
362 } // namespace chromeos | 258 } // namespace chromeos |
OLD | NEW |