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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 0x4f, 0x4d, 0xe1, 0x07, 0x8a, 0x76, 0x87, 0x88, 0x2f, 0x13, 0x35, 0xc1, | 59 0x4f, 0x4d, 0xe1, 0x07, 0x8a, 0x76, 0x87, 0x88, 0x2f, 0x13, 0x35, 0xc1, |
60 0x02, 0x20, 0x24, 0xc3, 0xd9, 0x2f, 0x13, 0x47, 0x99, 0x3e, 0x20, 0x59, | 60 0x02, 0x20, 0x24, 0xc3, 0xd9, 0x2f, 0x13, 0x47, 0x99, 0x3e, 0x20, 0x59, |
61 0xa1, 0x1a, 0xeb, 0x1c, 0x81, 0x53, 0x38, 0x7e, 0xc5, 0x9e, 0x71, 0xe5, | 61 0xa1, 0x1a, 0xeb, 0x1c, 0x81, 0x53, 0x38, 0x7e, 0xc5, 0x9e, 0x71, 0xe5, |
62 0xc0, 0x19, 0x95, 0xdb, 0xef, 0xf6, 0x46, 0xc8, 0x95, 0x3d, 0x02, 0x21, | 62 0xc0, 0x19, 0x95, 0xdb, 0xef, 0xf6, 0x46, 0xc8, 0x95, 0x3d, 0x02, 0x21, |
63 0x00, 0xaa, 0xb1, 0xff, 0x8a, 0xa2, 0xb2, 0x2b, 0xef, 0x9a, 0x83, 0x3f, | 63 0x00, 0xaa, 0xb1, 0xff, 0x8a, 0xa2, 0xb2, 0x2b, 0xef, 0x9a, 0x83, 0x3f, |
64 0xc5, 0xbc, 0xd4, 0x6a, 0x07, 0xe8, 0xc7, 0x0b, 0x2e, 0xd4, 0x0f, 0xf8, | 64 0xc5, 0xbc, 0xd4, 0x6a, 0x07, 0xe8, 0xc7, 0x0b, 0x2e, 0xd4, 0x0f, 0xf8, |
65 0x98, 0x68, 0xe1, 0x04, 0xa8, 0x92, 0xd0, 0x10, 0xaa, | 65 0x98, 0x68, 0xe1, 0x04, 0xa8, 0x92, 0xd0, 0x10, 0xaa, |
66 }; | 66 }; |
67 | 67 |
68 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { | 68 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { |
69 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 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 CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) { | 78 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) { |
79 MessageLoop::current()->PostTask( | 79 base::MessageLoop::current()->PostTask( |
80 FROM_HERE, base::Bind(callback, true, "fake_cert")); | 80 FROM_HERE, base::Bind(callback, true, "fake_cert")); |
81 } | 81 } |
82 | 82 |
83 void StatusCallbackSuccess( | 83 void StatusCallbackSuccess( |
84 const policy::CloudPolicyClient::StatusCallback& callback) { | 84 const policy::CloudPolicyClient::StatusCallback& callback) { |
85 MessageLoop::current()->PostTask( | 85 base::MessageLoop::current()->PostTask( |
86 FROM_HERE, base::Bind(callback, true)); | 86 FROM_HERE, base::Bind(callback, true)); |
87 } | 87 } |
88 | 88 |
89 class FakeDBusData { | 89 class FakeDBusData { |
90 public: | 90 public: |
91 explicit FakeDBusData(const std::string& data) : data_(data) {} | 91 explicit FakeDBusData(const std::string& data) : data_(data) {} |
92 | 92 |
93 void operator() (const CryptohomeClient::DataMethodCallback& callback) { | 93 void operator() (const CryptohomeClient::DataMethodCallback& callback) { |
94 MessageLoop::current()->PostTask( | 94 base::MessageLoop::current()->PostTask( |
95 FROM_HERE, | 95 FROM_HERE, |
96 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_)); | 96 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_)); |
97 } | 97 } |
98 | 98 |
99 private: | 99 private: |
100 std::string data_; | 100 std::string data_; |
101 }; | 101 }; |
102 | 102 |
103 } // namespace | 103 } // namespace |
104 | 104 |
105 class AttestationPolicyObserverTest : public ::testing::Test { | 105 class AttestationPolicyObserverTest : public ::testing::Test { |
106 public: | 106 public: |
107 AttestationPolicyObserverTest() | 107 AttestationPolicyObserverTest() |
108 : message_loop_(MessageLoop::TYPE_UI), | 108 : message_loop_(base::MessageLoop::TYPE_UI), |
109 ui_thread_(content::BrowserThread::UI, &message_loop_) { | 109 ui_thread_(content::BrowserThread::UI, &message_loop_) { |
110 // Remove the real DeviceSettingsProvider and replace it with a stub. | 110 // Remove the real DeviceSettingsProvider and replace it with a stub. |
111 CrosSettings* cros_settings = CrosSettings::Get(); | 111 CrosSettings* cros_settings = CrosSettings::Get(); |
112 device_settings_provider_ = | 112 device_settings_provider_ = |
113 cros_settings->GetProvider(kDeviceAttestationEnabled); | 113 cros_settings->GetProvider(kDeviceAttestationEnabled); |
114 cros_settings->RemoveSettingsProvider(device_settings_provider_); | 114 cros_settings->RemoveSettingsProvider(device_settings_provider_); |
115 cros_settings->AddSettingsProvider(&stub_settings_provider_); | 115 cros_settings->AddSettingsProvider(&stub_settings_provider_); |
116 cros_settings->SetBoolean(kDeviceAttestationEnabled, true); | 116 cros_settings->SetBoolean(kDeviceAttestationEnabled, true); |
117 policy_client_.SetDMToken("fake_dm_token"); | 117 policy_client_.SetDMToken("fake_dm_token"); |
118 } | 118 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 valid_start, | 228 valid_start, |
229 valid_expiry); | 229 valid_expiry); |
230 | 230 |
231 if (!handle) | 231 if (!handle) |
232 return false; | 232 return false; |
233 bool result = net::X509Certificate::GetDEREncoded(handle, certificate); | 233 bool result = net::X509Certificate::GetDEREncoded(handle, certificate); |
234 net::X509Certificate::FreeOSCertHandle(handle); | 234 net::X509Certificate::FreeOSCertHandle(handle); |
235 return result; | 235 return result; |
236 } | 236 } |
237 | 237 |
238 MessageLoop message_loop_; | 238 base::MessageLoop message_loop_; |
239 content::TestBrowserThread ui_thread_; | 239 content::TestBrowserThread ui_thread_; |
240 ScopedTestDeviceSettingsService test_device_settings_service_; | 240 ScopedTestDeviceSettingsService test_device_settings_service_; |
241 ScopedTestCrosSettings test_cros_settings_; | 241 ScopedTestCrosSettings test_cros_settings_; |
242 CrosSettingsProvider* device_settings_provider_; | 242 CrosSettingsProvider* device_settings_provider_; |
243 StubCrosSettingsProvider stub_settings_provider_; | 243 StubCrosSettingsProvider stub_settings_provider_; |
244 StrictMock<MockCryptohomeClient> cryptohome_client_; | 244 StrictMock<MockCryptohomeClient> cryptohome_client_; |
245 StrictMock<MockAttestationFlow> attestation_flow_; | 245 StrictMock<MockAttestationFlow> attestation_flow_; |
246 StrictMock<policy::MockCloudPolicyClient> policy_client_; | 246 StrictMock<policy::MockCloudPolicyClient> policy_client_; |
247 }; | 247 }; |
248 | 248 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 Run(); | 290 Run(); |
291 } | 291 } |
292 | 292 |
293 TEST_F(AttestationPolicyObserverTest, IgnoreUnknownCertFormat) { | 293 TEST_F(AttestationPolicyObserverTest, IgnoreUnknownCertFormat) { |
294 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED, "unsupported"); | 294 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED, "unsupported"); |
295 Run(); | 295 Run(); |
296 } | 296 } |
297 | 297 |
298 } // namespace attestation | 298 } // namespace attestation |
299 } // namespace chromeos | 299 } // namespace chromeos |
OLD | NEW |