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 <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/cros_settings.h" |
15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
17 #include "chrome/browser/profiles/profile_impl.h" | 17 #include "chrome/browser/profiles/profile_impl.h" |
18 #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h" | |
19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/base/testing_pref_service_syncable.h" | |
21 #include "chromeos/attestation/mock_attestation_flow.h" | 19 #include "chromeos/attestation/mock_attestation_flow.h" |
22 #include "chromeos/cryptohome/mock_async_method_caller.h" | 20 #include "chromeos/cryptohome/mock_async_method_caller.h" |
23 #include "chromeos/dbus/fake_cryptohome_client.h" | 21 #include "chromeos/dbus/fake_cryptohome_client.h" |
24 #include "chromeos/settings/cros_settings_names.h" | 22 #include "chromeos/settings/cros_settings_names.h" |
25 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
26 #include "components/content_settings/core/common/content_settings_pattern.h" | |
27 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
29 | 25 |
30 using testing::_; | 26 using testing::_; |
31 using testing::DoAll; | 27 using testing::DoAll; |
32 using testing::Invoke; | 28 using testing::Invoke; |
33 using testing::Return; | 29 using testing::Return; |
34 using testing::SetArgumentPointee; | 30 using testing::SetArgumentPointee; |
35 using testing::StrictMock; | 31 using testing::StrictMock; |
36 using testing::WithArgs; | 32 using testing::WithArgs; |
37 | 33 |
38 namespace chromeos { | 34 namespace chromeos { |
39 namespace attestation { | 35 namespace attestation { |
40 | 36 |
41 namespace { | 37 namespace { |
42 | 38 |
43 const char kTestID[] = "test_id"; | 39 const char kTestID[] = "test_id"; |
44 const char kTestChallenge[] = "test_challenge"; | 40 const char kTestChallenge[] = "test_challenge"; |
45 const char kTestSignedData[] = "test_challenge_with_salt"; | 41 const char kTestSignedData[] = "test_challenge_with_salt"; |
46 const char kTestSignature[] = "test_signature"; | 42 const char kTestSignature[] = "test_signature"; |
47 const char kTestCertificate[] = "test_certificate"; | 43 const char kTestCertificate[] = "test_certificate"; |
48 const char kTestEmail[] = "test_email@chromium.org"; | 44 const char kTestEmail[] = "test_email@chromium.org"; |
49 const char kTestURL[] = "http://mytestdomain/test"; | 45 const char kTestURL[] = "http://mytestdomain/test"; |
50 const char kTestURLSecure[] = "https://mytestdomain/test"; | |
51 const char kTestURLExtension[] = "chrome-extension://mytestextension"; | |
52 | 46 |
53 class FakeDelegate : public PlatformVerificationFlow::Delegate { | 47 class FakeDelegate : public PlatformVerificationFlow::Delegate { |
54 public: | 48 public: |
55 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW), | 49 FakeDelegate() |
56 num_consent_calls_(0), | 50 : url_(kTestURL), is_permitted_by_user_(true), is_incognito_(false) { |
57 url_(kTestURL), | |
58 is_incognito_(false) { | |
59 // Configure a user for the mock user manager. | 51 // Configure a user for the mock user manager. |
60 mock_user_manager_.SetActiveUser(kTestEmail); | 52 mock_user_manager_.SetActiveUser(kTestEmail); |
61 } | 53 } |
62 ~FakeDelegate() override {} | 54 ~FakeDelegate() override {} |
63 | 55 |
64 void SetUp() { | |
65 ProfileImpl::RegisterProfilePrefs(pref_service_.registry()); | |
66 chrome::DeviceIDFetcher::RegisterProfilePrefs(pref_service_.registry()); | |
67 PlatformVerificationFlow::RegisterProfilePrefs(pref_service_.registry()); | |
68 HostContentSettingsMap::RegisterProfilePrefs(pref_service_.registry()); | |
69 content_settings_ = new HostContentSettingsMap(&pref_service_, false); | |
70 } | |
71 | |
72 void TearDown() { | |
73 content_settings_->ShutdownOnUIThread(); | |
74 } | |
75 | |
76 void ShowConsentPrompt( | |
77 content::WebContents* web_contents, | |
78 const GURL& requesting_origin, | |
79 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) | |
80 override { | |
81 num_consent_calls_++; | |
82 callback.Run(response_); | |
83 } | |
84 | |
85 PrefService* GetPrefs(content::WebContents* web_contents) override { | |
86 return &pref_service_; | |
87 } | |
88 | |
89 const GURL& GetURL(content::WebContents* web_contents) override { | 56 const GURL& GetURL(content::WebContents* web_contents) override { |
90 return url_; | 57 return url_; |
91 } | 58 } |
92 | 59 |
93 user_manager::User* GetUser(content::WebContents* web_contents) override { | 60 user_manager::User* GetUser(content::WebContents* web_contents) override { |
94 return mock_user_manager_.GetActiveUser(); | 61 return mock_user_manager_.GetActiveUser(); |
95 } | 62 } |
96 | 63 |
97 HostContentSettingsMap* GetContentSettings( | 64 bool IsPermittedByUser(content::WebContents* web_contents) override { |
98 content::WebContents* web_contents) override { | 65 return is_permitted_by_user_; |
99 return content_settings_.get(); | |
100 } | 66 } |
101 | 67 |
102 bool IsGuestOrIncognito(content::WebContents* web_contents) override { | 68 bool IsGuestOrIncognito(content::WebContents* web_contents) override { |
103 return is_incognito_; | 69 return is_incognito_; |
104 } | 70 } |
105 | 71 |
106 void set_response(PlatformVerificationFlow::ConsentResponse response) { | 72 void set_url(const GURL& url) { |
107 response_ = response; | 73 url_ = url; |
108 } | 74 } |
109 | 75 |
110 int num_consent_calls() { | 76 void set_is_permitted_by_user(bool is_permitted_by_user) { |
111 return num_consent_calls_; | 77 is_permitted_by_user_ = is_permitted_by_user; |
112 } | |
113 | |
114 TestingPrefServiceSyncable& pref_service() { | |
115 return pref_service_; | |
116 } | |
117 | |
118 void set_url(const GURL& url) { | |
119 url_ = url; | |
120 } | 78 } |
121 | 79 |
122 void set_is_incognito(bool is_incognito) { | 80 void set_is_incognito(bool is_incognito) { |
123 is_incognito_ = is_incognito; | 81 is_incognito_ = is_incognito; |
124 } | 82 } |
125 | 83 |
126 private: | 84 private: |
127 PlatformVerificationFlow::ConsentResponse response_; | |
128 int num_consent_calls_; | |
129 TestingPrefServiceSyncable pref_service_; | |
130 MockUserManager mock_user_manager_; | 85 MockUserManager mock_user_manager_; |
131 GURL url_; | 86 GURL url_; |
132 scoped_refptr<HostContentSettingsMap> content_settings_; | 87 bool is_permitted_by_user_; |
133 bool is_incognito_; | 88 bool is_incognito_; |
134 | 89 |
135 DISALLOW_COPY_AND_ASSIGN(FakeDelegate); | 90 DISALLOW_COPY_AND_ASSIGN(FakeDelegate); |
136 }; | 91 }; |
137 | 92 |
138 class CustomFakeCryptohomeClient : public FakeCryptohomeClient { | 93 class CustomFakeCryptohomeClient : public FakeCryptohomeClient { |
139 public: | 94 public: |
140 CustomFakeCryptohomeClient() : call_status_(DBUS_METHOD_CALL_SUCCESS), | 95 CustomFakeCryptohomeClient() : call_status_(DBUS_METHOD_CALL_SUCCESS), |
141 attestation_enrolled_(true), | 96 attestation_enrolled_(true), |
142 attestation_prepared_(true) {} | 97 attestation_prepared_(true) {} |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 class PlatformVerificationFlowTest : public ::testing::Test { | 134 class PlatformVerificationFlowTest : public ::testing::Test { |
180 public: | 135 public: |
181 PlatformVerificationFlowTest() | 136 PlatformVerificationFlowTest() |
182 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 137 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
183 certificate_success_(true), | 138 certificate_success_(true), |
184 fake_certificate_index_(0), | 139 fake_certificate_index_(0), |
185 sign_challenge_success_(true), | 140 sign_challenge_success_(true), |
186 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} | 141 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} |
187 | 142 |
188 void SetUp() { | 143 void SetUp() { |
189 fake_delegate_.SetUp(); | |
190 | |
191 // Create a verifier for tests to call. | 144 // Create a verifier for tests to call. |
192 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, | 145 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, |
193 &mock_async_caller_, | 146 &mock_async_caller_, |
194 &fake_cryptohome_client_, | 147 &fake_cryptohome_client_, |
195 &fake_delegate_); | 148 &fake_delegate_); |
196 | 149 |
197 // Create callbacks for tests to use with verifier_. | 150 // Create callbacks for tests to use with verifier_. |
198 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, | 151 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, |
199 base::Unretained(this)); | 152 base::Unretained(this)); |
200 | 153 |
201 // Configure the global cros_settings. | 154 // Configure the global cros_settings. |
202 CrosSettings* cros_settings = CrosSettings::Get(); | 155 CrosSettings* cros_settings = CrosSettings::Get(); |
203 device_settings_provider_ = | 156 device_settings_provider_ = |
204 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); | 157 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); |
205 cros_settings->RemoveSettingsProvider(device_settings_provider_); | 158 cros_settings->RemoveSettingsProvider(device_settings_provider_); |
206 cros_settings->AddSettingsProvider(&stub_settings_provider_); | 159 cros_settings->AddSettingsProvider(&stub_settings_provider_); |
207 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); | 160 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); |
208 | |
209 // Start with the first-time setting set since most tests want this. | |
210 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentGranted, | |
211 new base::FundamentalValue(true)); | |
212 } | 161 } |
213 | 162 |
214 void TearDown() { | 163 void TearDown() { |
215 // Restore the real DeviceSettingsProvider. | 164 // Restore the real DeviceSettingsProvider. |
216 CrosSettings* cros_settings = CrosSettings::Get(); | 165 CrosSettings* cros_settings = CrosSettings::Get(); |
217 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); | 166 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); |
218 cros_settings->AddSettingsProvider(device_settings_provider_); | 167 cros_settings->AddSettingsProvider(device_settings_provider_); |
219 fake_delegate_.TearDown(); | |
220 } | 168 } |
221 | 169 |
222 void ExpectAttestationFlow() { | 170 void ExpectAttestationFlow() { |
223 // When consent is not given or the feature is disabled, it is important | 171 // When consent is not given or the feature is disabled, it is important |
224 // that there are no calls to the attestation service. Thus, a test must | 172 // that there are no calls to the attestation service. Thus, a test must |
225 // explicitly expect these calls or the mocks will fail the test. | 173 // explicitly expect these calls or the mocks will fail the test. |
226 | 174 |
227 // Configure the mock AttestationFlow to call FakeGetCertificate. | 175 // Configure the mock AttestationFlow to call FakeGetCertificate. |
228 EXPECT_CALL(mock_attestation_flow_, | 176 EXPECT_CALL(mock_attestation_flow_, |
229 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, | 177 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, |
230 kTestEmail, kTestID, _, _)) | 178 kTestEmail, kTestID, _, _)) |
231 .WillRepeatedly(WithArgs<4>(Invoke( | 179 .WillRepeatedly(WithArgs<4>(Invoke( |
232 this, &PlatformVerificationFlowTest::FakeGetCertificate))); | 180 this, &PlatformVerificationFlowTest::FakeGetCertificate))); |
233 | 181 |
234 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. | 182 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. |
235 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + | 183 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + |
236 std::string(kTestID); | 184 std::string(kTestID); |
237 EXPECT_CALL(mock_async_caller_, | 185 EXPECT_CALL(mock_async_caller_, |
238 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, | 186 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, |
239 expected_key_name, | 187 expected_key_name, |
240 kTestChallenge, _)) | 188 kTestChallenge, _)) |
241 .WillRepeatedly(WithArgs<4>(Invoke( | 189 .WillRepeatedly(WithArgs<4>(Invoke( |
242 this, &PlatformVerificationFlowTest::FakeSignChallenge))); | 190 this, &PlatformVerificationFlowTest::FakeSignChallenge))); |
243 } | 191 } |
244 | 192 |
245 void SetUserConsent(const GURL& url, bool allow) { | |
246 verifier_->RecordOriginConsent(fake_delegate_.GetContentSettings(NULL), url, | |
247 allow); | |
248 } | |
249 | |
250 void FakeGetCertificate( | 193 void FakeGetCertificate( |
251 const AttestationFlow::CertificateCallback& callback) { | 194 const AttestationFlow::CertificateCallback& callback) { |
252 std::string certificate = | 195 std::string certificate = |
253 (fake_certificate_index_ < fake_certificate_list_.size()) ? | 196 (fake_certificate_index_ < fake_certificate_list_.size()) ? |
254 fake_certificate_list_[fake_certificate_index_] : kTestCertificate; | 197 fake_certificate_list_[fake_certificate_index_] : kTestCertificate; |
255 base::MessageLoop::current()->PostTask(FROM_HERE, | 198 base::MessageLoop::current()->PostTask(FROM_HERE, |
256 base::Bind(callback, | 199 base::Bind(callback, |
257 certificate_success_, | 200 certificate_success_, |
258 certificate)); | 201 certificate)); |
259 ++fake_certificate_index_; | 202 ++fake_certificate_index_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 bool sign_challenge_success_; | 252 bool sign_challenge_success_; |
310 | 253 |
311 // Callback functions and data. | 254 // Callback functions and data. |
312 PlatformVerificationFlow::ChallengeCallback callback_; | 255 PlatformVerificationFlow::ChallengeCallback callback_; |
313 PlatformVerificationFlow::Result result_; | 256 PlatformVerificationFlow::Result result_; |
314 std::string challenge_salt_; | 257 std::string challenge_salt_; |
315 std::string challenge_signature_; | 258 std::string challenge_signature_; |
316 std::string certificate_; | 259 std::string certificate_; |
317 }; | 260 }; |
318 | 261 |
319 TEST_F(PlatformVerificationFlowTest, SuccessNoConsent) { | 262 TEST_F(PlatformVerificationFlowTest, Success) { |
320 SetUserConsent(GURL(kTestURL), true); | |
321 // Make sure the call will fail if consent is requested. | |
322 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | |
323 ExpectAttestationFlow(); | 263 ExpectAttestationFlow(); |
324 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 264 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
325 base::RunLoop().RunUntilIdle(); | 265 base::RunLoop().RunUntilIdle(); |
326 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | |
327 EXPECT_EQ(kTestSignedData, challenge_salt_); | |
328 EXPECT_EQ(kTestSignature, challenge_signature_); | |
329 EXPECT_EQ(kTestCertificate, certificate_); | |
330 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | |
331 } | |
332 | |
333 TEST_F(PlatformVerificationFlowTest, SuccessWithConsent) { | |
334 SetUserConsent(GURL(kTestURL), true); | |
335 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentGranted, | |
336 new base::FundamentalValue(false)); | |
337 ExpectAttestationFlow(); | |
338 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
339 base::RunLoop().RunUntilIdle(); | |
340 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 266 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
341 EXPECT_EQ(kTestSignedData, challenge_salt_); | 267 EXPECT_EQ(kTestSignedData, challenge_salt_); |
342 EXPECT_EQ(kTestSignature, challenge_signature_); | 268 EXPECT_EQ(kTestSignature, challenge_signature_); |
343 EXPECT_EQ(kTestCertificate, certificate_); | 269 EXPECT_EQ(kTestCertificate, certificate_); |
344 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | |
345 } | 270 } |
346 | 271 |
347 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { | 272 TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) { |
348 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | 273 fake_delegate_.set_is_permitted_by_user(false); |
349 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 274 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
350 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
351 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 276 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
352 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | |
353 } | 277 } |
354 | 278 |
355 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { | 279 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) { |
356 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, | 280 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, |
357 false); | 281 false); |
358 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 282 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
359 base::RunLoop().RunUntilIdle(); | 283 base::RunLoop().RunUntilIdle(); |
360 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | 284 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); |
361 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | |
362 } | |
363 | |
364 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { | |
365 fake_delegate_.pref_service().SetUserPref(prefs::kEnableDRM, | |
366 new base::FundamentalValue(false)); | |
367 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
368 base::RunLoop().RunUntilIdle(); | |
369 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | |
370 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | |
371 } | |
372 | |
373 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { | |
374 SetUserConsent(GURL(kTestURL), false); | |
375 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
376 base::RunLoop().RunUntilIdle(); | |
377 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | |
378 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); | |
379 } | 285 } |
380 | 286 |
381 TEST_F(PlatformVerificationFlowTest, NotVerified) { | 287 TEST_F(PlatformVerificationFlowTest, NotVerified) { |
382 certificate_success_ = false; | 288 certificate_success_ = false; |
383 ExpectAttestationFlow(); | 289 ExpectAttestationFlow(); |
384 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 290 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
385 base::RunLoop().RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
386 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); | 292 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); |
387 } | 293 } |
388 | 294 |
389 TEST_F(PlatformVerificationFlowTest, ChallengeSigningError) { | 295 TEST_F(PlatformVerificationFlowTest, ChallengeSigningError) { |
390 sign_challenge_success_ = false; | 296 sign_challenge_success_ = false; |
391 ExpectAttestationFlow(); | 297 ExpectAttestationFlow(); |
392 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 298 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
393 base::RunLoop().RunUntilIdle(); | 299 base::RunLoop().RunUntilIdle(); |
394 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); | 300 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); |
395 } | 301 } |
396 | 302 |
397 TEST_F(PlatformVerificationFlowTest, DBusFailure) { | 303 TEST_F(PlatformVerificationFlowTest, DBusFailure) { |
398 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); | 304 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); |
399 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 305 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
400 base::RunLoop().RunUntilIdle(); | 306 base::RunLoop().RunUntilIdle(); |
401 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); | 307 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); |
402 } | 308 } |
403 | 309 |
404 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { | |
405 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); | |
406 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
407 base::RunLoop().RunUntilIdle(); | |
408 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | |
409 } | |
410 | |
411 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) { | |
412 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | |
413 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
414 base::RunLoop().RunUntilIdle(); | |
415 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | |
416 // Call again and expect denial based on previous response. | |
417 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
418 base::RunLoop().RunUntilIdle(); | |
419 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); | |
420 // Call with a different scheme and expect another consent prompt. | |
421 fake_delegate_.set_url(GURL(kTestURLSecure)); | |
422 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
423 base::RunLoop().RunUntilIdle(); | |
424 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | |
425 EXPECT_EQ(2, fake_delegate_.num_consent_calls()); | |
426 } | |
427 | |
428 TEST_F(PlatformVerificationFlowTest, ConsentForExtension) { | |
429 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | |
430 fake_delegate_.set_url(GURL(kTestURLExtension)); | |
431 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | |
432 base::RunLoop().RunUntilIdle(); | |
433 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | |
434 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); | |
435 } | |
Darren Krahn
2015/03/12 22:12:17
Are the tests removed from here popping up elsewhe
xhwang
2015/03/13 00:54:42
No. The related logic are moved to ProtectedMediaI
| |
436 | |
437 TEST_F(PlatformVerificationFlowTest, Timeout) { | 310 TEST_F(PlatformVerificationFlowTest, Timeout) { |
438 verifier_->set_timeout_delay(base::TimeDelta::FromSeconds(0)); | 311 verifier_->set_timeout_delay(base::TimeDelta::FromSeconds(0)); |
439 ExpectAttestationFlow(); | 312 ExpectAttestationFlow(); |
440 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 313 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
441 base::RunLoop().RunUntilIdle(); | 314 base::RunLoop().RunUntilIdle(); |
442 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_); | 315 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_); |
443 } | 316 } |
444 | 317 |
445 TEST_F(PlatformVerificationFlowTest, ExpiredCert) { | 318 TEST_F(PlatformVerificationFlowTest, ExpiredCert) { |
446 ExpectAttestationFlow(); | 319 ExpectAttestationFlow(); |
447 fake_certificate_list_.resize(2); | 320 fake_certificate_list_.resize(2); |
448 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(-1), | 321 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(-1), |
449 &fake_certificate_list_[0])); | 322 &fake_certificate_list_[0])); |
450 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(1), | 323 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(1), |
451 &fake_certificate_list_[1])); | 324 &fake_certificate_list_[1])); |
452 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 325 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
453 base::RunLoop().RunUntilIdle(); | 326 base::RunLoop().RunUntilIdle(); |
454 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); | 327 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); |
455 EXPECT_EQ(certificate_, fake_certificate_list_[1]); | 328 EXPECT_EQ(certificate_, fake_certificate_list_[1]); |
456 } | 329 } |
457 | 330 |
458 TEST_F(PlatformVerificationFlowTest, IncognitoMode) { | 331 TEST_F(PlatformVerificationFlowTest, IncognitoMode) { |
459 fake_delegate_.set_is_incognito(true); | 332 fake_delegate_.set_is_incognito(true); |
460 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 333 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
461 base::RunLoop().RunUntilIdle(); | 334 base::RunLoop().RunUntilIdle(); |
462 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); | 335 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); |
463 } | 336 } |
464 | 337 |
465 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { | 338 TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { |
466 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); | |
467 fake_cryptohome_client_.set_attestation_enrolled(false); | 339 fake_cryptohome_client_.set_attestation_enrolled(false); |
468 fake_cryptohome_client_.set_attestation_prepared(false); | 340 fake_cryptohome_client_.set_attestation_prepared(false); |
469 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 341 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
470 base::RunLoop().RunUntilIdle(); | 342 base::RunLoop().RunUntilIdle(); |
471 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); | 343 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_); |
472 } | 344 } |
473 | 345 |
474 } // namespace attestation | 346 } // namespace attestation |
475 } // namespace chromeos | 347 } // namespace chromeos |
OLD | NEW |