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

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" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 30 matching lines...) Expand all
41 41
42 const char kTestID[] = "test_id"; 42 const char kTestID[] = "test_id";
43 const char kTestChallenge[] = "test_challenge"; 43 const char kTestChallenge[] = "test_challenge";
44 const char kTestSignedData[] = "test_challenge_with_salt"; 44 const char kTestSignedData[] = "test_challenge_with_salt";
45 const char kTestSignature[] = "test_signature"; 45 const char kTestSignature[] = "test_signature";
46 const char kTestCertificate[] = "test_certificate"; 46 const char kTestCertificate[] = "test_certificate";
47 const char kTestEmail[] = "test_email@chromium.org"; 47 const char kTestEmail[] = "test_email@chromium.org";
48 const char kTestURL[] = "http://mytestdomain/test"; 48 const char kTestURL[] = "http://mytestdomain/test";
49 const char kTestURLSecure[] = "https://mytestdomain/test"; 49 const char kTestURLSecure[] = "https://mytestdomain/test";
50 50
51 void RegisterHostContentSettingsPrefs(PrefRegistrySimple* registry) {
Mattias Nissler (ping if slow) 2013/12/19 09:21:13 This is fragile - you now need to keep this code i
Darren Krahn 2013/12/20 01:54:21 Yeah, I was looking at this thinking there must be
Mattias Nissler (ping if slow) 2013/12/20 12:46:17 We call this componentization ;)
52 registry->RegisterIntegerPref(
53 prefs::kContentSettingsWindowLastTabIndex,
54 0);
55 registry->RegisterIntegerPref(
56 prefs::kContentSettingsDefaultWhitelistVersion,
57 0);
58 registry->RegisterBooleanPref(
59 prefs::kContentSettingsClearOnExitMigrated,
60 false);
61 DictionaryValue* default_content_settings = new DictionaryValue();
62 registry->RegisterDictionaryPref(
63 prefs::kDefaultContentSettings,
64 default_content_settings);
65 registry->RegisterIntegerPref(
66 prefs::kContentSettingsVersion,
67 ContentSettingsPattern::kContentSettingsPatternVersion);
68 registry->RegisterDictionaryPref(
69 prefs::kContentSettingsPatternPairs);
70 registry->RegisterListPref(prefs::kManagedAutoSelectCertificateForUrls);
71 registry->RegisterListPref(prefs::kManagedCookiesAllowedForUrls);
72 registry->RegisterListPref(prefs::kManagedCookiesBlockedForUrls);
73 registry->RegisterListPref(prefs::kManagedCookiesSessionOnlyForUrls);
74 registry->RegisterListPref(prefs::kManagedImagesAllowedForUrls);
75 registry->RegisterListPref(prefs::kManagedImagesBlockedForUrls);
76 registry->RegisterListPref(prefs::kManagedJavaScriptAllowedForUrls);
77 registry->RegisterListPref(prefs::kManagedJavaScriptBlockedForUrls);
78 registry->RegisterListPref(prefs::kManagedPluginsAllowedForUrls);
79 registry->RegisterListPref(prefs::kManagedPluginsBlockedForUrls);
80 registry->RegisterListPref(prefs::kManagedPopupsAllowedForUrls);
81 registry->RegisterListPref(prefs::kManagedPopupsBlockedForUrls);
82 registry->RegisterListPref(prefs::kManagedNotificationsAllowedForUrls);
83 registry->RegisterListPref(prefs::kManagedNotificationsBlockedForUrls);
84 registry->RegisterIntegerPref(
85 prefs::kManagedDefaultCookiesSetting,
86 CONTENT_SETTING_DEFAULT);
87 registry->RegisterIntegerPref(
88 prefs::kManagedDefaultImagesSetting,
89 CONTENT_SETTING_DEFAULT);
90 registry->RegisterIntegerPref(
91 prefs::kManagedDefaultJavaScriptSetting,
92 CONTENT_SETTING_DEFAULT);
93 registry->RegisterIntegerPref(
94 prefs::kManagedDefaultPluginsSetting,
95 CONTENT_SETTING_DEFAULT);
96 registry->RegisterIntegerPref(
97 prefs::kManagedDefaultPopupsSetting,
98 CONTENT_SETTING_DEFAULT);
99 registry->RegisterIntegerPref(
100 prefs::kManagedDefaultGeolocationSetting,
101 CONTENT_SETTING_DEFAULT);
102 registry->RegisterIntegerPref(
103 prefs::kManagedDefaultNotificationsSetting,
104 CONTENT_SETTING_DEFAULT);
105 registry->RegisterIntegerPref(
106 prefs::kManagedDefaultMediaStreamSetting,
107 CONTENT_SETTING_DEFAULT);
108 registry->RegisterBooleanPref(
109 prefs::kClearSiteDataOnExit,
110 false);
111 }
112
51 class FakeDelegate : public PlatformVerificationFlow::Delegate { 113 class FakeDelegate : public PlatformVerificationFlow::Delegate {
52 public: 114 public:
53 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW), 115 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW),
54 num_consent_calls_(0) {} 116 num_consent_calls_(0),
117 url_(kTestURL),
118 is_incognito_(false) {
119 // Configure a user for the mock user manager.
120 mock_user_manager_.SetActiveUser(kTestEmail);
121 }
55 virtual ~FakeDelegate() {} 122 virtual ~FakeDelegate() {}
56 123
124 void SetUp() {
125 // Configure a test pref service.
126 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true);
127 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime,
128 true);
129 RegisterHostContentSettingsPrefs(pref_service_.registry());
130 content_settings_ = new HostContentSettingsMap(&pref_service_, false);
131 }
132
133 void TearDown() {
134 content_settings_->ShutdownOnUIThread();
135 }
136
57 virtual void ShowConsentPrompt( 137 virtual void ShowConsentPrompt(
58 content::WebContents* web_contents, 138 content::WebContents* web_contents,
59 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) 139 const PlatformVerificationFlow::Delegate::ConsentCallback& callback)
60 OVERRIDE { 140 OVERRIDE {
61 num_consent_calls_++; 141 num_consent_calls_++;
62 callback.Run(response_); 142 callback.Run(response_);
63 } 143 }
64 144
145 virtual PrefService* GetPrefs(content::WebContents* web_contents) OVERRIDE {
146 return &pref_service_;
147 }
148
149 virtual const GURL& GetURL(content::WebContents* web_contents) OVERRIDE {
150 return url_;
151 }
152
153 virtual User* GetUser(content::WebContents* web_contents) OVERRIDE {
154 return mock_user_manager_.GetActiveUser();
155 }
156
157 virtual HostContentSettingsMap* GetContentSettings(
158 content::WebContents* web_contents) OVERRIDE {
159 return content_settings_;
160 }
161
162 virtual bool IsGuestOrIncognito(content::WebContents* web_contents) OVERRIDE {
163 return is_incognito_;
164 }
165
65 void set_response(PlatformVerificationFlow::ConsentResponse response) { 166 void set_response(PlatformVerificationFlow::ConsentResponse response) {
66 response_ = response; 167 response_ = response;
67 } 168 }
68 169
69 int num_consent_calls() { 170 int num_consent_calls() {
70 return num_consent_calls_; 171 return num_consent_calls_;
71 } 172 }
72 173
174 TestingPrefServiceSimple& pref_service() {
175 return pref_service_;
176 }
177
178 void set_url(const GURL& url) {
179 url_ = url;
180 }
181
182 void set_is_incognito(bool is_incognito) {
183 is_incognito_ = is_incognito;
184 }
185
73 private: 186 private:
74 PlatformVerificationFlow::ConsentResponse response_; 187 PlatformVerificationFlow::ConsentResponse response_;
75 int num_consent_calls_; 188 int num_consent_calls_;
189 TestingPrefServiceSimple pref_service_;
190 MockUserManager mock_user_manager_;
191 GURL url_;
192 scoped_refptr<HostContentSettingsMap> content_settings_;
193 bool is_incognito_;
76 194
77 DISALLOW_COPY_AND_ASSIGN(FakeDelegate); 195 DISALLOW_COPY_AND_ASSIGN(FakeDelegate);
78 }; 196 };
79 197
80 class CustomFakeCryptohomeClient : public FakeCryptohomeClient { 198 class CustomFakeCryptohomeClient : public FakeCryptohomeClient {
81 public: 199 public:
82 CustomFakeCryptohomeClient() : call_status_(DBUS_METHOD_CALL_SUCCESS), 200 CustomFakeCryptohomeClient() : call_status_(DBUS_METHOD_CALL_SUCCESS),
83 attestation_enrolled_(true), 201 attestation_enrolled_(true),
84 attestation_prepared_(true) {} 202 attestation_prepared_(true) {}
85 virtual void TpmAttestationIsEnrolled( 203 virtual void TpmAttestationIsEnrolled(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 public: 240 public:
123 PlatformVerificationFlowTest() 241 PlatformVerificationFlowTest()
124 : message_loop_(base::MessageLoop::TYPE_UI), 242 : message_loop_(base::MessageLoop::TYPE_UI),
125 ui_thread_(content::BrowserThread::UI, &message_loop_), 243 ui_thread_(content::BrowserThread::UI, &message_loop_),
126 certificate_success_(true), 244 certificate_success_(true),
127 fake_certificate_index_(0), 245 fake_certificate_index_(0),
128 sign_challenge_success_(true), 246 sign_challenge_success_(true),
129 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} 247 result_(PlatformVerificationFlow::INTERNAL_ERROR) {}
130 248
131 void SetUp() { 249 void SetUp() {
132 // Configure a user for the mock user manager. 250 fake_delegate_.SetUp();
133 mock_user_manager_.SetActiveUser(kTestEmail);
134 251
135 // Create a verifier for tests to call. 252 // Create a verifier for tests to call.
136 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, 253 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_,
137 &mock_async_caller_, 254 &mock_async_caller_,
138 &fake_cryptohome_client_, 255 &fake_cryptohome_client_,
139 &mock_user_manager_,
140 &fake_delegate_); 256 &fake_delegate_);
141 257
142 // Create callbacks for tests to use with verifier_. 258 // Create callbacks for tests to use with verifier_.
143 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, 259 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback,
144 base::Unretained(this)); 260 base::Unretained(this));
145 261
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. 262 // Configure the global cros_settings.
156 CrosSettings* cros_settings = CrosSettings::Get(); 263 CrosSettings* cros_settings = CrosSettings::Get();
157 device_settings_provider_ = 264 device_settings_provider_ =
158 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); 265 cros_settings->GetProvider(kAttestationForContentProtectionEnabled);
159 cros_settings->RemoveSettingsProvider(device_settings_provider_); 266 cros_settings->RemoveSettingsProvider(device_settings_provider_);
160 cros_settings->AddSettingsProvider(&stub_settings_provider_); 267 cros_settings->AddSettingsProvider(&stub_settings_provider_);
161 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); 268 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true);
162
163 // Configure a test URL to shortcut the dependency on WebContents.
164 verifier_->set_testing_url(GURL(kTestURL));
165 }
166
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 } 269 }
228 270
229 void TearDown() { 271 void TearDown() {
230 // Restore the real DeviceSettingsProvider. 272 // Restore the real DeviceSettingsProvider.
231 CrosSettings* cros_settings = CrosSettings::Get(); 273 CrosSettings* cros_settings = CrosSettings::Get();
232 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); 274 cros_settings->RemoveSettingsProvider(&stub_settings_provider_);
233 cros_settings->AddSettingsProvider(device_settings_provider_); 275 cros_settings->AddSettingsProvider(device_settings_provider_);
234 test_content_settings_->ShutdownOnUIThread(); 276 fake_delegate_.TearDown();
235 } 277 }
236 278
237 void ExpectAttestationFlow() { 279 void ExpectAttestationFlow() {
238 // When consent is not given or the feature is disabled, it is important 280 // 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 281 // 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. 282 // explicitly expect these calls or the mocks will fail the test.
241 283
242 // Configure the mock AttestationFlow to call FakeGetCertificate. 284 // Configure the mock AttestationFlow to call FakeGetCertificate.
243 EXPECT_CALL(mock_attestation_flow_, 285 EXPECT_CALL(mock_attestation_flow_,
244 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE, 286 GetCertificate(PROFILE_CONTENT_PROTECTION_CERTIFICATE,
245 kTestEmail, kTestID, _, _)) 287 kTestEmail, kTestID, _, _))
246 .WillRepeatedly(WithArgs<4>(Invoke( 288 .WillRepeatedly(WithArgs<4>(Invoke(
247 this, &PlatformVerificationFlowTest::FakeGetCertificate))); 289 this, &PlatformVerificationFlowTest::FakeGetCertificate)));
248 290
249 // Configure the mock AsyncMethodCaller to call FakeSignChallenge. 291 // Configure the mock AsyncMethodCaller to call FakeSignChallenge.
250 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + 292 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) +
251 std::string(kTestID); 293 std::string(kTestID);
252 EXPECT_CALL(mock_async_caller_, 294 EXPECT_CALL(mock_async_caller_,
253 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, 295 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail,
254 expected_key_name, 296 expected_key_name,
255 kTestChallenge, _)) 297 kTestChallenge, _))
256 .WillRepeatedly(WithArgs<4>(Invoke( 298 .WillRepeatedly(WithArgs<4>(Invoke(
257 this, &PlatformVerificationFlowTest::FakeSignChallenge))); 299 this, &PlatformVerificationFlowTest::FakeSignChallenge)));
258 } 300 }
259 301
260 void SetUserConsent(const GURL& url, bool allow) { 302 void SetUserConsent(const GURL& url, bool allow) {
261 verifier_->RecordDomainConsent(test_content_settings_, url, allow); 303 verifier_->RecordDomainConsent(fake_delegate_.GetContentSettings(NULL),
262 } 304 url,
263 305 allow);
264 void SetURL(const GURL& url) {
265 verifier_->set_testing_url(url);
266 } 306 }
267 307
268 void FakeGetCertificate( 308 void FakeGetCertificate(
269 const AttestationFlow::CertificateCallback& callback) { 309 const AttestationFlow::CertificateCallback& callback) {
270 std::string certificate = 310 std::string certificate =
271 (fake_certificate_index_ < fake_certificate_list_.size()) ? 311 (fake_certificate_index_ < fake_certificate_list_.size()) ?
272 fake_certificate_list_[fake_certificate_index_] : kTestCertificate; 312 fake_certificate_list_[fake_certificate_index_] : kTestCertificate;
273 base::MessageLoop::current()->PostTask(FROM_HERE, 313 base::MessageLoop::current()->PostTask(FROM_HERE,
274 base::Bind(callback, 314 base::Bind(callback,
275 certificate_success_, 315 certificate_success_,
(...skipping 28 matching lines...) Expand all
304 CHECK(pb.SerializeToString(&serial)); 344 CHECK(pb.SerializeToString(&serial));
305 return serial; 345 return serial;
306 } 346 }
307 347
308 protected: 348 protected:
309 base::MessageLoop message_loop_; 349 base::MessageLoop message_loop_;
310 content::TestBrowserThread ui_thread_; 350 content::TestBrowserThread ui_thread_;
311 StrictMock<MockAttestationFlow> mock_attestation_flow_; 351 StrictMock<MockAttestationFlow> mock_attestation_flow_;
312 cryptohome::MockAsyncMethodCaller mock_async_caller_; 352 cryptohome::MockAsyncMethodCaller mock_async_caller_;
313 CustomFakeCryptohomeClient fake_cryptohome_client_; 353 CustomFakeCryptohomeClient fake_cryptohome_client_;
314 MockUserManager mock_user_manager_;
315 FakeDelegate fake_delegate_; 354 FakeDelegate fake_delegate_;
316 TestingPrefServiceSimple pref_service_;
317 CrosSettingsProvider* device_settings_provider_; 355 CrosSettingsProvider* device_settings_provider_;
318 StubCrosSettingsProvider stub_settings_provider_; 356 StubCrosSettingsProvider stub_settings_provider_;
319 ScopedTestDeviceSettingsService test_device_settings_service_; 357 ScopedTestDeviceSettingsService test_device_settings_service_;
320 ScopedTestCrosSettings test_cros_settings_; 358 ScopedTestCrosSettings test_cros_settings_;
321 scoped_refptr<HostContentSettingsMap> test_content_settings_;
322 scoped_refptr<PlatformVerificationFlow> verifier_; 359 scoped_refptr<PlatformVerificationFlow> verifier_;
323 360
324 // Controls result of FakeGetCertificate. 361 // Controls result of FakeGetCertificate.
325 bool certificate_success_; 362 bool certificate_success_;
326 std::vector<std::string> fake_certificate_list_; 363 std::vector<std::string> fake_certificate_list_;
327 size_t fake_certificate_index_; 364 size_t fake_certificate_index_;
328 365
329 // Controls result of FakeSignChallenge. 366 // Controls result of FakeSignChallenge.
330 bool sign_challenge_success_; 367 bool sign_challenge_success_;
331 368
(...skipping 27 matching lines...) Expand all
359 base::RunLoop().RunUntilIdle(); 396 base::RunLoop().RunUntilIdle();
360 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 397 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
361 EXPECT_EQ(kTestSignedData, challenge_salt_); 398 EXPECT_EQ(kTestSignedData, challenge_salt_);
362 EXPECT_EQ(kTestSignature, challenge_signature_); 399 EXPECT_EQ(kTestSignature, challenge_signature_);
363 EXPECT_EQ(kTestCertificate, certificate_); 400 EXPECT_EQ(kTestCertificate, certificate_);
364 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 401 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
365 } 402 }
366 403
367 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) { 404 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) {
368 SetUserConsent(GURL(kTestURL), true); 405 SetUserConsent(GURL(kTestURL), true);
369 pref_service_.SetUserPref(prefs::kRAConsentFirstTime, 406 fake_delegate_.pref_service().SetUserPref(prefs::kRAConsentFirstTime,
370 new base::FundamentalValue(false)); 407 new base::FundamentalValue(false));
371 ExpectAttestationFlow(); 408 ExpectAttestationFlow();
372 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 409 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
373 base::RunLoop().RunUntilIdle(); 410 base::RunLoop().RunUntilIdle();
374 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 411 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
375 EXPECT_EQ(kTestSignedData, challenge_salt_); 412 EXPECT_EQ(kTestSignedData, challenge_salt_);
376 EXPECT_EQ(kTestSignature, challenge_signature_); 413 EXPECT_EQ(kTestSignature, challenge_signature_);
377 EXPECT_EQ(kTestCertificate, certificate_); 414 EXPECT_EQ(kTestCertificate, certificate_);
378 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 415 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
379 } 416 }
380 417
381 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { 418 TEST_F(PlatformVerificationFlowTest, ConsentRejected) {
382 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 419 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
383 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 420 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
384 base::RunLoop().RunUntilIdle(); 421 base::RunLoop().RunUntilIdle();
385 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 422 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
386 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 423 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
387 } 424 }
388 425
389 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { 426 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) {
390 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, 427 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled,
391 false); 428 false);
392 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 429 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
393 base::RunLoop().RunUntilIdle(); 430 base::RunLoop().RunUntilIdle();
394 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 431 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
395 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 432 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
396 } 433 }
397 434
398 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { 435 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) {
399 pref_service_.SetUserPref(prefs::kEnableDRM, 436 fake_delegate_.pref_service().SetUserPref(prefs::kEnableDRM,
400 new base::FundamentalValue(false)); 437 new base::FundamentalValue(false));
401 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 438 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
402 base::RunLoop().RunUntilIdle(); 439 base::RunLoop().RunUntilIdle();
403 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 440 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
404 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 441 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
405 } 442 }
406 443
407 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { 444 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) {
408 SetUserConsent(GURL(kTestURL), false); 445 SetUserConsent(GURL(kTestURL), false);
409 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 446 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
410 base::RunLoop().RunUntilIdle(); 447 base::RunLoop().RunUntilIdle();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) { 482 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) {
446 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 483 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
447 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 484 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
448 base::RunLoop().RunUntilIdle(); 485 base::RunLoop().RunUntilIdle();
449 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 486 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
450 // Call again and expect denial based on previous response. 487 // Call again and expect denial based on previous response.
451 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 488 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
452 base::RunLoop().RunUntilIdle(); 489 base::RunLoop().RunUntilIdle();
453 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 490 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
454 // Call with a different scheme and expect another consent prompt. 491 // Call with a different scheme and expect another consent prompt.
455 SetURL(GURL(kTestURLSecure)); 492 fake_delegate_.set_url(GURL(kTestURLSecure));
456 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 493 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
457 base::RunLoop().RunUntilIdle(); 494 base::RunLoop().RunUntilIdle();
458 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 495 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
459 EXPECT_EQ(2, fake_delegate_.num_consent_calls()); 496 EXPECT_EQ(2, fake_delegate_.num_consent_calls());
460 } 497 }
461 498
462 TEST_F(PlatformVerificationFlowTest, Timeout) { 499 TEST_F(PlatformVerificationFlowTest, Timeout) {
463 verifier_->set_timeout_delay(base::TimeDelta::FromSeconds(0)); 500 verifier_->set_timeout_delay(base::TimeDelta::FromSeconds(0));
464 ExpectAttestationFlow(); 501 ExpectAttestationFlow();
465 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 502 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
466 base::RunLoop().RunUntilIdle(); 503 base::RunLoop().RunUntilIdle();
467 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_); 504 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_);
468 } 505 }
469 506
470 TEST_F(PlatformVerificationFlowTest, ExpiredCert) { 507 TEST_F(PlatformVerificationFlowTest, ExpiredCert) {
471 ExpectAttestationFlow(); 508 ExpectAttestationFlow();
472 fake_certificate_list_.resize(2); 509 fake_certificate_list_.resize(2);
473 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(-1), 510 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(-1),
474 &fake_certificate_list_[0])); 511 &fake_certificate_list_[0]));
475 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(1), 512 ASSERT_TRUE(GetFakeCertificate(base::TimeDelta::FromDays(1),
476 &fake_certificate_list_[1])); 513 &fake_certificate_list_[1]));
477 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 514 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
478 base::RunLoop().RunUntilIdle(); 515 base::RunLoop().RunUntilIdle();
479 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 516 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
480 EXPECT_EQ(certificate_, fake_certificate_list_[1]); 517 EXPECT_EQ(certificate_, fake_certificate_list_[1]);
481 } 518 }
482 519
520 TEST_F(PlatformVerificationFlowTest, IncognitoMode) {
521 fake_delegate_.set_is_incognito(true);
522 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
523 base::RunLoop().RunUntilIdle();
524 EXPECT_EQ(PlatformVerificationFlow::PLATFORM_NOT_VERIFIED, result_);
525 }
526
483 } // namespace attestation 527 } // namespace attestation
484 } // namespace chromeos 528 } // 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