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

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

Issue 106373003: Restructured PlatformVerificationFlow testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/attestation/platform_verification_flow.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h"
11 #include "base/run_loop.h" 9 #include "base/run_loop.h"
12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" 10 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h"
13 #include "chrome/browser/chromeos/attestation/fake_certificate.h" 11 #include "chrome/browser/chromeos/attestation/fake_certificate.h"
14 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" 12 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h"
15 #include "chrome/browser/chromeos/login/mock_user_manager.h" 13 #include "chrome/browser/chromeos/login/mock_user_manager.h"
16 #include "chrome/browser/chromeos/settings/cros_settings.h" 14 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h" 15 #include "chrome/browser/chromeos/settings/device_settings_service.h"
18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
19 #include "chrome/browser/content_settings/host_content_settings_map.h" 17 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/profiles/profile_impl.h"
19 #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
20 #include "chrome/common/content_settings_pattern.h" 20 #include "chrome/common/content_settings_pattern.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_pref_service_syncable.h"
22 #include "chromeos/attestation/mock_attestation_flow.h" 23 #include "chromeos/attestation/mock_attestation_flow.h"
23 #include "chromeos/cryptohome/mock_async_method_caller.h" 24 #include "chromeos/cryptohome/mock_async_method_caller.h"
24 #include "chromeos/dbus/fake_cryptohome_client.h" 25 #include "chromeos/dbus/fake_cryptohome_client.h"
25 #include "chromeos/settings/cros_settings_names.h" 26 #include "chromeos/settings/cros_settings_names.h"
26 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 using testing::_; 30 using testing::_;
30 using testing::DoAll; 31 using testing::DoAll;
31 using testing::Invoke; 32 using testing::Invoke;
(...skipping 12 matching lines...) Expand all
44 const char kTestSignedData[] = "test_challenge_with_salt"; 45 const char kTestSignedData[] = "test_challenge_with_salt";
45 const char kTestSignature[] = "test_signature"; 46 const char kTestSignature[] = "test_signature";
46 const char kTestCertificate[] = "test_certificate"; 47 const char kTestCertificate[] = "test_certificate";
47 const char kTestEmail[] = "test_email@chromium.org"; 48 const char kTestEmail[] = "test_email@chromium.org";
48 const char kTestURL[] = "http://mytestdomain/test"; 49 const char kTestURL[] = "http://mytestdomain/test";
49 const char kTestURLSecure[] = "https://mytestdomain/test"; 50 const char kTestURLSecure[] = "https://mytestdomain/test";
50 51
51 class FakeDelegate : public PlatformVerificationFlow::Delegate { 52 class FakeDelegate : public PlatformVerificationFlow::Delegate {
52 public: 53 public:
53 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW), 54 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW),
54 num_consent_calls_(0) {} 55 num_consent_calls_(0),
56 url_(kTestURL),
57 is_incognito_(false) {
58 // Configure a user for the mock user manager.
59 mock_user_manager_.SetActiveUser(kTestEmail);
60 }
55 virtual ~FakeDelegate() {} 61 virtual ~FakeDelegate() {}
56 62
63 void SetUp() {
64 ProfileImpl::RegisterProfilePrefs(pref_service_.registry());
65 chrome::DeviceIDFetcher::RegisterProfilePrefs(pref_service_.registry());
66 PlatformVerificationFlow::RegisterProfilePrefs(pref_service_.registry());
67 HostContentSettingsMap::RegisterProfilePrefs(pref_service_.registry());
68 content_settings_ = new HostContentSettingsMap(&pref_service_, false);
69 }
70
71 void TearDown() {
72 content_settings_->ShutdownOnUIThread();
73 }
74
57 virtual void ShowConsentPrompt( 75 virtual void ShowConsentPrompt(
58 content::WebContents* web_contents, 76 content::WebContents* web_contents,
59 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) 77 const PlatformVerificationFlow::Delegate::ConsentCallback& callback)
60 OVERRIDE { 78 OVERRIDE {
61 num_consent_calls_++; 79 num_consent_calls_++;
62 callback.Run(response_); 80 callback.Run(response_);
63 } 81 }
64 82
83 virtual PrefService* GetPrefs(content::WebContents* web_contents) OVERRIDE {
84 return &pref_service_;
85 }
86
87 virtual const GURL& GetURL(content::WebContents* web_contents) OVERRIDE {
88 return url_;
89 }
90
91 virtual User* GetUser(content::WebContents* web_contents) OVERRIDE {
92 return mock_user_manager_.GetActiveUser();
93 }
94
95 virtual HostContentSettingsMap* GetContentSettings(
96 content::WebContents* web_contents) OVERRIDE {
97 return content_settings_;
98 }
99
100 virtual bool IsGuestOrIncognito(content::WebContents* web_contents) OVERRIDE {
101 return is_incognito_;
102 }
103
65 void set_response(PlatformVerificationFlow::ConsentResponse response) { 104 void set_response(PlatformVerificationFlow::ConsentResponse response) {
66 response_ = response; 105 response_ = response;
67 } 106 }
68 107
69 int num_consent_calls() { 108 int num_consent_calls() {
70 return num_consent_calls_; 109 return num_consent_calls_;
71 } 110 }
72 111
112 TestingPrefServiceSyncable& pref_service() {
113 return pref_service_;
114 }
115
116 void set_url(const GURL& url) {
117 url_ = url;
118 }
119
120 void set_is_incognito(bool is_incognito) {
121 is_incognito_ = is_incognito;
122 }
123
73 private: 124 private:
74 PlatformVerificationFlow::ConsentResponse response_; 125 PlatformVerificationFlow::ConsentResponse response_;
75 int num_consent_calls_; 126 int num_consent_calls_;
127 TestingPrefServiceSyncable pref_service_;
128 MockUserManager mock_user_manager_;
129 GURL url_;
130 scoped_refptr<HostContentSettingsMap> content_settings_;
131 bool is_incognito_;
76 132
77 DISALLOW_COPY_AND_ASSIGN(FakeDelegate); 133 DISALLOW_COPY_AND_ASSIGN(FakeDelegate);
78 }; 134 };
79 135
80 class CustomFakeCryptohomeClient : public FakeCryptohomeClient { 136 class CustomFakeCryptohomeClient : public FakeCryptohomeClient {
81 public: 137 public:
82 CustomFakeCryptohomeClient() : call_status_(DBUS_METHOD_CALL_SUCCESS), 138 CustomFakeCryptohomeClient() : call_status_(DBUS_METHOD_CALL_SUCCESS),
83 attestation_enrolled_(true), 139 attestation_enrolled_(true),
84 attestation_prepared_(true) {} 140 attestation_prepared_(true) {}
85 virtual void TpmAttestationIsEnrolled( 141 virtual void TpmAttestationIsEnrolled(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 public: 178 public:
123 PlatformVerificationFlowTest() 179 PlatformVerificationFlowTest()
124 : message_loop_(base::MessageLoop::TYPE_UI), 180 : message_loop_(base::MessageLoop::TYPE_UI),
125 ui_thread_(content::BrowserThread::UI, &message_loop_), 181 ui_thread_(content::BrowserThread::UI, &message_loop_),
126 certificate_success_(true), 182 certificate_success_(true),
127 fake_certificate_index_(0), 183 fake_certificate_index_(0),
128 sign_challenge_success_(true), 184 sign_challenge_success_(true),
129 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} 185 result_(PlatformVerificationFlow::INTERNAL_ERROR) {}
130 186
131 void SetUp() { 187 void SetUp() {
132 // Configure a user for the mock user manager. 188 fake_delegate_.SetUp();
133 mock_user_manager_.SetActiveUser(kTestEmail);
134 189
135 // Create a verifier for tests to call. 190 // Create a verifier for tests to call.
136 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, 191 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_,
137 &mock_async_caller_, 192 &mock_async_caller_,
138 &fake_cryptohome_client_, 193 &fake_cryptohome_client_,
139 &mock_user_manager_,
140 &fake_delegate_); 194 &fake_delegate_);
141 195
142 // Create callbacks for tests to use with verifier_. 196 // Create callbacks for tests to use with verifier_.
143 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, 197 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback,
144 base::Unretained(this)); 198 base::Unretained(this));
145 199
146 // Configure the test pref service.
147 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true);
148 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime,
149 true);
150 RegisterHostContentSettingsPrefs(pref_service_.registry());
151 verifier_->set_testing_prefs(&pref_service_);
152 test_content_settings_ = new HostContentSettingsMap(&pref_service_, false);
153 verifier_->set_testing_content_settings(test_content_settings_);
154
155 // Configure the global cros_settings. 200 // Configure the global cros_settings.
156 CrosSettings* cros_settings = CrosSettings::Get(); 201 CrosSettings* cros_settings = CrosSettings::Get();
157 device_settings_provider_ = 202 device_settings_provider_ =
158 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); 203 cros_settings->GetProvider(kAttestationForContentProtectionEnabled);
159 cros_settings->RemoveSettingsProvider(device_settings_provider_); 204 cros_settings->RemoveSettingsProvider(device_settings_provider_);
160 cros_settings->AddSettingsProvider(&stub_settings_provider_); 205 cros_settings->AddSettingsProvider(&stub_settings_provider_);
161 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); 206 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true);
162 207
163 // Configure a test URL to shortcut the dependency on WebContents. 208 // Start with the first-time setting set since most tests want this.
164 verifier_->set_testing_url(GURL(kTestURL)); 209 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentFirstTime,
165 } 210 new base::FundamentalValue(true));
166 211
167 void RegisterHostContentSettingsPrefs(PrefRegistrySimple* registry) {
168 registry->RegisterIntegerPref(
169 prefs::kContentSettingsWindowLastTabIndex,
170 0);
171 registry->RegisterIntegerPref(
172 prefs::kContentSettingsDefaultWhitelistVersion,
173 0);
174 registry->RegisterBooleanPref(
175 prefs::kContentSettingsClearOnExitMigrated,
176 false);
177 DictionaryValue* default_content_settings = new DictionaryValue();
178 registry->RegisterDictionaryPref(
179 prefs::kDefaultContentSettings,
180 default_content_settings);
181 registry->RegisterIntegerPref(
182 prefs::kContentSettingsVersion,
183 ContentSettingsPattern::kContentSettingsPatternVersion);
184 registry->RegisterDictionaryPref(
185 prefs::kContentSettingsPatternPairs);
186 registry->RegisterListPref(prefs::kManagedAutoSelectCertificateForUrls);
187 registry->RegisterListPref(prefs::kManagedCookiesAllowedForUrls);
188 registry->RegisterListPref(prefs::kManagedCookiesBlockedForUrls);
189 registry->RegisterListPref(prefs::kManagedCookiesSessionOnlyForUrls);
190 registry->RegisterListPref(prefs::kManagedImagesAllowedForUrls);
191 registry->RegisterListPref(prefs::kManagedImagesBlockedForUrls);
192 registry->RegisterListPref(prefs::kManagedJavaScriptAllowedForUrls);
193 registry->RegisterListPref(prefs::kManagedJavaScriptBlockedForUrls);
194 registry->RegisterListPref(prefs::kManagedPluginsAllowedForUrls);
195 registry->RegisterListPref(prefs::kManagedPluginsBlockedForUrls);
196 registry->RegisterListPref(prefs::kManagedPopupsAllowedForUrls);
197 registry->RegisterListPref(prefs::kManagedPopupsBlockedForUrls);
198 registry->RegisterListPref(prefs::kManagedNotificationsAllowedForUrls);
199 registry->RegisterListPref(prefs::kManagedNotificationsBlockedForUrls);
200 registry->RegisterIntegerPref(
201 prefs::kManagedDefaultCookiesSetting,
202 CONTENT_SETTING_DEFAULT);
203 registry->RegisterIntegerPref(
204 prefs::kManagedDefaultImagesSetting,
205 CONTENT_SETTING_DEFAULT);
206 registry->RegisterIntegerPref(
207 prefs::kManagedDefaultJavaScriptSetting,
208 CONTENT_SETTING_DEFAULT);
209 registry->RegisterIntegerPref(
210 prefs::kManagedDefaultPluginsSetting,
211 CONTENT_SETTING_DEFAULT);
212 registry->RegisterIntegerPref(
213 prefs::kManagedDefaultPopupsSetting,
214 CONTENT_SETTING_DEFAULT);
215 registry->RegisterIntegerPref(
216 prefs::kManagedDefaultGeolocationSetting,
217 CONTENT_SETTING_DEFAULT);
218 registry->RegisterIntegerPref(
219 prefs::kManagedDefaultNotificationsSetting,
220 CONTENT_SETTING_DEFAULT);
221 registry->RegisterIntegerPref(
222 prefs::kManagedDefaultMediaStreamSetting,
223 CONTENT_SETTING_DEFAULT);
224 registry->RegisterBooleanPref(
225 prefs::kClearSiteDataOnExit,
226 false);
227 } 212 }
228 213
229 void TearDown() { 214 void TearDown() {
230 // Restore the real DeviceSettingsProvider. 215 // Restore the real DeviceSettingsProvider.
231 CrosSettings* cros_settings = CrosSettings::Get(); 216 CrosSettings* cros_settings = CrosSettings::Get();
232 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); 217 cros_settings->RemoveSettingsProvider(&stub_settings_provider_);
233 cros_settings->AddSettingsProvider(device_settings_provider_); 218 cros_settings->AddSettingsProvider(device_settings_provider_);
234 test_content_settings_->ShutdownOnUIThread(); 219 fake_delegate_.TearDown();
235 } 220 }
236 221
237 void ExpectAttestationFlow() { 222 void ExpectAttestationFlow() {
238 // When consent is not given or the feature is disabled, it is important 223 // When consent is not given or the feature is disabled, it is important
239 // that there are no calls to the attestation service. Thus, a test must 224 // that there are no calls to the attestation service. Thus, a test must
240 // explicitly expect these calls or the mocks will fail the test. 225 // explicitly expect these calls or the mocks will fail the test.
241 226
242 // Configure the mock AttestationFlow to call FakeGetCertificate. 227 // Configure the mock AttestationFlow to call FakeGetCertificate.
243 EXPECT_CALL(mock_attestation_flow_, 228 EXPECT_CALL(mock_attestation_flow_,
244 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, 229 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE,
245 kTestEmail, kTestID, _, _)) 230 kTestEmail, kTestID, _, _))
246 .WillRepeatedly(WithArgs<4>(Invoke( 231 .WillRepeatedly(WithArgs<4>(Invoke(
247 this, &PlatformVerificationFlowTest::FakeGetCertificate))); 232 this, &PlatformVerificationFlowTest::FakeGetCertificate)));
248 233
249 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. 234 // Configure the mock AsyncMethodCaller to call FakeSignChallenge.
250 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + 235 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) +
251 std::string(kTestID); 236 std::string(kTestID);
252 EXPECT_CALL(mock_async_caller_, 237 EXPECT_CALL(mock_async_caller_,
253 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, 238 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail,
254 expected_key_name, 239 expected_key_name,
255 kTestChallenge, _)) 240 kTestChallenge, _))
256 .WillRepeatedly(WithArgs<4>(Invoke( 241 .WillRepeatedly(WithArgs<4>(Invoke(
257 this, &PlatformVerificationFlowTest::FakeSignChallenge))); 242 this, &PlatformVerificationFlowTest::FakeSignChallenge)));
258 } 243 }
259 244
260 void SetUserConsent(const GURL& url, bool allow) { 245 void SetUserConsent(const GURL& url, bool allow) {
261 verifier_->RecordDomainConsent(test_content_settings_, url, allow); 246 verifier_->RecordDomainConsent(fake_delegate_.GetContentSettings(NULL),
262 } 247 url,
263 248 allow);
264 void SetURL(const GURL& url) {
265 verifier_->set_testing_url(url);
266 } 249 }
267 250
268 void FakeGetCertificate( 251 void FakeGetCertificate(
269 const AttestationFlow::CertificateCallback& callback) { 252 const AttestationFlow::CertificateCallback& callback) {
270 std::string certificate = 253 std::string certificate =
271 (fake_certificate_index_ < fake_certificate_list_.size()) ? 254 (fake_certificate_index_ < fake_certificate_list_.size()) ?
272 fake_certificate_list_[fake_certificate_index_] : kTestCertificate; 255 fake_certificate_list_[fake_certificate_index_] : kTestCertificate;
273 base::MessageLoop::current()->PostTask(FROM_HERE, 256 base::MessageLoop::current()->PostTask(FROM_HERE,
274 base::Bind(callback, 257 base::Bind(callback,
275 certificate_success_, 258 certificate_success_,
(...skipping 28 matching lines...) Expand all
304 CHECK(pb.SerializeToString(&serial)); 287 CHECK(pb.SerializeToString(&serial));
305 return serial; 288 return serial;
306 } 289 }
307 290
308 protected: 291 protected:
309 base::MessageLoop message_loop_; 292 base::MessageLoop message_loop_;
310 content::TestBrowserThread ui_thread_; 293 content::TestBrowserThread ui_thread_;
311 StrictMock<MockAttestationFlow> mock_attestation_flow_; 294 StrictMock<MockAttestationFlow> mock_attestation_flow_;
312 cryptohome::MockAsyncMethodCaller mock_async_caller_; 295 cryptohome::MockAsyncMethodCaller mock_async_caller_;
313 CustomFakeCryptohomeClient fake_cryptohome_client_; 296 CustomFakeCryptohomeClient fake_cryptohome_client_;
314 MockUserManager mock_user_manager_;
315 FakeDelegate fake_delegate_; 297 FakeDelegate fake_delegate_;
316 TestingPrefServiceSimple pref_service_;
317 CrosSettingsProvider* device_settings_provider_; 298 CrosSettingsProvider* device_settings_provider_;
318 StubCrosSettingsProvider stub_settings_provider_; 299 StubCrosSettingsProvider stub_settings_provider_;
319 ScopedTestDeviceSettingsService test_device_settings_service_; 300 ScopedTestDeviceSettingsService test_device_settings_service_;
320 ScopedTestCrosSettings test_cros_settings_; 301 ScopedTestCrosSettings test_cros_settings_;
321 scoped_refptr<HostContentSettingsMap> test_content_settings_;
322 scoped_refptr<PlatformVerificationFlow> verifier_; 302 scoped_refptr<PlatformVerificationFlow> verifier_;
323 303
324 // Controls result of FakeGetCertificate. 304 // Controls result of FakeGetCertificate.
325 bool certificate_success_; 305 bool certificate_success_;
326 std::vector<std::string> fake_certificate_list_; 306 std::vector<std::string> fake_certificate_list_;
327 size_t fake_certificate_index_; 307 size_t fake_certificate_index_;
328 308
329 // Controls result of FakeSignChallenge. 309 // Controls result of FakeSignChallenge.
330 bool sign_challenge_success_; 310 bool sign_challenge_success_;
331 311
(...skipping 27 matching lines...) Expand all
359 base::RunLoop().RunUntilIdle(); 339 base::RunLoop().RunUntilIdle();
360 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 340 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
361 EXPECT_EQ(kTestSignedData, challenge_salt_); 341 EXPECT_EQ(kTestSignedData, challenge_salt_);
362 EXPECT_EQ(kTestSignature, challenge_signature_); 342 EXPECT_EQ(kTestSignature, challenge_signature_);
363 EXPECT_EQ(kTestCertificate, certificate_); 343 EXPECT_EQ(kTestCertificate, certificate_);
364 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 344 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
365 } 345 }
366 346
367 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) { 347 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) {
368 SetUserConsent(GURL(kTestURL), true); 348 SetUserConsent(GURL(kTestURL), true);
369 pref_service_.SetUserPref(prefs::kRAConsentFirstTime, 349 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentFirstTime,
370 new base::FundamentalValue(false)); 350 new base::FundamentalValue(false));
371 ExpectAttestationFlow(); 351 ExpectAttestationFlow();
372 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 352 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
373 base::RunLoop().RunUntilIdle(); 353 base::RunLoop().RunUntilIdle();
374 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 354 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
375 EXPECT_EQ(kTestSignedData, challenge_salt_); 355 EXPECT_EQ(kTestSignedData, challenge_salt_);
376 EXPECT_EQ(kTestSignature, challenge_signature_); 356 EXPECT_EQ(kTestSignature, challenge_signature_);
377 EXPECT_EQ(kTestCertificate, certificate_); 357 EXPECT_EQ(kTestCertificate, certificate_);
378 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 358 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
379 } 359 }
380 360
381 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { 361 TEST_F(PlatformVerificationFlowTest, ConsentRejected) {
382 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 362 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
383 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 363 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
384 base::RunLoop().RunUntilIdle(); 364 base::RunLoop().RunUntilIdle();
385 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 365 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
386 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 366 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
387 } 367 }
388 368
389 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { 369 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) {
390 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, 370 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled,
391 false); 371 false);
392 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 372 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
393 base::RunLoop().RunUntilIdle(); 373 base::RunLoop().RunUntilIdle();
394 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 374 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
395 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 375 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
396 } 376 }
397 377
398 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { 378 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) {
399 pref_service_.SetUserPref(prefs::kEnableDRM, 379 fake_delegate_.pref_service().SetUserPref(prefs::kEnableDRM,
400 new base::FundamentalValue(false)); 380 new base::FundamentalValue(false));
401 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 381 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
402 base::RunLoop().RunUntilIdle(); 382 base::RunLoop().RunUntilIdle();
403 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 383 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
404 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 384 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
405 } 385 }
406 386
407 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { 387 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) {
408 SetUserConsent(GURL(kTestURL), false); 388 SetUserConsent(GURL(kTestURL), false);
409 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 389 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
410 base::RunLoop().RunUntilIdle(); 390 base::RunLoop().RunUntilIdle();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) { 425 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) {
446 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 426 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
447 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 427 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
448 base::RunLoop().RunUntilIdle(); 428 base::RunLoop().RunUntilIdle();
449 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 429 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
450 // Call again and expect denial based on previous response. 430 // Call again and expect denial based on previous response.
451 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 431 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
452 base::RunLoop().RunUntilIdle(); 432 base::RunLoop().RunUntilIdle();
453 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 433 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
454 // Call with a different scheme and expect another consent prompt. 434 // Call with a different scheme and expect another consent prompt.
455 SetURL(GURL(kTestURLSecure)); 435 fake_delegate_.set_url(GURL(kTestURLSecure));
456 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 436 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
457 base::RunLoop().RunUntilIdle(); 437 base::RunLoop().RunUntilIdle();
458 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 438 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
459 EXPECT_EQ(2, fake_delegate_.num_consent_calls()); 439 EXPECT_EQ(2, fake_delegate_.num_consent_calls());
460 } 440 }
461 441
462 TEST_F(PlatformVerificationFlowTest, Timeout) { 442 TEST_F(PlatformVerificationFlowTest, Timeout) {
463 verifier_->set_timeout_delay(base::TimeDelta::FromSeconds(0)); 443 verifier_->set_timeout_delay(base::TimeDelta::FromSeconds(0));
464 ExpectAttestationFlow(); 444 ExpectAttestationFlow();
465 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 445 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
466 base::RunLoop().RunUntilIdle(); 446 base::RunLoop().RunUntilIdle();
467 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_); 447 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_);
468 } 448 }
469 449
470 TEST_F(PlatformVerificationFlowTest, ExpiredCert) { 450 TEST_F(PlatformVerificationFlowTest, ExpiredCert) {
471 ExpectAttestationFlow(); 451 ExpectAttestationFlow();
472 fake_certificate_list_.resize(2); 452 fake_certificate_list_.resize(2);
473 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(-1), 453 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(-1),
474 &fake_certificate_list_[0])); 454 &fake_certificate_list_[0]));
475 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(1), 455 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(1),
476 &fake_certificate_list_[1])); 456 &fake_certificate_list_[1]));
477 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 457 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
478 base::RunLoop().RunUntilIdle(); 458 base::RunLoop().RunUntilIdle();
479 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 459 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
480 EXPECT_EQ(certificate_, fake_certificate_list_[1]); 460 EXPECT_EQ(certificate_, fake_certificate_list_[1]);
481 } 461 }
482 462
463 TEST_F(PlatformVerificationFlowTest, IncognitoMode) {
464 fake_delegate_.set_is_incognito(true);
465 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
466 base::RunLoop().RunUntilIdle();
467 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_);
468 }
469
483 } // namespace attestation 470 } // namespace attestation
484 } // namespace chromeos 471 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/attestation/platform_verification_flow.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698