| 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/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | |
| 11 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" | 12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" |
| 14 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" | 13 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" |
| 15 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 14 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 17 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 20 #include "chrome/common/content_settings_pattern.h" | 19 #include "chrome/common/content_settings_pattern.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ui_thread_(content::BrowserThread::UI, &message_loop_), | 124 ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 126 certificate_success_(true), | 125 certificate_success_(true), |
| 127 sign_challenge_success_(true), | 126 sign_challenge_success_(true), |
| 128 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} | 127 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} |
| 129 | 128 |
| 130 void SetUp() { | 129 void SetUp() { |
| 131 // Configure a user for the mock user manager. | 130 // Configure a user for the mock user manager. |
| 132 mock_user_manager_.SetActiveUser(kTestEmail); | 131 mock_user_manager_.SetActiveUser(kTestEmail); |
| 133 | 132 |
| 134 // Create a verifier for tests to call. | 133 // Create a verifier for tests to call. |
| 135 verifier_.reset(new PlatformVerificationFlow(&mock_attestation_flow_, | 134 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, |
| 136 &mock_async_caller_, | 135 &mock_async_caller_, |
| 137 &fake_cryptohome_client_, | 136 &fake_cryptohome_client_, |
| 138 &mock_user_manager_, | 137 &mock_user_manager_, |
| 139 &fake_delegate_)); | 138 &fake_delegate_); |
| 140 | 139 |
| 141 // Create callbacks for tests to use with verifier_. | 140 // Create callbacks for tests to use with verifier_. |
| 142 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, | 141 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, |
| 143 base::Unretained(this)); | 142 base::Unretained(this)); |
| 144 | 143 |
| 145 // Configure the test pref service. | 144 // Configure the test pref service. |
| 146 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true); | 145 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true); |
| 147 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime, | 146 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime, |
| 148 true); | 147 true); |
| 149 RegisterHostContentSettingsPrefs(pref_service_.registry()); | 148 RegisterHostContentSettingsPrefs(pref_service_.registry()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 CONTENT_SETTING_DEFAULT); | 218 CONTENT_SETTING_DEFAULT); |
| 220 registry->RegisterIntegerPref( | 219 registry->RegisterIntegerPref( |
| 221 prefs::kManagedDefaultMediaStreamSetting, | 220 prefs::kManagedDefaultMediaStreamSetting, |
| 222 CONTENT_SETTING_DEFAULT); | 221 CONTENT_SETTING_DEFAULT); |
| 223 registry->RegisterBooleanPref( | 222 registry->RegisterBooleanPref( |
| 224 prefs::kClearSiteDataOnExit, | 223 prefs::kClearSiteDataOnExit, |
| 225 false); | 224 false); |
| 226 } | 225 } |
| 227 | 226 |
| 228 void TearDown() { | 227 void TearDown() { |
| 229 verifier_.reset(); | |
| 230 // Restore the real DeviceSettingsProvider. | 228 // Restore the real DeviceSettingsProvider. |
| 231 CrosSettings* cros_settings = CrosSettings::Get(); | 229 CrosSettings* cros_settings = CrosSettings::Get(); |
| 232 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); | 230 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); |
| 233 cros_settings->AddSettingsProvider(device_settings_provider_); | 231 cros_settings->AddSettingsProvider(device_settings_provider_); |
| 234 test_content_settings_->ShutdownOnUIThread(); | 232 test_content_settings_->ShutdownOnUIThread(); |
| 235 } | 233 } |
| 236 | 234 |
| 237 void ExpectAttestationFlow() { | 235 void ExpectAttestationFlow() { |
| 238 // When consent is not given or the feature is disabled, it is important | 236 // When consent is not given or the feature is disabled, it is important |
| 239 // that there are no calls to the attestation service. Thus, a test must | 237 // that there are no calls to the attestation service. Thus, a test must |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 306 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
| 309 CustomFakeCryptohomeClient fake_cryptohome_client_; | 307 CustomFakeCryptohomeClient fake_cryptohome_client_; |
| 310 MockUserManager mock_user_manager_; | 308 MockUserManager mock_user_manager_; |
| 311 FakeDelegate fake_delegate_; | 309 FakeDelegate fake_delegate_; |
| 312 TestingPrefServiceSimple pref_service_; | 310 TestingPrefServiceSimple pref_service_; |
| 313 CrosSettingsProvider* device_settings_provider_; | 311 CrosSettingsProvider* device_settings_provider_; |
| 314 StubCrosSettingsProvider stub_settings_provider_; | 312 StubCrosSettingsProvider stub_settings_provider_; |
| 315 ScopedTestDeviceSettingsService test_device_settings_service_; | 313 ScopedTestDeviceSettingsService test_device_settings_service_; |
| 316 ScopedTestCrosSettings test_cros_settings_; | 314 ScopedTestCrosSettings test_cros_settings_; |
| 317 scoped_refptr<HostContentSettingsMap> test_content_settings_; | 315 scoped_refptr<HostContentSettingsMap> test_content_settings_; |
| 318 scoped_ptr<PlatformVerificationFlow> verifier_; | 316 scoped_refptr<PlatformVerificationFlow> verifier_; |
| 319 | 317 |
| 320 // Controls result of FakeGetCertificate. | 318 // Controls result of FakeGetCertificate. |
| 321 bool certificate_success_; | 319 bool certificate_success_; |
| 322 | 320 |
| 323 // Controls result of FakeSignChallenge. | 321 // Controls result of FakeSignChallenge. |
| 324 bool sign_challenge_success_; | 322 bool sign_challenge_success_; |
| 325 | 323 |
| 326 // Callback functions and data. | 324 // Callback functions and data. |
| 327 PlatformVerificationFlow::ChallengeCallback callback_; | 325 PlatformVerificationFlow::ChallengeCallback callback_; |
| 328 PlatformVerificationFlow::Result result_; | 326 PlatformVerificationFlow::Result result_; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 base::RunLoop().RunUntilIdle(); | 444 base::RunLoop().RunUntilIdle(); |
| 447 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 445 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 448 // Call with a different scheme and expect another consent prompt. | 446 // Call with a different scheme and expect another consent prompt. |
| 449 SetURL(GURL(kTestURLSecure)); | 447 SetURL(GURL(kTestURLSecure)); |
| 450 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 448 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 451 base::RunLoop().RunUntilIdle(); | 449 base::RunLoop().RunUntilIdle(); |
| 452 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 450 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 453 EXPECT_EQ(2, fake_delegate_.num_consent_calls()); | 451 EXPECT_EQ(2, fake_delegate_.num_consent_calls()); |
| 454 } | 452 } |
| 455 | 453 |
| 454 TEST_F(PlatformVerificationFlowTest, Timeout) { |
| 455 verifier_->set_timeout_delay(base::TimeDelta::FromSeconds(0)); |
| 456 ExpectAttestationFlow(); |
| 457 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 458 base::RunLoop().RunUntilIdle(); |
| 459 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_); |
| 460 } |
| 461 |
| 456 } // namespace attestation | 462 } // namespace attestation |
| 457 } // namespace chromeos | 463 } // namespace chromeos |
| OLD | NEW |