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

Side by Side Diff: components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc

Issue 1978513003: Save federated credential's signon_realm in the correct format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | components/password_manager/core/browser/password_form_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/password_manager/content/browser/credential_manager_dispatc her.h" 5 #include "components/password_manager/content/browser/credential_manager_dispatc her.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) 199 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage())
200 .WillByDefault(testing::Return(true)); 200 .WillByDefault(testing::Return(true));
201 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); 201 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false));
202 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) 202 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors())
203 .WillByDefault(testing::Return(false)); 203 .WillByDefault(testing::Return(false));
204 204
205 NavigateAndCommit(GURL("https://example.com/test.html")); 205 NavigateAndCommit(GURL("https://example.com/test.html"));
206 206
207 form_.username_value = base::ASCIIToUTF16("Username"); 207 form_.username_value = base::ASCIIToUTF16("Username");
208 form_.display_name = base::ASCIIToUTF16("Display Name"); 208 form_.display_name = base::ASCIIToUTF16("Display Name");
209 form_.icon_url = GURL("https://example.com/icon.png");
209 form_.password_value = base::ASCIIToUTF16("Password"); 210 form_.password_value = base::ASCIIToUTF16("Password");
210 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); 211 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin();
211 form_.signon_realm = form_.origin.spec(); 212 form_.signon_realm = form_.origin.spec();
212 form_.scheme = autofill::PasswordForm::SCHEME_HTML; 213 form_.scheme = autofill::PasswordForm::SCHEME_HTML;
213 form_.skip_zero_click = false; 214 form_.skip_zero_click = false;
214 form_.ssl_valid = true; 215 form_.ssl_valid = true;
215 216
216 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1"); 217 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1");
217 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name"); 218 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name");
218 affiliated_form1_.password_value = base::ASCIIToUTF16("Password"); 219 affiliated_form1_.password_value = base::ASCIIToUTF16("Password");
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 357
357 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); 358 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching());
358 359
359 autofill::PasswordForm new_form = 360 autofill::PasswordForm new_form =
360 client_->pending_manager()->pending_credentials(); 361 client_->pending_manager()->pending_credentials();
361 EXPECT_EQ(form_.username_value, new_form.username_value); 362 EXPECT_EQ(form_.username_value, new_form.username_value);
362 EXPECT_EQ(form_.display_name, new_form.display_name); 363 EXPECT_EQ(form_.display_name, new_form.display_name);
363 EXPECT_EQ(form_.password_value, new_form.password_value); 364 EXPECT_EQ(form_.password_value, new_form.password_value);
364 EXPECT_EQ(form_.origin, new_form.origin); 365 EXPECT_EQ(form_.origin, new_form.origin);
365 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); 366 EXPECT_EQ(form_.signon_realm, new_form.signon_realm);
367 EXPECT_TRUE(new_form.federation_origin.unique());
368 EXPECT_EQ(form_.icon_url, new_form.icon_url);
366 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); 369 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme);
367 } 370 }
368 371
372 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnStoreFederated) {
373 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
374 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
375 .Times(testing::Exactly(1));
376 EXPECT_CALL(*client_, NotifyStorePasswordCalled());
377
378 form_.federation_origin = url::Origin(GURL("https://google.com/"));
379 form_.password_value = base::string16();
380 form_.signon_realm = "federation://example.com/google.com";
381 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
382 dispatcher()->OnStore(kRequestId, info);
383
384 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID;
385 const IPC::Message* message =
386 process()->sink().GetFirstMessageMatching(kMsgID);
387 EXPECT_TRUE(message);
388 process()->sink().ClearMessages();
389
390 // Allow the PasswordFormManager to talk to the password store, determine
391 // that the form is new, and set it as pending.
392 RunAllPendingTasks();
393
394 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching());
395
396 autofill::PasswordForm new_form =
397 client_->pending_manager()->pending_credentials();
398 EXPECT_EQ(form_.username_value, new_form.username_value);
399 EXPECT_EQ(form_.display_name, new_form.display_name);
400 EXPECT_EQ(form_.password_value, new_form.password_value);
401 EXPECT_EQ(form_.origin, new_form.origin);
402 EXPECT_EQ(form_.signon_realm, new_form.signon_realm);
403 EXPECT_EQ(form_.federation_origin, new_form.federation_origin);
404 EXPECT_EQ(form_.icon_url, new_form.icon_url);
405 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme);
406 }
407
369 TEST_F(CredentialManagerDispatcherTest, CredentialManagerStoreOverwrite) { 408 TEST_F(CredentialManagerDispatcherTest, CredentialManagerStoreOverwrite) {
370 // Populate the PasswordStore with a form. 409 // Populate the PasswordStore with a form.
371 store_->AddLogin(form_); 410 store_->AddLogin(form_);
372 RunAllPendingTasks(); 411 RunAllPendingTasks();
373 412
374 // Calling 'OnStore' with a credential that matches |form_| should update 413 // Calling 'OnStore' with a credential that matches |form_| should update
375 // the password without prompting the user. 414 // the password without prompting the user.
376 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 415 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
377 info.password = base::ASCIIToUTF16("Totally new password."); 416 info.password = base::ASCIIToUTF16("Totally new password.");
378 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); 417 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 461 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
423 } 462 }
424 463
425 TEST_F(CredentialManagerDispatcherTest, 464 TEST_F(CredentialManagerDispatcherTest,
426 CredentialManagerFederatedStoreOverwriteZeroClick) { 465 CredentialManagerFederatedStoreOverwriteZeroClick) {
427 // Set the global zero click flag on, and populate the PasswordStore with a 466 // Set the global zero click flag on, and populate the PasswordStore with a
428 // form that's set to skip zero click. 467 // form that's set to skip zero click.
429 client_->set_zero_click_enabled(true); 468 client_->set_zero_click_enabled(true);
430 client_->set_first_run_seen(true); 469 client_->set_first_run_seen(true);
431 form_.federation_origin = url::Origin(GURL("https://example.com/")); 470 form_.federation_origin = url::Origin(GURL("https://example.com/"));
471 form_.password_value = base::string16();
432 form_.skip_zero_click = true; 472 form_.skip_zero_click = true;
433 form_.signon_realm = "federation://example.com/example.com"; 473 form_.signon_realm = "federation://example.com/example.com";
434 store_->AddLogin(form_); 474 store_->AddLogin(form_);
435 RunAllPendingTasks(); 475 RunAllPendingTasks();
436 476
437 // Calling 'OnStore' with a credential that matches |form_| should update 477 // Calling 'OnStore' with a credential that matches |form_| should update
438 // the credential without prompting the user. 478 // the credential without prompting the user.
439 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); 479 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
440 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); 480 EXPECT_CALL(*client_, NotifyStorePasswordCalled());
441 dispatcher()->OnStore(kRequestId, info); 481 dispatcher()->OnStore(kRequestId, info);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 760
721 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 761 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
722 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); 762 dispatcher()->OnRequestCredential(kRequestId, true, false, federations);
723 763
724 ExpectZeroClickSignInFailure(); 764 ExpectZeroClickSignInFailure();
725 } 765 }
726 766
727 TEST_F(CredentialManagerDispatcherTest, 767 TEST_F(CredentialManagerDispatcherTest,
728 CredentialManagerOnRequestCredentialFederatedMatch) { 768 CredentialManagerOnRequestCredentialFederatedMatch) {
729 form_.federation_origin = url::Origin(GURL("https://example.com/")); 769 form_.federation_origin = url::Origin(GURL("https://example.com/"));
770 form_.password_value = base::string16();
730 store_->AddLogin(form_); 771 store_->AddLogin(form_);
731 client_->set_first_run_seen(true); 772 client_->set_first_run_seen(true);
732 773
733 std::vector<GURL> federations; 774 std::vector<GURL> federations;
734 federations.push_back(GURL("https://example.com/")); 775 federations.push_back(GURL("https://example.com/"));
735 776
736 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 777 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
737 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 778 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
738 779
739 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); 780 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED);
740 } 781 }
741 782
742 TEST_F(CredentialManagerDispatcherTest, 783 TEST_F(CredentialManagerDispatcherTest,
743 CredentialManagerOnRequestCredentialFederatedNoMatch) { 784 CredentialManagerOnRequestCredentialFederatedNoMatch) {
744 form_.federation_origin = url::Origin(GURL("https://example.com/")); 785 form_.federation_origin = url::Origin(GURL("https://example.com/"));
786 form_.password_value = base::string16();
745 store_->AddLogin(form_); 787 store_->AddLogin(form_);
746 client_->set_first_run_seen(true); 788 client_->set_first_run_seen(true);
747 789
748 std::vector<GURL> federations; 790 std::vector<GURL> federations;
749 federations.push_back(GURL("https://not-example.com/")); 791 federations.push_back(GURL("https://not-example.com/"));
750 792
751 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 793 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
752 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 794 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
753 795
754 ExpectZeroClickSignInFailure(); 796 ExpectZeroClickSignInFailure();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 // password-type credentials are excluded as potential matches. 835 // password-type credentials are excluded as potential matches.
794 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); 836 dispatcher()->OnRequestCredential(kRequestId, true, false, federations);
795 837
796 ExpectZeroClickSignInFailure(); 838 ExpectZeroClickSignInFailure();
797 } 839 }
798 840
799 TEST_F(CredentialManagerDispatcherTest, 841 TEST_F(CredentialManagerDispatcherTest,
800 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { 842 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) {
801 affiliated_form1_.federation_origin = 843 affiliated_form1_.federation_origin =
802 url::Origin(GURL("https://example.com/")); 844 url::Origin(GURL("https://example.com/"));
845 affiliated_form1_.password_value = base::string16();
803 store_->AddLogin(affiliated_form1_); 846 store_->AddLogin(affiliated_form1_);
804 client_->set_first_run_seen(true); 847 client_->set_first_run_seen(true);
805 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 848 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
806 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 849 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
807 850
808 std::vector<GURL> federations; 851 std::vector<GURL> federations;
809 federations.push_back(GURL("https://example.com/")); 852 federations.push_back(GURL("https://example.com/"));
810 853
811 std::vector<std::string> affiliated_realms; 854 std::vector<std::string> affiliated_realms;
812 affiliated_realms.push_back(kTestAndroidRealm1); 855 affiliated_realms.push_back(kTestAndroidRealm1);
813 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 856 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
814 ->ExpectCallToGetAffiliatedAndroidRealms( 857 ->ExpectCallToGetAffiliatedAndroidRealms(
815 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 858 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms);
816 859
817 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 860 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
818 861
819 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); 862 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED);
820 } 863 }
821 864
822 TEST_F(CredentialManagerDispatcherTest, 865 TEST_F(CredentialManagerDispatcherTest,
823 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { 866 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) {
824 affiliated_form1_.federation_origin = 867 affiliated_form1_.federation_origin =
825 url::Origin(GURL("https://example.com/")); 868 url::Origin(GURL("https://example.com/"));
869 affiliated_form1_.password_value = base::string16();
826 store_->AddLogin(affiliated_form1_); 870 store_->AddLogin(affiliated_form1_);
827 client_->set_first_run_seen(true); 871 client_->set_first_run_seen(true);
828 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 872 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
829 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 873 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
830 874
831 std::vector<GURL> federations; 875 std::vector<GURL> federations;
832 federations.push_back(GURL("https://not-example.com/")); 876 federations.push_back(GURL("https://not-example.com/"));
833 877
834 std::vector<std::string> affiliated_realms; 878 std::vector<std::string> affiliated_realms;
835 affiliated_realms.push_back(kTestAndroidRealm1); 879 affiliated_realms.push_back(kTestAndroidRealm1);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 blacklisted.origin = form_.origin; 1271 blacklisted.origin = form_.origin;
1228 blacklisted.signon_realm = form_.signon_realm; 1272 blacklisted.signon_realm = form_.signon_realm;
1229 blacklisted.type = autofill::PasswordForm::TYPE_API; 1273 blacklisted.type = autofill::PasswordForm::TYPE_API;
1230 blacklisted.ssl_valid = true; 1274 blacklisted.ssl_valid = true;
1231 blacklisted.date_created = passwords[form_.signon_realm][0].date_created; 1275 blacklisted.date_created = passwords[form_.signon_realm][0].date_created;
1232 EXPECT_THAT(passwords[form_.signon_realm], testing::ElementsAre(blacklisted)); 1276 EXPECT_THAT(passwords[form_.signon_realm], testing::ElementsAre(blacklisted));
1233 } 1277 }
1234 1278
1235 TEST_F(CredentialManagerDispatcherTest, BlacklistFederatedCredential) { 1279 TEST_F(CredentialManagerDispatcherTest, BlacklistFederatedCredential) {
1236 form_.federation_origin = url::Origin(GURL("https://example.com/")); 1280 form_.federation_origin = url::Origin(GURL("https://example.com/"));
1281 form_.password_value = base::string16();
1237 form_.signon_realm = "federation://example.com/example.com"; 1282 form_.signon_realm = "federation://example.com/example.com";
1238 1283
1239 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 1284 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1240 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); 1285 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1241 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); 1286 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
1242 dispatcher()->OnStore(kRequestId, info); 1287 dispatcher()->OnStore(kRequestId, info);
1243 process()->sink().ClearMessages(); 1288 process()->sink().ClearMessages();
1244 // Allow the PasswordFormManager to talk to the password store 1289 // Allow the PasswordFormManager to talk to the password store
1245 RunAllPendingTasks(); 1290 RunAllPendingTasks();
1246 1291
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 TEST_F(CredentialManagerDispatcherTest, 1332 TEST_F(CredentialManagerDispatcherTest,
1288 RespectBlacklistingFederatedCredential) { 1333 RespectBlacklistingFederatedCredential) {
1289 autofill::PasswordForm blacklisted; 1334 autofill::PasswordForm blacklisted;
1290 blacklisted.blacklisted_by_user = true; 1335 blacklisted.blacklisted_by_user = true;
1291 blacklisted.origin = form_.origin; 1336 blacklisted.origin = form_.origin;
1292 blacklisted.signon_realm = blacklisted.origin.spec(); 1337 blacklisted.signon_realm = blacklisted.origin.spec();
1293 blacklisted.ssl_valid = true; 1338 blacklisted.ssl_valid = true;
1294 store_->AddLogin(blacklisted); 1339 store_->AddLogin(blacklisted);
1295 1340
1296 form_.federation_origin = url::Origin(GURL("https://example.com/")); 1341 form_.federation_origin = url::Origin(GURL("https://example.com/"));
1342 form_.password_value = base::string16();
1297 form_.signon_realm = "federation://example.com/example.com"; 1343 form_.signon_realm = "federation://example.com/example.com";
1298 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); 1344 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
1299 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 1345 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1300 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); 1346 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1301 dispatcher()->OnStore(kRequestId, info); 1347 dispatcher()->OnStore(kRequestId, info);
1302 process()->sink().ClearMessages(); 1348 process()->sink().ClearMessages();
1303 // Allow the PasswordFormManager to talk to the password store 1349 // Allow the PasswordFormManager to talk to the password store
1304 RunAllPendingTasks(); 1350 RunAllPendingTasks();
1305 1351
1306 ASSERT_TRUE(client_->pending_manager()); 1352 ASSERT_TRUE(client_->pending_manager());
1307 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); 1353 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1308 } 1354 }
1309 1355
1310 } // namespace password_manager 1356 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | components/password_manager/core/browser/password_form_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698