OLD | NEW |
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/run_loop.h" | 7 #include "base/run_loop.h" |
7 #include "chromeos/attestation/mock_attestation_flow.h" | 8 #include "chromeos/attestation/mock_attestation_flow.h" |
8 #include "chromeos/cryptohome/mock_async_method_caller.h" | 9 #include "chromeos/cryptohome/mock_async_method_caller.h" |
9 #include "chromeos/dbus/mock_cryptohome_client.h" | 10 #include "chromeos/dbus/mock_cryptohome_client.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 using testing::_; | 14 using testing::_; |
14 using testing::Invoke; | 15 using testing::Invoke; |
15 using testing::Sequence; | 16 using testing::Sequence; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 .InSequence(flow_order) | 62 .InSequence(flow_order) |
62 .WillRepeatedly(Invoke(DBusCallbackFalse)); | 63 .WillRepeatedly(Invoke(DBusCallbackFalse)); |
63 | 64 |
64 // Use StrictMock when we want to verify invocation frequency. | 65 // Use StrictMock when we want to verify invocation frequency. |
65 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 66 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
66 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 67 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
67 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) | 68 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) |
68 .Times(1) | 69 .Times(1) |
69 .InSequence(flow_order); | 70 .InSequence(flow_order); |
70 | 71 |
71 StrictMock<MockServerProxy> proxy; | 72 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
72 proxy.DeferToFake(true); | 73 proxy->DeferToFake(true); |
73 EXPECT_CALL(proxy, SendEnrollRequest( | 74 EXPECT_CALL(*proxy, SendEnrollRequest( |
74 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, | 75 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, |
75 _)).Times(1) | 76 _)).Times(1) |
76 .InSequence(flow_order); | 77 .InSequence(flow_order); |
77 | 78 |
78 std::string fake_enroll_response = | 79 std::string fake_enroll_response = |
79 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; | 80 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; |
80 fake_enroll_response += "_response"; | 81 fake_enroll_response += "_response"; |
81 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _)) | 82 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _)) |
82 .Times(1) | 83 .Times(1) |
83 .InSequence(flow_order); | 84 .InSequence(flow_order); |
84 | 85 |
85 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; | 86 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; |
86 EXPECT_CALL(async_caller, | 87 EXPECT_CALL(async_caller, |
87 AsyncTpmAttestationCreateCertRequest(options, _)) | 88 AsyncTpmAttestationCreateCertRequest(options, _)) |
88 .Times(1) | 89 .Times(1) |
89 .InSequence(flow_order); | 90 .InSequence(flow_order); |
90 | 91 |
91 EXPECT_CALL(proxy, SendCertificateRequest( | 92 EXPECT_CALL(*proxy, SendCertificateRequest( |
92 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, | 93 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, |
93 _)).Times(1) | 94 _)).Times(1) |
94 .InSequence(flow_order); | 95 .InSequence(flow_order); |
95 | 96 |
96 std::string fake_cert_response = | 97 std::string fake_cert_response = |
97 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; | 98 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; |
98 fake_cert_response += "_response"; | 99 fake_cert_response += "_response"; |
99 EXPECT_CALL(async_caller, | 100 EXPECT_CALL(async_caller, |
100 AsyncTpmAttestationFinishCertRequest(fake_cert_response, | 101 AsyncTpmAttestationFinishCertRequest(fake_cert_response, |
101 CryptohomeClient::USER_KEY, | 102 CryptohomeClient::USER_KEY, |
102 "test", | 103 "test", |
103 _)) | 104 _)) |
104 .Times(1) | 105 .Times(1) |
105 .InSequence(flow_order); | 106 .InSequence(flow_order); |
106 | 107 |
107 StrictMock<MockObserver> observer; | 108 StrictMock<MockObserver> observer; |
108 EXPECT_CALL(observer, MockCertificateCallback( | 109 EXPECT_CALL(observer, MockCertificateCallback( |
109 true, | 110 true, |
110 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) | 111 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) |
111 .Times(1) | 112 .Times(1) |
112 .InSequence(flow_order); | 113 .InSequence(flow_order); |
113 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 114 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
114 &MockObserver::MockCertificateCallback, | 115 &MockObserver::MockCertificateCallback, |
115 base::Unretained(&observer)); | 116 base::Unretained(&observer)); |
116 | 117 |
117 AttestationFlow flow(&async_caller, &client, &proxy); | 118 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 119 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
118 flow.GetCertificate("test", mock_callback); | 120 flow.GetCertificate("test", mock_callback); |
119 Run(); | 121 Run(); |
120 } | 122 } |
121 | 123 |
122 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { | 124 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { |
123 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 125 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
124 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 126 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
125 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) | 127 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) |
126 .Times(1); | 128 .Times(1); |
127 | 129 |
128 chromeos::MockCryptohomeClient client; | 130 chromeos::MockCryptohomeClient client; |
129 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 131 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
130 .WillRepeatedly(Invoke(DBusCallbackFalse)); | 132 .WillRepeatedly(Invoke(DBusCallbackFalse)); |
131 | 133 |
132 // We're not expecting any server calls in this case; StrictMock will verify. | 134 // We're not expecting any server calls in this case; StrictMock will verify. |
133 StrictMock<MockServerProxy> proxy; | 135 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
134 | 136 |
135 StrictMock<MockObserver> observer; | 137 StrictMock<MockObserver> observer; |
136 EXPECT_CALL(observer, MockCertificateCallback(false, "")) | 138 EXPECT_CALL(observer, MockCertificateCallback(false, "")) |
137 .Times(1); | 139 .Times(1); |
138 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 140 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
139 &MockObserver::MockCertificateCallback, | 141 &MockObserver::MockCertificateCallback, |
140 base::Unretained(&observer)); | 142 base::Unretained(&observer)); |
141 | 143 |
142 AttestationFlow flow(&async_caller, &client, &proxy); | 144 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 145 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
143 flow.GetCertificate("test", mock_callback); | 146 flow.GetCertificate("test", mock_callback); |
144 Run(); | 147 Run(); |
145 } | 148 } |
146 | 149 |
147 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { | 150 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { |
148 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 151 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
149 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 152 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
150 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) | 153 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) |
151 .Times(1); | 154 .Times(1); |
152 | 155 |
153 chromeos::MockCryptohomeClient client; | 156 chromeos::MockCryptohomeClient client; |
154 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 157 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
155 .WillRepeatedly(Invoke(DBusCallbackFalse)); | 158 .WillRepeatedly(Invoke(DBusCallbackFalse)); |
156 | 159 |
157 StrictMock<MockServerProxy> proxy; | 160 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
158 proxy.DeferToFake(false); | 161 proxy->DeferToFake(false); |
159 EXPECT_CALL(proxy, SendEnrollRequest( | 162 EXPECT_CALL(*proxy, SendEnrollRequest( |
160 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, | 163 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, |
161 _)).Times(1); | 164 _)).Times(1); |
162 | 165 |
163 StrictMock<MockObserver> observer; | 166 StrictMock<MockObserver> observer; |
164 EXPECT_CALL(observer, MockCertificateCallback(false, "")) | 167 EXPECT_CALL(observer, MockCertificateCallback(false, "")) |
165 .Times(1); | 168 .Times(1); |
166 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 169 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
167 &MockObserver::MockCertificateCallback, | 170 &MockObserver::MockCertificateCallback, |
168 base::Unretained(&observer)); | 171 base::Unretained(&observer)); |
169 | 172 |
170 AttestationFlow flow(&async_caller, &client, &proxy); | 173 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 174 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
171 flow.GetCertificate("test", mock_callback); | 175 flow.GetCertificate("test", mock_callback); |
172 Run(); | 176 Run(); |
173 } | 177 } |
174 | 178 |
175 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { | 179 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { |
176 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 180 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
177 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 181 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
178 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) | 182 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) |
179 .Times(1); | 183 .Times(1); |
180 std::string fake_enroll_response = | 184 std::string fake_enroll_response = |
181 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; | 185 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; |
182 fake_enroll_response += "_response"; | 186 fake_enroll_response += "_response"; |
183 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _)) | 187 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _)) |
184 .WillOnce(WithArgs<1>(Invoke(AsyncCallbackFalse))); | 188 .WillOnce(WithArgs<1>(Invoke(AsyncCallbackFalse))); |
185 | 189 |
186 chromeos::MockCryptohomeClient client; | 190 chromeos::MockCryptohomeClient client; |
187 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 191 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
188 .WillRepeatedly(Invoke(DBusCallbackFalse)); | 192 .WillRepeatedly(Invoke(DBusCallbackFalse)); |
189 | 193 |
190 StrictMock<MockServerProxy> proxy; | 194 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
191 proxy.DeferToFake(true); | 195 proxy->DeferToFake(true); |
192 EXPECT_CALL(proxy, SendEnrollRequest( | 196 EXPECT_CALL(*proxy, SendEnrollRequest( |
193 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, | 197 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, |
194 _)).Times(1); | 198 _)).Times(1); |
195 | 199 |
196 StrictMock<MockObserver> observer; | 200 StrictMock<MockObserver> observer; |
197 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 201 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
198 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 202 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
199 &MockObserver::MockCertificateCallback, | 203 &MockObserver::MockCertificateCallback, |
200 base::Unretained(&observer)); | 204 base::Unretained(&observer)); |
201 | 205 |
202 AttestationFlow flow(&async_caller, &client, &proxy); | 206 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 207 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
203 flow.GetCertificate("test", mock_callback); | 208 flow.GetCertificate("test", mock_callback); |
204 Run(); | 209 Run(); |
205 } | 210 } |
206 | 211 |
207 TEST_F(AttestationFlowTest, GetOwnerCertificateAlreadyEnrolled) { | 212 TEST_F(AttestationFlowTest, GetOwnerCertificateAlreadyEnrolled) { |
208 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 213 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
209 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 214 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
210 int options = CryptohomeClient::INCLUDE_DEVICE_STATE | | 215 int options = CryptohomeClient::INCLUDE_DEVICE_STATE | |
211 CryptohomeClient::INCLUDE_STABLE_ID; | 216 CryptohomeClient::INCLUDE_STABLE_ID; |
212 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(options, _)) | 217 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(options, _)) |
213 .Times(1); | 218 .Times(1); |
214 std::string fake_cert_response = | 219 std::string fake_cert_response = |
215 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; | 220 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; |
216 fake_cert_response += "_response"; | 221 fake_cert_response += "_response"; |
217 EXPECT_CALL(async_caller, | 222 EXPECT_CALL(async_caller, |
218 AsyncTpmAttestationFinishCertRequest(fake_cert_response, | 223 AsyncTpmAttestationFinishCertRequest(fake_cert_response, |
219 CryptohomeClient::DEVICE_KEY, | 224 CryptohomeClient::DEVICE_KEY, |
220 "attest-ent-machine", | 225 "attest-ent-machine", |
221 _)) | 226 _)) |
222 .Times(1); | 227 .Times(1); |
223 | 228 |
224 chromeos::MockCryptohomeClient client; | 229 chromeos::MockCryptohomeClient client; |
225 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 230 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
226 .WillRepeatedly(Invoke(DBusCallbackTrue)); | 231 .WillRepeatedly(Invoke(DBusCallbackTrue)); |
227 | 232 |
228 StrictMock<MockServerProxy> proxy; | 233 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
229 proxy.DeferToFake(true); | 234 proxy->DeferToFake(true); |
230 EXPECT_CALL(proxy, SendCertificateRequest( | 235 EXPECT_CALL(*proxy, SendCertificateRequest( |
231 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, | 236 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, |
232 _)).Times(1); | 237 _)).Times(1); |
233 | 238 |
234 StrictMock<MockObserver> observer; | 239 StrictMock<MockObserver> observer; |
235 EXPECT_CALL(observer, MockCertificateCallback( | 240 EXPECT_CALL(observer, MockCertificateCallback( |
236 true, | 241 true, |
237 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); | 242 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); |
238 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 243 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
239 &MockObserver::MockCertificateCallback, | 244 &MockObserver::MockCertificateCallback, |
240 base::Unretained(&observer)); | 245 base::Unretained(&observer)); |
241 | 246 |
242 AttestationFlow flow(&async_caller, &client, &proxy); | 247 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 248 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
243 flow.GetCertificate("attest-ent-machine", mock_callback); | 249 flow.GetCertificate("attest-ent-machine", mock_callback); |
244 Run(); | 250 Run(); |
245 } | 251 } |
246 | 252 |
247 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { | 253 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { |
248 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 254 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
249 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 255 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
250 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; | 256 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; |
251 EXPECT_CALL(async_caller, | 257 EXPECT_CALL(async_caller, |
252 AsyncTpmAttestationCreateCertRequest(options, _)) | 258 AsyncTpmAttestationCreateCertRequest(options, _)) |
253 .Times(1); | 259 .Times(1); |
254 | 260 |
255 chromeos::MockCryptohomeClient client; | 261 chromeos::MockCryptohomeClient client; |
256 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 262 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
257 .WillRepeatedly(Invoke(DBusCallbackTrue)); | 263 .WillRepeatedly(Invoke(DBusCallbackTrue)); |
258 | 264 |
259 // We're not expecting any server calls in this case; StrictMock will verify. | 265 // We're not expecting any server calls in this case; StrictMock will verify. |
260 StrictMock<MockServerProxy> proxy; | 266 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
261 | 267 |
262 StrictMock<MockObserver> observer; | 268 StrictMock<MockObserver> observer; |
263 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 269 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
264 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 270 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
265 &MockObserver::MockCertificateCallback, | 271 &MockObserver::MockCertificateCallback, |
266 base::Unretained(&observer)); | 272 base::Unretained(&observer)); |
267 | 273 |
268 AttestationFlow flow(&async_caller, &client, &proxy); | 274 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 275 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
269 flow.GetCertificate("test", mock_callback); | 276 flow.GetCertificate("test", mock_callback); |
270 Run(); | 277 Run(); |
271 } | 278 } |
272 | 279 |
273 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { | 280 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { |
274 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 281 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
275 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 282 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
276 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; | 283 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; |
277 EXPECT_CALL(async_caller, | 284 EXPECT_CALL(async_caller, |
278 AsyncTpmAttestationCreateCertRequest(options, _)) | 285 AsyncTpmAttestationCreateCertRequest(options, _)) |
279 .Times(1); | 286 .Times(1); |
280 | 287 |
281 chromeos::MockCryptohomeClient client; | 288 chromeos::MockCryptohomeClient client; |
282 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 289 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
283 .WillRepeatedly(Invoke(DBusCallbackTrue)); | 290 .WillRepeatedly(Invoke(DBusCallbackTrue)); |
284 | 291 |
285 StrictMock<MockServerProxy> proxy; | 292 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
286 proxy.DeferToFake(false); | 293 proxy->DeferToFake(false); |
287 EXPECT_CALL(proxy, SendCertificateRequest( | 294 EXPECT_CALL(*proxy, SendCertificateRequest( |
288 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, | 295 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, |
289 _)).Times(1); | 296 _)).Times(1); |
290 | 297 |
291 StrictMock<MockObserver> observer; | 298 StrictMock<MockObserver> observer; |
292 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 299 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
293 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 300 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
294 &MockObserver::MockCertificateCallback, | 301 &MockObserver::MockCertificateCallback, |
295 base::Unretained(&observer)); | 302 base::Unretained(&observer)); |
296 | 303 |
297 AttestationFlow flow(&async_caller, &client, &proxy); | 304 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 305 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
298 flow.GetCertificate("test", mock_callback); | 306 flow.GetCertificate("test", mock_callback); |
299 Run(); | 307 Run(); |
300 } | 308 } |
301 | 309 |
302 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { | 310 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { |
303 // We're not expecting any server calls in this case; StrictMock will verify. | 311 // We're not expecting any server calls in this case; StrictMock will verify. |
304 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 312 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
305 | 313 |
306 chromeos::MockCryptohomeClient client; | 314 chromeos::MockCryptohomeClient client; |
307 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 315 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
308 .WillRepeatedly(Invoke(DBusCallbackFail)); | 316 .WillRepeatedly(Invoke(DBusCallbackFail)); |
309 | 317 |
310 // We're not expecting any server calls in this case; StrictMock will verify. | 318 // We're not expecting any server calls in this case; StrictMock will verify. |
311 StrictMock<MockServerProxy> proxy; | 319 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
312 | 320 |
313 StrictMock<MockObserver> observer; | 321 StrictMock<MockObserver> observer; |
314 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 322 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
315 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 323 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
316 &MockObserver::MockCertificateCallback, | 324 &MockObserver::MockCertificateCallback, |
317 base::Unretained(&observer)); | 325 base::Unretained(&observer)); |
318 | 326 |
319 AttestationFlow flow(&async_caller, &client, &proxy); | 327 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 328 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
320 flow.GetCertificate("test", mock_callback); | 329 flow.GetCertificate("test", mock_callback); |
321 Run(); | 330 Run(); |
322 } | 331 } |
323 | 332 |
324 } // namespace attestation | 333 } // namespace attestation |
325 } // namespace chromeos | 334 } // namespace chromeos |
OLD | NEW |