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

Side by Side Diff: chrome/browser/password_manager/native_backend_gnome_x_unittest.cc

Issue 269813012: [Password Manager] Remove PSL matching for non-HTML forms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 6 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 | Annotate | Revision Log
OLDNEW
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 <stdarg.h> 5 #include <stdarg.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 form_facebook_.signon_realm = "http://www.facebook.com/"; 317 form_facebook_.signon_realm = "http://www.facebook.com/";
318 318
319 form_isc_.origin = GURL("http://www.isc.org/"); 319 form_isc_.origin = GURL("http://www.isc.org/");
320 form_isc_.action = GURL("http://www.isc.org/auth"); 320 form_isc_.action = GURL("http://www.isc.org/auth");
321 form_isc_.username_element = UTF8ToUTF16("id"); 321 form_isc_.username_element = UTF8ToUTF16("id");
322 form_isc_.username_value = UTF8ToUTF16("janedoe"); 322 form_isc_.username_value = UTF8ToUTF16("janedoe");
323 form_isc_.password_element = UTF8ToUTF16("passwd"); 323 form_isc_.password_element = UTF8ToUTF16("passwd");
324 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); 324 form_isc_.password_value = UTF8ToUTF16("ihazabukkit");
325 form_isc_.submit_element = UTF8ToUTF16("login"); 325 form_isc_.submit_element = UTF8ToUTF16("login");
326 form_isc_.signon_realm = "http://www.isc.org/"; 326 form_isc_.signon_realm = "http://www.isc.org/";
327
328 other_auth_.origin = GURL("http://www.example.com/");
329 other_auth_.username_value = UTF8ToUTF16("username");
330 other_auth_.password_value = UTF8ToUTF16("pass");
331 other_auth_.signon_realm = "http://www.example.com/Realm";
327 } 332 }
328 333
329 virtual void TearDown() { 334 virtual void TearDown() {
330 base::MessageLoop::current()->PostTask(FROM_HERE, 335 base::MessageLoop::current()->PostTask(FROM_HERE,
331 base::MessageLoop::QuitClosure()); 336 base::MessageLoop::QuitClosure());
332 base::MessageLoop::current()->Run(); 337 base::MessageLoop::current()->Run();
333 db_thread_.Stop(); 338 db_thread_.Stop();
334 } 339 }
335 340
336 void RunBothThreads() { 341 void RunBothThreads() {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 CheckUint32Attribute(item, "ssl_valid", form.ssl_valid); 399 CheckUint32Attribute(item, "ssl_valid", form.ssl_valid);
395 CheckUint32Attribute(item, "preferred", form.preferred); 400 CheckUint32Attribute(item, "preferred", form.preferred);
396 // We don't check the date created. It varies. 401 // We don't check the date created. It varies.
397 CheckUint32Attribute(item, "blacklisted_by_user", form.blacklisted_by_user); 402 CheckUint32Attribute(item, "blacklisted_by_user", form.blacklisted_by_user);
398 CheckUint32Attribute(item, "type", form.type); 403 CheckUint32Attribute(item, "type", form.type);
399 CheckUint32Attribute(item, "times_used", form.times_used); 404 CheckUint32Attribute(item, "times_used", form.times_used);
400 CheckUint32Attribute(item, "scheme", form.scheme); 405 CheckUint32Attribute(item, "scheme", form.scheme);
401 CheckStringAttribute(item, "application", app_string); 406 CheckStringAttribute(item, "application", app_string);
402 } 407 }
403 408
404 // Saves |credentials| and then gets login for origin and realm |url|. Returns 409 // Saves |credentials| and then gets login for origin and realm |url|. Returns
vabr (Chromium) 2014/05/09 09:19:58 nit: "|url|" -> "|url|, and |scheme|"
Garrett Casto 2014/05/09 18:32:13 Done.
405 // true when something is found, and in such case copies the result to 410 // true when something is found, and in such case copies the result to
406 // |result| when |result| is not NULL. (Note that there can be max. 1 result, 411 // |result| when |result| is not NULL. (Note that there can be max. 1 result,
407 // derived from |credentials|.) 412 // derived from |credentials|.)
408 bool CheckCredentialAvailability(const PasswordForm& credentials, 413 bool CheckCredentialAvailability(const PasswordForm& credentials,
409 const GURL& url, 414 const GURL& url,
415 const PasswordForm::Scheme& scheme,
410 PasswordForm* result) { 416 PasswordForm* result) {
411 NativeBackendGnome backend(321); 417 NativeBackendGnome backend(321);
412 backend.Init(); 418 backend.Init();
413 419
414 BrowserThread::PostTask( 420 BrowserThread::PostTask(
415 BrowserThread::DB, 421 BrowserThread::DB,
416 FROM_HERE, 422 FROM_HERE,
417 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), 423 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
418 base::Unretained(&backend), 424 base::Unretained(&backend),
419 credentials)); 425 credentials));
420 426
421 PasswordForm target_form; 427 PasswordForm target_form;
422 target_form.origin = url; 428 target_form.origin = url;
423 target_form.signon_realm = url.spec(); 429 target_form.signon_realm = url.spec();
430 if (scheme != PasswordForm::SCHEME_HTML) {
431 // For non-HTML forms, the realm used for authentication
432 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the
433 // signon_realm. Just use a default value for now.
434 target_form.signon_realm.append("Realm");
435 target_form.scheme = scheme;
436 }
424 std::vector<PasswordForm*> form_list; 437 std::vector<PasswordForm*> form_list;
425 BrowserThread::PostTask( 438 BrowserThread::PostTask(
426 BrowserThread::DB, 439 BrowserThread::DB,
427 FROM_HERE, 440 FROM_HERE,
428 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetLogins), 441 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetLogins),
429 base::Unretained(&backend), 442 base::Unretained(&backend),
430 target_form, 443 target_form,
431 &form_list)); 444 &form_list));
432 445
433 RunBothThreads(); 446 RunBothThreads();
434 447
435 EXPECT_EQ(1u, mock_keyring_items.size()); 448 EXPECT_EQ(1u, mock_keyring_items.size());
436 if (mock_keyring_items.size() > 0) 449 if (mock_keyring_items.size() > 0)
437 CheckMockKeyringItem(&mock_keyring_items[0], credentials, "chrome-321"); 450 CheckMockKeyringItem(&mock_keyring_items[0], credentials, "chrome-321");
451 mock_keyring_items.clear();
438 452
439 if (form_list.empty()) 453 if (form_list.empty())
440 return false; 454 return false;
441 EXPECT_EQ(1u, form_list.size()); 455 EXPECT_EQ(1u, form_list.size());
442 if (result) 456 if (result)
443 *result = *form_list[0]; 457 *result = *form_list[0];
444 STLDeleteElements(&form_list); 458 STLDeleteElements(&form_list);
445 return true; 459 return true;
446 } 460 }
447 461
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 index_non_psl = 0; 571 index_non_psl = 0;
558 if (!form_list[index_non_psl]->original_signon_realm.empty()) 572 if (!form_list[index_non_psl]->original_signon_realm.empty())
559 index_non_psl = 1; 573 index_non_psl = 1;
560 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); 574 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin);
561 EXPECT_EQ(form_facebook_.signon_realm, 575 EXPECT_EQ(form_facebook_.signon_realm,
562 form_list[index_non_psl]->signon_realm); 576 form_list[index_non_psl]->signon_realm);
563 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); 577 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value);
564 STLDeleteElements(&form_list); 578 STLDeleteElements(&form_list);
565 } 579 }
566 580
581 void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) {
582 other_auth_.scheme = scheme;
583
584 // Don't match a non-HTML form with an HTML form.
585 EXPECT_FALSE(CheckCredentialAvailability(
586 other_auth_, GURL("http://www.example.com"),
587 PasswordForm::SCHEME_HTML, NULL));
588 // Don't match an HTML form with non-HTML auth form.
589 EXPECT_FALSE(CheckCredentialAvailability(
590 form_google_, GURL("http://www.google.com/"), scheme, NULL));
591 // Don't match two different non-HTML auth forms with different origin.
592 EXPECT_FALSE(CheckCredentialAvailability(
593 other_auth_, GURL("http://first.example.com"), scheme, NULL));
594 }
595
567 base::MessageLoopForUI message_loop_; 596 base::MessageLoopForUI message_loop_;
568 content::TestBrowserThread ui_thread_; 597 content::TestBrowserThread ui_thread_;
569 content::TestBrowserThread db_thread_; 598 content::TestBrowserThread db_thread_;
570 599
571 // Provide some test forms to avoid having to set them up in each test. 600 // Provide some test forms to avoid having to set them up in each test.
572 PasswordForm form_google_; 601 PasswordForm form_google_;
573 PasswordForm form_facebook_; 602 PasswordForm form_facebook_;
574 PasswordForm form_isc_; 603 PasswordForm form_isc_;
604 PasswordForm other_auth_;
575 }; 605 };
576 606
577 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { 607 TEST_F(NativeBackendGnomeTest, BasicAddLogin) {
578 NativeBackendGnome backend(42); 608 NativeBackendGnome backend(42);
579 backend.Init(); 609 backend.Init();
580 610
581 BrowserThread::PostTask( 611 BrowserThread::PostTask(
582 BrowserThread::DB, FROM_HERE, 612 BrowserThread::DB, FROM_HERE,
583 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), 613 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
584 base::Unretained(&backend), form_google_)); 614 base::Unretained(&backend), form_google_));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 if (mock_keyring_items.size() > 0) 646 if (mock_keyring_items.size() > 0)
617 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 647 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
618 } 648 }
619 649
620 // Save a password for www.facebook.com and see it suggested for m.facebook.com. 650 // Save a password for www.facebook.com and see it suggested for m.facebook.com.
621 TEST_F(NativeBackendGnomeTest, PSLMatchingPositive) { 651 TEST_F(NativeBackendGnomeTest, PSLMatchingPositive) {
622 PasswordForm result; 652 PasswordForm result;
623 const GURL kMobileURL("http://m.facebook.com/"); 653 const GURL kMobileURL("http://m.facebook.com/");
624 password_manager::PSLMatchingHelper helper; 654 password_manager::PSLMatchingHelper helper;
625 ASSERT_TRUE(helper.IsMatchingEnabled()); 655 ASSERT_TRUE(helper.IsMatchingEnabled());
626 EXPECT_TRUE(CheckCredentialAvailability(form_facebook_, kMobileURL, &result)); 656 EXPECT_TRUE(CheckCredentialAvailability(
657 form_facebook_, kMobileURL, PasswordForm::SCHEME_HTML, &result));
627 EXPECT_EQ(kMobileURL, result.origin); 658 EXPECT_EQ(kMobileURL, result.origin);
628 EXPECT_EQ(kMobileURL.spec(), result.signon_realm); 659 EXPECT_EQ(kMobileURL.spec(), result.signon_realm);
629 } 660 }
630 661
631 // Save a password for www.facebook.com and see it not suggested for 662 // Save a password for www.facebook.com and see it not suggested for
632 // m-facebook.com. 663 // m-facebook.com.
633 TEST_F(NativeBackendGnomeTest, PSLMatchingNegativeDomainMismatch) { 664 TEST_F(NativeBackendGnomeTest, PSLMatchingNegativeDomainMismatch) {
634 password_manager::PSLMatchingHelper helper; 665 password_manager::PSLMatchingHelper helper;
635 ASSERT_TRUE(helper.IsMatchingEnabled()); 666 ASSERT_TRUE(helper.IsMatchingEnabled());
636 EXPECT_FALSE(CheckCredentialAvailability( 667 EXPECT_FALSE(CheckCredentialAvailability(
637 form_facebook_, GURL("http://m-facebook.com/"), NULL)); 668 form_facebook_, GURL("http://m-facebook.com/"),
669 PasswordForm::SCHEME_HTML, NULL));
638 } 670 }
639 671
640 // Test PSL matching is off for domains excluded from it. 672 // Test PSL matching is off for domains excluded from it.
641 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) { 673 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) {
642 password_manager::PSLMatchingHelper helper; 674 password_manager::PSLMatchingHelper helper;
643 ASSERT_TRUE(helper.IsMatchingEnabled()); 675 ASSERT_TRUE(helper.IsMatchingEnabled());
644 EXPECT_FALSE(CheckCredentialAvailability( 676 EXPECT_FALSE(CheckCredentialAvailability(
645 form_google_, GURL("http://one.google.com/"), NULL)); 677 form_google_, GURL("http://one.google.com/"),
678 PasswordForm::SCHEME_HTML, NULL));
679 }
680
681 // Make sure PSL matches aren't available for non-HTML forms.
682 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledForNonHTMLForms) {
683 password_manager::PSLMatchingHelper helper;
684 ASSERT_TRUE(helper.IsMatchingEnabled());
685
686 CheckMatchingWithScheme(PasswordForm::SCHEME_BASIC);
687 CheckMatchingWithScheme(PasswordForm::SCHEME_DIGEST);
688 CheckMatchingWithScheme(PasswordForm::SCHEME_OTHER);
689
646 } 690 }
647 691
648 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictUpdateLogin) { 692 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictUpdateLogin) {
649 CheckPSLUpdate(UPDATE_BY_UPDATELOGIN); 693 CheckPSLUpdate(UPDATE_BY_UPDATELOGIN);
650 } 694 }
651 695
652 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictAddLogin) { 696 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictAddLogin) {
653 // TODO(vabr): if AddLogin becomes no longer valid for existing logins, then 697 // TODO(vabr): if AddLogin becomes no longer valid for existing logins, then
654 // just delete this test. 698 // just delete this test.
655 CheckPSLUpdate(UPDATE_BY_ADDLOGIN); 699 CheckPSLUpdate(UPDATE_BY_ADDLOGIN);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // Quick check that we got two results back. 845 // Quick check that we got two results back.
802 EXPECT_EQ(2u, form_list.size()); 846 EXPECT_EQ(2u, form_list.size());
803 STLDeleteElements(&form_list); 847 STLDeleteElements(&form_list);
804 848
805 EXPECT_EQ(1u, mock_keyring_items.size()); 849 EXPECT_EQ(1u, mock_keyring_items.size());
806 if (mock_keyring_items.size() > 0) 850 if (mock_keyring_items.size() > 0)
807 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 851 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
808 } 852 }
809 853
810 // TODO(mdm): add more basic tests here at some point. 854 // TODO(mdm): add more basic tests here at some point.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698