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

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: 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 basic_auth_.origin = GURL("http://www.example.com/");
329 basic_auth_.username_value = UTF8ToUTF16("username");
330 basic_auth_.password_value = UTF8ToUTF16("pass");
331 basic_auth_.signon_realm = "http://www.example.com/Realm";
332 basic_auth_.scheme = PasswordForm::SCHEME_BASIC;
327 } 333 }
328 334
329 virtual void TearDown() { 335 virtual void TearDown() {
330 base::MessageLoop::current()->PostTask(FROM_HERE, 336 base::MessageLoop::current()->PostTask(FROM_HERE,
331 base::MessageLoop::QuitClosure()); 337 base::MessageLoop::QuitClosure());
332 base::MessageLoop::current()->Run(); 338 base::MessageLoop::current()->Run();
333 db_thread_.Stop(); 339 db_thread_.Stop();
334 } 340 }
335 341
336 void RunBothThreads() { 342 void RunBothThreads() {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 CheckUint32Attribute(item, "scheme", form.scheme); 406 CheckUint32Attribute(item, "scheme", form.scheme);
401 CheckStringAttribute(item, "application", app_string); 407 CheckStringAttribute(item, "application", app_string);
402 } 408 }
403 409
404 // Saves |credentials| and then gets login for origin and realm |url|. Returns 410 // Saves |credentials| and then gets login for origin and realm |url|. Returns
405 // true when something is found, and in such case copies the result to 411 // 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, 412 // |result| when |result| is not NULL. (Note that there can be max. 1 result,
407 // derived from |credentials|.) 413 // derived from |credentials|.)
408 bool CheckCredentialAvailability(const PasswordForm& credentials, 414 bool CheckCredentialAvailability(const PasswordForm& credentials,
409 const GURL& url, 415 const GURL& url,
416 const std::string& realm,
vabr (Chromium) 2014/05/07 07:57:38 Please explain the meaning of |realm| in the comme
Garrett Casto 2014/05/08 20:01:20 Done.
410 PasswordForm* result) { 417 PasswordForm* result) {
411 NativeBackendGnome backend(321); 418 NativeBackendGnome backend(321);
412 backend.Init(); 419 backend.Init();
413 420
414 BrowserThread::PostTask( 421 BrowserThread::PostTask(
415 BrowserThread::DB, 422 BrowserThread::DB,
416 FROM_HERE, 423 FROM_HERE,
417 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), 424 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
418 base::Unretained(&backend), 425 base::Unretained(&backend),
419 credentials)); 426 credentials));
420 427
421 PasswordForm target_form; 428 PasswordForm target_form;
422 target_form.origin = url; 429 target_form.origin = url;
423 target_form.signon_realm = url.spec(); 430 target_form.signon_realm = url.spec();
431 if (!realm.empty()) {
432 target_form.signon_realm.append(realm);
433 target_form.scheme = PasswordForm::SCHEME_BASIC;
434 }
424 std::vector<PasswordForm*> form_list; 435 std::vector<PasswordForm*> form_list;
425 BrowserThread::PostTask( 436 BrowserThread::PostTask(
426 BrowserThread::DB, 437 BrowserThread::DB,
427 FROM_HERE, 438 FROM_HERE,
428 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetLogins), 439 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetLogins),
429 base::Unretained(&backend), 440 base::Unretained(&backend),
430 target_form, 441 target_form,
431 &form_list)); 442 &form_list));
432 443
433 RunBothThreads(); 444 RunBothThreads();
434 445
435 EXPECT_EQ(1u, mock_keyring_items.size()); 446 EXPECT_EQ(1u, mock_keyring_items.size());
436 if (mock_keyring_items.size() > 0) 447 if (mock_keyring_items.size() > 0)
437 CheckMockKeyringItem(&mock_keyring_items[0], credentials, "chrome-321"); 448 CheckMockKeyringItem(&mock_keyring_items[0], credentials, "chrome-321");
449 mock_keyring_items.clear();
438 450
439 if (form_list.empty()) 451 if (form_list.empty())
440 return false; 452 return false;
441 EXPECT_EQ(1u, form_list.size()); 453 EXPECT_EQ(1u, form_list.size());
442 if (result) 454 if (result)
443 *result = *form_list[0]; 455 *result = *form_list[0];
444 STLDeleteElements(&form_list); 456 STLDeleteElements(&form_list);
445 return true; 457 return true;
446 } 458 }
447 459
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 577 }
566 578
567 base::MessageLoopForUI message_loop_; 579 base::MessageLoopForUI message_loop_;
568 content::TestBrowserThread ui_thread_; 580 content::TestBrowserThread ui_thread_;
569 content::TestBrowserThread db_thread_; 581 content::TestBrowserThread db_thread_;
570 582
571 // Provide some test forms to avoid having to set them up in each test. 583 // Provide some test forms to avoid having to set them up in each test.
572 PasswordForm form_google_; 584 PasswordForm form_google_;
573 PasswordForm form_facebook_; 585 PasswordForm form_facebook_;
574 PasswordForm form_isc_; 586 PasswordForm form_isc_;
587 PasswordForm basic_auth_;
575 }; 588 };
576 589
577 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { 590 TEST_F(NativeBackendGnomeTest, BasicAddLogin) {
578 NativeBackendGnome backend(42); 591 NativeBackendGnome backend(42);
579 backend.Init(); 592 backend.Init();
580 593
581 BrowserThread::PostTask( 594 BrowserThread::PostTask(
582 BrowserThread::DB, FROM_HERE, 595 BrowserThread::DB, FROM_HERE,
583 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), 596 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
584 base::Unretained(&backend), form_google_)); 597 base::Unretained(&backend), form_google_));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 if (mock_keyring_items.size() > 0) 629 if (mock_keyring_items.size() > 0)
617 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 630 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
618 } 631 }
619 632
620 // Save a password for www.facebook.com and see it suggested for m.facebook.com. 633 // Save a password for www.facebook.com and see it suggested for m.facebook.com.
621 TEST_F(NativeBackendGnomeTest, PSLMatchingPositive) { 634 TEST_F(NativeBackendGnomeTest, PSLMatchingPositive) {
622 PasswordForm result; 635 PasswordForm result;
623 const GURL kMobileURL("http://m.facebook.com/"); 636 const GURL kMobileURL("http://m.facebook.com/");
624 password_manager::PSLMatchingHelper helper; 637 password_manager::PSLMatchingHelper helper;
625 ASSERT_TRUE(helper.IsMatchingEnabled()); 638 ASSERT_TRUE(helper.IsMatchingEnabled());
626 EXPECT_TRUE(CheckCredentialAvailability(form_facebook_, kMobileURL, &result)); 639 EXPECT_TRUE(CheckCredentialAvailability(
640 form_facebook_, kMobileURL, "", &result));
627 EXPECT_EQ(kMobileURL, result.origin); 641 EXPECT_EQ(kMobileURL, result.origin);
628 EXPECT_EQ(kMobileURL.spec(), result.signon_realm); 642 EXPECT_EQ(kMobileURL.spec(), result.signon_realm);
629 } 643 }
630 644
631 // Save a password for www.facebook.com and see it not suggested for 645 // Save a password for www.facebook.com and see it not suggested for
632 // m-facebook.com. 646 // m-facebook.com.
633 TEST_F(NativeBackendGnomeTest, PSLMatchingNegativeDomainMismatch) { 647 TEST_F(NativeBackendGnomeTest, PSLMatchingNegativeDomainMismatch) {
634 password_manager::PSLMatchingHelper helper; 648 password_manager::PSLMatchingHelper helper;
635 ASSERT_TRUE(helper.IsMatchingEnabled()); 649 ASSERT_TRUE(helper.IsMatchingEnabled());
636 EXPECT_FALSE(CheckCredentialAvailability( 650 EXPECT_FALSE(CheckCredentialAvailability(
637 form_facebook_, GURL("http://m-facebook.com/"), NULL)); 651 form_facebook_, GURL("http://m-facebook.com/"), "", NULL));
638 } 652 }
639 653
640 // Test PSL matching is off for domains excluded from it. 654 // Test PSL matching is off for domains excluded from it.
641 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) { 655 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) {
642 password_manager::PSLMatchingHelper helper; 656 password_manager::PSLMatchingHelper helper;
643 ASSERT_TRUE(helper.IsMatchingEnabled()); 657 ASSERT_TRUE(helper.IsMatchingEnabled());
644 EXPECT_FALSE(CheckCredentialAvailability( 658 EXPECT_FALSE(CheckCredentialAvailability(
645 form_google_, GURL("http://one.google.com/"), NULL)); 659 form_google_, GURL("http://one.google.com/"), "", NULL));
660 }
661
662 // Make sure PSL matches aren't available for non-HTML forms.
663 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledForNonHTMLForms) {
vabr (Chromium) 2014/05/07 07:57:38 The code change applies to all possible schemes, b
Garrett Casto 2014/05/08 20:01:20 Done.
664 password_manager::PSLMatchingHelper helper;
665 ASSERT_TRUE(helper.IsMatchingEnabled());
666 // Don't match basic auth form with an HTML form.
667 EXPECT_FALSE(CheckCredentialAvailability(
668 basic_auth_, GURL("http://www.example.com"), "", NULL));
669 // Don't match an HTML form with a basic auth form.
670 EXPECT_FALSE(CheckCredentialAvailability(
671 form_google_, GURL("http://www.google.com/"), "Realm", NULL));
672 // Don't match two different basic auth forms with different origin.
673 EXPECT_FALSE(CheckCredentialAvailability(
674 basic_auth_, GURL("http://first.example.com"), "Realm", NULL));
646 } 675 }
647 676
648 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictUpdateLogin) { 677 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictUpdateLogin) {
649 CheckPSLUpdate(UPDATE_BY_UPDATELOGIN); 678 CheckPSLUpdate(UPDATE_BY_UPDATELOGIN);
650 } 679 }
651 680
652 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictAddLogin) { 681 TEST_F(NativeBackendGnomeTest, PSLUpdatingStrictAddLogin) {
653 // TODO(vabr): if AddLogin becomes no longer valid for existing logins, then 682 // TODO(vabr): if AddLogin becomes no longer valid for existing logins, then
654 // just delete this test. 683 // just delete this test.
655 CheckPSLUpdate(UPDATE_BY_ADDLOGIN); 684 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. 830 // Quick check that we got two results back.
802 EXPECT_EQ(2u, form_list.size()); 831 EXPECT_EQ(2u, form_list.size());
803 STLDeleteElements(&form_list); 832 STLDeleteElements(&form_list);
804 833
805 EXPECT_EQ(1u, mock_keyring_items.size()); 834 EXPECT_EQ(1u, mock_keyring_items.size());
806 if (mock_keyring_items.size() > 0) 835 if (mock_keyring_items.size() > 0)
807 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 836 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
808 } 837 }
809 838
810 // TODO(mdm): add more basic tests here at some point. 839 // TODO(mdm): add more basic tests here at some point.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698