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

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 cryptohome::Identification() . 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, AsyncTpmAttestationCreateCertRequest(
249 AsyncTpmAttestationCreateCertRequest( 249 _, PROFILE_ENTERPRISE_MACHINE_CERTIFICATE,
250 _, PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", _)) 250 cryptohome::Identification(), "", _))
251 .Times(1); 251 .Times(1);
252 std::string fake_cert_response = 252 std::string fake_cert_response =
253 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 253 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
254 fake_cert_response += "_response"; 254 fake_cert_response += "_response";
255 EXPECT_CALL(async_caller, 255 EXPECT_CALL(async_caller,
256 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 256 AsyncTpmAttestationFinishCertRequest(
257 KEY_DEVICE, 257 fake_cert_response, KEY_DEVICE, cryptohome::Identification(),
258 "", 258 kEnterpriseMachineKey, _))
259 kEnterpriseMachineKey,
260 _))
261 .Times(1); 259 .Times(1);
262 260
263 chromeos::MockCryptohomeClient client; 261 chromeos::MockCryptohomeClient client;
264 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 262 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
265 .WillRepeatedly(Invoke(DBusCallbackTrue)); 263 .WillRepeatedly(Invoke(DBusCallbackTrue));
266 264
267 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 265 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
268 proxy->DeferToFake(true); 266 proxy->DeferToFake(true);
269 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 267 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
270 EXPECT_CALL(*proxy, SendCertificateRequest( 268 EXPECT_CALL(*proxy, SendCertificateRequest(
271 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 269 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
272 _)).Times(1); 270 _)).Times(1);
273 271
274 StrictMock<MockObserver> observer; 272 StrictMock<MockObserver> observer;
275 EXPECT_CALL(observer, MockCertificateCallback( 273 EXPECT_CALL(observer, MockCertificateCallback(
276 true, 274 true,
277 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 275 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
278 AttestationFlow::CertificateCallback mock_callback = base::Bind( 276 AttestationFlow::CertificateCallback mock_callback = base::Bind(
279 &MockObserver::MockCertificateCallback, 277 &MockObserver::MockCertificateCallback,
280 base::Unretained(&observer)); 278 base::Unretained(&observer));
281 279
282 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 280 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
283 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 281 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
284 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, "", "", true, 282 flow.GetCertificate(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, EmptyAccountId(),
285 mock_callback); 283 "", true, mock_callback);
286 Run(); 284 Run();
287 } 285 }
288 286
289 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { 287 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) {
290 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 288 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
291 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); 289 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
292 EXPECT_CALL(async_caller, 290 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(
293 AsyncTpmAttestationCreateCertRequest( 291 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
294 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _)) 292 cryptohome::Identification(), "", _))
295 .Times(1); 293 .Times(1);
296 294
297 chromeos::MockCryptohomeClient client; 295 chromeos::MockCryptohomeClient client;
298 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 296 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
299 .WillRepeatedly(Invoke(DBusCallbackTrue)); 297 .WillRepeatedly(Invoke(DBusCallbackTrue));
300 298
301 // We're not expecting any server calls in this case; StrictMock will verify. 299 // We're not expecting any server calls in this case; StrictMock will verify.
302 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 300 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
303 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 301 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
304 302
305 StrictMock<MockObserver> observer; 303 StrictMock<MockObserver> observer;
306 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 304 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
307 AttestationFlow::CertificateCallback mock_callback = base::Bind( 305 AttestationFlow::CertificateCallback mock_callback = base::Bind(
308 &MockObserver::MockCertificateCallback, 306 &MockObserver::MockCertificateCallback,
309 base::Unretained(&observer)); 307 base::Unretained(&observer));
310 308
311 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 309 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
312 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 310 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
313 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 311 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
314 mock_callback); 312 true, mock_callback);
315 Run(); 313 Run();
316 } 314 }
317 315
318 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { 316 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) {
319 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 317 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
320 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 318 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
321 EXPECT_CALL(async_caller, 319 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(
322 AsyncTpmAttestationCreateCertRequest( 320 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
323 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _)) 321 cryptohome::Identification(), "", _))
324 .Times(1); 322 .Times(1);
325 323
326 chromeos::MockCryptohomeClient client; 324 chromeos::MockCryptohomeClient client;
327 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 325 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
328 .WillRepeatedly(Invoke(DBusCallbackTrue)); 326 .WillRepeatedly(Invoke(DBusCallbackTrue));
329 327
330 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 328 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
331 proxy->DeferToFake(false); 329 proxy->DeferToFake(false);
332 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 330 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
333 EXPECT_CALL(*proxy, SendCertificateRequest( 331 EXPECT_CALL(*proxy, SendCertificateRequest(
334 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 332 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
335 _)).Times(1); 333 _)).Times(1);
336 334
337 StrictMock<MockObserver> observer; 335 StrictMock<MockObserver> observer;
338 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 336 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
339 AttestationFlow::CertificateCallback mock_callback = base::Bind( 337 AttestationFlow::CertificateCallback mock_callback = base::Bind(
340 &MockObserver::MockCertificateCallback, 338 &MockObserver::MockCertificateCallback,
341 base::Unretained(&observer)); 339 base::Unretained(&observer));
342 340
343 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 341 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
344 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 342 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
345 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 343 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
346 mock_callback); 344 true, mock_callback);
347 Run(); 345 Run();
348 } 346 }
349 347
350 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { 348 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) {
351 // We're not expecting any async calls in this case; StrictMock will verify. 349 // We're not expecting any async calls in this case; StrictMock will verify.
352 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 350 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
353 351
354 chromeos::MockCryptohomeClient client; 352 chromeos::MockCryptohomeClient client;
355 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 353 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
356 .WillRepeatedly(Invoke(DBusCallbackFail)); 354 .WillRepeatedly(Invoke(DBusCallbackFail));
357 355
358 // We're not expecting any server calls in this case; StrictMock will verify. 356 // We're not expecting any server calls in this case; StrictMock will verify.
359 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 357 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
360 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 358 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
361 359
362 StrictMock<MockObserver> observer; 360 StrictMock<MockObserver> observer;
363 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); 361 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1);
364 AttestationFlow::CertificateCallback mock_callback = base::Bind( 362 AttestationFlow::CertificateCallback mock_callback = base::Bind(
365 &MockObserver::MockCertificateCallback, 363 &MockObserver::MockCertificateCallback,
366 base::Unretained(&observer)); 364 base::Unretained(&observer));
367 365
368 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 366 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
369 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 367 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
370 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 368 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
371 mock_callback); 369 true, mock_callback);
372 Run(); 370 Run();
373 } 371 }
374 372
375 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) { 373 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) {
376 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 374 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
377 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); 375 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
378 EXPECT_CALL(async_caller, 376 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(
379 AsyncTpmAttestationCreateCertRequest( 377 _, PROFILE_ENTERPRISE_USER_CERTIFICATE,
380 _, PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", _)) 378 cryptohome::Identification(), "", _))
381 .Times(1); 379 .Times(1);
382 std::string fake_cert_response = 380 std::string fake_cert_response =
383 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; 381 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest;
384 fake_cert_response += "_response"; 382 fake_cert_response += "_response";
385 EXPECT_CALL(async_caller, 383 EXPECT_CALL(async_caller,
386 AsyncTpmAttestationFinishCertRequest(fake_cert_response, 384 AsyncTpmAttestationFinishCertRequest(fake_cert_response, KEY_USER,
387 KEY_USER, 385 cryptohome::Identification(),
388 "", 386 kEnterpriseUserKey, _))
389 kEnterpriseUserKey,
390 _))
391 .Times(1); 387 .Times(1);
392 388
393 chromeos::MockCryptohomeClient client; 389 chromeos::MockCryptohomeClient client;
394 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 390 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
395 .WillRepeatedly(Invoke(DBusCallbackTrue)); 391 .WillRepeatedly(Invoke(DBusCallbackTrue));
396 EXPECT_CALL(client, 392 EXPECT_CALL(client,
397 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _)) 393 TpmAttestationDoesKeyExist(KEY_USER, cryptohome::Identification(),
394 kEnterpriseUserKey, _))
398 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse))); 395 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse)));
399 396
400 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 397 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
401 proxy->DeferToFake(true); 398 proxy->DeferToFake(true);
402 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 399 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
403 EXPECT_CALL(*proxy, SendCertificateRequest( 400 EXPECT_CALL(*proxy, SendCertificateRequest(
404 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, 401 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest,
405 _)).Times(1); 402 _)).Times(1);
406 403
407 StrictMock<MockObserver> observer; 404 StrictMock<MockObserver> observer;
408 EXPECT_CALL(observer, MockCertificateCallback( 405 EXPECT_CALL(observer, MockCertificateCallback(
409 true, 406 true,
410 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); 407 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1);
411 AttestationFlow::CertificateCallback mock_callback = base::Bind( 408 AttestationFlow::CertificateCallback mock_callback = base::Bind(
412 &MockObserver::MockCertificateCallback, 409 &MockObserver::MockCertificateCallback,
413 base::Unretained(&observer)); 410 base::Unretained(&observer));
414 411
415 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 412 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
416 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 413 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
417 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false, 414 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
418 mock_callback); 415 false, mock_callback);
419 Run(); 416 Run();
420 } 417 }
421 418
422 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) { 419 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) {
423 // We're not expecting any async calls in this case; StrictMock will verify. 420 // We're not expecting any async calls in this case; StrictMock will verify.
424 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; 421 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
425 422
426 chromeos::MockCryptohomeClient client; 423 chromeos::MockCryptohomeClient client;
427 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) 424 EXPECT_CALL(client, TpmAttestationIsEnrolled(_))
428 .WillRepeatedly(Invoke(DBusCallbackTrue)); 425 .WillRepeatedly(Invoke(DBusCallbackTrue));
429 EXPECT_CALL(client, 426 EXPECT_CALL(client,
430 TpmAttestationDoesKeyExist(KEY_USER, "", kEnterpriseUserKey, _)) 427 TpmAttestationDoesKeyExist(KEY_USER, cryptohome::Identification(),
428 kEnterpriseUserKey, _))
431 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackTrue))); 429 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackTrue)));
432 EXPECT_CALL(client, 430 EXPECT_CALL(client, TpmAttestationGetCertificate(KEY_USER,
433 TpmAttestationGetCertificate(KEY_USER, "", kEnterpriseUserKey, _)) 431 cryptohome::Identification(),
432 kEnterpriseUserKey, _))
434 .WillRepeatedly(WithArgs<3>(Invoke(FakeDBusData("fake_cert")))); 433 .WillRepeatedly(WithArgs<3>(Invoke(FakeDBusData("fake_cert"))));
435 434
436 // We're not expecting any server calls in this case; StrictMock will verify. 435 // We're not expecting any server calls in this case; StrictMock will verify.
437 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); 436 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
438 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault()); 437 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(DoDefault());
439 438
440 StrictMock<MockObserver> observer; 439 StrictMock<MockObserver> observer;
441 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1); 440 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1);
442 AttestationFlow::CertificateCallback mock_callback = base::Bind( 441 AttestationFlow::CertificateCallback mock_callback = base::Bind(
443 &MockObserver::MockCertificateCallback, 442 &MockObserver::MockCertificateCallback,
444 base::Unretained(&observer)); 443 base::Unretained(&observer));
445 444
446 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 445 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
447 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 446 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
448 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", false, 447 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
449 mock_callback); 448 false, mock_callback);
450 Run(); 449 Run();
451 } 450 }
452 451
453 TEST_F(AttestationFlowTest, AlternatePCA) { 452 TEST_F(AttestationFlowTest, AlternatePCA) {
454 // Strategy: Create a ServerProxy mock which reports ALTERNATE_PCA and check 453 // Strategy: Create a ServerProxy mock which reports ALTERNATE_PCA and check
455 // that all calls to the AsyncMethodCaller reflect this PCA type. 454 // that all calls to the AsyncMethodCaller reflect this PCA type.
456 scoped_ptr<MockServerProxy> proxy(new NiceMock<MockServerProxy>()); 455 scoped_ptr<MockServerProxy> proxy(new NiceMock<MockServerProxy>());
457 proxy->DeferToFake(true); 456 proxy->DeferToFake(true);
458 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(Return(ALTERNATE_PCA)); 457 EXPECT_CALL(*proxy, GetType()).WillRepeatedly(Return(ALTERNATE_PCA));
459 458
(...skipping 13 matching lines...) Expand all
473 AsyncTpmAttestationCreateCertRequest(ALTERNATE_PCA, _, _, _, _)) 472 AsyncTpmAttestationCreateCertRequest(ALTERNATE_PCA, _, _, _, _))
474 .Times(AtLeast(1)); 473 .Times(AtLeast(1));
475 474
476 NiceMock<MockObserver> observer; 475 NiceMock<MockObserver> observer;
477 AttestationFlow::CertificateCallback mock_callback = base::Bind( 476 AttestationFlow::CertificateCallback mock_callback = base::Bind(
478 &MockObserver::MockCertificateCallback, 477 &MockObserver::MockCertificateCallback,
479 base::Unretained(&observer)); 478 base::Unretained(&observer));
480 479
481 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); 480 scoped_ptr<ServerProxy> proxy_interface(proxy.release());
482 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface)); 481 AttestationFlow flow(&async_caller, &client, std::move(proxy_interface));
483 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, "", "", true, 482 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, EmptyAccountId(), "",
484 mock_callback); 483 true, mock_callback);
485 Run(); 484 Run();
486 } 485 }
487 486
488 } // namespace attestation 487 } // namespace attestation
489 } // namespace chromeos 488 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698