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

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

Issue 20873002: Added support for the content protection profile to AttestationFlow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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
« no previous file with comments | « chromeos/attestation/attestation_flow.cc ('k') | chromeos/attestation/mock_attestation_flow.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chromeos/attestation/mock_attestation_flow.h" 8 #include "chromeos/attestation/mock_attestation_flow.h"
9 #include "chromeos/cryptohome/mock_async_method_caller.h" 9 #include "chromeos/cryptohome/mock_async_method_caller.h"
10 #include "chromeos/dbus/mock_cryptohome_client.h" 10 #include "chromeos/dbus/mock_cryptohome_client.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 std::string fake_enroll_response = 93 std::string fake_enroll_response =
94 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; 94 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest;
95 fake_enroll_response += "_response"; 95 fake_enroll_response += "_response";
96 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _)) 96 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _))
97 .Times(1) 97 .Times(1)
98 .InSequence(flow_order); 98 .InSequence(flow_order);
99 99
100 EXPECT_CALL( 100 EXPECT_CALL(
101 async_caller, 101 async_caller,
102 AsyncTpmAttestationCreateCertRequest(CERTIFICATE_INCLUDE_DEVICE_STATE, _)) 102 AsyncTpmAttestationCreateCertRequest(PROFILE_ENTERPRISE_USER_CERTIFICATE,
103 "fake_email", "fake_origin", _))
103 .Times(1) 104 .Times(1)
104 .InSequence(flow_order); 105 .InSequence(flow_order);
105 106
106 EXPECT_CALL(*proxy, SendCertificateRequest( 107 EXPECT_CALL(*proxy, SendCertificateRequest(
107 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 108 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
108 _)).Times(1) 109 _)).Times(1)
109 .InSequence(flow_order); 110 .InSequence(flow_order);
110 111
111 std::string fake_cert_response = 112 std::string fake_cert_response =
112 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 113 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
(...skipping 11 matching lines...) Expand all
124 true, 125 true,
125 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) 126 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert))
126 .Times(1) 127 .Times(1)
127 .InSequence(flow_order); 128 .InSequence(flow_order);
128 AttestationFlow::CertificateCallback mock_callback = base::Bind( 129 AttestationFlow::CertificateCallback mock_callback = base::Bind(
129 &MockObserver::MockCertificateCallback, 130 &MockObserver::MockCertificateCallback,
130 base::Unretained(&observer)); 131 base::Unretained(&observer));
131 132
132 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 133 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
133 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 134 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
134 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, true, mock_callback); 135 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "fake_email",
136 "fake_origin", true, mock_callback);
135 Run(); 137 Run();
136 } 138 }
137 139
138 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { 140 TEST_F(AttestationFlowTest, GetCertificate_NoEK) {
139 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 141 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
140 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 142 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
141 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) 143 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_))
142 .Times(1); 144 .Times(1);
143 145
144 chromeos::MockCryptohomeClient client; 146 chromeos::MockCryptohomeClient client;
145 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 147 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
146 .WillRepeatedly(Invoke(DBusCallbackFalse)); 148 .WillRepeatedly(Invoke(DBusCallbackFalse));
147 149
148 // We're not expecting any server calls in this case; StrictMock will verify. 150 // We're not expecting any server calls in this case; StrictMock will verify.
149 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 151 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
150 152
151 StrictMock<MockObserver> observer; 153 StrictMock<MockObserver> observer;
152 EXPECT_CALL(observer, MockCertificateCallback(false, "")) 154 EXPECT_CALL(observer, MockCertificateCallback(false, ""))
153 .Times(1); 155 .Times(1);
154 AttestationFlow::CertificateCallback mock_callback = base::Bind( 156 AttestationFlow::CertificateCallback mock_callback = base::Bind(
155 &MockObserver::MockCertificateCallback, 157 &MockObserver::MockCertificateCallback,
156 base::Unretained(&observer)); 158 base::Unretained(&observer));
157 159
158 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 160 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
159 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 161 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
160 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, true, mock_callback); 162 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true,
163 mock_callback);
161 Run(); 164 Run();
162 } 165 }
163 166
164 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { 167 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) {
165 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 168 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
166 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 169 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
167 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) 170 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_))
168 .Times(1); 171 .Times(1);
169 172
170 chromeos::MockCryptohomeClient client; 173 chromeos::MockCryptohomeClient client;
171 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 174 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
172 .WillRepeatedly(Invoke(DBusCallbackFalse)); 175 .WillRepeatedly(Invoke(DBusCallbackFalse));
173 176
174 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 177 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
175 proxy->DeferToFake(false); 178 proxy->DeferToFake(false);
176 EXPECT_CALL(*proxy, SendEnrollRequest( 179 EXPECT_CALL(*proxy, SendEnrollRequest(
177 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, 180 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest,
178 _)).Times(1); 181 _)).Times(1);
179 182
180 StrictMock<MockObserver> observer; 183 StrictMock<MockObserver> observer;
181 EXPECT_CALL(observer, MockCertificateCallback(false, "")) 184 EXPECT_CALL(observer, MockCertificateCallback(false, ""))
182 .Times(1); 185 .Times(1);
183 AttestationFlow::CertificateCallback mock_callback = base::Bind( 186 AttestationFlow::CertificateCallback mock_callback = base::Bind(
184 &MockObserver::MockCertificateCallback, 187 &MockObserver::MockCertificateCallback,
185 base::Unretained(&observer)); 188 base::Unretained(&observer));
186 189
187 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 190 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
188 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 191 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
189 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, true, mock_callback); 192 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true,
193 mock_callback);
190 Run(); 194 Run();
191 } 195 }
192 196
193 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { 197 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) {
194 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 198 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
195 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 199 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
196 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) 200 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_))
197 .Times(1); 201 .Times(1);
198 std::string fake_enroll_response = 202 std::string fake_enroll_response =
199 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; 203 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest;
(...skipping 12 matching lines...) Expand all
212 _)).Times(1); 216 _)).Times(1);
213 217
214 StrictMock<MockObserver> observer; 218 StrictMock<MockObserver> observer;
215 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 219 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
216 AttestationFlow::CertificateCallback mock_callback = base::Bind( 220 AttestationFlow::CertificateCallback mock_callback = base::Bind(
217 &MockObserver::MockCertificateCallback, 221 &MockObserver::MockCertificateCallback,
218 base::Unretained(&observer)); 222 base::Unretained(&observer));
219 223
220 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 224 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
221 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 225 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
222 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, true, mock_callback); 226 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true,
227 mock_callback);
223 Run(); 228 Run();
224 } 229 }
225 230
226 TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) { 231 TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) {
227 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 232 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
228 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 233 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
229 int options = CERTIFICATE_INCLUDE_DEVICE_STATE | 234 EXPECT_CALL(async_caller,
230 CERTIFICATE_INCLUDE_STABLE_ID; 235 AsyncTpmAttestationCreateCertRequest(
231 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(options, _)) 236 PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", _))
232 .Times(1); 237 .Times(1);
233 std::string fake_cert_response = 238 std::string fake_cert_response =
234 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 239 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
235 fake_cert_response += "_response"; 240 fake_cert_response += "_response";
236 EXPECT_CALL(async_caller, 241 EXPECT_CALL(async_caller,
237 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 242 AsyncTpmAttestationFinishCertRequest(fake_cert_response,
238 KEY_DEVICE, 243 KEY_DEVICE,
239 kEnterpriseMachineKey, 244 kEnterpriseMachineKey,
240 _)) 245 _))
241 .Times(1); 246 .Times(1);
(...skipping 11 matching lines...) Expand all
253 StrictMock<MockObserver> observer; 258 StrictMock<MockObserver> observer;
254 EXPECT_CALL(observer, MockCertificateCallback( 259 EXPECT_CALL(observer, MockCertificateCallback(
255 true, 260 true,
256 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 261 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
257 AttestationFlow::CertificateCallback mock_callback = base::Bind( 262 AttestationFlow::CertificateCallback mock_callback = base::Bind(
258 &MockObserver::MockCertificateCallback, 263 &MockObserver::MockCertificateCallback,
259 base::Unretained(&observer)); 264 base::Unretained(&observer));
260 265
261 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 266 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
262 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 267 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
263 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, 268 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", true,
264 true, mock_callback); 269 mock_callback);
265 Run(); 270 Run();
266 } 271 }
267 272
268 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { 273 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) {
269 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 274 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
270 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 275 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
271 int options = CERTIFICATE_INCLUDE_DEVICE_STATE;
272 EXPECT_CALL(async_caller, 276 EXPECT_CALL(async_caller,
273 AsyncTpmAttestationCreateCertRequest(options, _)) 277 AsyncTpmAttestationCreateCertRequest(
278 PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _))
274 .Times(1); 279 .Times(1);
275 280
276 chromeos::MockCryptohomeClient client; 281 chromeos::MockCryptohomeClient client;
277 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 282 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
278 .WillRepeatedly(Invoke(DBusCallbackTrue)); 283 .WillRepeatedly(Invoke(DBusCallbackTrue));
279 284
280 // We're not expecting any server calls in this case; StrictMock will verify. 285 // We're not expecting any server calls in this case; StrictMock will verify.
281 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 286 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
282 287
283 StrictMock<MockObserver> observer; 288 StrictMock<MockObserver> observer;
284 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 289 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
285 AttestationFlow::CertificateCallback mock_callback = base::Bind( 290 AttestationFlow::CertificateCallback mock_callback = base::Bind(
286 &MockObserver::MockCertificateCallback, 291 &MockObserver::MockCertificateCallback,
287 base::Unretained(&observer)); 292 base::Unretained(&observer));
288 293
289 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 294 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
290 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 295 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
291 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, true, mock_callback); 296 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true,
297 mock_callback);
292 Run(); 298 Run();
293 } 299 }
294 300
295 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { 301 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) {
296 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 302 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
297 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 303 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
298 int options = CERTIFICATE_INCLUDE_DEVICE_STATE;
299 EXPECT_CALL(async_caller, 304 EXPECT_CALL(async_caller,
300 AsyncTpmAttestationCreateCertRequest(options, _)) 305 AsyncTpmAttestationCreateCertRequest(
306 PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _))
301 .Times(1); 307 .Times(1);
302 308
303 chromeos::MockCryptohomeClient client; 309 chromeos::MockCryptohomeClient client;
304 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 310 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
305 .WillRepeatedly(Invoke(DBusCallbackTrue)); 311 .WillRepeatedly(Invoke(DBusCallbackTrue));
306 312
307 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 313 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
308 proxy->DeferToFake(false); 314 proxy->DeferToFake(false);
309 EXPECT_CALL(*proxy, SendCertificateRequest( 315 EXPECT_CALL(*proxy, SendCertificateRequest(
310 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 316 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
311 _)).Times(1); 317 _)).Times(1);
312 318
313 StrictMock<MockObserver> observer; 319 StrictMock<MockObserver> observer;
314 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 320 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
315 AttestationFlow::CertificateCallback mock_callback = base::Bind( 321 AttestationFlow::CertificateCallback mock_callback = base::Bind(
316 &MockObserver::MockCertificateCallback, 322 &MockObserver::MockCertificateCallback,
317 base::Unretained(&observer)); 323 base::Unretained(&observer));
318 324
319 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 325 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
320 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 326 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
321 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, true, mock_callback); 327 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true,
328 mock_callback);
322 Run(); 329 Run();
323 } 330 }
324 331
325 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { 332 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) {
326 // We're not expecting any async calls in this case; StrictMock will verify. 333 // We're not expecting any async calls in this case; StrictMock will verify.
327 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 334 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
328 335
329 chromeos::MockCryptohomeClient client; 336 chromeos::MockCryptohomeClient client;
330 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 337 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
331 .WillRepeatedly(Invoke(DBusCallbackFail)); 338 .WillRepeatedly(Invoke(DBusCallbackFail));
332 339
333 // We're not expecting any server calls in this case; StrictMock will verify. 340 // We're not expecting any server calls in this case; StrictMock will verify.
334 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 341 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
335 342
336 StrictMock<MockObserver> observer; 343 StrictMock<MockObserver> observer;
337 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 344 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
338 AttestationFlow::CertificateCallback mock_callback = base::Bind( 345 AttestationFlow::CertificateCallback mock_callback = base::Bind(
339 &MockObserver::MockCertificateCallback, 346 &MockObserver::MockCertificateCallback,
340 base::Unretained(&observer)); 347 base::Unretained(&observer));
341 348
342 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 349 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
343 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 350 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
344 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, true, mock_callback); 351 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true,
352 mock_callback);
345 Run(); 353 Run();
346 } 354 }
347 355
348 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) { 356 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) {
349 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 357 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
350 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 358 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
351 int options = CERTIFICATE_INCLUDE_DEVICE_STATE; 359 EXPECT_CALL(async_caller,
352 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(options, _)) 360 AsyncTpmAttestationCreateCertRequest(
361 PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _))
353 .Times(1); 362 .Times(1);
354 std::string fake_cert_response = 363 std::string fake_cert_response =
355 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 364 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
356 fake_cert_response += "_response"; 365 fake_cert_response += "_response";
357 EXPECT_CALL(async_caller, 366 EXPECT_CALL(async_caller,
358 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 367 AsyncTpmAttestationFinishCertRequest(fake_cert_response,
359 KEY_USER, 368 KEY_USER,
360 kEnterpriseUserKey, 369 kEnterpriseUserKey,
361 _)) 370 _))
362 .Times(1); 371 .Times(1);
(...skipping 14 matching lines...) Expand all
377 StrictMock<MockObserver> observer; 386 StrictMock<MockObserver> observer;
378 EXPECT_CALL(observer, MockCertificateCallback( 387 EXPECT_CALL(observer, MockCertificateCallback(
379 true, 388 true,
380 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 389 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
381 AttestationFlow::CertificateCallback mock_callback = base::Bind( 390 AttestationFlow::CertificateCallback mock_callback = base::Bind(
382 &MockObserver::MockCertificateCallback, 391 &MockObserver::MockCertificateCallback,
383 base::Unretained(&observer)); 392 base::Unretained(&observer));
384 393
385 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 394 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
386 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 395 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
387 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, 396 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false,
388 false, mock_callback); 397 mock_callback);
389 Run(); 398 Run();
390 } 399 }
391 400
392 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) { 401 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) {
393 // We're not expecting any async calls in this case; StrictMock will verify. 402 // We're not expecting any async calls in this case; StrictMock will verify.
394 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 403 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
395 404
396 chromeos::MockCryptohomeClient client; 405 chromeos::MockCryptohomeClient client;
397 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 406 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
398 .WillRepeatedly(Invoke(DBusCallbackTrue)); 407 .WillRepeatedly(Invoke(DBusCallbackTrue));
399 EXPECT_CALL(client, 408 EXPECT_CALL(client,
400 TpmAttestationDoesKeyExist(KEY_USER, kEnterpriseUserKey, _)) 409 TpmAttestationDoesKeyExist(KEY_USER, kEnterpriseUserKey, _))
401 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackTrue))); 410 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackTrue)));
402 EXPECT_CALL(client, 411 EXPECT_CALL(client,
403 TpmAttestationGetCertificate(KEY_USER, kEnterpriseUserKey, _)) 412 TpmAttestationGetCertificate(KEY_USER, kEnterpriseUserKey, _))
404 .WillRepeatedly(WithArgs<2>(Invoke(FakeDBusData("fake_cert")))); 413 .WillRepeatedly(WithArgs<2>(Invoke(FakeDBusData("fake_cert"))));
405 414
406 // We're not expecting any server calls in this case; StrictMock will verify. 415 // We're not expecting any server calls in this case; StrictMock will verify.
407 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 416 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
408 417
409 StrictMock<MockObserver> observer; 418 StrictMock<MockObserver> observer;
410 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1); 419 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1);
411 AttestationFlow::CertificateCallback mock_callback = base::Bind( 420 AttestationFlow::CertificateCallback mock_callback = base::Bind(
412 &MockObserver::MockCertificateCallback, 421 &MockObserver::MockCertificateCallback,
413 base::Unretained(&observer)); 422 base::Unretained(&observer));
414 423
415 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 424 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
416 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 425 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
417 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, 426 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false,
418 false, mock_callback); 427 mock_callback);
419 Run(); 428 Run();
420 } 429 }
421 430
422 } // namespace attestation 431 } // namespace attestation
423 } // namespace chromeos 432 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/attestation/attestation_flow.cc ('k') | chromeos/attestation/mock_attestation_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698