| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "chrome/browser/chromeos/attestation/fake_certificate.h" | 16 #include "chrome/browser/chromeos/attestation/fake_certificate.h" |
| 18 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" | 17 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" |
| 19 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 18 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 20 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" | 19 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" |
| 21 #include "chrome/browser/profiles/profile_impl.h" | 20 #include "chrome/browser/profiles/profile_impl.h" |
| 22 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 23 #include "chromeos/attestation/attestation.pb.h" | 22 #include "chromeos/attestation/attestation.pb.h" |
| 24 #include "chromeos/attestation/mock_attestation_flow.h" | 23 #include "chromeos/attestation/mock_attestation_flow.h" |
| 25 #include "chromeos/cryptohome/mock_async_method_caller.h" | 24 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 26 #include "chromeos/dbus/fake_cryptohome_client.h" | 25 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 27 #include "chromeos/settings/cros_settings_names.h" | 26 #include "chromeos/settings/cros_settings_names.h" |
| 28 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 29 |
| 31 using testing::_; | 30 using testing::_; |
| 32 using testing::DoAll; | 31 using testing::DoAll; |
| 33 using testing::Invoke; | 32 using testing::Invoke; |
| 34 using testing::Return; | 33 using testing::Return; |
| 35 using testing::SetArgumentPointee; | 34 using testing::SetArgumentPointee; |
| 36 using testing::StrictMock; | 35 using testing::StrictMock; |
| 37 using testing::WithArgs; | 36 using testing::WithArgs; |
| 38 | 37 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 DBusMethodCallStatus call_status_; | 129 DBusMethodCallStatus call_status_; |
| 131 bool attestation_enrolled_; | 130 bool attestation_enrolled_; |
| 132 bool attestation_prepared_; | 131 bool attestation_prepared_; |
| 133 }; | 132 }; |
| 134 | 133 |
| 135 } // namespace | 134 } // namespace |
| 136 | 135 |
| 137 class PlatformVerificationFlowTest : public ::testing::Test { | 136 class PlatformVerificationFlowTest : public ::testing::Test { |
| 138 public: | 137 public: |
| 139 PlatformVerificationFlowTest() | 138 PlatformVerificationFlowTest() |
| 140 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 139 : certificate_success_(true), |
| 141 certificate_success_(true), | |
| 142 fake_certificate_index_(0), | 140 fake_certificate_index_(0), |
| 143 sign_challenge_success_(true), | 141 sign_challenge_success_(true), |
| 144 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} | 142 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} |
| 145 | 143 |
| 146 void SetUp() { | 144 void SetUp() { |
| 147 // Create a verifier for tests to call. | 145 // Create a verifier for tests to call. |
| 148 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, | 146 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, |
| 149 &mock_async_caller_, | 147 &mock_async_caller_, |
| 150 &fake_cryptohome_client_, | 148 &fake_cryptohome_client_, |
| 151 &fake_delegate_); | 149 &fake_delegate_); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 std::string CreateFakeResponseProto() { | 210 std::string CreateFakeResponseProto() { |
| 213 SignedData pb; | 211 SignedData pb; |
| 214 pb.set_data(kTestSignedData); | 212 pb.set_data(kTestSignedData); |
| 215 pb.set_signature(kTestSignature); | 213 pb.set_signature(kTestSignature); |
| 216 std::string serial; | 214 std::string serial; |
| 217 CHECK(pb.SerializeToString(&serial)); | 215 CHECK(pb.SerializeToString(&serial)); |
| 218 return serial; | 216 return serial; |
| 219 } | 217 } |
| 220 | 218 |
| 221 protected: | 219 protected: |
| 222 base::MessageLoopForUI message_loop_; | 220 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 223 content::TestBrowserThread ui_thread_; | |
| 224 StrictMock<MockAttestationFlow> mock_attestation_flow_; | 221 StrictMock<MockAttestationFlow> mock_attestation_flow_; |
| 225 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 222 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
| 226 CustomFakeCryptohomeClient fake_cryptohome_client_; | 223 CustomFakeCryptohomeClient fake_cryptohome_client_; |
| 227 FakeDelegate fake_delegate_; | 224 FakeDelegate fake_delegate_; |
| 228 ScopedCrosSettingsTestHelper settings_helper_; | 225 ScopedCrosSettingsTestHelper settings_helper_; |
| 229 scoped_refptr<PlatformVerificationFlow> verifier_; | 226 scoped_refptr<PlatformVerificationFlow> verifier_; |
| 230 | 227 |
| 231 // Controls result of FakeGetCertificate. | 228 // Controls result of FakeGetCertificate. |
| 232 bool certificate_success_; | 229 bool certificate_success_; |
| 233 std::vector<std::string> fake_certificate_list_; | 230 std::vector<std::string> fake_certificate_list_; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { | 395 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { |
| 399 fake_cryptohome_client_.set_attestation_enrolled(false); | 396 fake_cryptohome_client_.set_attestation_enrolled(false); |
| 400 fake_cryptohome_client_.set_attestation_prepared(false); | 397 fake_cryptohome_client_.set_attestation_prepared(false); |
| 401 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 398 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 402 base::RunLoop().RunUntilIdle(); | 399 base::RunLoop().RunUntilIdle(); |
| 403 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); | 400 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); |
| 404 } | 401 } |
| 405 | 402 |
| 406 } // namespace attestation | 403 } // namespace attestation |
| 407 } // namespace chromeos | 404 } // namespace chromeos |
| OLD | NEW |