OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" | 10 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" |
11 #include "chrome/browser/chromeos/attestation/fake_certificate.h" | 11 #include "chrome/browser/chromeos/attestation/fake_certificate.h" |
12 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" | 12 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" |
13 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" |
15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 15 #include "chrome/browser/chromeos/settings/settings_provider_test_base.h" |
16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
17 #include "chrome/browser/profiles/profile_impl.h" | 16 #include "chrome/browser/profiles/profile_impl.h" |
18 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
19 #include "chromeos/attestation/mock_attestation_flow.h" | 18 #include "chromeos/attestation/mock_attestation_flow.h" |
20 #include "chromeos/cryptohome/mock_async_method_caller.h" | 19 #include "chromeos/cryptohome/mock_async_method_caller.h" |
21 #include "chromeos/dbus/fake_cryptohome_client.h" | 20 #include "chromeos/dbus/fake_cryptohome_client.h" |
22 #include "chromeos/settings/cros_settings_names.h" | 21 #include "chromeos/settings/cros_settings_names.h" |
23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
25 | 24 |
26 using testing::_; | 25 using testing::_; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 } | 123 } |
125 | 124 |
126 private: | 125 private: |
127 DBusMethodCallStatus call_status_; | 126 DBusMethodCallStatus call_status_; |
128 bool attestation_enrolled_; | 127 bool attestation_enrolled_; |
129 bool attestation_prepared_; | 128 bool attestation_prepared_; |
130 }; | 129 }; |
131 | 130 |
132 } // namespace | 131 } // namespace |
133 | 132 |
134 class PlatformVerificationFlowTest : public ::testing::Test { | 133 class PlatformVerificationFlowTest : public ::testing::Test, |
134 public chromeos::SettingsProviderTestBase { | |
bartfab (slow)
2015/03/31 14:12:39
Nit: s/chromeos:://
| |
135 public: | 135 public: |
136 PlatformVerificationFlowTest() | 136 PlatformVerificationFlowTest() |
137 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 137 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
138 certificate_success_(true), | 138 certificate_success_(true), |
139 fake_certificate_index_(0), | 139 fake_certificate_index_(0), |
140 sign_challenge_success_(true), | 140 sign_challenge_success_(true), |
141 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} | 141 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} |
142 | 142 |
143 void SetUp() { | 143 void SetUp() { |
144 // Create a verifier for tests to call. | 144 // Create a verifier for tests to call. |
145 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, | 145 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, |
146 &mock_async_caller_, | 146 &mock_async_caller_, |
147 &fake_cryptohome_client_, | 147 &fake_cryptohome_client_, |
148 &fake_delegate_); | 148 &fake_delegate_); |
149 | 149 |
150 // Create callbacks for tests to use with verifier_. | 150 // Create callbacks for tests to use with verifier_. |
151 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, | 151 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, |
152 base::Unretained(this)); | 152 base::Unretained(this)); |
153 | 153 |
154 // Configure the global cros_settings. | 154 ReplaceProvider(kAttestationForContentProtectionEnabled); |
155 CrosSettings* cros_settings = CrosSettings::Get(); | 155 InitOwnerSettingsService(nullptr); |
156 device_settings_provider_ = | 156 owner_settings_service_->SetBoolean(kAttestationForContentProtectionEnabled, |
157 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); | 157 true); |
158 cros_settings->RemoveSettingsProvider(device_settings_provider_); | |
159 cros_settings->AddSettingsProvider(&stub_settings_provider_); | |
160 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); | |
161 } | 158 } |
162 | 159 |
163 void TearDown() { | 160 void TearDown() { RestoreProvider(); } |
bartfab (slow)
2015/03/31 14:12:39
Nit: The style guide mandates that you break after
| |
164 // Restore the real DeviceSettingsProvider. | |
165 CrosSettings* cros_settings = CrosSettings::Get(); | |
166 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); | |
167 cros_settings->AddSettingsProvider(device_settings_provider_); | |
168 } | |
169 | 161 |
170 void ExpectAttestationFlow() { | 162 void ExpectAttestationFlow() { |
171 // When consent is not given or the feature is disabled, it is important | 163 // When consent is not given or the feature is disabled, it is important |
172 // that there are no calls to the attestation service. Thus, a test must | 164 // that there are no calls to the attestation service. Thus, a test must |
173 // explicitly expect these calls or the mocks will fail the test. | 165 // explicitly expect these calls or the mocks will fail the test. |
174 | 166 |
175 // Configure the mock AttestationFlow to call FakeGetCertificate. | 167 // Configure the mock AttestationFlow to call FakeGetCertificate. |
176 EXPECT_CALL(mock_attestation_flow_, | 168 EXPECT_CALL(mock_attestation_flow_, |
177 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, | 169 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, |
178 kTestEmail, kTestID, _, _)) | 170 kTestEmail, kTestID, _, _)) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 return serial; | 222 return serial; |
231 } | 223 } |
232 | 224 |
233 protected: | 225 protected: |
234 base::MessageLoopForUI message_loop_; | 226 base::MessageLoopForUI message_loop_; |
235 content::TestBrowserThread ui_thread_; | 227 content::TestBrowserThread ui_thread_; |
236 StrictMock<MockAttestationFlow> mock_attestation_flow_; | 228 StrictMock<MockAttestationFlow> mock_attestation_flow_; |
237 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 229 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
238 CustomFakeCryptohomeClient fake_cryptohome_client_; | 230 CustomFakeCryptohomeClient fake_cryptohome_client_; |
239 FakeDelegate fake_delegate_; | 231 FakeDelegate fake_delegate_; |
240 CrosSettingsProvider* device_settings_provider_; | |
241 StubCrosSettingsProvider stub_settings_provider_; | |
242 ScopedTestDeviceSettingsService test_device_settings_service_; | |
243 ScopedTestCrosSettings test_cros_settings_; | |
244 scoped_refptr<PlatformVerificationFlow> verifier_; | 232 scoped_refptr<PlatformVerificationFlow> verifier_; |
245 | 233 |
246 // Controls result of FakeGetCertificate. | 234 // Controls result of FakeGetCertificate. |
247 bool certificate_success_; | 235 bool certificate_success_; |
248 std::vector<std::string> fake_certificate_list_; | 236 std::vector<std::string> fake_certificate_list_; |
249 size_t fake_certificate_index_; | 237 size_t fake_certificate_index_; |
250 | 238 |
251 // Controls result of FakeSignChallenge. | 239 // Controls result of FakeSignChallenge. |
252 bool sign_challenge_success_; | 240 bool sign_challenge_success_; |
253 | 241 |
(...skipping 16 matching lines...) Expand all Loading... | |
270 } | 258 } |
271 | 259 |
272 TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) { | 260 TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) { |
273 fake_delegate_.set_is_permitted_by_user(false); | 261 fake_delegate_.set_is_permitted_by_user(false); |
274 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 262 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
275 base::RunLoop().RunUntilIdle(); | 263 base::RunLoop().RunUntilIdle(); |
276 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 264 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
277 } | 265 } |
278 | 266 |
279 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) { | 267 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) { |
280 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, | 268 owner_settings_service_->SetBoolean(kAttestationForContentProtectionEnabled, |
281 false); | 269 false); |
282 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 270 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
283 base::RunLoop().RunUntilIdle(); | 271 base::RunLoop().RunUntilIdle(); |
284 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 272 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
285 } | 273 } |
286 | 274 |
287 TEST_F(PlatformVerificationFlowTest, NotVerified) { | 275 TEST_F(PlatformVerificationFlowTest, NotVerified) { |
288 certificate_success_ = false; | 276 certificate_success_ = false; |
289 ExpectAttestationFlow(); | 277 ExpectAttestationFlow(); |
290 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 278 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
291 base::RunLoop().RunUntilIdle(); | 279 base::RunLoop().RunUntilIdle(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { | 326 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { |
339 fake_cryptohome_client_.set_attestation_enrolled(false); | 327 fake_cryptohome_client_.set_attestation_enrolled(false); |
340 fake_cryptohome_client_.set_attestation_prepared(false); | 328 fake_cryptohome_client_.set_attestation_prepared(false); |
341 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 329 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
342 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
343 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); | 331 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); |
344 } | 332 } |
345 | 333 |
346 } // namespace attestation | 334 } // namespace attestation |
347 } // namespace chromeos | 335 } // namespace chromeos |
OLD | NEW |