OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h" | 10 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { | 68 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { |
69 base::MessageLoop::current()->PostTask( | 69 base::MessageLoop::current()->PostTask( |
70 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 70 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
71 } | 71 } |
72 | 72 |
73 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { | 73 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { |
74 base::MessageLoop::current()->PostTask( | 74 base::MessageLoop::current()->PostTask( |
75 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 75 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
76 } | 76 } |
77 | 77 |
| 78 void DBusCallbackError(const BoolDBusMethodCallback& callback) { |
| 79 base::MessageLoop::current()->PostTask( |
| 80 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false)); |
| 81 } |
| 82 |
78 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) { | 83 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) { |
79 base::MessageLoop::current()->PostTask( | 84 base::MessageLoop::current()->PostTask( |
80 FROM_HERE, base::Bind(callback, true, "fake_cert")); | 85 FROM_HERE, base::Bind(callback, true, "fake_cert")); |
81 } | 86 } |
82 | 87 |
83 void StatusCallbackSuccess( | 88 void StatusCallbackSuccess( |
84 const policy::CloudPolicyClient::StatusCallback& callback) { | 89 const policy::CloudPolicyClient::StatusCallback& callback) { |
85 base::MessageLoop::current()->PostTask( | 90 base::MessageLoop::current()->PostTask( |
86 FROM_HERE, base::Bind(callback, true)); | 91 FROM_HERE, base::Bind(callback, true)); |
87 } | 92 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (new_key) { | 185 if (new_key) { |
181 EXPECT_CALL(attestation_flow_, GetCertificate(_, _, _)) | 186 EXPECT_CALL(attestation_flow_, GetCertificate(_, _, _)) |
182 .WillOnce(WithArgs<2>(Invoke(CertCallbackSuccess))); | 187 .WillOnce(WithArgs<2>(Invoke(CertCallbackSuccess))); |
183 } | 188 } |
184 } | 189 } |
185 | 190 |
186 void Run() { | 191 void Run() { |
187 AttestationPolicyObserver observer(&policy_client_, | 192 AttestationPolicyObserver observer(&policy_client_, |
188 &cryptohome_client_, | 193 &cryptohome_client_, |
189 &attestation_flow_); | 194 &attestation_flow_); |
| 195 observer.set_retry_delay(0); |
190 base::RunLoop().RunUntilIdle(); | 196 base::RunLoop().RunUntilIdle(); |
191 } | 197 } |
192 | 198 |
193 std::string CreatePayload() { | 199 std::string CreatePayload() { |
194 AttestationKeyPayload proto; | 200 AttestationKeyPayload proto; |
195 proto.set_is_certificate_uploaded(true); | 201 proto.set_is_certificate_uploaded(true); |
196 std::string serialized; | 202 std::string serialized; |
197 proto.SerializeToString(&serialized); | 203 proto.SerializeToString(&serialized); |
198 return serialized; | 204 return serialized; |
199 } | 205 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 ASSERT_TRUE(CreateCertificate(CERT_EXPIRED, &certificate)); | 294 ASSERT_TRUE(CreateCertificate(CERT_EXPIRED, &certificate)); |
289 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED | MOCK_NEW_KEY, certificate); | 295 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED | MOCK_NEW_KEY, certificate); |
290 Run(); | 296 Run(); |
291 } | 297 } |
292 | 298 |
293 TEST_F(AttestationPolicyObserverTest, IgnoreUnknownCertFormat) { | 299 TEST_F(AttestationPolicyObserverTest, IgnoreUnknownCertFormat) { |
294 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED, "unsupported"); | 300 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED, "unsupported"); |
295 Run(); | 301 Run(); |
296 } | 302 } |
297 | 303 |
| 304 TEST_F(AttestationPolicyObserverTest, DBusFailureRetry) { |
| 305 SetupMocks(MOCK_NEW_KEY, ""); |
| 306 // Simulate a DBus failure. |
| 307 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _)) |
| 308 .WillOnce(WithArgs<2>(Invoke(DBusCallbackError))) |
| 309 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackFalse))); |
| 310 Run(); |
| 311 } |
| 312 |
298 } // namespace attestation | 313 } // namespace attestation |
299 } // namespace chromeos | 314 } // namespace chromeos |
OLD | NEW |