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

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

Issue 1693383003: ChromeOS cryptohome should be able to use gaia id as user identifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing files. Created 4 years, 10 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
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 <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chromeos/attestation/mock_attestation_flow.h" 10 #include "chromeos/attestation/mock_attestation_flow.h"
11 #include "chromeos/cryptohome/cryptohome_parameters.h"
11 #include "chromeos/cryptohome/mock_async_method_caller.h" 12 #include "chromeos/cryptohome/mock_async_method_caller.h"
12 #include "chromeos/dbus/mock_cryptohome_client.h" 13 #include "chromeos/dbus/mock_cryptohome_client.h"
14 #include "components/signin/core/account_id/account_id.h"
13 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 using testing::_; 18 using testing::_;
17 using testing::AtLeast; 19 using testing::AtLeast;
18 using testing::DoDefault; 20 using testing::DoDefault;
19 using testing::Invoke; 21 using testing::Invoke;
20 using testing::NiceMock; 22 using testing::NiceMock;
21 using testing::Return; 23 using testing::Return;
22 using testing::Sequence; 24 using testing::Sequence;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 .InSequence(flow_order); 100 .InSequence(flow_order);
99 101
100 std::string fake_enroll_response = 102 std::string fake_enroll_response =
101 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; 103 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest;
102 fake_enroll_response += "_response"; 104 fake_enroll_response += "_response";
103 EXPECT_CALL(async_caller, 105 EXPECT_CALL(async_caller,
104 AsyncTpmAttestationEnroll(_, fake_enroll_response, _)) 106 AsyncTpmAttestationEnroll(_, fake_enroll_response, _))
105 .Times(1) 107 .Times(1)
106 .InSequence(flow_order); 108 .InSequence(flow_order);
107 109
108 EXPECT_CALL( 110 const AccountId account_id = AccountId::FromUserEmail("fake@test.com");
109 async_caller, 111 EXPECT_CALL(async_caller,
110 AsyncTpmAttestationCreateCertRequest(_, 112 AsyncTpmAttestationCreateCertRequest(
111 PROFILE_ENTERPRISE_USER_CERTIFICATE, 113 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
112 "fake@test.com", "fake_origin", _)) 114 cryptohome::Identification(account_id), "fake_origin", _))
113 .Times(1) 115 .Times(1)
114 .InSequence(flow_order); 116 .InSequence(flow_order);
115 117
116 EXPECT_CALL(*proxy, SendCertificateRequest( 118 EXPECT_CALL(*proxy, SendCertificateRequest(
117 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 119 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
118 _)).Times(1) 120 _)).Times(1)
119 .InSequence(flow_order); 121 .InSequence(flow_order);
120 122
121 std::string fake_cert_response = 123 std::string fake_cert_response =
122 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 124 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
123 fake_cert_response += "_response"; 125 fake_cert_response += "_response";
124 EXPECT_CALL(async_caller, 126 EXPECT_CALL(async_caller, AsyncTpmAttestationFinishCertRequest(
125 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 127 fake_cert_response, KEY_USER,
126 KEY_USER, 128 cryptohome::Identification(account_id),
127 "fake@test.com", 129 kEnterpriseUserKey, _))
128 kEnterpriseUserKey,
129 _))
130 .Times(1) 130 .Times(1)
131 .InSequence(flow_order); 131 .InSequence(flow_order);
132 132
133 StrictMock<MockObserver> observer; 133 StrictMock<MockObserver> observer;
134 EXPECT_CALL(observer, MockCertificateCallback( 134 EXPECT_CALL(observer, MockCertificateCallback(
135 true, 135 true,
136 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) 136 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert))
137 .Times(1) 137 .Times(1)
138 .InSequence(flow_order); 138 .InSequence(flow_order);
139 AttestationFlow::CertificateCallback mock_callback = base::Bind( 139 AttestationFlow::CertificateCallback mock_callback = base::Bind(
140 &MockObserver::MockCertificateCallback, 140 &MockObserver::MockCertificateCallback,
141 base::Unretained(&observer)); 141 base::Unretained(&observer));
142 142
143 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 143 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
144 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 144 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
145 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "fake@test.com", 145 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, account_id,
146 "fake_origin", true, mock_callback); 146 "fake_origin", true, mock_callback);
147 Run(); 147 Run();
148 } 148 }
149 149
150 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { 150 TEST_F(AttestationFlowTest, GetCertificate_NoEK) {
151 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 151 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
152 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 152 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
153 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _)) 153 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
154 .Times(1); 154 .Times(1);
155 155
156 chromeos::MockCryptohomeClient client; 156 chromeos::MockCryptohomeClient client;
157 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 157 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
158 .WillRepeatedly(Invoke(DBusCallbackFalse)); 158 .WillRepeatedly(Invoke(DBusCallbackFalse));
159 159
160 // We're not expecting any server calls in this case; StrictMock will verify. 160 // We're not expecting any server calls in this case; StrictMock will verify.
161 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 161 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
162 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 162 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
163 163
164 StrictMock<MockObserver> observer; 164 StrictMock<MockObserver> observer;
165 EXPECT_CALL(observer, MockCertificateCallback(false, "")) 165 EXPECT_CALL(observer, MockCertificateCallback(false, ""))
166 .Times(1); 166 .Times(1);
167 AttestationFlow::CertificateCallback mock_callback = base::Bind( 167 AttestationFlow::CertificateCallback mock_callback = base::Bind(
168 &MockObserver::MockCertificateCallback, 168 &MockObserver::MockCertificateCallback,
169 base::Unretained(&observer)); 169 base::Unretained(&observer));
170 170
171 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 171 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
172 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 172 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
173 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 173 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
174 mock_callback); 174 true, mock_callback);
175 Run(); 175 Run();
176 } 176 }
177 177
178 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { 178 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) {
179 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 179 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
180 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 180 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
181 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _)) 181 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
182 .Times(1); 182 .Times(1);
183 183
184 chromeos::MockCryptohomeClient client; 184 chromeos::MockCryptohomeClient client;
185 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 185 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
186 .WillRepeatedly(Invoke(DBusCallbackFalse)); 186 .WillRepeatedly(Invoke(DBusCallbackFalse));
187 187
188 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 188 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
189 proxy->DeferToFake(false); 189 proxy->DeferToFake(false);
190 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 190 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
191 EXPECT_CALL(*proxy, SendEnrollRequest( 191 EXPECT_CALL(*proxy, SendEnrollRequest(
192 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, 192 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest,
193 _)).Times(1); 193 _)).Times(1);
194 194
195 StrictMock<MockObserver> observer; 195 StrictMock<MockObserver> observer;
196 EXPECT_CALL(observer, MockCertificateCallback(false, "")) 196 EXPECT_CALL(observer, MockCertificateCallback(false, ""))
197 .Times(1); 197 .Times(1);
198 AttestationFlow::CertificateCallback mock_callback = base::Bind( 198 AttestationFlow::CertificateCallback mock_callback = base::Bind(
199 &MockObserver::MockCertificateCallback, 199 &MockObserver::MockCertificateCallback,
200 base::Unretained(&observer)); 200 base::Unretained(&observer));
201 201
202 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 202 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
203 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 203 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
204 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 204 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
205 mock_callback); 205 true, mock_callback);
206 Run(); 206 Run();
207 } 207 }
208 208
209 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { 209 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) {
210 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 210 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
211 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 211 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
212 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _)) 212 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_, _))
213 .Times(1); 213 .Times(1);
214 std::string fake_enroll_response = 214 std::string fake_enroll_response =
215 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; 215 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest;
(...skipping 14 matching lines...) Expand all
230 _)).Times(1); 230 _)).Times(1);
231 231
232 StrictMock<MockObserver> observer; 232 StrictMock<MockObserver> observer;
233 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 233 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
234 AttestationFlow::CertificateCallback mock_callback = base::Bind( 234 AttestationFlow::CertificateCallback mock_callback = base::Bind(
235 &MockObserver::MockCertificateCallback, 235 &MockObserver::MockCertificateCallback,
236 base::Unretained(&observer)); 236 base::Unretained(&observer));
237 237
238 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 238 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
239 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 239 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
240 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 240 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
241 mock_callback); 241 true, mock_callback);
242 Run(); 242 Run();
243 } 243 }
244 244
245 TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) { 245 TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) {
246 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 246 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
247 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 247 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
248 EXPECT_CALL(async_caller, 248 EXPECT_CALL(async_caller,
249 AsyncTpmAttestationCreateCertRequest( 249 AsyncTpmAttestationCreateCertRequest(
250 _, PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", _)) 250 _, PROFILE_ENTERPRISE_MACHINE_CERTIFICATE,
251 cryptohome::Identification(EmptyAccountId()), "", _))
251 .Times(1); 252 .Times(1);
252 std::string fake_cert_response = 253 std::string fake_cert_response =
253 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 254 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
254 fake_cert_response += "_response"; 255 fake_cert_response += "_response";
255 EXPECT_CALL(async_caller, 256 EXPECT_CALL(async_caller, AsyncTpmAttestationFinishCertRequest(
256 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 257 fake_cert_response, KEY_DEVICE,
257 KEY_DEVICE, 258 cryptohome::Identification(EmptyAccountId()),
258 "", 259 kEnterpriseMachineKey, _))
259 kEnterpriseMachineKey,
260 _))
261 .Times(1); 260 .Times(1);
262 261
263 chromeos::MockCryptohomeClient client; 262 chromeos::MockCryptohomeClient client;
264 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 263 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
265 .WillRepeatedly(Invoke(DBusCallbackTrue)); 264 .WillRepeatedly(Invoke(DBusCallbackTrue));
266 265
267 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 266 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
268 proxy->DeferToFake(true); 267 proxy->DeferToFake(true);
269 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 268 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
270 EXPECT_CALL(*proxy, SendCertificateRequest( 269 EXPECT_CALL(*proxy, SendCertificateRequest(
271 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 270 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
272 _)).Times(1); 271 _)).Times(1);
273 272
274 StrictMock<MockObserver> observer; 273 StrictMock<MockObserver> observer;
275 EXPECT_CALL(observer, MockCertificateCallback( 274 EXPECT_CALL(observer, MockCertificateCallback(
276 true, 275 true,
277 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 276 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
278 AttestationFlow::CertificateCallback mock_callback = base::Bind( 277 AttestationFlow::CertificateCallback mock_callback = base::Bind(
279 &MockObserver::MockCertificateCallback, 278 &MockObserver::MockCertificateCallback,
280 base::Unretained(&observer)); 279 base::Unretained(&observer));
281 280
282 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 281 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
283 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 282 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
284 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", true, 283 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, EmptyAccountId(),
285 mock_callback); 284 "", true, mock_callback);
286 Run(); 285 Run();
287 } 286 }
288 287
289 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { 288 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) {
290 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 289 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
291 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 290 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
292 EXPECT_CALL(async_caller, 291 EXPECT_CALL(async_caller,
293 AsyncTpmAttestationCreateCertRequest( 292 AsyncTpmAttestationCreateCertRequest(
294 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _)) 293 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
294 cryptohome::Identification(EmptyAccountId()), "", _))
295 .Times(1); 295 .Times(1);
296 296
297 chromeos::MockCryptohomeClient client; 297 chromeos::MockCryptohomeClient client;
298 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 298 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
299 .WillRepeatedly(Invoke(DBusCallbackTrue)); 299 .WillRepeatedly(Invoke(DBusCallbackTrue));
300 300
301 // We're not expecting any server calls in this case; StrictMock will verify. 301 // We're not expecting any server calls in this case; StrictMock will verify.
302 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 302 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
303 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 303 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
304 304
305 StrictMock<MockObserver> observer; 305 StrictMock<MockObserver> observer;
306 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 306 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
307 AttestationFlow::CertificateCallback mock_callback = base::Bind( 307 AttestationFlow::CertificateCallback mock_callback = base::Bind(
308 &MockObserver::MockCertificateCallback, 308 &MockObserver::MockCertificateCallback,
309 base::Unretained(&observer)); 309 base::Unretained(&observer));
310 310
311 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 311 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
312 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 312 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
313 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 313 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
314 mock_callback); 314 true, mock_callback);
315 Run(); 315 Run();
316 } 316 }
317 317
318 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { 318 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) {
319 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 319 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
320 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 320 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
321 EXPECT_CALL(async_caller, 321 EXPECT_CALL(async_caller,
322 AsyncTpmAttestationCreateCertRequest( 322 AsyncTpmAttestationCreateCertRequest(
323 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _)) 323 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
324 cryptohome::Identification(EmptyAccountId()), "", _))
324 .Times(1); 325 .Times(1);
325 326
326 chromeos::MockCryptohomeClient client; 327 chromeos::MockCryptohomeClient client;
327 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 328 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
328 .WillRepeatedly(Invoke(DBusCallbackTrue)); 329 .WillRepeatedly(Invoke(DBusCallbackTrue));
329 330
330 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 331 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
331 proxy->DeferToFake(false); 332 proxy->DeferToFake(false);
332 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 333 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
333 EXPECT_CALL(*proxy, SendCertificateRequest( 334 EXPECT_CALL(*proxy, SendCertificateRequest(
334 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 335 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
335 _)).Times(1); 336 _)).Times(1);
336 337
337 StrictMock<MockObserver> observer; 338 StrictMock<MockObserver> observer;
338 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 339 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
339 AttestationFlow::CertificateCallback mock_callback = base::Bind( 340 AttestationFlow::CertificateCallback mock_callback = base::Bind(
340 &MockObserver::MockCertificateCallback, 341 &MockObserver::MockCertificateCallback,
341 base::Unretained(&observer)); 342 base::Unretained(&observer));
342 343
343 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 344 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
344 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 345 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
345 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 346 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
346 mock_callback); 347 true, mock_callback);
347 Run(); 348 Run();
348 } 349 }
349 350
350 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { 351 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) {
351 // We're not expecting any async calls in this case; StrictMock will verify. 352 // We're not expecting any async calls in this case; StrictMock will verify.
352 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 353 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
353 354
354 chromeos::MockCryptohomeClient client; 355 chromeos::MockCryptohomeClient client;
355 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 356 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
356 .WillRepeatedly(Invoke(DBusCallbackFail)); 357 .WillRepeatedly(Invoke(DBusCallbackFail));
357 358
358 // We're not expecting any server calls in this case; StrictMock will verify. 359 // We're not expecting any server calls in this case; StrictMock will verify.
359 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 360 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
360 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 361 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
361 362
362 StrictMock<MockObserver> observer; 363 StrictMock<MockObserver> observer;
363 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 364 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
364 AttestationFlow::CertificateCallback mock_callback = base::Bind( 365 AttestationFlow::CertificateCallback mock_callback = base::Bind(
365 &MockObserver::MockCertificateCallback, 366 &MockObserver::MockCertificateCallback,
366 base::Unretained(&observer)); 367 base::Unretained(&observer));
367 368
368 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 369 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
369 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 370 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
370 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 371 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
371 mock_callback); 372 true, mock_callback);
372 Run(); 373 Run();
373 } 374 }
374 375
375 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) { 376 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) {
376 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 377 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
377 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 378 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
378 EXPECT_CALL(async_caller, 379 EXPECT_CALL(async_caller,
379 AsyncTpmAttestationCreateCertRequest( 380 AsyncTpmAttestationCreateCertRequest(
380 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _)) 381 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
382 cryptohome::Identification(EmptyAccountId()), "", _))
381 .Times(1); 383 .Times(1);
382 std::string fake_cert_response = 384 std::string fake_cert_response =
383 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 385 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
384 fake_cert_response += "_response"; 386 fake_cert_response += "_response";
385 EXPECT_CALL(async_caller, 387 EXPECT_CALL(async_caller, AsyncTpmAttestationFinishCertRequest(
386 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 388 fake_cert_response, KEY_USER,
387 KEY_USER, 389 cryptohome::Identification(EmptyAccountId()),
388 "", 390 kEnterpriseUserKey, _))
389 kEnterpriseUserKey,
390 _))
391 .Times(1); 391 .Times(1);
392 392
393 chromeos::MockCryptohomeClient client; 393 chromeos::MockCryptohomeClient client;
394 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 394 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
395 .WillRepeatedly(Invoke(DBusCallbackTrue)); 395 .WillRepeatedly(Invoke(DBusCallbackTrue));
396 EXPECT_CALL(client, 396 EXPECT_CALL(client,
397 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _)) 397 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _))
398 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse))); 398 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse)));
399 399
400 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 400 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
401 proxy->DeferToFake(true); 401 proxy->DeferToFake(true);
402 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 402 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
403 EXPECT_CALL(*proxy, SendCertificateRequest( 403 EXPECT_CALL(*proxy, SendCertificateRequest(
404 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 404 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
405 _)).Times(1); 405 _)).Times(1);
406 406
407 StrictMock<MockObserver> observer; 407 StrictMock<MockObserver> observer;
408 EXPECT_CALL(observer, MockCertificateCallback( 408 EXPECT_CALL(observer, MockCertificateCallback(
409 true, 409 true,
410 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 410 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
411 AttestationFlow::CertificateCallback mock_callback = base::Bind( 411 AttestationFlow::CertificateCallback mock_callback = base::Bind(
412 &MockObserver::MockCertificateCallback, 412 &MockObserver::MockCertificateCallback,
413 base::Unretained(&observer)); 413 base::Unretained(&observer));
414 414
415 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 415 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
416 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 416 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
417 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false, 417 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
418 mock_callback); 418 false, mock_callback);
419 Run(); 419 Run();
420 } 420 }
421 421
422 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) { 422 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) {
423 // We're not expecting any async calls in this case; StrictMock will verify. 423 // We're not expecting any async calls in this case; StrictMock will verify.
424 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 424 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
425 425
426 chromeos::MockCryptohomeClient client; 426 chromeos::MockCryptohomeClient client;
427 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 427 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
428 .WillRepeatedly(Invoke(DBusCallbackTrue)); 428 .WillRepeatedly(Invoke(DBusCallbackTrue));
429 EXPECT_CALL(client, 429 EXPECT_CALL(client,
430 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _)) 430 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _))
431 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackTrue))); 431 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackTrue)));
432 EXPECT_CALL(client, 432 EXPECT_CALL(client,
433 TpmAttestationGetCertificate(KEY_USER, "", kEnterpriseUserKey, _)) 433 TpmAttestationGetCertificate(
434 KEY_USER, cryptohome::Identification(EmptyAccountId()).id(),
435 kEnterpriseUserKey, _))
434 .WillRepeatedly(WithArgs<3>(Invoke(FakeDBusData("fake_cert")))); 436 .WillRepeatedly(WithArgs<3>(Invoke(FakeDBusData("fake_cert"))));
435 437
436 // We're not expecting any server calls in this case; StrictMock will verify. 438 // We're not expecting any server calls in this case; StrictMock will verify.
437 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 439 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
438 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 440 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
439 441
440 StrictMock<MockObserver> observer; 442 StrictMock<MockObserver> observer;
441 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1); 443 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1);
442 AttestationFlow::CertificateCallback mock_callback = base::Bind( 444 AttestationFlow::CertificateCallback mock_callback = base::Bind(
443 &MockObserver::MockCertificateCallback, 445 &MockObserver::MockCertificateCallback,
444 base::Unretained(&observer)); 446 base::Unretained(&observer));
445 447
446 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 448 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
447 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 449 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
448 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false, 450 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
449 mock_callback); 451 false, mock_callback);
450 Run(); 452 Run();
451 } 453 }
452 454
453 TEST_F(AttestationFlowTest, AlternatePCA) { 455 TEST_F(AttestationFlowTest, AlternatePCA) {
454 // Strategy: Create a ServerProxy mock which reports ALTERNATE_PCA and check 456 // Strategy: Create a ServerProxy mock which reports ALTERNATE_PCA and check
455 // that all calls to the AsyncMethodCaller reflect this PCA type. 457 // that all calls to the AsyncMethodCaller reflect this PCA type.
456 scoped_ptr<MockServerProxy> proxy(new NiceMock<MockServerProxy>()); 458 scoped_ptr<MockServerProxy> proxy(new NiceMock<MockServerProxy>());
457 proxy->DeferToFake(true); 459 proxy->DeferToFake(true);
458 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(Return(ALTERNATE_PCA)); 460 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(Return(ALTERNATE_PCA));
459 461
(...skipping 13 matching lines...) Expand all
473 AsyncTpmAttestationCreateCertRequest(ALTERNATE_PCA, _, _, _, _)) 475 AsyncTpmAttestationCreateCertRequest(ALTERNATE_PCA, _, _, _, _))
474 .Times(AtLeast(1)); 476 .Times(AtLeast(1));
475 477
476 NiceMock<MockObserver> observer; 478 NiceMock<MockObserver> observer;
477 AttestationFlow::CertificateCallback mock_callback = base::Bind( 479 AttestationFlow::CertificateCallback mock_callback = base::Bind(
478 &MockObserver::MockCertificateCallback, 480 &MockObserver::MockCertificateCallback,
479 base::Unretained(&observer)); 481 base::Unretained(&observer));
480 482
481 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 483 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
482 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 484 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
483 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 485 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
484 mock_callback); 486 true, mock_callback);
485 Run(); 487 Run();
486 } 488 }
487 489
488 } // namespace attestation 490 } // namespace attestation
489 } // namespace chromeos 491 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698