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

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

Issue 27044004: Added multi-profile support for attestation on chromeos. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 2 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/cryptohome/async_method_caller.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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(PROFILE_ENTERPRISE_USER_CERTIFICATE, 102 AsyncTpmAttestationCreateCertRequest(PROFILE_ENTERPRISE_USER_CERTIFICATE,
103 "fake_email", "fake_origin", _)) 103 "fake@test.com", "fake_origin", _))
104 .Times(1) 104 .Times(1)
105 .InSequence(flow_order); 105 .InSequence(flow_order);
106 106
107 EXPECT_CALL(*proxy, SendCertificateRequest( 107 EXPECT_CALL(*proxy, SendCertificateRequest(
108 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 108 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
109 _)).Times(1) 109 _)).Times(1)
110 .InSequence(flow_order); 110 .InSequence(flow_order);
111 111
112 std::string fake_cert_response = 112 std::string fake_cert_response =
113 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 113 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
114 fake_cert_response += "_response"; 114 fake_cert_response += "_response";
115 EXPECT_CALL(async_caller, 115 EXPECT_CALL(async_caller,
116 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 116 AsyncTpmAttestationFinishCertRequest(fake_cert_response,
117 KEY_USER, 117 KEY_USER,
118 "fake@test.com",
118 kEnterpriseUserKey, 119 kEnterpriseUserKey,
119 _)) 120 _))
120 .Times(1) 121 .Times(1)
121 .InSequence(flow_order); 122 .InSequence(flow_order);
122 123
123 StrictMock<MockObserver> observer; 124 StrictMock<MockObserver> observer;
124 EXPECT_CALL(observer, MockCertificateCallback( 125 EXPECT_CALL(observer, MockCertificateCallback(
125 true, 126 true,
126 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) 127 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert))
127 .Times(1) 128 .Times(1)
128 .InSequence(flow_order); 129 .InSequence(flow_order);
129 AttestationFlow::CertificateCallback mock_callback = base::Bind( 130 AttestationFlow::CertificateCallback mock_callback = base::Bind(
130 &MockObserver::MockCertificateCallback, 131 &MockObserver::MockCertificateCallback,
131 base::Unretained(&observer)); 132 base::Unretained(&observer));
132 133
133 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 134 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
134 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 135 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
135 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "fake_email", 136 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "fake@test.com",
136 "fake_origin", true, mock_callback); 137 "fake_origin", true, mock_callback);
137 Run(); 138 Run();
138 } 139 }
139 140
140 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { 141 TEST_F(AttestationFlowTest, GetCertificate_NoEK) {
141 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 142 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
142 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 143 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
143 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) 144 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_))
144 .Times(1); 145 .Times(1);
145 146
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 EXPECT_CALL(async_caller, 235 EXPECT_CALL(async_caller,
235 AsyncTpmAttestationCreateCertRequest( 236 AsyncTpmAttestationCreateCertRequest(
236 PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", _)) 237 PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", _))
237 .Times(1); 238 .Times(1);
238 std::string fake_cert_response = 239 std::string fake_cert_response =
239 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 240 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
240 fake_cert_response += "_response"; 241 fake_cert_response += "_response";
241 EXPECT_CALL(async_caller, 242 EXPECT_CALL(async_caller,
242 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 243 AsyncTpmAttestationFinishCertRequest(fake_cert_response,
243 KEY_DEVICE, 244 KEY_DEVICE,
245 "",
244 kEnterpriseMachineKey, 246 kEnterpriseMachineKey,
245 _)) 247 _))
246 .Times(1); 248 .Times(1);
247 249
248 chromeos::MockCryptohomeClient client; 250 chromeos::MockCryptohomeClient client;
249 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 251 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
250 .WillRepeatedly(Invoke(DBusCallbackTrue)); 252 .WillRepeatedly(Invoke(DBusCallbackTrue));
251 253
252 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 254 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
253 proxy->DeferToFake(true); 255 proxy->DeferToFake(true);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 EXPECT_CALL(async_caller, 361 EXPECT_CALL(async_caller,
360 AsyncTpmAttestationCreateCertRequest( 362 AsyncTpmAttestationCreateCertRequest(
361 PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _)) 363 PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _))
362 .Times(1); 364 .Times(1);
363 std::string fake_cert_response = 365 std::string fake_cert_response =
364 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 366 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
365 fake_cert_response += "_response"; 367 fake_cert_response += "_response";
366 EXPECT_CALL(async_caller, 368 EXPECT_CALL(async_caller,
367 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 369 AsyncTpmAttestationFinishCertRequest(fake_cert_response,
368 KEY_USER, 370 KEY_USER,
371 "",
369 kEnterpriseUserKey, 372 kEnterpriseUserKey,
370 _)) 373 _))
371 .Times(1); 374 .Times(1);
372 375
373 chromeos::MockCryptohomeClient client; 376 chromeos::MockCryptohomeClient client;
374 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 377 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
375 .WillRepeatedly(Invoke(DBusCallbackTrue)); 378 .WillRepeatedly(Invoke(DBusCallbackTrue));
376 EXPECT_CALL(client, 379 EXPECT_CALL(client,
377 TpmAttestationDoesKeyExist(KEY_USER, kEnterpriseUserKey, _)) 380 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _))
378 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackFalse))); 381 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse)));
379 382
380 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 383 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
381 proxy->DeferToFake(true); 384 proxy->DeferToFake(true);
382 EXPECT_CALL(*proxy, SendCertificateRequest( 385 EXPECT_CALL(*proxy, SendCertificateRequest(
383 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 386 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
384 _)).Times(1); 387 _)).Times(1);
385 388
386 StrictMock<MockObserver> observer; 389 StrictMock<MockObserver> observer;
387 EXPECT_CALL(observer, MockCertificateCallback( 390 EXPECT_CALL(observer, MockCertificateCallback(
388 true, 391 true,
(...skipping 10 matching lines...) Expand all
399 } 402 }
400 403
401 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) { 404 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) {
402 // We're not expecting any async calls in this case; StrictMock will verify. 405 // We're not expecting any async calls in this case; StrictMock will verify.
403 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 406 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
404 407
405 chromeos::MockCryptohomeClient client; 408 chromeos::MockCryptohomeClient client;
406 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 409 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
407 .WillRepeatedly(Invoke(DBusCallbackTrue)); 410 .WillRepeatedly(Invoke(DBusCallbackTrue));
408 EXPECT_CALL(client, 411 EXPECT_CALL(client,
409 TpmAttestationDoesKeyExist(KEY_USER, kEnterpriseUserKey, _)) 412 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _))
410 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackTrue))); 413 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackTrue)));
411 EXPECT_CALL(client, 414 EXPECT_CALL(client,
412 TpmAttestationGetCertificate(KEY_USER, kEnterpriseUserKey, _)) 415 TpmAttestationGetCertificate(KEY_USER, "", kEnterpriseUserKey, _))
413 .WillRepeatedly(WithArgs<2>(Invoke(FakeDBusData("fake_cert")))); 416 .WillRepeatedly(WithArgs<3>(Invoke(FakeDBusData("fake_cert"))));
414 417
415 // We're not expecting any server calls in this case; StrictMock will verify. 418 // We're not expecting any server calls in this case; StrictMock will verify.
416 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 419 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
417 420
418 StrictMock<MockObserver> observer; 421 StrictMock<MockObserver> observer;
419 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1); 422 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1);
420 AttestationFlow::CertificateCallback mock_callback = base::Bind( 423 AttestationFlow::CertificateCallback mock_callback = base::Bind(
421 &MockObserver::MockCertificateCallback, 424 &MockObserver::MockCertificateCallback,
422 base::Unretained(&observer)); 425 base::Unretained(&observer));
423 426
424 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 427 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
425 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); 428 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass());
426 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false, 429 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false,
427 mock_callback); 430 mock_callback);
428 Run(); 431 Run();
429 } 432 }
430 433
431 } // namespace attestation 434 } // namespace attestation
432 } // namespace chromeos 435 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/attestation/attestation_flow.cc ('k') | chromeos/cryptohome/async_method_caller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698