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

Side by Side Diff: chromeos/attestation/attestation_flow_unittest.cc

Issue 2529743002: Wait for the attestation to be ready (TPM being prepared for attestation) before trying to enroll. (Closed)
Patch Set: Smaller timeouts or tests fail for being too chatty. Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/time/tick_clock.h"
15 #include "base/timer/timer.h"
13 #include "chromeos/attestation/mock_attestation_flow.h" 16 #include "chromeos/attestation/mock_attestation_flow.h"
14 #include "chromeos/cryptohome/cryptohome_parameters.h" 17 #include "chromeos/cryptohome/cryptohome_parameters.h"
15 #include "chromeos/cryptohome/mock_async_method_caller.h" 18 #include "chromeos/cryptohome/mock_async_method_caller.h"
16 #include "chromeos/dbus/mock_cryptohome_client.h" 19 #include "chromeos/dbus/mock_cryptohome_client.h"
17 #include "components/signin/core/account_id/account_id.h" 20 #include "components/signin/core/account_id/account_id.h"
18 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
20 23
21 using testing::_; 24 using testing::_;
22 using testing::AtLeast; 25 using testing::AtLeast;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_)); 64 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_));
62 } 65 }
63 66
64 private: 67 private:
65 std::string data_; 68 std::string data_;
66 }; 69 };
67 70
68 } // namespace 71 } // namespace
69 72
70 class AttestationFlowTest : public testing::Test { 73 class AttestationFlowTest : public testing::Test {
74 public:
75 void QuitRunLoopCertificateCallback(
76 const AttestationFlow::CertificateCallback& callback,
77 bool success,
78 const std::string& cert) {
79 LOG(WARNING) << "Quitting run loop.";
80 run_loop_.Quit();
81 if (!callback.is_null())
82 callback.Run(success, cert);
83 }
84
71 protected: 85 protected:
72 void Run() { 86 void RunUntilIdle() { run_loop_.RunUntilIdle(); }
73 base::RunLoop run_loop; 87
74 run_loop.RunUntilIdle(); 88 void Run() { run_loop_.Run(); }
75 } 89
76 base::MessageLoop message_loop_; 90 base::MessageLoop message_loop_;
91 base::RunLoop run_loop_;
Darren Krahn 2016/12/08 18:06:06 Moving this to a class member means you can only c
The one and only Dr. Crash 2016/12/08 19:41:10 No. Changed.
77 }; 92 };
78 93
79 TEST_F(AttestationFlowTest, GetCertificate) { 94 TEST_F(AttestationFlowTest, GetCertificate) {
80 // Verify the order of calls in a sequence. 95 // Verify the order of calls in a sequence.
81 Sequence flow_order; 96 Sequence flow_order;
82 97
83 // Use DBusCallbackFalse so the full enrollment flow is triggered. 98 // Use DBusCallbackFalse so the full enrollment flow is triggered.
84 chromeos::MockCryptohomeClient client; 99 chromeos::MockCryptohomeClient client;
85 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 100 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
86 .InSequence(flow_order) 101 .InSequence(flow_order)
87 .WillRepeatedly(Invoke(DBusCallbackFalse)); 102 .WillRepeatedly(Invoke(DBusCallbackFalse));
88 103
104 EXPECT_CALL(client, TpmAttestationIsPrepared(_))
105 .InSequence(flow_order)
106 .WillOnce(Invoke(DBusCallbackTrue));
107
89 // Use StrictMock when we want to verify invocation frequency. 108 // Use StrictMock when we want to verify invocation frequency.
90 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 109 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
91 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 110 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
111 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
112 .Times(1)
113 .InSequence(flow_order);
114
115 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
116 proxy->DeferToFake(true);
117 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
118 EXPECT_CALL(
119 *proxy,
120 SendEnrollRequest(
121 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, _))
122 .Times(1)
123 .InSequence(flow_order);
124
125 std::string fake_enroll_response =
126 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest;
127 fake_enroll_response += "_response";
128 EXPECT_CALL(async_caller,
129 AsyncTpmAttestationEnroll(_, fake_enroll_response, _))
130 .Times(1)
131 .InSequence(flow_order);
132
133 const AccountId account_id = AccountId::FromUserEmail("fake@test.com");
134 EXPECT_CALL(async_caller,
135 AsyncTpmAttestationCreateCertRequest(
136 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
137 cryptohome::Identification(account_id), "fake_origin", _))
138 .Times(1)
139 .InSequence(flow_order);
140
141 EXPECT_CALL(
142 *proxy,
143 SendCertificateRequest(
144 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, _))
145 .Times(1)
146 .InSequence(flow_order);
147
148 std::string fake_cert_response =
149 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
150 fake_cert_response += "_response";
151 EXPECT_CALL(async_caller, AsyncTpmAttestationFinishCertRequest(
152 fake_cert_response, KEY_USER,
153 cryptohome::Identification(account_id),
154 kEnterpriseUserKey, _))
155 .Times(1)
156 .InSequence(flow_order);
157
158 StrictMock<MockObserver> observer;
159 EXPECT_CALL(
160 observer,
161 MockCertificateCallback(
162 true, cryptohome::MockAsyncMethodCaller::kFakeAttestationCert))
163 .Times(1)
164 .InSequence(flow_order);
165 AttestationFlow::CertificateCallback mock_callback = base::Bind(
166 &MockObserver::MockCertificateCallback, base::Unretained(&observer));
167
168 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
169 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
170 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, account_id,
171 "fake_origin", true, mock_callback);
172 RunUntilIdle();
173 }
174
175 TEST_F(AttestationFlowTest, GetCertificate_Attestation_Not_Prepared) {
176 // Verify the order of calls in a sequence.
177 Sequence flow_order;
178
179 // Use DBusCallbackFalse so the full enrollment flow is triggered.
180 chromeos::MockCryptohomeClient client;
181 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
182 .InSequence(flow_order)
183 .WillRepeatedly(Invoke(DBusCallbackFalse));
184
185 // It will take a bit for attestation to be prepared.
186 EXPECT_CALL(client, TpmAttestationIsPrepared(_))
187 .InSequence(flow_order)
188 .WillOnce(Invoke(DBusCallbackFalse))
189 .WillOnce(Invoke(DBusCallbackTrue));
190
191 // Use StrictMock when we want to verify invocation frequency.
192 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
193 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
92 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _)) 194 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
93 .Times(1) 195 .Times(1)
94 .InSequence(flow_order); 196 .InSequence(flow_order);
95 197
96 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 198 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
97 proxy->DeferToFake(true); 199 proxy->DeferToFake(true);
98 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 200 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
99 EXPECT_CALL(*proxy, SendEnrollRequest( 201 EXPECT_CALL(*proxy, SendEnrollRequest(
100 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, 202 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest,
101 _)).Times(1) 203 _)).Times(1)
(...skipping 19 matching lines...) Expand all
121 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 223 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
122 _)).Times(1) 224 _)).Times(1)
123 .InSequence(flow_order); 225 .InSequence(flow_order);
124 226
125 std::string fake_cert_response = 227 std::string fake_cert_response =
126 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 228 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
127 fake_cert_response += "_response"; 229 fake_cert_response += "_response";
128 EXPECT_CALL(async_caller, AsyncTpmAttestationFinishCertRequest( 230 EXPECT_CALL(async_caller, AsyncTpmAttestationFinishCertRequest(
129 fake_cert_response, KEY_USER, 231 fake_cert_response, KEY_USER,
130 cryptohome::Identification(account_id), 232 cryptohome::Identification(account_id),
131 kEnterpriseUserKey, _)) 233 kEnterpriseUserKey, _));
132 .Times(1)
133 .InSequence(flow_order);
134 234
135 StrictMock<MockObserver> observer; 235 StrictMock<MockObserver> observer;
136 EXPECT_CALL(observer, MockCertificateCallback( 236 EXPECT_CALL(observer, MockCertificateCallback(
137 true, 237 true,
138 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) 238 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert))
139 .Times(1) 239 .Times(1)
140 .InSequence(flow_order); 240 .InSequence(flow_order);
141 AttestationFlow::CertificateCallback mock_callback = base::Bind( 241 AttestationFlow::CertificateCallback callback = base::Bind(
142 &MockObserver::MockCertificateCallback, 242 &AttestationFlowTest::QuitRunLoopCertificateCallback,
143 base::Unretained(&observer)); 243 base::Unretained(this), base::Bind(&MockObserver::MockCertificateCallback,
244 base::Unretained(&observer)));
144 245
145 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 246 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
146 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 247 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
248 flow.SetRetryDelay(base::TimeDelta::FromMilliseconds(30));
147 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, account_id, 249 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, account_id,
148 "fake_origin", true, mock_callback); 250 "fake_origin", true, callback);
251
149 Run(); 252 Run();
150 } 253 }
151 254
255 TEST_F(AttestationFlowTest, GetCertificate_Attestation_Never_Prepared) {
256 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
257 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
258
259 chromeos::MockCryptohomeClient client;
260 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
261 .WillRepeatedly(Invoke(DBusCallbackFalse));
262
263 EXPECT_CALL(client, TpmAttestationIsPrepared(_))
264 .WillRepeatedly(Invoke(DBusCallbackFalse));
265
266 // We're not expecting any server calls in this case; StrictMock will verify.
267 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
268 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
269
270 StrictMock<MockObserver> observer;
271 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
272 AttestationFlow::CertificateCallback callback = base::Bind(
273 &AttestationFlowTest::QuitRunLoopCertificateCallback,
274 base::Unretained(this), base::Bind(&MockObserver::MockCertificateCallback,
275 base::Unretained(&observer)));
276
277 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
278 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
279 flow.SetReadyTimeout(base::TimeDelta::FromMilliseconds(20));
280 flow.SetRetryDelay(base::TimeDelta::FromMilliseconds(6));
281 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(),
282 "fake_origin", true, callback);
283
284 Run();
285 }
286
152 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { 287 TEST_F(AttestationFlowTest, GetCertificate_NoEK) {
153 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 288 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
154 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 289 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
155 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _)) 290 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
156 .Times(1); 291 .Times(1);
157 292
158 chromeos::MockCryptohomeClient client; 293 chromeos::MockCryptohomeClient client;
159 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 294 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
160 .WillRepeatedly(Invoke(DBusCallbackFalse)); 295 .WillRepeatedly(Invoke(DBusCallbackFalse));
161 296
297 EXPECT_CALL(client, TpmAttestationIsPrepared(_))
298 .WillOnce(Invoke(DBusCallbackTrue));
299
162 // We're not expecting any server calls in this case; StrictMock will verify. 300 // We're not expecting any server calls in this case; StrictMock will verify.
163 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 301 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
164 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 302 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
165 303
166 StrictMock<MockObserver> observer; 304 StrictMock<MockObserver> observer;
167 EXPECT_CALL(observer, MockCertificateCallback(false, "")) 305 EXPECT_CALL(observer, MockCertificateCallback(false, ""))
168 .Times(1); 306 .Times(1);
169 AttestationFlow::CertificateCallback mock_callback = base::Bind( 307 AttestationFlow::CertificateCallback mock_callback = base::Bind(
170 &MockObserver::MockCertificateCallback, 308 &MockObserver::MockCertificateCallback,
171 base::Unretained(&observer)); 309 base::Unretained(&observer));
172 310
173 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 311 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
174 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 312 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
175 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 313 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
176 true, mock_callback); 314 true, mock_callback);
177 Run(); 315 RunUntilIdle();
178 } 316 }
179 317
180 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { 318 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) {
181 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 319 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
182 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 320 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
183 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _)) 321 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
184 .Times(1); 322 .Times(1);
185 323
186 chromeos::MockCryptohomeClient client; 324 chromeos::MockCryptohomeClient client;
187 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 325 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
188 .WillRepeatedly(Invoke(DBusCallbackFalse)); 326 .WillRepeatedly(Invoke(DBusCallbackFalse));
189 327
328 EXPECT_CALL(client, TpmAttestationIsPrepared(_))
329 .WillOnce(Invoke(DBusCallbackTrue));
330
190 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 331 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
191 proxy->DeferToFake(false); 332 proxy->DeferToFake(false);
192 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 333 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
193 EXPECT_CALL(*proxy, SendEnrollRequest( 334 EXPECT_CALL(*proxy, SendEnrollRequest(
194 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, 335 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest,
195 _)).Times(1); 336 _)).Times(1);
196 337
197 StrictMock<MockObserver> observer; 338 StrictMock<MockObserver> observer;
198 EXPECT_CALL(observer, MockCertificateCallback(false, "")) 339 EXPECT_CALL(observer, MockCertificateCallback(false, ""))
199 .Times(1); 340 .Times(1);
200 AttestationFlow::CertificateCallback mock_callback = base::Bind( 341 AttestationFlow::CertificateCallback mock_callback = base::Bind(
201 &MockObserver::MockCertificateCallback, 342 &MockObserver::MockCertificateCallback,
202 base::Unretained(&observer)); 343 base::Unretained(&observer));
203 344
204 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 345 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
205 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 346 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
206 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 347 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
207 true, mock_callback); 348 true, mock_callback);
208 Run(); 349 RunUntilIdle();
209 } 350 }
210 351
211 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { 352 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) {
212 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 353 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
213 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 354 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
214 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _)) 355 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
215 .Times(1); 356 .Times(1);
216 std::string fake_enroll_response = 357 std::string fake_enroll_response =
217 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; 358 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest;
218 fake_enroll_response += "_response"; 359 fake_enroll_response += "_response";
219 EXPECT_CALL(async_caller, 360 EXPECT_CALL(async_caller,
220 AsyncTpmAttestationEnroll(_, fake_enroll_response, _)) 361 AsyncTpmAttestationEnroll(_, fake_enroll_response, _))
221 .WillOnce(WithArgs<2>(Invoke(AsyncCallbackFalse))); 362 .WillOnce(WithArgs<2>(Invoke(AsyncCallbackFalse)));
222 363
223 chromeos::MockCryptohomeClient client; 364 chromeos::MockCryptohomeClient client;
224 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 365 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
225 .WillRepeatedly(Invoke(DBusCallbackFalse)); 366 .WillRepeatedly(Invoke(DBusCallbackFalse));
226 367
368 EXPECT_CALL(client, TpmAttestationIsPrepared(_))
369 .WillOnce(Invoke(DBusCallbackTrue));
370
227 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 371 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
228 proxy->DeferToFake(true); 372 proxy->DeferToFake(true);
229 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 373 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
230 EXPECT_CALL(*proxy, SendEnrollRequest( 374 EXPECT_CALL(*proxy, SendEnrollRequest(
231 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, 375 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest,
232 _)).Times(1); 376 _)).Times(1);
233 377
234 StrictMock<MockObserver> observer; 378 StrictMock<MockObserver> observer;
235 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 379 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
236 AttestationFlow::CertificateCallback mock_callback = base::Bind( 380 AttestationFlow::CertificateCallback mock_callback = base::Bind(
237 &MockObserver::MockCertificateCallback, 381 &MockObserver::MockCertificateCallback,
238 base::Unretained(&observer)); 382 base::Unretained(&observer));
239 383
240 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 384 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
241 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 385 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
242 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 386 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
243 true, mock_callback); 387 true, mock_callback);
244 Run(); 388 RunUntilIdle();
245 } 389 }
246 390
247 TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) { 391 TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) {
248 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 392 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
249 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 393 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
250 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest( 394 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(
251 _, PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, 395 _, PROFILE_ENTERPRISE_MACHINE_CERTIFICATE,
252 cryptohome::Identification(), "", _)) 396 cryptohome::Identification(), "", _))
253 .Times(1); 397 .Times(1);
254 std::string fake_cert_response = 398 std::string fake_cert_response =
(...skipping 21 matching lines...) Expand all
276 true, 420 true,
277 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 421 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
278 AttestationFlow::CertificateCallback mock_callback = base::Bind( 422 AttestationFlow::CertificateCallback mock_callback = base::Bind(
279 &MockObserver::MockCertificateCallback, 423 &MockObserver::MockCertificateCallback,
280 base::Unretained(&observer)); 424 base::Unretained(&observer));
281 425
282 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 426 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
283 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 427 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
284 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, EmptyAccountId(), 428 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, EmptyAccountId(),
285 "", true, mock_callback); 429 "", true, mock_callback);
286 Run(); 430 RunUntilIdle();
287 } 431 }
288 432
289 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { 433 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) {
290 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 434 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
291 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 435 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
292 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest( 436 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(
293 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, 437 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
294 cryptohome::Identification(), "", _)) 438 cryptohome::Identification(), "", _))
295 .Times(1); 439 .Times(1);
296 440
297 chromeos::MockCryptohomeClient client; 441 chromeos::MockCryptohomeClient client;
298 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 442 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
299 .WillRepeatedly(Invoke(DBusCallbackTrue)); 443 .WillRepeatedly(Invoke(DBusCallbackTrue));
300 444
301 // We're not expecting any server calls in this case; StrictMock will verify. 445 // We're not expecting any server calls in this case; StrictMock will verify.
302 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 446 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
303 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 447 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
304 448
305 StrictMock<MockObserver> observer; 449 StrictMock<MockObserver> observer;
306 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 450 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
307 AttestationFlow::CertificateCallback mock_callback = base::Bind( 451 AttestationFlow::CertificateCallback mock_callback = base::Bind(
308 &MockObserver::MockCertificateCallback, 452 &MockObserver::MockCertificateCallback,
309 base::Unretained(&observer)); 453 base::Unretained(&observer));
310 454
311 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 455 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
312 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 456 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
313 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 457 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
314 true, mock_callback); 458 true, mock_callback);
315 Run(); 459 RunUntilIdle();
316 } 460 }
317 461
318 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { 462 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) {
319 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 463 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
320 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 464 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
321 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest( 465 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(
322 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, 466 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
323 cryptohome::Identification(), "", _)) 467 cryptohome::Identification(), "", _))
324 .Times(1); 468 .Times(1);
325 469
(...skipping 11 matching lines...) Expand all
337 StrictMock<MockObserver> observer; 481 StrictMock<MockObserver> observer;
338 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 482 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
339 AttestationFlow::CertificateCallback mock_callback = base::Bind( 483 AttestationFlow::CertificateCallback mock_callback = base::Bind(
340 &MockObserver::MockCertificateCallback, 484 &MockObserver::MockCertificateCallback,
341 base::Unretained(&observer)); 485 base::Unretained(&observer));
342 486
343 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 487 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
344 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 488 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
345 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 489 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
346 true, mock_callback); 490 true, mock_callback);
347 Run(); 491 RunUntilIdle();
348 } 492 }
349 493
350 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { 494 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) {
351 // We're not expecting any async calls in this case; StrictMock will verify. 495 // We're not expecting any async calls in this case; StrictMock will verify.
352 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 496 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
353 497
354 chromeos::MockCryptohomeClient client; 498 chromeos::MockCryptohomeClient client;
355 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 499 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
356 .WillRepeatedly(Invoke(DBusCallbackFail)); 500 .WillRepeatedly(Invoke(DBusCallbackFail));
357 501
358 // We're not expecting any server calls in this case; StrictMock will verify. 502 // We're not expecting any server calls in this case; StrictMock will verify.
359 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 503 std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
360 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 504 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
361 505
362 StrictMock<MockObserver> observer; 506 StrictMock<MockObserver> observer;
363 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 507 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
364 AttestationFlow::CertificateCallback mock_callback = base::Bind( 508 AttestationFlow::CertificateCallback mock_callback = base::Bind(
365 &MockObserver::MockCertificateCallback, 509 &MockObserver::MockCertificateCallback,
366 base::Unretained(&observer)); 510 base::Unretained(&observer));
367 511
368 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 512 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
369 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 513 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
370 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 514 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
371 true, mock_callback); 515 true, mock_callback);
372 Run(); 516 RunUntilIdle();
373 } 517 }
374 518
375 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) { 519 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) {
376 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 520 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
377 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 521 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
378 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest( 522 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(
379 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, 523 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
380 cryptohome::Identification(), "", _)) 524 cryptohome::Identification(), "", _))
381 .Times(1); 525 .Times(1);
382 std::string fake_cert_response = 526 std::string fake_cert_response =
(...skipping 25 matching lines...) Expand all
408 true, 552 true,
409 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 553 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
410 AttestationFlow::CertificateCallback mock_callback = base::Bind( 554 AttestationFlow::CertificateCallback mock_callback = base::Bind(
411 &MockObserver::MockCertificateCallback, 555 &MockObserver::MockCertificateCallback,
412 base::Unretained(&observer)); 556 base::Unretained(&observer));
413 557
414 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 558 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
415 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 559 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
416 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 560 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
417 false, mock_callback); 561 false, mock_callback);
418 Run(); 562 RunUntilIdle();
419 } 563 }
420 564
421 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) { 565 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) {
422 // We're not expecting any async calls in this case; StrictMock will verify. 566 // We're not expecting any async calls in this case; StrictMock will verify.
423 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 567 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
424 568
425 chromeos::MockCryptohomeClient client; 569 chromeos::MockCryptohomeClient client;
426 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 570 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
427 .WillRepeatedly(Invoke(DBusCallbackTrue)); 571 .WillRepeatedly(Invoke(DBusCallbackTrue));
428 EXPECT_CALL(client, 572 EXPECT_CALL(client,
(...skipping 12 matching lines...) Expand all
441 StrictMock<MockObserver> observer; 585 StrictMock<MockObserver> observer;
442 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1); 586 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1);
443 AttestationFlow::CertificateCallback mock_callback = base::Bind( 587 AttestationFlow::CertificateCallback mock_callback = base::Bind(
444 &MockObserver::MockCertificateCallback, 588 &MockObserver::MockCertificateCallback,
445 base::Unretained(&observer)); 589 base::Unretained(&observer));
446 590
447 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 591 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
448 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 592 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
449 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 593 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
450 false, mock_callback); 594 false, mock_callback);
451 Run(); 595 RunUntilIdle();
452 } 596 }
453 597
454 TEST_F(AttestationFlowTest, AlternatePCA) { 598 TEST_F(AttestationFlowTest, AlternatePCA) {
455 // Strategy: Create a ServerProxy mock which reports ALTERNATE_PCA and check 599 // Strategy: Create a ServerProxy mock which reports ALTERNATE_PCA and check
456 // that all calls to the AsyncMethodCaller reflect this PCA type. 600 // that all calls to the AsyncMethodCaller reflect this PCA type.
457 std::unique_ptr<MockServerProxy> proxy(new NiceMock<MockServerProxy>()); 601 std::unique_ptr<MockServerProxy> proxy(new NiceMock<MockServerProxy>());
458 proxy->DeferToFake(true); 602 proxy->DeferToFake(true);
459 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(Return(ALTERNATE_PCA)); 603 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(Return(ALTERNATE_PCA));
460 604
461 chromeos::MockCryptohomeClient client; 605 chromeos::MockCryptohomeClient client;
462 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 606 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
463 .WillRepeatedly(Invoke(DBusCallbackFalse)); 607 .WillRepeatedly(Invoke(DBusCallbackFalse));
464 608
609 EXPECT_CALL(client, TpmAttestationIsPrepared(_))
610 .WillRepeatedly(Invoke(DBusCallbackTrue));
611
465 NiceMock<cryptohome::MockAsyncMethodCaller> async_caller; 612 NiceMock<cryptohome::MockAsyncMethodCaller> async_caller;
466 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 613 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
467 EXPECT_CALL(async_caller, 614 EXPECT_CALL(async_caller,
468 AsyncTpmAttestationCreateEnrollRequest(ALTERNATE_PCA, _)) 615 AsyncTpmAttestationCreateEnrollRequest(ALTERNATE_PCA, _))
469 .Times(AtLeast(1)); 616 .Times(AtLeast(1));
470 EXPECT_CALL(async_caller, 617 EXPECT_CALL(async_caller,
471 AsyncTpmAttestationEnroll(ALTERNATE_PCA, _, _)) 618 AsyncTpmAttestationEnroll(ALTERNATE_PCA, _, _))
472 .Times(AtLeast(1)); 619 .Times(AtLeast(1));
473 EXPECT_CALL(async_caller, 620 EXPECT_CALL(async_caller,
474 AsyncTpmAttestationCreateCertRequest(ALTERNATE_PCA, _, _, _, _)) 621 AsyncTpmAttestationCreateCertRequest(ALTERNATE_PCA, _, _, _, _))
475 .Times(AtLeast(1)); 622 .Times(AtLeast(1));
476 623
477 NiceMock<MockObserver> observer; 624 NiceMock<MockObserver> observer;
478 AttestationFlow::CertificateCallback mock_callback = base::Bind( 625 AttestationFlow::CertificateCallback mock_callback = base::Bind(
479 &MockObserver::MockCertificateCallback, 626 &MockObserver::MockCertificateCallback,
480 base::Unretained(&observer)); 627 base::Unretained(&observer));
481 628
482 std::unique_ptr<ServerProxy> proxy_interface(proxy.release()); 629 std::unique_ptr<ServerProxy> proxy_interface(proxy.release());
483 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 630 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
484 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "", 631 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
485 true, mock_callback); 632 true, mock_callback);
486 Run(); 633 RunUntilIdle();
487 } 634 }
488 635
489 } // namespace attestation 636 } // namespace attestation
490 } // namespace chromeos 637 } // namespace chromeos
OLDNEW
« chromeos/attestation/attestation_flow.cc ('K') | « chromeos/attestation/attestation_flow.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698