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

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

Issue 979273003: Simplify PlatformVerificationFlow::CheckConsent() logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years, 9 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"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 // Configure the global cros_settings. 201 // Configure the global cros_settings.
202 CrosSettings* cros_settings = CrosSettings::Get(); 202 CrosSettings* cros_settings = CrosSettings::Get();
203 device_settings_provider_ = 203 device_settings_provider_ =
204 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); 204 cros_settings->GetProvider(kAttestationForContentProtectionEnabled);
205 cros_settings->RemoveSettingsProvider(device_settings_provider_); 205 cros_settings->RemoveSettingsProvider(device_settings_provider_);
206 cros_settings->AddSettingsProvider(&stub_settings_provider_); 206 cros_settings->AddSettingsProvider(&stub_settings_provider_);
207 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); 207 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true);
208 208
209 // Start with the first-time setting set since most tests want this. 209 // Start with the first-time setting set since most tests want this.
210 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentFirstTime, 210 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentGranted,
211 new base::FundamentalValue(true)); 211 new base::FundamentalValue(true));
212
213 } 212 }
214 213
215 void TearDown() { 214 void TearDown() {
216 // Restore the real DeviceSettingsProvider. 215 // Restore the real DeviceSettingsProvider.
217 CrosSettings* cros_settings = CrosSettings::Get(); 216 CrosSettings* cros_settings = CrosSettings::Get();
218 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); 217 cros_settings->RemoveSettingsProvider(&stub_settings_provider_);
219 cros_settings->AddSettingsProvider(device_settings_provider_); 218 cros_settings->AddSettingsProvider(device_settings_provider_);
220 fake_delegate_.TearDown(); 219 fake_delegate_.TearDown();
221 } 220 }
222 221
(...skipping 14 matching lines...) Expand all
237 std::string(kTestID); 236 std::string(kTestID);
238 EXPECT_CALL(mock_async_caller_, 237 EXPECT_CALL(mock_async_caller_,
239 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, 238 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail,
240 expected_key_name, 239 expected_key_name,
241 kTestChallenge, _)) 240 kTestChallenge, _))
242 .WillRepeatedly(WithArgs<4>(Invoke( 241 .WillRepeatedly(WithArgs<4>(Invoke(
243 this, &PlatformVerificationFlowTest::FakeSignChallenge))); 242 this, &PlatformVerificationFlowTest::FakeSignChallenge)));
244 } 243 }
245 244
246 void SetUserConsent(const GURL& url, bool allow) { 245 void SetUserConsent(const GURL& url, bool allow) {
247 verifier_->RecordDomainConsent(fake_delegate_.GetContentSettings(NULL), 246 verifier_->RecordOriginConsent(fake_delegate_.GetContentSettings(NULL), url,
248 url,
249 allow); 247 allow);
250 } 248 }
251 249
252 void FakeGetCertificate( 250 void FakeGetCertificate(
253 const AttestationFlow::CertificateCallback& callback) { 251 const AttestationFlow::CertificateCallback& callback) {
254 std::string certificate = 252 std::string certificate =
255 (fake_certificate_index_ < fake_certificate_list_.size()) ? 253 (fake_certificate_index_ < fake_certificate_list_.size()) ?
256 fake_certificate_list_[fake_certificate_index_] : kTestCertificate; 254 fake_certificate_list_[fake_certificate_index_] : kTestCertificate;
257 base::MessageLoop::current()->PostTask(FROM_HERE, 255 base::MessageLoop::current()->PostTask(FROM_HERE,
258 base::Bind(callback, 256 base::Bind(callback,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 ExpectAttestationFlow(); 323 ExpectAttestationFlow();
326 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 324 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
327 base::RunLoop().RunUntilIdle(); 325 base::RunLoop().RunUntilIdle();
328 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 326 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
329 EXPECT_EQ(kTestSignedData, challenge_salt_); 327 EXPECT_EQ(kTestSignedData, challenge_salt_);
330 EXPECT_EQ(kTestSignature, challenge_signature_); 328 EXPECT_EQ(kTestSignature, challenge_signature_);
331 EXPECT_EQ(kTestCertificate, certificate_); 329 EXPECT_EQ(kTestCertificate, certificate_);
332 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 330 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
333 } 331 }
334 332
335 TEST_F(PlatformVerificationFlowTest, SuccessWithAttestationConsent) { 333 TEST_F(PlatformVerificationFlowTest, SuccessWithConsent) {
336 SetUserConsent(GURL(kTestURL), true); 334 SetUserConsent(GURL(kTestURL), true);
337 fake_cryptohome_client_.set_attestation_enrolled(false); 335 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentGranted,
338 ExpectAttestationFlow();
339 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
340 base::RunLoop().RunUntilIdle();
341 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
342 EXPECT_EQ(kTestSignedData, challenge_salt_);
343 EXPECT_EQ(kTestSignature, challenge_signature_);
344 EXPECT_EQ(kTestCertificate, certificate_);
345 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
346 }
347
348 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) {
349 SetUserConsent(GURL(kTestURL), true);
350 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentFirstTime,
351 new base::FundamentalValue(false)); 336 new base::FundamentalValue(false));
352 ExpectAttestationFlow(); 337 ExpectAttestationFlow();
353 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 338 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
354 base::RunLoop().RunUntilIdle(); 339 base::RunLoop().RunUntilIdle();
355 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 340 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
356 EXPECT_EQ(kTestSignedData, challenge_salt_); 341 EXPECT_EQ(kTestSignedData, challenge_salt_);
357 EXPECT_EQ(kTestSignature, challenge_signature_); 342 EXPECT_EQ(kTestSignature, challenge_signature_);
358 EXPECT_EQ(kTestCertificate, certificate_); 343 EXPECT_EQ(kTestCertificate, certificate_);
359 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 344 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
360 } 345 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 466 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
482 fake_cryptohome_client_.set_attestation_enrolled(false); 467 fake_cryptohome_client_.set_attestation_enrolled(false);
483 fake_cryptohome_client_.set_attestation_prepared(false); 468 fake_cryptohome_client_.set_attestation_prepared(false);
484 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 469 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
485 base::RunLoop().RunUntilIdle(); 470 base::RunLoop().RunUntilIdle();
486 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); 471 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_);
487 } 472 }
488 473
489 } // namespace attestation 474 } // namespace attestation
490 } // namespace chromeos 475 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/attestation/platform_verification_flow.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698