OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/password_manager/password_store_mac.h" | 5 #include "chrome/browser/password_manager/password_store_mac.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 { PasswordForm::SCHEME_DIGEST, "https://some.domain.com/high_security", | 495 { PasswordForm::SCHEME_DIGEST, "https://some.domain.com/high_security", |
496 "https://some.domain.com", | 496 "https://some.domain.com", |
497 NULL, NULL, NULL, NULL, L"digest_auth_user", NULL, true, true, 0 }, | 497 NULL, NULL, NULL, NULL, L"digest_auth_user", NULL, true, true, 0 }, |
498 }; | 498 }; |
499 | 499 |
500 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { | 500 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { |
501 // Create a base form and make sure we find a match. | 501 // Create a base form and make sure we find a match. |
502 scoped_ptr<PasswordForm> base_form(CreatePasswordFormFromData( | 502 scoped_ptr<PasswordForm> base_form(CreatePasswordFormFromData( |
503 base_form_data[i])); | 503 base_form_data[i])); |
504 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); | 504 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); |
505 PasswordForm* match = | 505 EXPECT_TRUE(keychain_adapter.HasPasswordExactlyMatchingForm(*base_form)); |
506 keychain_adapter.PasswordExactlyMatchingForm(*base_form); | |
507 EXPECT_TRUE(match != NULL); | |
508 if (match) { | |
509 EXPECT_EQ(base_form->scheme, match->scheme); | |
510 EXPECT_EQ(base_form->origin, match->origin); | |
511 EXPECT_EQ(base_form->username_value, match->username_value); | |
512 delete match; | |
513 } | |
514 | 506 |
515 // Make sure that the matching isn't looser than it should be by checking | 507 // Make sure that the matching isn't looser than it should be by checking |
516 // that slightly altered forms don't match. | 508 // that slightly altered forms don't match. |
517 std::vector<PasswordForm*> modified_forms; | 509 std::vector<PasswordForm*> modified_forms; |
518 | 510 |
519 modified_forms.push_back(new PasswordForm(*base_form)); | 511 modified_forms.push_back(new PasswordForm(*base_form)); |
520 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); | 512 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); |
521 | 513 |
522 modified_forms.push_back(new PasswordForm(*base_form)); | 514 modified_forms.push_back(new PasswordForm(*base_form)); |
523 SetPasswordFormPath(modified_forms.back(), "elsewhere.html"); | 515 SetPasswordFormPath(modified_forms.back(), "elsewhere.html"); |
524 | 516 |
525 modified_forms.push_back(new PasswordForm(*base_form)); | 517 modified_forms.push_back(new PasswordForm(*base_form)); |
526 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER; | 518 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER; |
527 | 519 |
528 modified_forms.push_back(new PasswordForm(*base_form)); | 520 modified_forms.push_back(new PasswordForm(*base_form)); |
529 SetPasswordFormPort(modified_forms.back(), "1234"); | 521 SetPasswordFormPort(modified_forms.back(), "1234"); |
530 | 522 |
531 modified_forms.push_back(new PasswordForm(*base_form)); | 523 modified_forms.push_back(new PasswordForm(*base_form)); |
532 modified_forms.back()->blacklisted_by_user = true; | 524 modified_forms.back()->blacklisted_by_user = true; |
533 | 525 |
534 if (base_form->scheme == PasswordForm::SCHEME_BASIC || | 526 if (base_form->scheme == PasswordForm::SCHEME_BASIC || |
535 base_form->scheme == PasswordForm::SCHEME_DIGEST) { | 527 base_form->scheme == PasswordForm::SCHEME_DIGEST) { |
536 modified_forms.push_back(new PasswordForm(*base_form)); | 528 modified_forms.push_back(new PasswordForm(*base_form)); |
537 SetPasswordFormRealm(modified_forms.back(), "incorrect"); | 529 SetPasswordFormRealm(modified_forms.back(), "incorrect"); |
538 } | 530 } |
539 | 531 |
540 for (unsigned int j = 0; j < modified_forms.size(); ++j) { | 532 for (unsigned int j = 0; j < modified_forms.size(); ++j) { |
541 PasswordForm* match = | 533 bool match = keychain_adapter.HasPasswordExactlyMatchingForm( |
542 keychain_adapter.PasswordExactlyMatchingForm(*modified_forms[j]); | 534 *modified_forms[j]); |
543 EXPECT_EQ(NULL, match) << "In modified version " << j << " of base form " | 535 EXPECT_FALSE(match) << "In modified version " << j |
544 << i; | 536 << " of base form " << i; |
545 } | 537 } |
546 STLDeleteElements(&modified_forms); | 538 STLDeleteElements(&modified_forms); |
547 } | 539 } |
548 } | 540 } |
549 | 541 |
550 TEST_F(PasswordStoreMacInternalsTest, TestKeychainAdd) { | 542 TEST_F(PasswordStoreMacInternalsTest, TestKeychainAdd) { |
551 struct TestDataAndExpectation { | 543 struct TestDataAndExpectation { |
552 PasswordFormData data; | 544 PasswordFormData data; |
553 bool should_succeed; | 545 bool should_succeed; |
554 }; | 546 }; |
(...skipping 27 matching lines...) Expand all Loading... |
582 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 574 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
583 | 575 |
584 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 576 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
585 scoped_ptr<PasswordForm> in_form( | 577 scoped_ptr<PasswordForm> in_form( |
586 CreatePasswordFormFromData(test_data[i].data)); | 578 CreatePasswordFormFromData(test_data[i].data)); |
587 bool add_succeeded = owned_keychain_adapter.AddPassword(*in_form); | 579 bool add_succeeded = owned_keychain_adapter.AddPassword(*in_form); |
588 EXPECT_EQ(test_data[i].should_succeed, add_succeeded); | 580 EXPECT_EQ(test_data[i].should_succeed, add_succeeded); |
589 if (add_succeeded) { | 581 if (add_succeeded) { |
590 EXPECT_TRUE(owned_keychain_adapter.HasPasswordsMergeableWithForm( | 582 EXPECT_TRUE(owned_keychain_adapter.HasPasswordsMergeableWithForm( |
591 *in_form)); | 583 *in_form)); |
592 scoped_ptr<PasswordForm> out_form( | 584 EXPECT_TRUE(owned_keychain_adapter.HasPasswordExactlyMatchingForm( |
593 owned_keychain_adapter.PasswordExactlyMatchingForm(*in_form)); | 585 *in_form)); |
594 EXPECT_TRUE(out_form.get() != NULL); | |
595 EXPECT_EQ(out_form->scheme, in_form->scheme); | |
596 EXPECT_EQ(out_form->signon_realm, in_form->signon_realm); | |
597 EXPECT_EQ(out_form->origin, in_form->origin); | |
598 EXPECT_EQ(out_form->username_value, in_form->username_value); | |
599 EXPECT_EQ(out_form->password_value, in_form->password_value); | |
600 } | 586 } |
601 } | 587 } |
602 | 588 |
603 // Test that adding duplicate item updates the existing item. | 589 // Test that adding duplicate item updates the existing item. |
604 { | 590 { |
605 PasswordFormData data = { | 591 PasswordFormData data = { |
606 PasswordForm::SCHEME_HTML, "http://some.domain.com", | 592 PasswordForm::SCHEME_HTML, "http://some.domain.com", |
607 "http://some.domain.com/insecure.html", NULL, | 593 "http://some.domain.com/insecure.html", NULL, |
608 NULL, NULL, NULL, L"joe_user", L"updated_password", false, false, 0 | 594 NULL, NULL, NULL, L"joe_user", L"updated_password", false, false, 0 |
609 }; | 595 }; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*add_form)); | 630 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*add_form)); |
645 delete add_form; | 631 delete add_form; |
646 | 632 |
647 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 633 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
648 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData( | 634 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData( |
649 test_data[i].data)); | 635 test_data[i].data)); |
650 EXPECT_EQ(test_data[i].should_succeed, | 636 EXPECT_EQ(test_data[i].should_succeed, |
651 owned_keychain_adapter.RemovePassword(*form)); | 637 owned_keychain_adapter.RemovePassword(*form)); |
652 | 638 |
653 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 639 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); |
654 PasswordForm* match = keychain_adapter.PasswordExactlyMatchingForm(*form); | 640 bool match = keychain_adapter.HasPasswordExactlyMatchingForm(*form); |
655 EXPECT_EQ(test_data[i].should_succeed, match == NULL); | 641 EXPECT_EQ(test_data[i].should_succeed, !match); |
656 if (match) { | |
657 delete match; | |
658 } | |
659 } | 642 } |
660 } | 643 } |
661 | 644 |
662 TEST_F(PasswordStoreMacInternalsTest, TestFormMatch) { | 645 TEST_F(PasswordStoreMacInternalsTest, TestFormMatch) { |
663 PasswordForm base_form; | 646 PasswordForm base_form; |
664 base_form.signon_realm = std::string("http://some.domain.com/"); | 647 base_form.signon_realm = std::string("http://some.domain.com/"); |
665 base_form.origin = GURL("http://some.domain.com/page.html"); | 648 base_form.origin = GURL("http://some.domain.com/page.html"); |
666 base_form.username_value = ASCIIToUTF16("joe_user"); | 649 base_form.username_value = ASCIIToUTF16("joe_user"); |
667 | 650 |
668 { | 651 { |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 ASSERT_EQ(1u, matching_items.size()); | 1427 ASSERT_EQ(1u, matching_items.size()); |
1445 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); | 1428 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); |
1446 matching_items.clear(); | 1429 matching_items.clear(); |
1447 | 1430 |
1448 // Check the third-party password is still there. | 1431 // Check the third-party password is still there. |
1449 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | 1432 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
1450 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1433 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( |
1451 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); | 1434 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); |
1452 ASSERT_EQ(1u, matching_items.size()); | 1435 ASSERT_EQ(1u, matching_items.size()); |
1453 } | 1436 } |
OLD | NEW |