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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc

Issue 491123004: Make sure that HttpRequestHeaders contains valid key-value pairs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: edit comment Created 6 years, 3 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) 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 // Disable everything on windows only. http://crbug.com/306144 5 // Disable everything on windows only. http://crbug.com/306144
6 #ifndef OS_WIN 6 #ifndef OS_WIN
7 7
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 "sEc-", 1596 "sEc-",
1597 "pRoxY-probably-not-evil", 1597 "pRoxY-probably-not-evil",
1598 "sEc-probably-not-evil", 1598 "sEc-probably-not-evil",
1599 "oRiGiN", 1599 "oRiGiN",
1600 "Access-Control-Request-Headers", 1600 "Access-Control-Request-Headers",
1601 "Access-Control-Request-Method", 1601 "Access-Control-Request-Method",
1602 }; 1602 };
1603 1603
1604 for (size_t index = 0; index < arraysize(kUnsafeHeaders); ++index) { 1604 for (size_t index = 0; index < arraysize(kUnsafeHeaders); ++index) {
1605 std::string download_url = test_server()->GetURL("slow?0").spec(); 1605 std::string download_url = test_server()->GetURL("slow?0").spec();
1606 EXPECT_STREQ(errors::kInvalidHeader, 1606 EXPECT_STREQ(errors::kInvalidHeaderUnsafe,
1607 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1607 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1608 base::StringPrintf( 1608 base::StringPrintf(
1609 "[{\"url\": \"%s\"," 1609 "[{\"url\": \"%s\","
1610 " \"filename\": \"unsafe-header-%d.txt\"," 1610 " \"filename\": \"unsafe-header-%d.txt\","
1611 " \"headers\": [{" 1611 " \"headers\": [{"
1612 " \"name\": \"%s\"," 1612 " \"name\": \"%s\","
1613 " \"value\": \"unsafe\"}]}]", 1613 " \"value\": \"unsafe\"}]}]",
1614 download_url.c_str(), 1614 download_url.c_str(),
1615 static_cast<int>(index), 1615 static_cast<int>(index),
1616 kUnsafeHeaders[index])).c_str()); 1616 kUnsafeHeaders[index])).c_str());
1617 } 1617 }
1618 } 1618 }
1619 1619
1620 // Tests that invalid header names and values are rejected.
1621 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1622 DownloadExtensionTest_Download_InvalidHeaders) {
1623 LoadExtension("downloads_split");
1624 ASSERT_TRUE(StartEmbeddedTestServer());
1625 ASSERT_TRUE(test_server()->Start());
1626 GoOnTheRecord();
1627 std::string download_url = test_server()->GetURL("slow?0").spec();
1628 EXPECT_STREQ(errors::kInvalidHeaderName,
1629 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1630 base::StringPrintf(
1631 "[{\"url\": \"%s\","
1632 " \"filename\": \"unsafe-header-crlf.txt\","
1633 " \"headers\": [{"
1634 " \"name\": \"Header\\r\\nSec-Spoof: Hey\\r\\nX-Split:X\","
1635 " \"value\": \"unsafe\"}]}]",
1636 download_url.c_str())).c_str());
1637
1638 EXPECT_STREQ(errors::kInvalidHeaderValue,
1639 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1640 base::StringPrintf(
1641 "[{\"url\": \"%s\","
1642 " \"filename\": \"unsafe-header-crlf.txt\","
1643 " \"headers\": [{"
1644 " \"name\": \"Invalid-value\","
1645 " \"value\": \"hey\\r\\nSec-Spoof: Hey\"}]}]",
1646 download_url.c_str())).c_str());
1647 }
1648
1620 #if defined(OS_WIN) 1649 #if defined(OS_WIN)
1621 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ 1650 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\
1622 DISABLED_DownloadExtensionTest_Download_Subdirectory 1651 DISABLED_DownloadExtensionTest_Download_Subdirectory
1623 #else 1652 #else
1624 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ 1653 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\
1625 DownloadExtensionTest_Download_Subdirectory 1654 DownloadExtensionTest_Download_Subdirectory
1626 #endif 1655 #endif
1627 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1656 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1628 MAYBE_DownloadExtensionTest_Download_Subdirectory) { 1657 MAYBE_DownloadExtensionTest_Download_Subdirectory) {
1629 LoadExtension("downloads_split"); 1658 LoadExtension("downloads_split");
(...skipping 2495 matching lines...) Expand 10 before | Expand all | Expand 10 after
4125 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); 4154 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action);
4126 EXPECT_FALSE(warnings.empty()); 4155 EXPECT_FALSE(warnings.empty());
4127 EXPECT_EQ(ExtensionWarning::kDownloadFilenameConflict, 4156 EXPECT_EQ(ExtensionWarning::kDownloadFilenameConflict,
4128 warnings.begin()->warning_type()); 4157 warnings.begin()->warning_type());
4129 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); 4158 EXPECT_EQ("incumbent", warnings.begin()->extension_id());
4130 } 4159 }
4131 4160
4132 } // namespace extensions 4161 } // namespace extensions
4133 4162
4134 #endif // http://crbug.com/3061144 4163 #endif // http://crbug.com/3061144
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | chrome/browser/extensions/api/web_request/web_request_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698