| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/extensions/api/enterprise_platform_keys_private/enterpr
ise_platform_keys_private_api.h" | 5 #include "chrome/browser/extensions/api/enterprise_platform_keys_private/enterpr
ise_platform_keys_private_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | |
| 12 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" | 15 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
| 16 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" | 16 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" |
| 17 #include "chrome/browser/extensions/extension_function_test_utils.h" | 17 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/base/browser_with_test_window_test.h" | 21 #include "chrome/test/base/browser_with_test_window_test.h" |
| 22 #include "chromeos/attestation/attestation_constants.h" | 22 #include "chromeos/attestation/attestation_constants.h" |
| 23 #include "chromeos/attestation/mock_attestation_flow.h" | 23 #include "chromeos/attestation/mock_attestation_flow.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 50 const int kResetRequired = 4; | 50 const int kResetRequired = 4; |
| 51 | 51 |
| 52 // A simple functor to invoke a callback with predefined arguments. | 52 // A simple functor to invoke a callback with predefined arguments. |
| 53 class FakeBoolDBusMethod { | 53 class FakeBoolDBusMethod { |
| 54 public: | 54 public: |
| 55 FakeBoolDBusMethod(chromeos::DBusMethodCallStatus status, bool value) | 55 FakeBoolDBusMethod(chromeos::DBusMethodCallStatus status, bool value) |
| 56 : status_(status), | 56 : status_(status), |
| 57 value_(value) {} | 57 value_(value) {} |
| 58 | 58 |
| 59 void operator() (const chromeos::BoolDBusMethodCallback& callback) { | 59 void operator() (const chromeos::BoolDBusMethodCallback& callback) { |
| 60 base::MessageLoopProxy::current()->PostTask( | 60 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 61 FROM_HERE, | 61 FROM_HERE, |
| 62 base::Bind(callback, status_, value_)); | 62 base::Bind(callback, status_, value_)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 chromeos::DBusMethodCallStatus status_; | 66 chromeos::DBusMethodCallStatus status_; |
| 67 bool value_; | 67 bool value_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 void RegisterKeyCallbackTrue( | 70 void RegisterKeyCallbackTrue( |
| 71 chromeos::attestation::AttestationKeyType key_type, | 71 chromeos::attestation::AttestationKeyType key_type, |
| 72 const std::string& user_id, | 72 const std::string& user_id, |
| 73 const std::string& key_name, | 73 const std::string& key_name, |
| 74 const cryptohome::AsyncMethodCaller::Callback& callback) { | 74 const cryptohome::AsyncMethodCaller::Callback& callback) { |
| 75 base::MessageLoopProxy::current()->PostTask( | 75 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 76 FROM_HERE, | 76 FROM_HERE, |
| 77 base::Bind(callback, true, cryptohome::MOUNT_ERROR_NONE)); | 77 base::Bind(callback, true, cryptohome::MOUNT_ERROR_NONE)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void RegisterKeyCallbackFalse( | 80 void RegisterKeyCallbackFalse( |
| 81 chromeos::attestation::AttestationKeyType key_type, | 81 chromeos::attestation::AttestationKeyType key_type, |
| 82 const std::string& user_id, | 82 const std::string& user_id, |
| 83 const std::string& key_name, | 83 const std::string& key_name, |
| 84 const cryptohome::AsyncMethodCaller::Callback& callback) { | 84 const cryptohome::AsyncMethodCaller::Callback& callback) { |
| 85 base::MessageLoopProxy::current()->PostTask( | 85 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 86 FROM_HERE, | 86 FROM_HERE, |
| 87 base::Bind(callback, false, cryptohome::MOUNT_ERROR_NONE)); | 87 base::Bind(callback, false, cryptohome::MOUNT_ERROR_NONE)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SignChallengeCallbackTrue( | 90 void SignChallengeCallbackTrue( |
| 91 chromeos::attestation::AttestationKeyType key_type, | 91 chromeos::attestation::AttestationKeyType key_type, |
| 92 const std::string& user_id, | 92 const std::string& user_id, |
| 93 const std::string& key_name, | 93 const std::string& key_name, |
| 94 const std::string& domain, | 94 const std::string& domain, |
| 95 const std::string& device_id, | 95 const std::string& device_id, |
| 96 chromeos::attestation::AttestationChallengeOptions options, | 96 chromeos::attestation::AttestationChallengeOptions options, |
| 97 const std::string& challenge, | 97 const std::string& challenge, |
| 98 const cryptohome::AsyncMethodCaller::DataCallback& callback) { | 98 const cryptohome::AsyncMethodCaller::DataCallback& callback) { |
| 99 base::MessageLoopProxy::current()->PostTask( | 99 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 100 FROM_HERE, | 100 FROM_HERE, |
| 101 base::Bind(callback, true, "response")); | 101 base::Bind(callback, true, "response")); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void SignChallengeCallbackFalse( | 104 void SignChallengeCallbackFalse( |
| 105 chromeos::attestation::AttestationKeyType key_type, | 105 chromeos::attestation::AttestationKeyType key_type, |
| 106 const std::string& user_id, | 106 const std::string& user_id, |
| 107 const std::string& key_name, | 107 const std::string& key_name, |
| 108 const std::string& domain, | 108 const std::string& domain, |
| 109 const std::string& device_id, | 109 const std::string& device_id, |
| 110 chromeos::attestation::AttestationChallengeOptions options, | 110 chromeos::attestation::AttestationChallengeOptions options, |
| 111 const std::string& challenge, | 111 const std::string& challenge, |
| 112 const cryptohome::AsyncMethodCaller::DataCallback& callback) { | 112 const cryptohome::AsyncMethodCaller::DataCallback& callback) { |
| 113 base::MessageLoopProxy::current()->PostTask( | 113 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 114 FROM_HERE, | 114 FROM_HERE, |
| 115 base::Bind(callback, false, "")); | 115 base::Bind(callback, false, "")); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void GetCertificateCallbackTrue( | 118 void GetCertificateCallbackTrue( |
| 119 chromeos::attestation::AttestationCertificateProfile certificate_profile, | 119 chromeos::attestation::AttestationCertificateProfile certificate_profile, |
| 120 const std::string& user_id, | 120 const std::string& user_id, |
| 121 const std::string& request_origin, | 121 const std::string& request_origin, |
| 122 bool force_new_key, | 122 bool force_new_key, |
| 123 const chromeos::attestation::AttestationFlow::CertificateCallback& | 123 const chromeos::attestation::AttestationFlow::CertificateCallback& |
| 124 callback) { | 124 callback) { |
| 125 base::MessageLoopProxy::current()->PostTask( | 125 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 126 FROM_HERE, | 126 FROM_HERE, |
| 127 base::Bind(callback, true, "certificate")); | 127 base::Bind(callback, true, "certificate")); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void GetCertificateCallbackFalse( | 130 void GetCertificateCallbackFalse( |
| 131 chromeos::attestation::AttestationCertificateProfile certificate_profile, | 131 chromeos::attestation::AttestationCertificateProfile certificate_profile, |
| 132 const std::string& user_id, | 132 const std::string& user_id, |
| 133 const std::string& request_origin, | 133 const std::string& request_origin, |
| 134 bool force_new_key, | 134 bool force_new_key, |
| 135 const chromeos::attestation::AttestationFlow::CertificateCallback& | 135 const chromeos::attestation::AttestationFlow::CertificateCallback& |
| 136 callback) { | 136 callback) { |
| 137 base::MessageLoopProxy::current()->PostTask( | 137 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 138 FROM_HERE, | 138 FROM_HERE, |
| 139 base::Bind(callback, false, "")); | 139 base::Bind(callback, false, "")); |
| 140 } | 140 } |
| 141 | 141 |
| 142 class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { | 142 class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { |
| 143 protected: | 143 protected: |
| 144 EPKPChallengeKeyTestBase() | 144 EPKPChallengeKeyTestBase() |
| 145 : settings_helper_(false), extension_(test_util::CreateEmptyExtension()) { | 145 : settings_helper_(false), extension_(test_util::CreateEmptyExtension()) { |
| 146 // Set up the default behavior of mocks. | 146 // Set up the default behavior of mocks. |
| 147 ON_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) | 147 ON_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 515 } |
| 516 }; | 516 }; |
| 517 | 517 |
| 518 TEST_F(EPKPChallengeUserKeyUnmanagedUserTest, UserNotManaged) { | 518 TEST_F(EPKPChallengeUserKeyUnmanagedUserTest, UserNotManaged) { |
| 519 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, | 519 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, |
| 520 utils::RunFunctionAndReturnError(func_.get(), kArgs, browser())); | 520 utils::RunFunctionAndReturnError(func_.get(), kArgs, browser())); |
| 521 } | 521 } |
| 522 | 522 |
| 523 } // namespace | 523 } // namespace |
| 524 } // namespace extensions | 524 } // namespace extensions |
| OLD | NEW |