| 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/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" | 12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" |
| 13 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" | 13 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" |
| 14 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 14 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 15 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 18 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 20 #include "chrome/common/content_settings_pattern.h" |
| 18 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 19 #include "chromeos/attestation/mock_attestation_flow.h" | 22 #include "chromeos/attestation/mock_attestation_flow.h" |
| 20 #include "chromeos/cryptohome/mock_async_method_caller.h" | 23 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 21 #include "chromeos/dbus/fake_cryptohome_client.h" | 24 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 22 #include "chromeos/settings/cros_settings_names.h" | 25 #include "chromeos/settings/cros_settings_names.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 28 |
| 26 using testing::_; | 29 using testing::_; |
| 27 using testing::DoAll; | 30 using testing::DoAll; |
| 28 using testing::Invoke; | 31 using testing::Invoke; |
| 29 using testing::Return; | 32 using testing::Return; |
| 30 using testing::SetArgumentPointee; | 33 using testing::SetArgumentPointee; |
| 31 using testing::StrictMock; | 34 using testing::StrictMock; |
| 32 using testing::WithArgs; | 35 using testing::WithArgs; |
| 33 | 36 |
| 34 namespace chromeos { | 37 namespace chromeos { |
| 35 namespace attestation { | 38 namespace attestation { |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| 38 | 41 |
| 39 const char kTestID[] = "test_id"; | 42 const char kTestID[] = "test_id"; |
| 40 const char kTestChallenge[] = "test_challenge"; | 43 const char kTestChallenge[] = "test_challenge"; |
| 41 const char kTestSignedData[] = "test_challenge_with_salt"; | 44 const char kTestSignedData[] = "test_challenge_with_salt"; |
| 42 const char kTestSignature[] = "test_signature"; | 45 const char kTestSignature[] = "test_signature"; |
| 43 const char kTestCertificate[] = "test_certificate"; | 46 const char kTestCertificate[] = "test_certificate"; |
| 44 const char kTestEmail[] = "test_email@chromium.org"; | 47 const char kTestEmail[] = "test_email@chromium.org"; |
| 45 const char kTestURL[] = "http://mytestdomain/test"; | 48 const char kTestURL[] = "http://mytestdomain/test"; |
| 46 const char kTestDomain[] = "mytestdomain"; | 49 const char kTestURLSecure[] = "https://mytestdomain/test"; |
| 47 | 50 |
| 48 class FakeDelegate : public PlatformVerificationFlow::Delegate { | 51 class FakeDelegate : public PlatformVerificationFlow::Delegate { |
| 49 public: | 52 public: |
| 50 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW), | 53 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW), |
| 51 num_consent_calls_(0) {} | 54 num_consent_calls_(0) {} |
| 52 virtual ~FakeDelegate() {} | 55 virtual ~FakeDelegate() {} |
| 53 | 56 |
| 54 virtual void ShowConsentPrompt( | 57 virtual void ShowConsentPrompt( |
| 55 PlatformVerificationFlow::ConsentType type, | |
| 56 content::WebContents* web_contents, | 58 content::WebContents* web_contents, |
| 57 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) | 59 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) |
| 58 OVERRIDE { | 60 OVERRIDE { |
| 59 num_consent_calls_++; | 61 num_consent_calls_++; |
| 60 callback.Run(response_); | 62 callback.Run(response_); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void set_response(PlatformVerificationFlow::ConsentResponse response) { | 65 void set_response(PlatformVerificationFlow::ConsentResponse response) { |
| 64 response_ = response; | 66 response_ = response; |
| 65 } | 67 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 &fake_delegate_)); | 139 &fake_delegate_)); |
| 138 | 140 |
| 139 // Create callbacks for tests to use with verifier_. | 141 // Create callbacks for tests to use with verifier_. |
| 140 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, | 142 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, |
| 141 base::Unretained(this)); | 143 base::Unretained(this)); |
| 142 | 144 |
| 143 // Configure the test pref service. | 145 // Configure the test pref service. |
| 144 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true); | 146 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true); |
| 145 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime, | 147 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime, |
| 146 true); | 148 true); |
| 147 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentAlways, | 149 RegisterHostContentSettingsPrefs(pref_service_.registry()); |
| 148 false); | |
| 149 pref_service_.registry()->RegisterDictionaryPref(prefs::kRAConsentDomains); | |
| 150 verifier_->set_testing_prefs(&pref_service_); | 150 verifier_->set_testing_prefs(&pref_service_); |
| 151 test_content_settings_ = new HostContentSettingsMap(&pref_service_, false); |
| 152 verifier_->set_testing_content_settings(test_content_settings_); |
| 151 | 153 |
| 152 // Configure the global cros_settings. | 154 // Configure the global cros_settings. |
| 153 CrosSettings* cros_settings = CrosSettings::Get(); | 155 CrosSettings* cros_settings = CrosSettings::Get(); |
| 154 device_settings_provider_ = | 156 device_settings_provider_ = |
| 155 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); | 157 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); |
| 156 cros_settings->RemoveSettingsProvider(device_settings_provider_); | 158 cros_settings->RemoveSettingsProvider(device_settings_provider_); |
| 157 cros_settings->AddSettingsProvider(&stub_settings_provider_); | 159 cros_settings->AddSettingsProvider(&stub_settings_provider_); |
| 158 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); | 160 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); |
| 159 | 161 |
| 160 // Configure a test URL to shortcut the dependency on WebContents. | 162 // Configure a test URL to shortcut the dependency on WebContents. |
| 161 verifier_->set_testing_url(GURL(kTestURL)); | 163 verifier_->set_testing_url(GURL(kTestURL)); |
| 162 } | 164 } |
| 163 | 165 |
| 166 void RegisterHostContentSettingsPrefs(PrefRegistrySimple* registry) { |
| 167 registry->RegisterIntegerPref( |
| 168 prefs::kContentSettingsWindowLastTabIndex, |
| 169 0); |
| 170 registry->RegisterIntegerPref( |
| 171 prefs::kContentSettingsDefaultWhitelistVersion, |
| 172 0); |
| 173 registry->RegisterBooleanPref( |
| 174 prefs::kContentSettingsClearOnExitMigrated, |
| 175 false); |
| 176 DictionaryValue* default_content_settings = new DictionaryValue(); |
| 177 registry->RegisterDictionaryPref( |
| 178 prefs::kDefaultContentSettings, |
| 179 default_content_settings); |
| 180 registry->RegisterIntegerPref( |
| 181 prefs::kContentSettingsVersion, |
| 182 ContentSettingsPattern::kContentSettingsPatternVersion); |
| 183 registry->RegisterDictionaryPref( |
| 184 prefs::kContentSettingsPatternPairs); |
| 185 registry->RegisterListPref(prefs::kManagedAutoSelectCertificateForUrls); |
| 186 registry->RegisterListPref(prefs::kManagedCookiesAllowedForUrls); |
| 187 registry->RegisterListPref(prefs::kManagedCookiesBlockedForUrls); |
| 188 registry->RegisterListPref(prefs::kManagedCookiesSessionOnlyForUrls); |
| 189 registry->RegisterListPref(prefs::kManagedImagesAllowedForUrls); |
| 190 registry->RegisterListPref(prefs::kManagedImagesBlockedForUrls); |
| 191 registry->RegisterListPref(prefs::kManagedJavaScriptAllowedForUrls); |
| 192 registry->RegisterListPref(prefs::kManagedJavaScriptBlockedForUrls); |
| 193 registry->RegisterListPref(prefs::kManagedPluginsAllowedForUrls); |
| 194 registry->RegisterListPref(prefs::kManagedPluginsBlockedForUrls); |
| 195 registry->RegisterListPref(prefs::kManagedPopupsAllowedForUrls); |
| 196 registry->RegisterListPref(prefs::kManagedPopupsBlockedForUrls); |
| 197 registry->RegisterListPref(prefs::kManagedNotificationsAllowedForUrls); |
| 198 registry->RegisterListPref(prefs::kManagedNotificationsBlockedForUrls); |
| 199 registry->RegisterIntegerPref( |
| 200 prefs::kManagedDefaultCookiesSetting, |
| 201 CONTENT_SETTING_DEFAULT); |
| 202 registry->RegisterIntegerPref( |
| 203 prefs::kManagedDefaultImagesSetting, |
| 204 CONTENT_SETTING_DEFAULT); |
| 205 registry->RegisterIntegerPref( |
| 206 prefs::kManagedDefaultJavaScriptSetting, |
| 207 CONTENT_SETTING_DEFAULT); |
| 208 registry->RegisterIntegerPref( |
| 209 prefs::kManagedDefaultPluginsSetting, |
| 210 CONTENT_SETTING_DEFAULT); |
| 211 registry->RegisterIntegerPref( |
| 212 prefs::kManagedDefaultPopupsSetting, |
| 213 CONTENT_SETTING_DEFAULT); |
| 214 registry->RegisterIntegerPref( |
| 215 prefs::kManagedDefaultGeolocationSetting, |
| 216 CONTENT_SETTING_DEFAULT); |
| 217 registry->RegisterIntegerPref( |
| 218 prefs::kManagedDefaultNotificationsSetting, |
| 219 CONTENT_SETTING_DEFAULT); |
| 220 registry->RegisterIntegerPref( |
| 221 prefs::kManagedDefaultMediaStreamSetting, |
| 222 CONTENT_SETTING_DEFAULT); |
| 223 registry->RegisterBooleanPref( |
| 224 prefs::kClearSiteDataOnExit, |
| 225 false); |
| 226 } |
| 227 |
| 164 void TearDown() { | 228 void TearDown() { |
| 165 verifier_.reset(); | 229 verifier_.reset(); |
| 166 // Restore the real DeviceSettingsProvider. | 230 // Restore the real DeviceSettingsProvider. |
| 167 CrosSettings* cros_settings = CrosSettings::Get(); | 231 CrosSettings* cros_settings = CrosSettings::Get(); |
| 168 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); | 232 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); |
| 169 cros_settings->AddSettingsProvider(device_settings_provider_); | 233 cros_settings->AddSettingsProvider(device_settings_provider_); |
| 234 test_content_settings_->ShutdownOnUIThread(); |
| 170 } | 235 } |
| 171 | 236 |
| 172 void ExpectAttestationFlow() { | 237 void ExpectAttestationFlow() { |
| 173 // When consent is not given or the feature is disabled, it is important | 238 // When consent is not given or the feature is disabled, it is important |
| 174 // that there are no calls to the attestation service. Thus, a test must | 239 // that there are no calls to the attestation service. Thus, a test must |
| 175 // explicitly expect these calls or the mocks will fail the test. | 240 // explicitly expect these calls or the mocks will fail the test. |
| 176 | 241 |
| 177 // Configure the mock AttestationFlow to call FakeGetCertificate. | 242 // Configure the mock AttestationFlow to call FakeGetCertificate. |
| 178 EXPECT_CALL(mock_attestation_flow_, | 243 EXPECT_CALL(mock_attestation_flow_, |
| 179 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, | 244 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, |
| 180 kTestEmail, kTestID, _, _)) | 245 kTestEmail, kTestID, _, _)) |
| 181 .WillRepeatedly(WithArgs<4>(Invoke( | 246 .WillRepeatedly(WithArgs<4>(Invoke( |
| 182 this, &PlatformVerificationFlowTest::FakeGetCertificate))); | 247 this, &PlatformVerificationFlowTest::FakeGetCertificate))); |
| 183 | 248 |
| 184 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. | 249 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. |
| 185 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + | 250 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + |
| 186 std::string(kTestID); | 251 std::string(kTestID); |
| 187 EXPECT_CALL(mock_async_caller_, | 252 EXPECT_CALL(mock_async_caller_, |
| 188 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, | 253 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, |
| 189 expected_key_name, | 254 expected_key_name, |
| 190 kTestChallenge, _)) | 255 kTestChallenge, _)) |
| 191 .WillRepeatedly(WithArgs<4>(Invoke( | 256 .WillRepeatedly(WithArgs<4>(Invoke( |
| 192 this, &PlatformVerificationFlowTest::FakeSignChallenge))); | 257 this, &PlatformVerificationFlowTest::FakeSignChallenge))); |
| 193 } | 258 } |
| 194 | 259 |
| 260 void SetUserConsent(const GURL& url, bool allow) { |
| 261 verifier_->RecordDomainConsent(test_content_settings_, url, allow); |
| 262 } |
| 263 |
| 195 void FakeGetCertificate( | 264 void FakeGetCertificate( |
| 196 const AttestationFlow::CertificateCallback& callback) { | 265 const AttestationFlow::CertificateCallback& callback) { |
| 197 base::MessageLoop::current()->PostTask(FROM_HERE, | 266 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 198 base::Bind(callback, | 267 base::Bind(callback, |
| 199 certificate_success_, | 268 certificate_success_, |
| 200 kTestCertificate)); | 269 kTestCertificate)); |
| 201 } | 270 } |
| 202 | 271 |
| 203 void FakeSignChallenge( | 272 void FakeSignChallenge( |
| 204 const cryptohome::AsyncMethodCaller::DataCallback& callback) { | 273 const cryptohome::AsyncMethodCaller::DataCallback& callback) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 234 StrictMock<MockAttestationFlow> mock_attestation_flow_; | 303 StrictMock<MockAttestationFlow> mock_attestation_flow_; |
| 235 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 304 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
| 236 CustomFakeCryptohomeClient fake_cryptohome_client_; | 305 CustomFakeCryptohomeClient fake_cryptohome_client_; |
| 237 MockUserManager mock_user_manager_; | 306 MockUserManager mock_user_manager_; |
| 238 FakeDelegate fake_delegate_; | 307 FakeDelegate fake_delegate_; |
| 239 TestingPrefServiceSimple pref_service_; | 308 TestingPrefServiceSimple pref_service_; |
| 240 CrosSettingsProvider* device_settings_provider_; | 309 CrosSettingsProvider* device_settings_provider_; |
| 241 StubCrosSettingsProvider stub_settings_provider_; | 310 StubCrosSettingsProvider stub_settings_provider_; |
| 242 ScopedTestDeviceSettingsService test_device_settings_service_; | 311 ScopedTestDeviceSettingsService test_device_settings_service_; |
| 243 ScopedTestCrosSettings test_cros_settings_; | 312 ScopedTestCrosSettings test_cros_settings_; |
| 313 scoped_refptr<HostContentSettingsMap> test_content_settings_; |
| 244 scoped_ptr<PlatformVerificationFlow> verifier_; | 314 scoped_ptr<PlatformVerificationFlow> verifier_; |
| 245 | 315 |
| 246 // Controls result of FakeGetCertificate. | 316 // Controls result of FakeGetCertificate. |
| 247 bool certificate_success_; | 317 bool certificate_success_; |
| 248 | 318 |
| 249 // Controls result of FakeSignChallenge. | 319 // Controls result of FakeSignChallenge. |
| 250 bool sign_challenge_success_; | 320 bool sign_challenge_success_; |
| 251 | 321 |
| 252 // Callback functions and data. | 322 // Callback functions and data. |
| 253 PlatformVerificationFlow::ChallengeCallback callback_; | 323 PlatformVerificationFlow::ChallengeCallback callback_; |
| 254 PlatformVerificationFlow::Result result_; | 324 PlatformVerificationFlow::Result result_; |
| 255 std::string challenge_salt_; | 325 std::string challenge_salt_; |
| 256 std::string challenge_signature_; | 326 std::string challenge_signature_; |
| 257 std::string certificate_; | 327 std::string certificate_; |
| 258 }; | 328 }; |
| 259 | 329 |
| 260 TEST_F(PlatformVerificationFlowTest, SuccessNoConsent) { | 330 TEST_F(PlatformVerificationFlowTest, SuccessNoConsent) { |
| 331 SetUserConsent(GURL(kTestURL), true); |
| 261 // Make sure the call will fail if consent is requested. | 332 // Make sure the call will fail if consent is requested. |
| 262 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | 333 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); |
| 263 ExpectAttestationFlow(); | 334 ExpectAttestationFlow(); |
| 264 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 335 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 265 base::RunLoop().RunUntilIdle(); | 336 base::RunLoop().RunUntilIdle(); |
| 266 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 337 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
| 267 EXPECT_EQ(kTestSignedData, challenge_salt_); | 338 EXPECT_EQ(kTestSignedData, challenge_salt_); |
| 268 EXPECT_EQ(kTestSignature, challenge_signature_); | 339 EXPECT_EQ(kTestSignature, challenge_signature_); |
| 269 EXPECT_EQ(kTestCertificate, certificate_); | 340 EXPECT_EQ(kTestCertificate, certificate_); |
| 270 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 341 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 271 } | 342 } |
| 272 | 343 |
| 273 TEST_F(PlatformVerificationFlowTest, SuccessWithAlwaysAskConsent) { | |
| 274 pref_service_.SetUserPref(prefs::kRAConsentAlways, | |
| 275 new base::FundamentalValue(true)); | |
| 276 ExpectAttestationFlow(); | |
| 277 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
| 278 base::RunLoop().RunUntilIdle(); | |
| 279 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | |
| 280 EXPECT_EQ(kTestSignedData, challenge_salt_); | |
| 281 EXPECT_EQ(kTestSignature, challenge_signature_); | |
| 282 EXPECT_EQ(kTestCertificate, certificate_); | |
| 283 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | |
| 284 } | |
| 285 | |
| 286 TEST_F(PlatformVerificationFlowTest, SuccessWithAttestationConsent) { | 344 TEST_F(PlatformVerificationFlowTest, SuccessWithAttestationConsent) { |
| 345 SetUserConsent(GURL(kTestURL), true); |
| 287 fake_cryptohome_client_.set_attestation_enrolled(false); | 346 fake_cryptohome_client_.set_attestation_enrolled(false); |
| 288 ExpectAttestationFlow(); | 347 ExpectAttestationFlow(); |
| 289 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 348 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 290 base::RunLoop().RunUntilIdle(); | 349 base::RunLoop().RunUntilIdle(); |
| 291 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 350 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
| 292 EXPECT_EQ(kTestSignedData, challenge_salt_); | 351 EXPECT_EQ(kTestSignedData, challenge_salt_); |
| 293 EXPECT_EQ(kTestSignature, challenge_signature_); | 352 EXPECT_EQ(kTestSignature, challenge_signature_); |
| 294 EXPECT_EQ(kTestCertificate, certificate_); | 353 EXPECT_EQ(kTestCertificate, certificate_); |
| 295 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | 354 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); |
| 296 } | 355 } |
| 297 | 356 |
| 298 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) { | 357 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) { |
| 358 SetUserConsent(GURL(kTestURL), true); |
| 299 pref_service_.SetUserPref(prefs::kRAConsentFirstTime, | 359 pref_service_.SetUserPref(prefs::kRAConsentFirstTime, |
| 300 new base::FundamentalValue(false)); | 360 new base::FundamentalValue(false)); |
| 301 ExpectAttestationFlow(); | 361 ExpectAttestationFlow(); |
| 302 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 362 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 303 base::RunLoop().RunUntilIdle(); | 363 base::RunLoop().RunUntilIdle(); |
| 304 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 364 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
| 305 EXPECT_EQ(kTestSignedData, challenge_salt_); | 365 EXPECT_EQ(kTestSignedData, challenge_salt_); |
| 306 EXPECT_EQ(kTestSignature, challenge_signature_); | 366 EXPECT_EQ(kTestSignature, challenge_signature_); |
| 307 EXPECT_EQ(kTestCertificate, certificate_); | 367 EXPECT_EQ(kTestCertificate, certificate_); |
| 308 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | 368 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); |
| 309 } | 369 } |
| 310 | 370 |
| 311 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { | 371 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { |
| 312 pref_service_.SetUserPref(prefs::kRAConsentAlways, | |
| 313 new base::FundamentalValue(true)); | |
| 314 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | 372 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); |
| 315 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 373 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 316 base::RunLoop().RunUntilIdle(); | 374 base::RunLoop().RunUntilIdle(); |
| 317 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 375 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 318 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | 376 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); |
| 319 } | 377 } |
| 320 | 378 |
| 321 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { | 379 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { |
| 322 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, | 380 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, |
| 323 false); | 381 false); |
| 324 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 382 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 325 base::RunLoop().RunUntilIdle(); | 383 base::RunLoop().RunUntilIdle(); |
| 326 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 384 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 327 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 385 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 328 } | 386 } |
| 329 | 387 |
| 330 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { | 388 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { |
| 331 pref_service_.SetUserPref(prefs::kEnableDRM, | 389 pref_service_.SetUserPref(prefs::kEnableDRM, |
| 332 new base::FundamentalValue(false)); | 390 new base::FundamentalValue(false)); |
| 333 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 391 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 334 base::RunLoop().RunUntilIdle(); | 392 base::RunLoop().RunUntilIdle(); |
| 335 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 393 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 336 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 394 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 337 } | 395 } |
| 338 | 396 |
| 339 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { | 397 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { |
| 340 base::DictionaryValue* domains = new base::DictionaryValue(); | 398 SetUserConsent(GURL(kTestURL), false); |
| 341 domains->SetBoolean(kTestDomain, false); | |
| 342 pref_service_.SetUserPref(prefs::kRAConsentDomains, domains); | |
| 343 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 399 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 344 base::RunLoop().RunUntilIdle(); | 400 base::RunLoop().RunUntilIdle(); |
| 345 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 401 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 346 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 402 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 347 } | 403 } |
| 348 | 404 |
| 349 TEST_F(PlatformVerificationFlowTest, NotVerified) { | 405 TEST_F(PlatformVerificationFlowTest, NotVerified) { |
| 350 certificate_success_ = false; | 406 certificate_success_ = false; |
| 351 ExpectAttestationFlow(); | 407 ExpectAttestationFlow(); |
| 352 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 408 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 364 | 420 |
| 365 TEST_F(PlatformVerificationFlowTest, DBusFailure) { | 421 TEST_F(PlatformVerificationFlowTest, DBusFailure) { |
| 366 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); | 422 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); |
| 367 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 423 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 368 base::RunLoop().RunUntilIdle(); | 424 base::RunLoop().RunUntilIdle(); |
| 369 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); | 425 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); |
| 370 } | 426 } |
| 371 | 427 |
| 372 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { | 428 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { |
| 373 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); | 429 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); |
| 374 pref_service_.SetUserPref(prefs::kRAConsentAlways, | |
| 375 new base::FundamentalValue(true)); | |
| 376 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 430 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 377 base::RunLoop().RunUntilIdle(); | 431 base::RunLoop().RunUntilIdle(); |
| 378 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 432 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 379 } | 433 } |
| 380 | 434 |
| 435 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) { |
| 436 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); |
| 437 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 438 base::RunLoop().RunUntilIdle(); |
| 439 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 440 // Call again and expect denial based on previous response. |
| 441 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 442 base::RunLoop().RunUntilIdle(); |
| 443 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 444 // Call with a different scheme and expect another consent prompt. |
| 445 verifier_->set_testing_url(GURL(kTestURLSecure)); |
| 446 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 447 base::RunLoop().RunUntilIdle(); |
| 448 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 449 EXPECT_EQ(2, fake_delegate_.num_consent_calls()); |
| 450 } |
| 451 |
| 381 } // namespace attestation | 452 } // namespace attestation |
| 382 } // namespace chromeos | 453 } // namespace chromeos |
| OLD | NEW |