| 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/settings/scoped_cros_settings_test_helper.h" |
| 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
| 17 #include "chrome/browser/profiles/profile_impl.h" | 15 #include "chrome/browser/profiles/profile_impl.h" |
| 18 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 19 #include "chromeos/attestation/mock_attestation_flow.h" | 17 #include "chromeos/attestation/mock_attestation_flow.h" |
| 20 #include "chromeos/cryptohome/mock_async_method_caller.h" | 18 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 21 #include "chromeos/dbus/fake_cryptohome_client.h" | 19 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 22 #include "chromeos/settings/cros_settings_names.h" | 20 #include "chromeos/settings/cros_settings_names.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 23 |
| 26 using testing::_; | 24 using testing::_; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // Create a verifier for tests to call. | 144 // Create a verifier for tests to call. |
| 147 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, | 145 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, |
| 148 &mock_async_caller_, | 146 &mock_async_caller_, |
| 149 &fake_cryptohome_client_, | 147 &fake_cryptohome_client_, |
| 150 &fake_delegate_); | 148 &fake_delegate_); |
| 151 | 149 |
| 152 // Create callbacks for tests to use with verifier_. | 150 // Create callbacks for tests to use with verifier_. |
| 153 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, | 151 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, |
| 154 base::Unretained(this)); | 152 base::Unretained(this)); |
| 155 | 153 |
| 156 // Configure the global cros_settings. | 154 settings_helper_.ReplaceProvider(kAttestationForContentProtectionEnabled); |
| 157 CrosSettings* cros_settings = CrosSettings::Get(); | 155 settings_helper_.SetBoolean(kAttestationForContentProtectionEnabled, true); |
| 158 device_settings_provider_ = | |
| 159 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); | |
| 160 cros_settings->RemoveSettingsProvider(device_settings_provider_); | |
| 161 cros_settings->AddSettingsProvider(&stub_settings_provider_); | |
| 162 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); | |
| 163 } | |
| 164 | |
| 165 void TearDown() { | |
| 166 // Restore the real DeviceSettingsProvider. | |
| 167 CrosSettings* cros_settings = CrosSettings::Get(); | |
| 168 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); | |
| 169 cros_settings->AddSettingsProvider(device_settings_provider_); | |
| 170 } | 156 } |
| 171 | 157 |
| 172 void ExpectAttestationFlow() { | 158 void ExpectAttestationFlow() { |
| 173 // When consent is not given or the feature is disabled, it is important | 159 // 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 | 160 // 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. | 161 // explicitly expect these calls or the mocks will fail the test. |
| 176 | 162 |
| 177 // Configure the mock AttestationFlow to call FakeGetCertificate. | 163 // Configure the mock AttestationFlow to call FakeGetCertificate. |
| 178 EXPECT_CALL(mock_attestation_flow_, | 164 EXPECT_CALL(mock_attestation_flow_, |
| 179 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, | 165 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return serial; | 218 return serial; |
| 233 } | 219 } |
| 234 | 220 |
| 235 protected: | 221 protected: |
| 236 base::MessageLoopForUI message_loop_; | 222 base::MessageLoopForUI message_loop_; |
| 237 content::TestBrowserThread ui_thread_; | 223 content::TestBrowserThread ui_thread_; |
| 238 StrictMock<MockAttestationFlow> mock_attestation_flow_; | 224 StrictMock<MockAttestationFlow> mock_attestation_flow_; |
| 239 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 225 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
| 240 CustomFakeCryptohomeClient fake_cryptohome_client_; | 226 CustomFakeCryptohomeClient fake_cryptohome_client_; |
| 241 FakeDelegate fake_delegate_; | 227 FakeDelegate fake_delegate_; |
| 242 CrosSettingsProvider* device_settings_provider_; | 228 ScopedCrosSettingsTestHelper settings_helper_; |
| 243 StubCrosSettingsProvider stub_settings_provider_; | |
| 244 ScopedTestDeviceSettingsService test_device_settings_service_; | |
| 245 ScopedTestCrosSettings test_cros_settings_; | |
| 246 scoped_refptr<PlatformVerificationFlow> verifier_; | 229 scoped_refptr<PlatformVerificationFlow> verifier_; |
| 247 | 230 |
| 248 // Controls result of FakeGetCertificate. | 231 // Controls result of FakeGetCertificate. |
| 249 bool certificate_success_; | 232 bool certificate_success_; |
| 250 std::vector<std::string> fake_certificate_list_; | 233 std::vector<std::string> fake_certificate_list_; |
| 251 size_t fake_certificate_index_; | 234 size_t fake_certificate_index_; |
| 252 | 235 |
| 253 // Controls result of FakeSignChallenge. | 236 // Controls result of FakeSignChallenge. |
| 254 bool sign_challenge_success_; | 237 bool sign_challenge_success_; |
| 255 | 238 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 272 } | 255 } |
| 273 | 256 |
| 274 TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) { | 257 TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) { |
| 275 fake_delegate_.set_is_permitted_by_user(false); | 258 fake_delegate_.set_is_permitted_by_user(false); |
| 276 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 259 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 277 base::RunLoop().RunUntilIdle(); | 260 base::RunLoop().RunUntilIdle(); |
| 278 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 261 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 279 } | 262 } |
| 280 | 263 |
| 281 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) { | 264 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) { |
| 282 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, | 265 settings_helper_.SetBoolean(kAttestationForContentProtectionEnabled, false); |
| 283 false); | |
| 284 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 266 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 285 base::RunLoop().RunUntilIdle(); | 267 base::RunLoop().RunUntilIdle(); |
| 286 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 268 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
| 287 } | 269 } |
| 288 | 270 |
| 289 TEST_F(PlatformVerificationFlowTest, NotVerified) { | 271 TEST_F(PlatformVerificationFlowTest, NotVerified) { |
| 290 certificate_success_ = false; | 272 certificate_success_ = false; |
| 291 ExpectAttestationFlow(); | 273 ExpectAttestationFlow(); |
| 292 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 274 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 293 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { | 322 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { |
| 341 fake_cryptohome_client_.set_attestation_enrolled(false); | 323 fake_cryptohome_client_.set_attestation_enrolled(false); |
| 342 fake_cryptohome_client_.set_attestation_prepared(false); | 324 fake_cryptohome_client_.set_attestation_prepared(false); |
| 343 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 325 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 344 base::RunLoop().RunUntilIdle(); | 326 base::RunLoop().RunUntilIdle(); |
| 345 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); | 327 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); |
| 346 } | 328 } |
| 347 | 329 |
| 348 } // namespace attestation | 330 } // namespace attestation |
| 349 } // namespace chromeos | 331 } // namespace chromeos |
| OLD | NEW |