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

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

Issue 2133953002: PasswordForm -> FormDigest for GetLogins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@413020_ssl_valid
Patch Set: Nits addressed Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "chrome/browser/password_manager/native_backend_libsecret.h" 18 #include "chrome/browser/password_manager/native_backend_libsecret.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "components/autofill/core/common/password_form.h" 20 #include "components/autofill/core/common/password_form.h"
21 #include "components/password_manager/core/browser/psl_matching_helper.h" 21 #include "components/password_manager/core/browser/psl_matching_helper.h"
22 #include "components/password_manager/core/common/password_manager_pref_names.h" 22 #include "components/password_manager/core/common/password_manager_pref_names.h"
23 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
24 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 using autofill::PasswordForm; 27 using autofill::PasswordForm;
28 using base::UTF8ToUTF16; 28 using base::UTF8ToUTF16;
29 using base::UTF16ToUTF8; 29 using base::UTF16ToUTF8;
30 using password_manager::PasswordStore;
30 using password_manager::PasswordStoreChange; 31 using password_manager::PasswordStoreChange;
31 using password_manager::PasswordStoreChangeList; 32 using password_manager::PasswordStoreChangeList;
32 using testing::Pointee; 33 using testing::Pointee;
33 using testing::UnorderedElementsAre; 34 using testing::UnorderedElementsAre;
34 35
35 namespace { 36 namespace {
36 37
37 // What follows is a very simple implementation of the subset of the Libsecret 38 // What follows is a very simple implementation of the subset of the Libsecret
38 // API that we actually use. It gets substituted for the real one by 39 // API that we actually use. It gets substituted for the real one by
39 // MockLibsecretLoader, which hooks into the facility normally used to load 40 // MockLibsecretLoader, which hooks into the facility normally used to load
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // |result| when |result| is not nullptr. (Note that there can be max. 1 420 // |result| when |result| is not nullptr. (Note that there can be max. 1
420 // result derived from |credentials|.) 421 // result derived from |credentials|.)
421 bool CheckCredentialAvailability(const PasswordForm& credentials, 422 bool CheckCredentialAvailability(const PasswordForm& credentials,
422 const GURL& url, 423 const GURL& url,
423 const PasswordForm::Scheme& scheme, 424 const PasswordForm::Scheme& scheme,
424 PasswordForm* result) { 425 PasswordForm* result) {
425 NativeBackendLibsecret backend(321); 426 NativeBackendLibsecret backend(321);
426 427
427 VerifiedAdd(&backend, credentials); 428 VerifiedAdd(&backend, credentials);
428 429
429 PasswordForm target_form; 430 PasswordStore::FormDigest target_form = {PasswordForm::SCHEME_HTML,
430 target_form.origin = url; 431 url.spec(), url};
431 target_form.signon_realm = url.spec();
432 if (scheme != PasswordForm::SCHEME_HTML) { 432 if (scheme != PasswordForm::SCHEME_HTML) {
433 // For non-HTML forms, the realm used for authentication 433 // For non-HTML forms, the realm used for authentication
434 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the 434 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the
435 // signon_realm. Just use a default value for now. 435 // signon_realm. Just use a default value for now.
436 target_form.signon_realm.append("Realm"); 436 target_form.signon_realm.append("Realm");
437 target_form.scheme = scheme;
438 } 437 }
439 ScopedVector<autofill::PasswordForm> form_list; 438 ScopedVector<autofill::PasswordForm> form_list;
440 EXPECT_TRUE(backend.GetLogins(target_form, &form_list)); 439 EXPECT_TRUE(backend.GetLogins(target_form, &form_list));
441 440
442 EXPECT_EQ(1u, global_mock_libsecret_items->size()); 441 EXPECT_EQ(1u, global_mock_libsecret_items->size());
443 if (!global_mock_libsecret_items->empty()) 442 if (!global_mock_libsecret_items->empty())
444 CheckMockSecretItem((*global_mock_libsecret_items)[0], credentials, 443 CheckMockSecretItem((*global_mock_libsecret_items)[0], credentials,
445 "chrome-321"); 444 "chrome-321");
446 global_mock_libsecret_items->clear(); 445 global_mock_libsecret_items->clear();
447 446
(...skipping 10 matching lines...) Expand all
458 // add that copy as well. Now update the www.facebook.com password -- the 457 // add that copy as well. Now update the www.facebook.com password -- the
459 // m.facebook.com password should not get updated. Depending on the argument, 458 // m.facebook.com password should not get updated. Depending on the argument,
460 // the credential update is done via UpdateLogin or AddLogin. 459 // the credential update is done via UpdateLogin or AddLogin.
461 void CheckPSLUpdate(UpdateType update_type) { 460 void CheckPSLUpdate(UpdateType update_type) {
462 NativeBackendLibsecret backend(321); 461 NativeBackendLibsecret backend(321);
463 462
464 VerifiedAdd(&backend, form_facebook_); 463 VerifiedAdd(&backend, form_facebook_);
465 464
466 // Get the PSL-matched copy of the saved login for m.facebook. 465 // Get the PSL-matched copy of the saved login for m.facebook.
467 const GURL kMobileURL("http://m.facebook.com/"); 466 const GURL kMobileURL("http://m.facebook.com/");
468 PasswordForm m_facebook_lookup; 467 PasswordStore::FormDigest m_facebook_lookup = {
469 m_facebook_lookup.origin = kMobileURL; 468 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL};
470 m_facebook_lookup.signon_realm = kMobileURL.spec();
471 ScopedVector<autofill::PasswordForm> form_list; 469 ScopedVector<autofill::PasswordForm> form_list;
472 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list)); 470 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list));
473 471
474 EXPECT_EQ(1u, global_mock_libsecret_items->size()); 472 EXPECT_EQ(1u, global_mock_libsecret_items->size());
475 EXPECT_EQ(1u, form_list.size()); 473 EXPECT_EQ(1u, form_list.size());
476 PasswordForm m_facebook = *form_list[0]; 474 PasswordForm m_facebook = *form_list[0];
477 form_list.clear(); 475 form_list.clear();
478 m_facebook.origin = kMobileURL; 476 m_facebook.origin = kMobileURL;
479 m_facebook.signon_realm = kMobileURL.spec(); 477 m_facebook.signon_realm = kMobileURL.spec();
480 478
(...skipping 26 matching lines...) Expand all
507 EXPECT_EQ(2u, form_list.size()); 505 EXPECT_EQ(2u, form_list.size());
508 size_t index_non_psl = 0; 506 size_t index_non_psl = 0;
509 if (form_list[index_non_psl]->is_public_suffix_match) 507 if (form_list[index_non_psl]->is_public_suffix_match)
510 index_non_psl = 1; 508 index_non_psl = 1;
511 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); 509 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin);
512 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); 510 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm);
513 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); 511 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value);
514 form_list.clear(); 512 form_list.clear();
515 513
516 // Check that www.facebook.com login was modified by the update. 514 // Check that www.facebook.com login was modified by the update.
517 EXPECT_TRUE(backend.GetLogins(form_facebook_, &form_list)); 515 EXPECT_TRUE(backend.GetLogins(PasswordStore::FormDigest(form_facebook_),
516 &form_list));
518 // There should be two results -- the exact one, and the PSL-matched one. 517 // There should be two results -- the exact one, and the PSL-matched one.
519 EXPECT_EQ(2u, form_list.size()); 518 EXPECT_EQ(2u, form_list.size());
520 index_non_psl = 0; 519 index_non_psl = 0;
521 if (form_list[index_non_psl]->is_public_suffix_match) 520 if (form_list[index_non_psl]->is_public_suffix_match)
522 index_non_psl = 1; 521 index_non_psl = 1;
523 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); 522 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin);
524 EXPECT_EQ(form_facebook_.signon_realm, 523 EXPECT_EQ(form_facebook_.signon_realm,
525 form_list[index_non_psl]->signon_realm); 524 form_list[index_non_psl]->signon_realm);
526 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); 525 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value);
527 form_list.clear(); 526 form_list.clear();
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 EXPECT_EQ(form_google_, *form_list[0]); 974 EXPECT_EQ(form_google_, *form_list[0]);
976 975
977 EXPECT_EQ(1u, global_mock_libsecret_items->size()); 976 EXPECT_EQ(1u, global_mock_libsecret_items->size());
978 if (!global_mock_libsecret_items->empty()) { 977 if (!global_mock_libsecret_items->empty()) {
979 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, 978 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
980 "chrome-42"); 979 "chrome-42");
981 } 980 }
982 } 981 }
983 982
984 // TODO(mdm): add more basic tests here at some point. 983 // TODO(mdm): add more basic tests here at some point.
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/native_backend_libsecret.cc ('k') | chrome/browser/password_manager/password_store_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698