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

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

Issue 2607413003: Add security feature to ProvisionalSavePassword (Closed)
Patch Set: Almost Working Browser Test Created 3 years, 11 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 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 std::unique_ptr<BubbleObserver> prompt_observer( 1405 std::unique_ptr<BubbleObserver> prompt_observer(
1406 new BubbleObserver(WebContents())); 1406 new BubbleObserver(WebContents()));
1407 ui_test_utils::NavigateToURL(browser(), https_url); 1407 ui_test_utils::NavigateToURL(browser(), https_url);
1408 1408
1409 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); 1409 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html");
1410 observer.Wait(); 1410 observer.Wait();
1411 1411
1412 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1412 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
1413 } 1413 }
1414 1414
1415 IN_PROC_BROWSER_TEST_F(
1416 PasswordManagerBrowserTestBase,
1417 NoPromptForSeperateLoginFormWhenSwitchingFromHttpsToHttp) {
1418 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1419 ::switches::kAllowRunningInsecureContent);
1420 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1421 ::switches::kIgnoreCertificateErrors);
1422 const base::FilePath::CharType kDocRoot[] =
1423 FILE_PATH_LITERAL("chrome/test/data");
1424 net::EmbeddedTestServer https_test_server(
1425 net::EmbeddedTestServer::TYPE_HTTPS);
1426 https_test_server.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
1427 ASSERT_TRUE(https_test_server.Start());
1428
1429 // Setup the mock host resolver
1430 host_resolver()->AddRule("*", "127.0.0.1");
1431
1432 std::string path = "/password/password_form.html";
1433 GURL https_url(https_test_server.GetURL(path));
1434 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme));
1435
1436 NavigationObserver form_observer(WebContents());
1437 ui_test_utils::NavigateToURL(browser(), https_url);
1438 form_observer.Wait();
1439
1440 std::string fill_and_submit_redirect =
1441 "document.getElementById('username_redirect').value = 'user';"
1442 "document.getElementById('password_redirect').value = 'password';"
1443 "document.getElementById('submit_redirect').click()";
1444 ASSERT_TRUE(
1445 content::ExecuteScript(RenderViewHost(), fill_and_submit_redirect));
1446
1447 NavigationObserver redirect_observer(WebContents());
1448 redirect_observer.SetPathToWaitFor("/password/redirect.html");
1449 redirect_observer.Wait();
1450
1451 GURL http_url(embedded_test_server()->GetURL("/password/done.html"));
1452 std::string http_redirect =
1453 "window.location.href = '" + http_url.spec() + "';";
1454 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), http_redirect));
1455
1456 NavigationObserver first_done_observer(WebContents());
1457 first_done_observer.SetPathToWaitFor("/password/done.html");
vasilii 2017/01/05 11:26:11 Looks like an unnecessary step. You can land on si
jdoerrie 2017/01/05 18:11:30 You are right. My intention was to simulate an att
vasilii 2017/01/09 14:16:55 The attacker don't need to redirect to simple_pass
1458 first_done_observer.Wait();
1459
1460 std::string attacker_redirect =
1461 "window.location.href = 'simple_password.html'";
1462 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), attacker_redirect));
1463
1464 NavigationObserver attacker_observer(WebContents());
1465 attacker_observer.SetPathToWaitFor("/password/simple_password.html");
1466 attacker_observer.Wait();
1467
1468 std::string fill_and_submit_attacker_form =
1469 "document.getElementById('username_field').value = 'attacker_username';"
1470 "document.getElementById('password_field').value = 'attacker_password';"
1471 "document.getElementById('input_submit_button').click()";
1472 ASSERT_TRUE(
1473 content::ExecuteScript(RenderViewHost(), fill_and_submit_attacker_form));
1474
1475 NavigationObserver second_done_observer(WebContents());
1476 second_done_observer.SetPathToWaitFor("/password/done.html");
1477 second_done_observer.Wait();
1478
1479 BubbleObserver prompt_observer(WebContents());
1480 EXPECT_TRUE(prompt_observer.IsShowingSavePrompt());
1481 prompt_observer.AcceptSavePrompt();
1482
1483 // Check that credentials are stored.
1484 scoped_refptr<password_manager::TestPasswordStore> password_store =
1485 static_cast<password_manager::TestPasswordStore*>(
1486 PasswordStoreFactory::GetForProfile(
1487 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
1488 .get());
1489
1490 // Spin the message loop to make sure the password store had a chance to save
1491 // the password.
1492 base::RunLoop run_loop;
1493 run_loop.RunUntilIdle();
vasilii 2017/01/05 11:26:11 It's dangerous in the browser test. Use WaitForPas
jdoerrie 2017/01/05 18:11:30 WaitForPasswordStore() is only implemented for Cre
vasilii 2017/01/09 14:16:55 They are all unsafe. The documentation says clearl
1494 EXPECT_FALSE(password_store->IsEmpty());
1495
1496 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("user"),
jdoerrie 2017/01/04 16:55:18 This test currently fails, because |ShouldBlockPas
vasilii 2017/01/05 11:26:11 Sounds like a bug in production. In the real world
jdoerrie 2017/01/05 18:11:30 Acknowledged, dropped the check for port equality.
1497 base::ASCIIToUTF16("password"));
1498 }
1499
1415 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1500 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1416 PromptWhenPasswordFormWithoutUsernameFieldSubmitted) { 1501 PromptWhenPasswordFormWithoutUsernameFieldSubmitted) {
1417 scoped_refptr<password_manager::TestPasswordStore> password_store = 1502 scoped_refptr<password_manager::TestPasswordStore> password_store =
1418 static_cast<password_manager::TestPasswordStore*>( 1503 static_cast<password_manager::TestPasswordStore*>(
1419 PasswordStoreFactory::GetForProfile( 1504 PasswordStoreFactory::GetForProfile(
1420 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); 1505 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
1421 1506
1422 EXPECT_TRUE(password_store->IsEmpty()); 1507 EXPECT_TRUE(password_store->IsEmpty());
1423 1508
1424 NavigateToFile("/password/form_with_only_password_field.html"); 1509 NavigateToFile("/password/form_with_only_password_field.html");
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after
3077 // about all frames, not just the main one. The factories should receive 3162 // about all frames, not just the main one. The factories should receive
3078 // messages for non-main frames, in particular 3163 // messages for non-main frames, in particular
3079 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the 3164 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the
3080 // factories hear about such frames, this would crash. 3165 // factories hear about such frames, this would crash.
3081 tab_strip_model->AddWebContents(detached_web_contents.release(), -1, 3166 tab_strip_model->AddWebContents(detached_web_contents.release(), -1,
3082 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 3167 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
3083 TabStripModel::ADD_ACTIVE); 3168 TabStripModel::ADD_ACTIVE);
3084 } 3169 }
3085 3170
3086 } // namespace password_manager 3171 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698