| 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" |
| 10 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" | 13 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" |
| 13 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" | 14 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" |
| 14 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 15 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 15 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 17 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 19 #include "chrome/browser/content_settings/host_content_settings_map.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 |
| 264 void SetURL(const GURL& url) { |
| 265 verifier_->set_testing_url(url); |
| 266 } |
| 267 |
| 195 void FakeGetCertificate( | 268 void FakeGetCertificate( |
| 196 const AttestationFlow::CertificateCallback& callback) { | 269 const AttestationFlow::CertificateCallback& callback) { |
| 197 base::MessageLoop::current()->PostTask(FROM_HERE, | 270 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 198 base::Bind(callback, | 271 base::Bind(callback, |
| 199 certificate_success_, | 272 certificate_success_, |
| 200 kTestCertificate)); | 273 kTestCertificate)); |
| 201 } | 274 } |
| 202 | 275 |
| 203 void FakeSignChallenge( | 276 void FakeSignChallenge( |
| 204 const cryptohome::AsyncMethodCaller::DataCallback& callback) { | 277 const cryptohome::AsyncMethodCaller::DataCallback& callback) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 234 StrictMock<MockAttestationFlow> mock_attestation_flow_; | 307 StrictMock<MockAttestationFlow> mock_attestation_flow_; |
| 235 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 308 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
| 236 CustomFakeCryptohomeClient fake_cryptohome_client_; | 309 CustomFakeCryptohomeClient fake_cryptohome_client_; |
| 237 MockUserManager mock_user_manager_; | 310 MockUserManager mock_user_manager_; |
| 238 FakeDelegate fake_delegate_; | 311 FakeDelegate fake_delegate_; |
| 239 TestingPrefServiceSimple pref_service_; | 312 TestingPrefServiceSimple pref_service_; |
| 240 CrosSettingsProvider* device_settings_provider_; | 313 CrosSettingsProvider* device_settings_provider_; |
| 241 StubCrosSettingsProvider stub_settings_provider_; | 314 StubCrosSettingsProvider stub_settings_provider_; |
| 242 ScopedTestDeviceSettingsService test_device_settings_service_; | 315 ScopedTestDeviceSettingsService test_device_settings_service_; |
| 243 ScopedTestCrosSettings test_cros_settings_; | 316 ScopedTestCrosSettings test_cros_settings_; |
| 317 scoped_refptr<HostContentSettingsMap> test_content_settings_; |
| 244 scoped_ptr<PlatformVerificationFlow> verifier_; | 318 scoped_ptr<PlatformVerificationFlow> verifier_; |
| 245 | 319 |
| 246 // Controls result of FakeGetCertificate. | 320 // Controls result of FakeGetCertificate. |
| 247 bool certificate_success_; | 321 bool certificate_success_; |
| 248 | 322 |
| 249 // Controls result of FakeSignChallenge. | 323 // Controls result of FakeSignChallenge. |
| 250 bool sign_challenge_success_; | 324 bool sign_challenge_success_; |
| 251 | 325 |
| 252 // Callback functions and data. | 326 // Callback functions and data. |
| 253 PlatformVerificationFlow::ChallengeCallback callback_; | 327 PlatformVerificationFlow::ChallengeCallback callback_; |
| 254 PlatformVerificationFlow::Result result_; | 328 PlatformVerificationFlow::Result result_; |
| 255 std::string challenge_salt_; | 329 std::string challenge_salt_; |
| 256 std::string challenge_signature_; | 330 std::string challenge_signature_; |
| 257 std::string certificate_; | 331 std::string certificate_; |
| 258 }; | 332 }; |
| 259 | 333 |
| 260 TEST_F(PlatformVerificationFlowTest, SuccessNoConsent) { | 334 TEST_F(PlatformVerificationFlowTest, SuccessNoConsent) { |
| 335 SetUserConsent(GURL(kTestURL), true); |
| 261 // Make sure the call will fail if consent is requested. | 336 // Make sure the call will fail if consent is requested. |
| 262 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | 337 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); |
| 263 ExpectAttestationFlow(); | 338 ExpectAttestationFlow(); |
| 264 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 339 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 265 base::RunLoop().RunUntilIdle(); | 340 base::RunLoop().RunUntilIdle(); |
| 266 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 341 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
| 267 EXPECT_EQ(kTestSignedData, challenge_salt_); | 342 EXPECT_EQ(kTestSignedData, challenge_salt_); |
| 268 EXPECT_EQ(kTestSignature, challenge_signature_); | 343 EXPECT_EQ(kTestSignature, challenge_signature_); |
| 269 EXPECT_EQ(kTestCertificate, certificate_); | 344 EXPECT_EQ(kTestCertificate, certificate_); |
| 270 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 345 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 271 } | 346 } |
| 272 | 347 |
| 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) { | 348 TEST_F(PlatformVerificationFlowTest, SuccessWithAttestationConsent) { |
| 349 SetUserConsent(GURL(kTestURL), true); |
| 287 fake_cryptohome_client_.set_attestation_enrolled(false); | 350 fake_cryptohome_client_.set_attestation_enrolled(false); |
| 288 ExpectAttestationFlow(); | 351 ExpectAttestationFlow(); |
| 289 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 352 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 290 base::RunLoop().RunUntilIdle(); | 353 base::RunLoop().RunUntilIdle(); |
| 291 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 354 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
| 292 EXPECT_EQ(kTestSignedData, challenge_salt_); | 355 EXPECT_EQ(kTestSignedData, challenge_salt_); |
| 293 EXPECT_EQ(kTestSignature, challenge_signature_); | 356 EXPECT_EQ(kTestSignature, challenge_signature_); |
| 294 EXPECT_EQ(kTestCertificate, certificate_); | 357 EXPECT_EQ(kTestCertificate, certificate_); |
| 295 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | 358 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); |
| 296 } | 359 } |
| 297 | 360 |
| 298 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) { | 361 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) { |
| 362 SetUserConsent(GURL(kTestURL), true); |
| 299 pref_service_.SetUserPref(prefs::kRAConsentFirstTime, | 363 pref_service_.SetUserPref(prefs::kRAConsentFirstTime, |
| 300 new base::FundamentalValue(false)); | 364 new base::FundamentalValue(false)); |
| 301 ExpectAttestationFlow(); | 365 ExpectAttestationFlow(); |
| 302 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 366 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 303 base::RunLoop().RunUntilIdle(); | 367 base::RunLoop().RunUntilIdle(); |
| 304 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 368 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
| 305 EXPECT_EQ(kTestSignedData, challenge_salt_); | 369 EXPECT_EQ(kTestSignedData, challenge_salt_); |
| 306 EXPECT_EQ(kTestSignature, challenge_signature_); | 370 EXPECT_EQ(kTestSignature, challenge_signature_); |
| 307 EXPECT_EQ(kTestCertificate, certificate_); | 371 EXPECT_EQ(kTestCertificate, certificate_); |
| 308 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | 372 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); |
| 309 } | 373 } |
| 310 | 374 |
| 311 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { | 375 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { |
| 312 pref_service_.SetUserPref(prefs::kRAConsentAlways, | |
| 313 new base::FundamentalValue(true)); | |
| 314 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | 376 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); |
| 315 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 377 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 316 base::RunLoop().RunUntilIdle(); | 378 base::RunLoop().RunUntilIdle(); |
| 317 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 379 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 318 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | 380 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); |
| 319 } | 381 } |
| 320 | 382 |
| 321 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { | 383 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { |
| 322 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, | 384 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, |
| 323 false); | 385 false); |
| 324 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 386 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 325 base::RunLoop().RunUntilIdle(); | 387 base::RunLoop().RunUntilIdle(); |
| 326 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 388 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 327 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 389 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 328 } | 390 } |
| 329 | 391 |
| 330 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { | 392 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { |
| 331 pref_service_.SetUserPref(prefs::kEnableDRM, | 393 pref_service_.SetUserPref(prefs::kEnableDRM, |
| 332 new base::FundamentalValue(false)); | 394 new base::FundamentalValue(false)); |
| 333 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 395 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 334 base::RunLoop().RunUntilIdle(); | 396 base::RunLoop().RunUntilIdle(); |
| 335 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 397 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 336 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 398 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 337 } | 399 } |
| 338 | 400 |
| 339 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { | 401 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { |
| 340 base::DictionaryValue* domains = new base::DictionaryValue(); | 402 SetUserConsent(GURL(kTestURL), false); |
| 341 domains->SetBoolean(kTestDomain, false); | |
| 342 pref_service_.SetUserPref(prefs::kRAConsentDomains, domains); | |
| 343 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 403 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 344 base::RunLoop().RunUntilIdle(); | 404 base::RunLoop().RunUntilIdle(); |
| 345 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 405 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 346 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | 406 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); |
| 347 } | 407 } |
| 348 | 408 |
| 349 TEST_F(PlatformVerificationFlowTest, NotVerified) { | 409 TEST_F(PlatformVerificationFlowTest, NotVerified) { |
| 350 certificate_success_ = false; | 410 certificate_success_ = false; |
| 351 ExpectAttestationFlow(); | 411 ExpectAttestationFlow(); |
| 352 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 412 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 364 | 424 |
| 365 TEST_F(PlatformVerificationFlowTest, DBusFailure) { | 425 TEST_F(PlatformVerificationFlowTest, DBusFailure) { |
| 366 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); | 426 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); |
| 367 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 427 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 368 base::RunLoop().RunUntilIdle(); | 428 base::RunLoop().RunUntilIdle(); |
| 369 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); | 429 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); |
| 370 } | 430 } |
| 371 | 431 |
| 372 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { | 432 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { |
| 373 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); | 433 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_); | 434 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 377 base::RunLoop().RunUntilIdle(); | 435 base::RunLoop().RunUntilIdle(); |
| 378 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 436 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 379 } | 437 } |
| 380 | 438 |
| 439 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) { |
| 440 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); |
| 441 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 442 base::RunLoop().RunUntilIdle(); |
| 443 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 444 // Call again and expect denial based on previous response. |
| 445 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 446 base::RunLoop().RunUntilIdle(); |
| 447 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 448 // Call with a different scheme and expect another consent prompt. |
| 449 SetURL(GURL(kTestURLSecure)); |
| 450 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 451 base::RunLoop().RunUntilIdle(); |
| 452 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 453 EXPECT_EQ(2, fake_delegate_.num_consent_calls()); |
| 454 } |
| 455 |
| 381 } // namespace attestation | 456 } // namespace attestation |
| 382 } // namespace chromeos | 457 } // namespace chromeos |
| OLD | NEW |