summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/url_request/url_request_unittest.cc70
-rw-r--r--net/url_request/url_request_unittest.h71
-rw-r--r--third_party/pyftpdlib/README.chromium6
-rw-r--r--third_party/pyftpdlib/chromium.patch23
-rw-r--r--third_party/pyftpdlib/pyftpdlib/ftpserver.py8
5 files changed, 99 insertions, 79 deletions
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 6f4338c..640174f 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -1919,15 +1919,30 @@ TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) {
EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
}
-TEST_F(URLRequestTest, FTPGetTestAnonymous) {
- scoped_refptr<FTPTestServer> server = FTPTestServer::CreateServer(L"");
- ASSERT_TRUE(NULL != server.get());
+class URLRequestTestFTP : public URLRequestTest {
+ protected:
+ static void SetUpTestCase() {
+ server_ = FTPTestServer::CreateServer(L"");
+ }
+
+ static void TearDownTestCase() {
+ server_ = NULL;
+ }
+
+ static scoped_refptr<FTPTestServer> server_;
+};
+
+// static
+scoped_refptr<FTPTestServer> URLRequestTestFTP::server_;
+
+TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -1943,16 +1958,15 @@ TEST_F(URLRequestTest, FTPGetTestAnonymous) {
}
}
-TEST_F(URLRequestTest, FTPGetTest) {
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "chrome", "chrome");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPGetTest) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "chrome"),
+ &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -1968,16 +1982,15 @@ TEST_F(URLRequestTest, FTPGetTest) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongPassword) {
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "chrome", "wrong_password");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "chrome", "wrong_password"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -1993,11 +2006,8 @@ TEST_F(URLRequestTest, FTPCheckWrongPassword) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongPasswordRestart) {
- // Pass wrong login credentials in the request URL.
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "chrome", "wrong_password");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
@@ -2007,7 +2017,8 @@ TEST_F(URLRequestTest, FTPCheckWrongPasswordRestart) {
d.set_username(L"chrome");
d.set_password(L"chrome");
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "chrome", "wrong_password"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -2023,16 +2034,15 @@ TEST_F(URLRequestTest, FTPCheckWrongPasswordRestart) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongUser) {
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "wrong_user", "chrome");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "wrong_user", "chrome"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -2048,11 +2058,8 @@ TEST_F(URLRequestTest, FTPCheckWrongUser) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongUserRestart) {
- // Pass wrong login credentials in the request URL.
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "wrong_user", "chrome");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
@@ -2062,7 +2069,8 @@ TEST_F(URLRequestTest, FTPCheckWrongUserRestart) {
d.set_username(L"chrome");
d.set_password(L"chrome");
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "wrong_user", "chrome"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index e058957..f16f0ae 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -263,11 +263,27 @@ class BaseTestServer : public base::RefCounted<BaseTestServer> {
}
GURL TestServerPage(const std::string& path) {
- return GURL(base_address_ + path);
+ // TODO(phajdan.jr): Check for problems with IPv6.
+ return GURL(scheme_ + "://" + host_name_ + ":" + port_str_ + "/" + path);
}
+ GURL TestServerPage(const std::string& path,
+ const std::string& user,
+ const std::string& password) {
+ // TODO(phajdan.jr): Check for problems with IPv6.
+
+ if (password.empty())
+ return GURL(scheme_ + "://" + user + "@" +
+ host_name_ + ":" + port_str_ + "/" + path);
+
+ return GURL(scheme_ + "://" + user + ":" + password +
+ "@" + host_name_ + ":" + port_str_ + "/" + path);
+ }
+
+ // Deprecated in favor of TestServerPage.
+ // TODO(phajdan.jr): Remove TestServerPageW.
GURL TestServerPageW(const std::wstring& path) {
- return GURL(base_address_ + WideToUTF8(path));
+ return TestServerPage(WideToUTF8(path));
}
virtual bool MakeGETRequest(const std::string& page_name) = 0;
@@ -282,41 +298,19 @@ class BaseTestServer : public base::RefCounted<BaseTestServer> {
const FilePath& document_root,
const FilePath& cert_path,
const std::wstring& file_root_url) {
- std::string blank;
- return Start(protocol, host_name, port, document_root, cert_path,
- file_root_url, blank, blank);
- }
-
- bool Start(net::TestServerLauncher::Protocol protocol,
- const std::string& host_name, int port,
- const FilePath& document_root,
- const FilePath& cert_path,
- const std::wstring& file_root_url,
- const std::string& url_user,
- const std::string& url_password) {
if (!launcher_.Start(protocol,
host_name, port, document_root, cert_path, file_root_url))
return false;
- std::string scheme;
if (protocol == net::TestServerLauncher::ProtoFTP)
- scheme = "ftp";
+ scheme_ = "ftp";
else
- scheme = "http";
+ scheme_ = "http";
if (!cert_path.empty())
- scheme.push_back('s');
+ scheme_.push_back('s');
- std::string port_str = IntToString(port);
- if (url_user.empty()) {
- base_address_ = scheme + "://" + host_name + ":" + port_str + "/";
- } else {
- if (url_password.empty())
- base_address_ = scheme + "://" + url_user + "@" +
- host_name + ":" + port_str + "/";
- else
- base_address_ = scheme + "://" + url_user + ":" + url_password +
- "@" + host_name + ":" + port_str + "/";
- }
+ host_name_ = host_name;
+ port_str_ = IntToString(port);
return true;
}
@@ -344,7 +338,9 @@ class BaseTestServer : public base::RefCounted<BaseTestServer> {
};
net::TestServerLauncher launcher_;
- std::string base_address_;
+ std::string scheme_;
+ std::string host_name_;
+ std::string port_str_;
};
@@ -419,7 +415,7 @@ class HTTPTestServer : public BaseTestServer {
const std::wstring& file_root_url) {
return server->Start(net::TestServerLauncher::ProtoHTTP, kDefaultHostName,
kHTTPDefaultPort, document_root, cert_path,
- file_root_url, "", "");
+ file_root_url);
}
// A subclass may wish to send the request in a different manner
@@ -577,27 +573,18 @@ class FTPTestServer : public BaseTestServer {
static scoped_refptr<FTPTestServer> CreateServer(
const std::wstring& document_root) {
- std::string blank;
- return CreateServer(document_root, blank, blank);
- }
-
- static scoped_refptr<FTPTestServer> CreateServer(
- const std::wstring& document_root,
- const std::string& url_user,
- const std::string& url_password) {
scoped_refptr<FTPTestServer> test_server = new FTPTestServer();
FilePath docroot = FilePath::FromWStringHack(document_root);
FilePath no_cert;
if (!test_server->Start(net::TestServerLauncher::ProtoFTP,
- kDefaultHostName, kFTPDefaultPort, docroot, no_cert, std::wstring(),
- url_user, url_password)) {
+ kDefaultHostName, kFTPDefaultPort, docroot, no_cert, std::wstring())) {
return NULL;
}
return test_server;
}
virtual bool MakeGETRequest(const std::string& page_name) {
- const GURL& url = TestServerPage(base_address_, page_name);
+ const GURL& url = TestServerPage(page_name);
TestDelegate d;
URLRequest request(url, &d);
request.set_context(new TestURLRequestContext());
diff --git a/third_party/pyftpdlib/README.chromium b/third_party/pyftpdlib/README.chromium
index a36b118..6415902 100644
--- a/third_party/pyftpdlib/README.chromium
+++ b/third_party/pyftpdlib/README.chromium
@@ -1,5 +1,9 @@
This library was downloaded from http://code.google.com/p/pyftpdlib/
+Chromium-specific changes are in chromium.patch file. Currently it removes the
+delay after invalid login (which helps protect against brute-force attacks),
+which is slowing down some tests.
+
For licensing information please LICENSE file
Python FTP server library provides an high-level portable interface to easily
@@ -9,4 +13,4 @@ available for Python programming language.
Version: 0.5.0
-Learn more by visiting: http://code.google.com/p/pyftpdlib/wiki/FAQ \ No newline at end of file
+Learn more by visiting: http://code.google.com/p/pyftpdlib/wiki/FAQ
diff --git a/third_party/pyftpdlib/chromium.patch b/third_party/pyftpdlib/chromium.patch
new file mode 100644
index 0000000..43a74c2
--- /dev/null
+++ b/third_party/pyftpdlib/chromium.patch
@@ -0,0 +1,23 @@
+--- pyftpdlib/ftpserver.py
++++ pyftpdlib/ftpserver.py
+@@ -2546,14 +2546,12 @@ class FTPHandler(asynchat.async_chat):
+ self.fs.root = self.authorizer.get_home_dir(self.username)
+ self.log("User %s logged in." %self.username)
+ else:
+- CallLater(5, auth_failed)
++ auth_failed()
+ self.username = ""
+- self.sleeping = True
+ # wrong username
+ else:
+ if self.username.lower() == 'anonymous':
+- CallLater(5, auth_failed, "Anonymous access not allowed.")
++ auth_failed("Anonymous access not allowed.")
+ else:
+- CallLater(5, auth_failed)
++ auth_failed()
+ self.username = ""
+- self.sleeping = True
+
+ def ftp_REIN(self, line):
+ """Reinitialize user's current session."""
diff --git a/third_party/pyftpdlib/pyftpdlib/ftpserver.py b/third_party/pyftpdlib/pyftpdlib/ftpserver.py
index d273f84..d48f010 100644
--- a/third_party/pyftpdlib/pyftpdlib/ftpserver.py
+++ b/third_party/pyftpdlib/pyftpdlib/ftpserver.py
@@ -2546,17 +2546,15 @@ class FTPHandler(asynchat.async_chat):
self.fs.root = self.authorizer.get_home_dir(self.username)
self.log("User %s logged in." %self.username)
else:
- CallLater(5, auth_failed)
+ auth_failed()
self.username = ""
- self.sleeping = True
# wrong username
else:
if self.username.lower() == 'anonymous':
- CallLater(5, auth_failed, "Anonymous access not allowed.")
+ auth_failed("Anonymous access not allowed.")
else:
- CallLater(5, auth_failed)
+ auth_failed()
self.username = ""
- self.sleeping = True
def ftp_REIN(self, line):
"""Reinitialize user's current session."""