| OLD | NEW |
| 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_impl.h" | 5 #include "components/password_manager/content/browser/credential_manager_impl.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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 210 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 211 .WillByDefault(testing::Return(true)); | 211 .WillByDefault(testing::Return(true)); |
| 212 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); | 212 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); |
| 213 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) | 213 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) |
| 214 .WillByDefault(testing::Return(false)); | 214 .WillByDefault(testing::Return(false)); |
| 215 | 215 |
| 216 NavigateAndCommit(GURL("https://example.com/test.html")); | 216 NavigateAndCommit(GURL("https://example.com/test.html")); |
| 217 | 217 |
| 218 form_.username_value = base::ASCIIToUTF16("Username"); | 218 form_.username_value = base::ASCIIToUTF16("Username"); |
| 219 form_.display_name = base::ASCIIToUTF16("Display Name"); | 219 form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 220 form_.icon_url = GURL("https://example.com/icon.png"); |
| 220 form_.password_value = base::ASCIIToUTF16("Password"); | 221 form_.password_value = base::ASCIIToUTF16("Password"); |
| 221 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 222 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 222 form_.signon_realm = form_.origin.spec(); | 223 form_.signon_realm = form_.origin.spec(); |
| 223 form_.scheme = autofill::PasswordForm::SCHEME_HTML; | 224 form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 224 form_.skip_zero_click = false; | 225 form_.skip_zero_click = false; |
| 225 form_.ssl_valid = true; | 226 form_.ssl_valid = true; |
| 226 | 227 |
| 227 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1"); | 228 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1"); |
| 228 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name"); | 229 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name"); |
| 229 affiliated_form1_.password_value = base::ASCIIToUTF16("Password"); | 230 affiliated_form1_.password_value = base::ASCIIToUTF16("Password"); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 EXPECT_TRUE(called); | 408 EXPECT_TRUE(called); |
| 408 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); | 409 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); |
| 409 | 410 |
| 410 autofill::PasswordForm new_form = | 411 autofill::PasswordForm new_form = |
| 411 client_->pending_manager()->pending_credentials(); | 412 client_->pending_manager()->pending_credentials(); |
| 412 EXPECT_EQ(form_.username_value, new_form.username_value); | 413 EXPECT_EQ(form_.username_value, new_form.username_value); |
| 413 EXPECT_EQ(form_.display_name, new_form.display_name); | 414 EXPECT_EQ(form_.display_name, new_form.display_name); |
| 414 EXPECT_EQ(form_.password_value, new_form.password_value); | 415 EXPECT_EQ(form_.password_value, new_form.password_value); |
| 415 EXPECT_EQ(form_.origin, new_form.origin); | 416 EXPECT_EQ(form_.origin, new_form.origin); |
| 416 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); | 417 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); |
| 418 EXPECT_TRUE(new_form.federation_origin.unique()); |
| 419 EXPECT_EQ(form_.icon_url, new_form.icon_url); |
| 417 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); | 420 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); |
| 418 } | 421 } |
| 419 | 422 |
| 423 TEST_F(CredentialManagerImplTest, CredentialManagerOnStoreFederated) { |
| 424 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 425 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 426 .Times(testing::Exactly(1)); |
| 427 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 428 |
| 429 bool called = false; |
| 430 form_.federation_origin = url::Origin(GURL("https://google.com/")); |
| 431 form_.password_value = base::string16(); |
| 432 form_.signon_realm = "federation://example.com/google.com"; |
| 433 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 434 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 435 |
| 436 // Allow the PasswordFormManager to talk to the password store, determine |
| 437 // that the form is new, and set it as pending. |
| 438 RunAllPendingTasks(); |
| 439 |
| 440 EXPECT_TRUE(called); |
| 441 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); |
| 442 |
| 443 autofill::PasswordForm new_form = |
| 444 client_->pending_manager()->pending_credentials(); |
| 445 EXPECT_EQ(form_.username_value, new_form.username_value); |
| 446 EXPECT_EQ(form_.display_name, new_form.display_name); |
| 447 EXPECT_EQ(form_.password_value, new_form.password_value); |
| 448 EXPECT_EQ(form_.origin, new_form.origin); |
| 449 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); |
| 450 EXPECT_EQ(form_.federation_origin, new_form.federation_origin); |
| 451 EXPECT_EQ(form_.icon_url, new_form.icon_url); |
| 452 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); |
| 453 } |
| 454 |
| 420 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { | 455 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { |
| 421 // Populate the PasswordStore with a form. | 456 // Populate the PasswordStore with a form. |
| 422 store_->AddLogin(form_); | 457 store_->AddLogin(form_); |
| 423 RunAllPendingTasks(); | 458 RunAllPendingTasks(); |
| 424 | 459 |
| 425 // Calling 'Store' with a credential that matches |form_| should update | 460 // Calling 'Store' with a credential that matches |form_| should update |
| 426 // the password without prompting the user. | 461 // the password without prompting the user. |
| 427 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 462 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 428 info.password = base::ASCIIToUTF16("Totally new password."); | 463 info.password = base::ASCIIToUTF16("Totally new password."); |
| 429 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); | 464 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 504 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 470 } | 505 } |
| 471 | 506 |
| 472 TEST_F(CredentialManagerImplTest, | 507 TEST_F(CredentialManagerImplTest, |
| 473 CredentialManagerFederatedStoreOverwriteZeroClick) { | 508 CredentialManagerFederatedStoreOverwriteZeroClick) { |
| 474 // Set the global zero click flag on, and populate the PasswordStore with a | 509 // Set the global zero click flag on, and populate the PasswordStore with a |
| 475 // form that's set to skip zero click. | 510 // form that's set to skip zero click. |
| 476 client_->set_zero_click_enabled(true); | 511 client_->set_zero_click_enabled(true); |
| 477 client_->set_first_run_seen(true); | 512 client_->set_first_run_seen(true); |
| 478 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 513 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 514 form_.password_value = base::string16(); |
| 479 form_.skip_zero_click = true; | 515 form_.skip_zero_click = true; |
| 480 form_.signon_realm = "federation://example.com/example.com"; | 516 form_.signon_realm = "federation://example.com/example.com"; |
| 481 store_->AddLogin(form_); | 517 store_->AddLogin(form_); |
| 482 RunAllPendingTasks(); | 518 RunAllPendingTasks(); |
| 483 | 519 |
| 484 // Calling 'Store' with a credential that matches |form_| should update | 520 // Calling 'Store' with a credential that matches |form_| should update |
| 485 // the credential without prompting the user. | 521 // the credential without prompting the user. |
| 486 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); | 522 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 487 bool called = false; | 523 bool called = false; |
| 488 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); | 524 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 std::vector<GURL> federations; | 769 std::vector<GURL> federations; |
| 734 | 770 |
| 735 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 771 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 736 | 772 |
| 737 ExpectZeroClickSignInFailure(true, false, federations); | 773 ExpectZeroClickSignInFailure(true, false, federations); |
| 738 } | 774 } |
| 739 | 775 |
| 740 TEST_F(CredentialManagerImplTest, | 776 TEST_F(CredentialManagerImplTest, |
| 741 CredentialManagerOnRequestCredentialFederatedMatch) { | 777 CredentialManagerOnRequestCredentialFederatedMatch) { |
| 742 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 778 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 779 form_.password_value = base::string16(); |
| 743 store_->AddLogin(form_); | 780 store_->AddLogin(form_); |
| 744 client_->set_first_run_seen(true); | 781 client_->set_first_run_seen(true); |
| 745 | 782 |
| 746 std::vector<GURL> federations; | 783 std::vector<GURL> federations; |
| 747 federations.push_back(GURL("https://example.com/")); | 784 federations.push_back(GURL("https://example.com/")); |
| 748 | 785 |
| 749 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 786 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 750 | 787 |
| 751 ExpectZeroClickSignInSuccess(true, true, federations, | 788 ExpectZeroClickSignInSuccess(true, true, federations, |
| 752 mojom::CredentialType::FEDERATED); | 789 mojom::CredentialType::FEDERATED); |
| 753 } | 790 } |
| 754 | 791 |
| 755 TEST_F(CredentialManagerImplTest, | 792 TEST_F(CredentialManagerImplTest, |
| 756 CredentialManagerOnRequestCredentialFederatedNoMatch) { | 793 CredentialManagerOnRequestCredentialFederatedNoMatch) { |
| 757 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 794 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 795 form_.password_value = base::string16(); |
| 758 store_->AddLogin(form_); | 796 store_->AddLogin(form_); |
| 759 client_->set_first_run_seen(true); | 797 client_->set_first_run_seen(true); |
| 760 | 798 |
| 761 std::vector<GURL> federations; | 799 std::vector<GURL> federations; |
| 762 federations.push_back(GURL("https://not-example.com/")); | 800 federations.push_back(GURL("https://not-example.com/")); |
| 763 | 801 |
| 764 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 802 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 765 | 803 |
| 766 ExpectZeroClickSignInFailure(true, true, federations); | 804 ExpectZeroClickSignInFailure(true, true, federations); |
| 767 } | 805 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 | 840 |
| 803 // We pass in 'false' for the 'include_passwords' argument to ensure that | 841 // We pass in 'false' for the 'include_passwords' argument to ensure that |
| 804 // password-type credentials are excluded as potential matches. | 842 // password-type credentials are excluded as potential matches. |
| 805 ExpectZeroClickSignInFailure(true, false, federations); | 843 ExpectZeroClickSignInFailure(true, false, federations); |
| 806 } | 844 } |
| 807 | 845 |
| 808 TEST_F(CredentialManagerImplTest, | 846 TEST_F(CredentialManagerImplTest, |
| 809 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { | 847 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { |
| 810 affiliated_form1_.federation_origin = | 848 affiliated_form1_.federation_origin = |
| 811 url::Origin(GURL("https://example.com/")); | 849 url::Origin(GURL("https://example.com/")); |
| 850 affiliated_form1_.password_value = base::string16(); |
| 812 store_->AddLogin(affiliated_form1_); | 851 store_->AddLogin(affiliated_form1_); |
| 813 client_->set_first_run_seen(true); | 852 client_->set_first_run_seen(true); |
| 814 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 853 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 815 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 854 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 816 | 855 |
| 817 std::vector<GURL> federations; | 856 std::vector<GURL> federations; |
| 818 federations.push_back(GURL("https://example.com/")); | 857 federations.push_back(GURL("https://example.com/")); |
| 819 | 858 |
| 820 std::vector<std::string> affiliated_realms; | 859 std::vector<std::string> affiliated_realms; |
| 821 affiliated_realms.push_back(kTestAndroidRealm1); | 860 affiliated_realms.push_back(kTestAndroidRealm1); |
| 822 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 861 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 823 ->ExpectCallToGetAffiliatedAndroidRealms( | 862 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 824 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); | 863 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 825 | 864 |
| 826 ExpectZeroClickSignInSuccess(true, true, federations, | 865 ExpectZeroClickSignInSuccess(true, true, federations, |
| 827 mojom::CredentialType::FEDERATED); | 866 mojom::CredentialType::FEDERATED); |
| 828 } | 867 } |
| 829 | 868 |
| 830 TEST_F(CredentialManagerImplTest, | 869 TEST_F(CredentialManagerImplTest, |
| 831 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { | 870 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { |
| 832 affiliated_form1_.federation_origin = | 871 affiliated_form1_.federation_origin = |
| 833 url::Origin(GURL("https://example.com/")); | 872 url::Origin(GURL("https://example.com/")); |
| 873 affiliated_form1_.password_value = base::string16(); |
| 834 store_->AddLogin(affiliated_form1_); | 874 store_->AddLogin(affiliated_form1_); |
| 835 client_->set_first_run_seen(true); | 875 client_->set_first_run_seen(true); |
| 836 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 876 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 837 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 877 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 838 | 878 |
| 839 std::vector<GURL> federations; | 879 std::vector<GURL> federations; |
| 840 federations.push_back(GURL("https://not-example.com/")); | 880 federations.push_back(GURL("https://not-example.com/")); |
| 841 | 881 |
| 842 std::vector<std::string> affiliated_realms; | 882 std::vector<std::string> affiliated_realms; |
| 843 affiliated_realms.push_back(kTestAndroidRealm1); | 883 affiliated_realms.push_back(kTestAndroidRealm1); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 blacklisted.origin = form_.origin; | 1225 blacklisted.origin = form_.origin; |
| 1186 blacklisted.signon_realm = form_.signon_realm; | 1226 blacklisted.signon_realm = form_.signon_realm; |
| 1187 blacklisted.type = autofill::PasswordForm::TYPE_API; | 1227 blacklisted.type = autofill::PasswordForm::TYPE_API; |
| 1188 blacklisted.ssl_valid = true; | 1228 blacklisted.ssl_valid = true; |
| 1189 blacklisted.date_created = passwords[form_.signon_realm][0].date_created; | 1229 blacklisted.date_created = passwords[form_.signon_realm][0].date_created; |
| 1190 EXPECT_THAT(passwords[form_.signon_realm], testing::ElementsAre(blacklisted)); | 1230 EXPECT_THAT(passwords[form_.signon_realm], testing::ElementsAre(blacklisted)); |
| 1191 } | 1231 } |
| 1192 | 1232 |
| 1193 TEST_F(CredentialManagerImplTest, BlacklistFederatedCredential) { | 1233 TEST_F(CredentialManagerImplTest, BlacklistFederatedCredential) { |
| 1194 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 1234 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 1235 form_.password_value = base::string16(); |
| 1195 form_.signon_realm = "federation://example.com/example.com"; | 1236 form_.signon_realm = "federation://example.com/example.com"; |
| 1196 | 1237 |
| 1197 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 1238 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 1198 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | 1239 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 1199 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); | 1240 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 1200 bool called = false; | 1241 bool called = false; |
| 1201 CallStore(info, base::Bind(&RespondCallback, &called)); | 1242 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 1202 // Allow the PasswordFormManager to talk to the password store | 1243 // Allow the PasswordFormManager to talk to the password store |
| 1203 RunAllPendingTasks(); | 1244 RunAllPendingTasks(); |
| 1204 | 1245 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 | 1285 |
| 1245 TEST_F(CredentialManagerImplTest, RespectBlacklistingFederatedCredential) { | 1286 TEST_F(CredentialManagerImplTest, RespectBlacklistingFederatedCredential) { |
| 1246 autofill::PasswordForm blacklisted; | 1287 autofill::PasswordForm blacklisted; |
| 1247 blacklisted.blacklisted_by_user = true; | 1288 blacklisted.blacklisted_by_user = true; |
| 1248 blacklisted.origin = form_.origin; | 1289 blacklisted.origin = form_.origin; |
| 1249 blacklisted.signon_realm = blacklisted.origin.spec(); | 1290 blacklisted.signon_realm = blacklisted.origin.spec(); |
| 1250 blacklisted.ssl_valid = true; | 1291 blacklisted.ssl_valid = true; |
| 1251 store_->AddLogin(blacklisted); | 1292 store_->AddLogin(blacklisted); |
| 1252 | 1293 |
| 1253 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 1294 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 1295 form_.password_value = base::string16(); |
| 1254 form_.signon_realm = "federation://example.com/example.com"; | 1296 form_.signon_realm = "federation://example.com/example.com"; |
| 1255 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); | 1297 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 1256 bool called = false; | 1298 bool called = false; |
| 1257 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 1299 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 1258 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | 1300 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 1259 CallStore(info, base::Bind(&RespondCallback, &called)); | 1301 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 1260 // Allow the PasswordFormManager to talk to the password store | 1302 // Allow the PasswordFormManager to talk to the password store |
| 1261 RunAllPendingTasks(); | 1303 RunAllPendingTasks(); |
| 1262 | 1304 |
| 1263 ASSERT_TRUE(client_->pending_manager()); | 1305 ASSERT_TRUE(client_->pending_manager()); |
| 1264 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1306 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
| 1265 } | 1307 } |
| 1266 | 1308 |
| 1267 } // namespace password_manager | 1309 } // namespace password_manager |
| OLD | NEW |