Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/chromeos/attestation/platform_verification_flow_unittest.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rearrange device settings list. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/device_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"
24 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
25 22
26 using testing::_; 23 using testing::_;
27 using testing::DoAll; 24 using testing::DoAll;
28 using testing::Invoke; 25 using testing::Invoke;
29 using testing::Return; 26 using testing::Return;
30 using testing::SetArgumentPointee; 27 using testing::SetArgumentPointee;
31 using testing::StrictMock; 28 using testing::StrictMock;
32 using testing::WithArgs; 29 using testing::WithArgs;
33 30
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 121 }
125 122
126 private: 123 private:
127 DBusMethodCallStatus call_status_; 124 DBusMethodCallStatus call_status_;
128 bool attestation_enrolled_; 125 bool attestation_enrolled_;
129 bool attestation_prepared_; 126 bool attestation_prepared_;
130 }; 127 };
131 128
132 } // namespace 129 } // namespace
133 130
134 class PlatformVerificationFlowTest : public ::testing::Test { 131 class PlatformVerificationFlowTest : public chromeos::OwnerSettingsTestBase {
135 public: 132 public:
136 PlatformVerificationFlowTest() 133 PlatformVerificationFlowTest()
137 : ui_thread_(content::BrowserThread::UI, &message_loop_), 134 : certificate_success_(true),
138 certificate_success_(true),
139 fake_certificate_index_(0), 135 fake_certificate_index_(0),
140 sign_challenge_success_(true), 136 sign_challenge_success_(true),
141 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} 137 result_(PlatformVerificationFlow::INTERNAL_ERROR) {}
142 138
143 void SetUp() { 139 void SetUp() {
140 chromeos::OwnerSettingsTestBase::SetUp();
144 // Create a verifier for tests to call. 141 // Create a verifier for tests to call.
145 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, 142 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_,
146 &mock_async_caller_, 143 &mock_async_caller_,
147 &fake_cryptohome_client_, 144 &fake_cryptohome_client_,
148 &fake_delegate_); 145 &fake_delegate_);
149 146
150 // Create callbacks for tests to use with verifier_. 147 // Create callbacks for tests to use with verifier_.
151 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, 148 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback,
152 base::Unretained(this)); 149 base::Unretained(this));
153 150
154 // Configure the global cros_settings. 151 ReplaceProvider(kAttestationForContentProtectionEnabled);
155 CrosSettings* cros_settings = CrosSettings::Get(); 152 owner_settings_service_->SetBoolean(kAttestationForContentProtectionEnabled,
156 device_settings_provider_ = 153 true);
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 std::string CreateFakeResponseProto() { 210 std::string CreateFakeResponseProto() {
225 SignedData pb; 211 SignedData pb;
226 pb.set_data(kTestSignedData); 212 pb.set_data(kTestSignedData);
227 pb.set_signature(kTestSignature); 213 pb.set_signature(kTestSignature);
228 std::string serial; 214 std::string serial;
229 CHECK(pb.SerializeToString(&serial)); 215 CHECK(pb.SerializeToString(&serial));
230 return serial; 216 return serial;
231 } 217 }
232 218
233 protected: 219 protected:
234 base::MessageLoopForUI message_loop_;
235 content::TestBrowserThread ui_thread_;
236 StrictMock<MockAttestationFlow> mock_attestation_flow_; 220 StrictMock<MockAttestationFlow> mock_attestation_flow_;
237 cryptohome::MockAsyncMethodCaller mock_async_caller_; 221 cryptohome::MockAsyncMethodCaller mock_async_caller_;
238 CustomFakeCryptohomeClient fake_cryptohome_client_; 222 CustomFakeCryptohomeClient fake_cryptohome_client_;
239 FakeDelegate fake_delegate_; 223 FakeDelegate fake_delegate_;
240 CrosSettingsProvider* device_settings_provider_;
241 StubCrosSettingsProvider stub_settings_provider_;
242 ScopedTestDeviceSettingsService test_device_settings_service_;
243 ScopedTestCrosSettings test_cros_settings_;
244 scoped_refptr<PlatformVerificationFlow> verifier_; 224 scoped_refptr<PlatformVerificationFlow> verifier_;
245 225
246 // Controls result of FakeGetCertificate. 226 // Controls result of FakeGetCertificate.
247 bool certificate_success_; 227 bool certificate_success_;
248 std::vector<std::string> fake_certificate_list_; 228 std::vector<std::string> fake_certificate_list_;
249 size_t fake_certificate_index_; 229 size_t fake_certificate_index_;
250 230
251 // Controls result of FakeSignChallenge. 231 // Controls result of FakeSignChallenge.
252 bool sign_challenge_success_; 232 bool sign_challenge_success_;
253 233
(...skipping 16 matching lines...) Expand all
270 } 250 }
271 251
272 TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) { 252 TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) {
273 fake_delegate_.set_is_permitted_by_user(false); 253 fake_delegate_.set_is_permitted_by_user(false);
274 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 254 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
275 base::RunLoop().RunUntilIdle(); 255 base::RunLoop().RunUntilIdle();
276 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 256 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
277 } 257 }
278 258
279 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) { 259 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) {
280 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, 260 owner_settings_service_->SetBoolean(kAttestationForContentProtectionEnabled,
281 false); 261 false);
282 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 262 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
283 base::RunLoop().RunUntilIdle(); 263 base::RunLoop().RunUntilIdle();
284 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 264 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
285 } 265 }
286 266
287 TEST_F(PlatformVerificationFlowTest, NotVerified) { 267 TEST_F(PlatformVerificationFlowTest, NotVerified) {
288 certificate_success_ = false; 268 certificate_success_ = false;
289 ExpectAttestationFlow(); 269 ExpectAttestationFlow();
290 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 270 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
291 base::RunLoop().RunUntilIdle(); 271 base::RunLoop().RunUntilIdle();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { 318 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) {
339 fake_cryptohome_client_.set_attestation_enrolled(false); 319 fake_cryptohome_client_.set_attestation_enrolled(false);
340 fake_cryptohome_client_.set_attestation_prepared(false); 320 fake_cryptohome_client_.set_attestation_prepared(false);
341 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 321 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
342 base::RunLoop().RunUntilIdle(); 322 base::RunLoop().RunUntilIdle();
343 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); 323 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_);
344 } 324 }
345 325
346 } // namespace attestation 326 } // namespace attestation
347 } // namespace chromeos 327 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698