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

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: 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 ExpectAttestationFlow(); 324 ExpectAttestationFlow();
326 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 325 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
327 base::RunLoop().RunUntilIdle(); 326 base::RunLoop().RunUntilIdle();
328 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 327 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
329 EXPECT_EQ(kTestSignedData, challenge_salt_); 328 EXPECT_EQ(kTestSignedData, challenge_salt_);
330 EXPECT_EQ(kTestSignature, challenge_signature_); 329 EXPECT_EQ(kTestSignature, challenge_signature_);
331 EXPECT_EQ(kTestCertificate, certificate_); 330 EXPECT_EQ(kTestCertificate, certificate_);
332 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 331 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
333 } 332 }
334 333
335 TEST_F(PlatformVerificationFlowTest, SuccessWithAttestationConsent) { 334 TEST_F(PlatformVerificationFlowTest, SuccessWithConsent) {
336 SetUserConsent(GURL(kTestURL), true); 335 SetUserConsent(GURL(kTestURL), true);
337 fake_cryptohome_client_.set_attestation_enrolled(false); 336 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)); 337 new base::FundamentalValue(false));
352 ExpectAttestationFlow(); 338 ExpectAttestationFlow();
353 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 339 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
354 base::RunLoop().RunUntilIdle(); 340 base::RunLoop().RunUntilIdle();
355 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 341 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
356 EXPECT_EQ(kTestSignedData, challenge_salt_); 342 EXPECT_EQ(kTestSignedData, challenge_salt_);
357 EXPECT_EQ(kTestSignature, challenge_signature_); 343 EXPECT_EQ(kTestSignature, challenge_signature_);
358 EXPECT_EQ(kTestCertificate, certificate_); 344 EXPECT_EQ(kTestCertificate, certificate_);
359 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 345 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
360 } 346 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 467 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
482 fake_cryptohome_client_.set_attestation_enrolled(false); 468 fake_cryptohome_client_.set_attestation_enrolled(false);
483 fake_cryptohome_client_.set_attestation_prepared(false); 469 fake_cryptohome_client_.set_attestation_prepared(false);
484 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 470 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
485 base::RunLoop().RunUntilIdle(); 471 base::RunLoop().RunUntilIdle();
486 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); 472 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_);
487 } 473 }
488 474
489 } // namespace attestation 475 } // namespace attestation
490 } // namespace chromeos 476 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698