| 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" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 settings_helper_.ReplaceProvider(kAttestationForContentProtectionEnabled); | 158 settings_helper_.ReplaceProvider(kAttestationForContentProtectionEnabled); |
| 159 settings_helper_.SetBoolean(kAttestationForContentProtectionEnabled, true); | 159 settings_helper_.SetBoolean(kAttestationForContentProtectionEnabled, true); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void ExpectAttestationFlow() { | 162 void ExpectAttestationFlow() { |
| 163 // When consent is not given or the feature is disabled, it is important | 163 // When consent is not given or the feature is disabled, it is important |
| 164 // that there are no calls to the attestation service. Thus, a test must | 164 // that there are no calls to the attestation service. Thus, a test must |
| 165 // explicitly expect these calls or the mocks will fail the test. | 165 // explicitly expect these calls or the mocks will fail the test. |
| 166 | 166 |
| 167 const AccountId account_id = AccountId::FromUserEmail(kTestEmail); |
| 167 // Configure the mock AttestationFlow to call FakeGetCertificate. | 168 // Configure the mock AttestationFlow to call FakeGetCertificate. |
| 168 EXPECT_CALL(mock_attestation_flow_, | 169 EXPECT_CALL(mock_attestation_flow_, |
| 169 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, | 170 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, |
| 170 kTestEmail, kTestID, _, _)) | 171 account_id, kTestID, _, _)) |
| 171 .WillRepeatedly(WithArgs<4>(Invoke( | 172 .WillRepeatedly(WithArgs<4>( |
| 172 this, &PlatformVerificationFlowTest::FakeGetCertificate))); | 173 Invoke(this, &PlatformVerificationFlowTest::FakeGetCertificate))); |
| 173 | 174 |
| 174 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. | 175 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. |
| 175 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + | 176 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + |
| 176 std::string(kTestID); | 177 std::string(kTestID); |
| 177 EXPECT_CALL(mock_async_caller_, | 178 EXPECT_CALL(mock_async_caller_, |
| 178 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, | 179 TpmAttestationSignSimpleChallenge( |
| 179 expected_key_name, | 180 KEY_USER, cryptohome::Identification(account_id), |
| 180 kTestChallenge, _)) | 181 expected_key_name, kTestChallenge, _)) |
| 181 .WillRepeatedly(WithArgs<4>(Invoke( | 182 .WillRepeatedly(WithArgs<4>( |
| 182 this, &PlatformVerificationFlowTest::FakeSignChallenge))); | 183 Invoke(this, &PlatformVerificationFlowTest::FakeSignChallenge))); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void FakeGetCertificate( | 186 void FakeGetCertificate( |
| 186 const AttestationFlow::CertificateCallback& callback) { | 187 const AttestationFlow::CertificateCallback& callback) { |
| 187 std::string certificate = | 188 std::string certificate = |
| 188 (fake_certificate_index_ < fake_certificate_list_.size()) ? | 189 (fake_certificate_index_ < fake_certificate_list_.size()) ? |
| 189 fake_certificate_list_[fake_certificate_index_] : kTestCertificate; | 190 fake_certificate_list_[fake_certificate_index_] : kTestCertificate; |
| 190 base::MessageLoop::current()->PostTask(FROM_HERE, | 191 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 191 base::Bind(callback, | 192 base::Bind(callback, |
| 192 certificate_success_, | 193 certificate_success_, |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { | 403 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { |
| 403 fake_cryptohome_client_.set_attestation_enrolled(false); | 404 fake_cryptohome_client_.set_attestation_enrolled(false); |
| 404 fake_cryptohome_client_.set_attestation_prepared(false); | 405 fake_cryptohome_client_.set_attestation_prepared(false); |
| 405 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 406 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 406 base::RunLoop().RunUntilIdle(); | 407 base::RunLoop().RunUntilIdle(); |
| 407 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); | 408 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); |
| 408 } | 409 } |
| 409 | 410 |
| 410 } // namespace attestation | 411 } // namespace attestation |
| 411 } // namespace chromeos | 412 } // namespace chromeos |
| OLD | NEW |