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