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/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "chromeos/attestation/mock_attestation_flow.h" | 19 #include "chromeos/attestation/mock_attestation_flow.h" |
20 #include "chromeos/cryptohome/mock_async_method_caller.h" | 20 #include "chromeos/cryptohome/mock_async_method_caller.h" |
21 #include "chromeos/dbus/fake_cryptohome_client.h" | 21 #include "chromeos/dbus/fake_cryptohome_client.h" |
22 #include "chromeos/settings/cros_settings_names.h" | 22 #include "chromeos/settings/cros_settings_names.h" |
23 #include "chromeos/system/mock_statistics_provider.h" | |
24 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
26 | 25 |
27 using testing::_; | 26 using testing::_; |
28 using testing::DoAll; | 27 using testing::DoAll; |
29 using testing::Invoke; | 28 using testing::Invoke; |
30 using testing::Return; | 29 using testing::Return; |
31 using testing::SetArgumentPointee; | 30 using testing::SetArgumentPointee; |
32 using testing::StrictMock; | 31 using testing::StrictMock; |
33 using testing::WithArgs; | 32 using testing::WithArgs; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 ui_thread_(content::BrowserThread::UI, &message_loop_), | 123 ui_thread_(content::BrowserThread::UI, &message_loop_), |
125 certificate_success_(true), | 124 certificate_success_(true), |
126 sign_challenge_success_(true), | 125 sign_challenge_success_(true), |
127 result_(PlatformVerificationFlow::INTERNAL_ERROR), | 126 result_(PlatformVerificationFlow::INTERNAL_ERROR), |
128 check_state_result_(false) {} | 127 check_state_result_(false) {} |
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 // Configure the statistics provider to report verified mode. | |
135 EXPECT_CALL(mock_statistics_provider_, | |
136 GetMachineStatistic(system::kDevSwitchBootMode, _)) | |
137 .WillRepeatedly(DoAll(SetArgumentPointee<1>(std::string("0")), | |
138 Return(true))); | |
139 | |
140 // Create a verifier for tests to call. | 133 // Create a verifier for tests to call. |
141 verifier_.reset(new PlatformVerificationFlow(&mock_attestation_flow_, | 134 verifier_.reset(new PlatformVerificationFlow(&mock_attestation_flow_, |
142 &mock_async_caller_, | 135 &mock_async_caller_, |
143 &fake_cryptohome_client_, | 136 &fake_cryptohome_client_, |
144 &mock_user_manager_, | 137 &mock_user_manager_, |
145 &mock_statistics_provider_, | |
146 &fake_delegate_)); | 138 &fake_delegate_)); |
147 | 139 |
148 // Create callbacks for tests to use with verifier_. | 140 // Create callbacks for tests to use with verifier_. |
149 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, | 141 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, |
150 base::Unretained(this)); | 142 base::Unretained(this)); |
151 check_state_callback_ = base::Bind( | 143 check_state_callback_ = base::Bind( |
152 &PlatformVerificationFlowTest::FakeCheckStateCallback, | 144 &PlatformVerificationFlowTest::FakeCheckStateCallback, |
153 base::Unretained(this)); | 145 base::Unretained(this)); |
154 | 146 |
155 // Configure the test pref service. | 147 // Configure the test pref service. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return serial; | 235 return serial; |
244 } | 236 } |
245 | 237 |
246 protected: | 238 protected: |
247 base::MessageLoop message_loop_; | 239 base::MessageLoop message_loop_; |
248 content::TestBrowserThread ui_thread_; | 240 content::TestBrowserThread ui_thread_; |
249 StrictMock<MockAttestationFlow> mock_attestation_flow_; | 241 StrictMock<MockAttestationFlow> mock_attestation_flow_; |
250 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 242 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
251 CustomFakeCryptohomeClient fake_cryptohome_client_; | 243 CustomFakeCryptohomeClient fake_cryptohome_client_; |
252 MockUserManager mock_user_manager_; | 244 MockUserManager mock_user_manager_; |
253 system::MockStatisticsProvider mock_statistics_provider_; | |
254 FakeDelegate fake_delegate_; | 245 FakeDelegate fake_delegate_; |
255 TestingPrefServiceSimple pref_service_; | 246 TestingPrefServiceSimple pref_service_; |
256 CrosSettingsProvider* device_settings_provider_; | 247 CrosSettingsProvider* device_settings_provider_; |
257 StubCrosSettingsProvider stub_settings_provider_; | 248 StubCrosSettingsProvider stub_settings_provider_; |
258 ScopedTestDeviceSettingsService test_device_settings_service_; | 249 ScopedTestDeviceSettingsService test_device_settings_service_; |
259 ScopedTestCrosSettings test_cros_settings_; | 250 ScopedTestCrosSettings test_cros_settings_; |
260 scoped_ptr<PlatformVerificationFlow> verifier_; | 251 scoped_ptr<PlatformVerificationFlow> verifier_; |
261 | 252 |
262 // Controls result of FakeGetCertificate. | 253 // Controls result of FakeGetCertificate. |
263 bool certificate_success_; | 254 bool certificate_success_; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 base::RunLoop().RunUntilIdle(); | 386 base::RunLoop().RunUntilIdle(); |
396 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 387 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
397 } | 388 } |
398 | 389 |
399 TEST_F(PlatformVerificationFlowTest, FastCheck) { | 390 TEST_F(PlatformVerificationFlowTest, FastCheck) { |
400 verifier_->CheckPlatformState(check_state_callback_); | 391 verifier_->CheckPlatformState(check_state_callback_); |
401 base::RunLoop().RunUntilIdle(); | 392 base::RunLoop().RunUntilIdle(); |
402 EXPECT_TRUE(check_state_result_); | 393 EXPECT_TRUE(check_state_result_); |
403 } | 394 } |
404 | 395 |
405 TEST_F(PlatformVerificationFlowTest, FastCheckNoStat) { | |
406 // Configure the stats provider to fail. | |
407 EXPECT_CALL(mock_statistics_provider_, | |
408 GetMachineStatistic(system::kDevSwitchBootMode, _)) | |
409 .WillRepeatedly(Return(false)); | |
410 | |
411 verifier_->CheckPlatformState(check_state_callback_); | |
412 base::RunLoop().RunUntilIdle(); | |
413 EXPECT_FALSE(check_state_result_); | |
414 } | |
415 | |
416 TEST_F(PlatformVerificationFlowTest, FastCheckStatDevMode) { | |
417 // Configure the stats provider to fail. | |
418 EXPECT_CALL(mock_statistics_provider_, | |
419 GetMachineStatistic(system::kDevSwitchBootMode, _)) | |
420 .WillRepeatedly(DoAll(SetArgumentPointee<1>(std::string("1")), | |
421 Return(true))); | |
422 | |
423 verifier_->CheckPlatformState(check_state_callback_); | |
424 base::RunLoop().RunUntilIdle(); | |
425 EXPECT_FALSE(check_state_result_); | |
426 } | |
427 | |
428 TEST_F(PlatformVerificationFlowTest, FastCheckStatInvalidMode) { | |
429 // Configure the stats provider to fail. | |
430 EXPECT_CALL(mock_statistics_provider_, | |
431 GetMachineStatistic(system::kDevSwitchBootMode, _)) | |
432 .WillRepeatedly(DoAll(SetArgumentPointee<1>(std::string("INVALID")), | |
433 Return(true))); | |
434 | |
435 verifier_->CheckPlatformState(check_state_callback_); | |
436 base::RunLoop().RunUntilIdle(); | |
437 EXPECT_FALSE(check_state_result_); | |
438 } | |
439 | |
440 TEST_F(PlatformVerificationFlowTest, FastCheckNoAttestation) { | |
441 fake_cryptohome_client_.set_attestation_prepared(false); | |
442 verifier_->CheckPlatformState(check_state_callback_); | |
443 base::RunLoop().RunUntilIdle(); | |
444 EXPECT_FALSE(check_state_result_); | |
445 } | |
446 | |
447 TEST_F(PlatformVerificationFlowTest, FastCheckDBusFailure) { | |
448 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); | |
449 verifier_->CheckPlatformState(check_state_callback_); | |
450 base::RunLoop().RunUntilIdle(); | |
451 EXPECT_FALSE(check_state_result_); | |
452 } | |
453 | |
454 } // namespace attestation | 396 } // namespace attestation |
455 } // namespace chromeos | 397 } // namespace chromeos |
OLD | NEW |