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

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

Issue 2721663002: Move Credentials when migrating to HSTS page (Closed)
Patch Set: More Explanation Created 3 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 1374
1375 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); 1375 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html");
1376 observer.Wait(); 1376 observer.Wait();
1377 1377
1378 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1378 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
1379 } 1379 }
1380 1380
1381 IN_PROC_BROWSER_TEST_F( 1381 IN_PROC_BROWSER_TEST_F(
1382 PasswordManagerBrowserTestBase, 1382 PasswordManagerBrowserTestBase,
1383 NoPromptForLoginFailedAndServerPushSeperateLoginForm_HttpsToHttp) { 1383 NoPromptForLoginFailedAndServerPushSeperateLoginForm_HttpsToHttp) {
1384 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1385 ::switches::kAllowRunningInsecureContent);
1386 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1387 ::switches::kIgnoreCertificateErrors);
1388
1389 // This test case cannot inject the scripts via content::ExecuteScript() in 1384 // This test case cannot inject the scripts via content::ExecuteScript() in
1390 // files served through HTTPS. Therefore the scripts are made part of the HTML 1385 // files served through HTTPS. Therefore the scripts are made part of the HTML
1391 // site and executed on load. 1386 // site and executed on load.
1392 std::string path = 1387 std::string path =
1393 "/password/separate_login_form_with_onload_submit_script.html"; 1388 "/password/separate_login_form_with_onload_submit_script.html";
1394 GURL https_url(https_test_server().GetURL(path)); 1389 GURL https_url(https_test_server().GetURL(path));
1395 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme)); 1390 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme));
1396 1391
1397 NavigationObserver observer(WebContents()); 1392 NavigationObserver observer(WebContents());
1398 std::unique_ptr<BubbleObserver> prompt_observer( 1393 std::unique_ptr<BubbleObserver> prompt_observer(
1399 new BubbleObserver(WebContents())); 1394 new BubbleObserver(WebContents()));
1400 ui_test_utils::NavigateToURL(browser(), https_url); 1395 ui_test_utils::NavigateToURL(browser(), https_url);
1401 1396
1402 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); 1397 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html");
1403 observer.Wait(); 1398 observer.Wait();
1404 1399
1405 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1400 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
1406 } 1401 }
1407 1402
1408 // Tests whether a attempted submission of a malicious credentials gets blocked. 1403 // Tests whether a attempted submission of a malicious credentials gets blocked.
1409 // This simulates a case which is described in http://crbug.com/571580. 1404 // This simulates a case which is described in http://crbug.com/571580.
1410 IN_PROC_BROWSER_TEST_F( 1405 IN_PROC_BROWSER_TEST_F(
1411 PasswordManagerBrowserTestBase, 1406 PasswordManagerBrowserTestBase,
1412 NoPromptForSeperateLoginFormWhenSwitchingFromHttpsToHttp) { 1407 NoPromptForSeperateLoginFormWhenSwitchingFromHttpsToHttp) {
1413 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1414 ::switches::kAllowRunningInsecureContent);
1415 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1416 ::switches::kIgnoreCertificateErrors);
1417
1418 std::string path = "/password/password_form.html"; 1408 std::string path = "/password/password_form.html";
1419 GURL https_url(https_test_server().GetURL(path)); 1409 GURL https_url(https_test_server().GetURL(path));
1420 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme)); 1410 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme));
1421 1411
1422 NavigationObserver form_observer(WebContents()); 1412 NavigationObserver form_observer(WebContents());
1423 ui_test_utils::NavigateToURL(browser(), https_url); 1413 ui_test_utils::NavigateToURL(browser(), https_url);
1424 form_observer.Wait(); 1414 form_observer.Wait();
1425 1415
1426 std::string fill_and_submit_redirect = 1416 std::string fill_and_submit_redirect =
1427 "document.getElementById('username_redirect').value = 'user';" 1417 "document.getElementById('username_redirect').value = 'user';"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 WaitForPasswordStore(); 1494 WaitForPasswordStore();
1505 1495
1506 // Let the user interact with the page, so that DOM gets modification events, 1496 // Let the user interact with the page, so that DOM gets modification events,
1507 // needed for autofilling fields. 1497 // needed for autofilling fields.
1508 content::SimulateMouseClickAt( 1498 content::SimulateMouseClickAt(
1509 WebContents(), 0, blink::WebMouseEvent::Button::Left, gfx::Point(1, 1)); 1499 WebContents(), 0, blink::WebMouseEvent::Button::Left, gfx::Point(1, 1));
1510 WaitForElementValue("username_field", "user"); 1500 WaitForElementValue("username_field", "user");
1511 CheckElementValue("password_field", "12345"); 1501 CheckElementValue("password_field", "12345");
1512 } 1502 }
1513 1503
1504 // Tests that obsolete HTTP credentials are moved when a site migrated to HTTPS
1505 // and has HSTS enabled.
1506 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1507 ObsoleteHttpCredentialMovedOnMigrationToHstsSite) {
1508 // Add an http credential to the password store.
1509 GURL https_origin = https_test_server().base_url();
1510 ASSERT_TRUE(https_origin.SchemeIs(url::kHttpsScheme));
1511 GURL::Replacements rep;
1512 rep.SetSchemeStr(url::kHttpScheme);
1513 GURL http_origin = https_origin.ReplaceComponents(rep);
1514 autofill::PasswordForm http_form;
1515 http_form.signon_realm = http_origin.spec();
1516 http_form.origin = http_origin;
1517 http_form.username_value = base::ASCIIToUTF16("user");
1518 http_form.password_value = base::ASCIIToUTF16("12345");
1519 scoped_refptr<password_manager::TestPasswordStore> password_store =
1520 static_cast<password_manager::TestPasswordStore*>(
1521 PasswordStoreFactory::GetForProfile(
1522 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
1523 .get());
1524 password_store->AddLogin(http_form);
1525
1526 // Treat the host of the HTTPS test server as HSTS.
1527 AddHSTSHost(https_test_server().host_port_pair().host());
1528
1529 // Navigate to HTTPS page and trigger the migration.
1530 NavigationObserver form_observer(WebContents());
1531 ui_test_utils::NavigateToURL(
1532 browser(), https_test_server().GetURL("/password/password_form.html"));
1533 form_observer.Wait();
1534
1535 // Issue the query for HTTPS credentials.
1536 WaitForPasswordStore();
1537
1538 // Realize there are no HTTPS credentials and issue the query for HTTP
1539 // credentials instead.
1540 WaitForPasswordStore();
1541
1542 // Sync with IO thread before continuing. This is necessary, because the
1543 // credential migration triggers a query for the HSTS state which gets
1544 // executed on the IO thread. The actual task is empty, because only the reply
1545 // is relevant. By the time the reply is executed it is guaranteed that the
1546 // migration is completed.
1547 const auto empty_lambda = []() {};
1548 base::RunLoop run_loop;
1549 content::BrowserThread::PostTaskAndReply(content::BrowserThread::IO,
1550 FROM_HERE, base::Bind(empty_lambda),
1551 run_loop.QuitClosure());
1552 run_loop.Run();
1553
1554 // Only HTTPS passwords should be present.
1555 EXPECT_TRUE(
1556 password_store->stored_passwords().at(http_origin.spec()).empty());
1557 EXPECT_FALSE(
1558 password_store->stored_passwords().at(https_origin.spec()).empty());
1559 }
1560
1514 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1561 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1515 PromptWhenPasswordFormWithoutUsernameFieldSubmitted) { 1562 PromptWhenPasswordFormWithoutUsernameFieldSubmitted) {
1516 scoped_refptr<password_manager::TestPasswordStore> password_store = 1563 scoped_refptr<password_manager::TestPasswordStore> password_store =
1517 static_cast<password_manager::TestPasswordStore*>( 1564 static_cast<password_manager::TestPasswordStore*>(
1518 PasswordStoreFactory::GetForProfile( 1565 PasswordStoreFactory::GetForProfile(
1519 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); 1566 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
1520 1567
1521 EXPECT_TRUE(password_store->IsEmpty()); 1568 EXPECT_TRUE(password_store->IsEmpty());
1522 1569
1523 NavigateToFile("/password/form_with_only_password_field.html"); 1570 NavigateToFile("/password/form_with_only_password_field.html");
(...skipping 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after
3296 gfx::Point(left + 1, top + 1)); 3343 gfx::Point(left + 1, top + 1));
3297 // Force a round-trip. 3344 // Force a round-trip.
3298 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), "var noop = 'noop';")); 3345 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), "var noop = 'noop';"));
3299 // Ensure the warning was not triggered. 3346 // Ensure the warning was not triggered.
3300 ASSERT_FALSE(observing_autofill_client->DidPopupAppear()); 3347 ASSERT_FALSE(observing_autofill_client->DidPopupAppear());
3301 // Ensure the histogram remains empty. 3348 // Ensure the histogram remains empty.
3302 histograms.ExpectTotalCount(kHistogram, 0); 3349 histograms.ExpectTotalCount(kHistogram, 0);
3303 } 3350 }
3304 3351
3305 } // namespace password_manager 3352 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698