summaryrefslogtreecommitdiffstats
path: root/net/socket/socks5_client_socket_unittest.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 00:24:37 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 00:24:37 +0000
commitf209dba88c91b0461dc5acd02af0b3685213938c (patch)
tree00fd853220b8ad787dc9134f7494da1b8c30af6f /net/socket/socks5_client_socket_unittest.cc
parenta784b84a86ec0103b9af04772b573a91684a8a73 (diff)
downloadchromium_src-f209dba88c91b0461dc5acd02af0b3685213938c.zip
chromium_src-f209dba88c91b0461dc5acd02af0b3685213938c.tar.gz
chromium_src-f209dba88c91b0461dc5acd02af0b3685213938c.tar.bz2
When talking to a SOCKS v5 proxy, default to sending addresses as raw domains rather than IP addresses.
Before, we would default to client-side DNS resolution (sending IP addresses to the proxy) for both v4 and v5. However if you are using a v5 server, it is most likely that you want to do the resolves on the proxy-side. And in fact if you are using a SOCKS 5 proxy to anonymize your browsing, you definitely don't want that as the default policy. Embedders of the network stack can select the alternate policy by passing a non-NULL Host resolver into SOCKS5ClientSocket. BUG=29914 TEST=HttpNetworkTransactionTest.SOCKS5_HTTP_GET, HttpNetworkTransactionTest.SOCKS5_SSL_GET Review URL: http://codereview.chromium.org/507033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34903 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socks5_client_socket_unittest.cc')
-rw-r--r--net/socket/socks5_client_socket_unittest.cc71
1 files changed, 58 insertions, 13 deletions
diff --git a/net/socket/socks5_client_socket_unittest.cc b/net/socket/socks5_client_socket_unittest.cc
index aa4c454..b03d92b 100644
--- a/net/socket/socks5_client_socket_unittest.cc
+++ b/net/socket/socks5_client_socket_unittest.cc
@@ -31,7 +31,9 @@ class SOCKS5ClientSocketTest : public PlatformTest {
SOCKS5ClientSocket* BuildMockSocket(MockRead reads[],
MockWrite writes[],
const std::string& hostname,
- int port);
+ int port,
+ HostResolver* host_resolver);
+
virtual void SetUp();
protected:
@@ -65,8 +67,8 @@ SOCKS5ClientSocket* SOCKS5ClientSocketTest::BuildMockSocket(
MockRead reads[],
MockWrite writes[],
const std::string& hostname,
- int port) {
-
+ int port,
+ net::HostResolver* host_resolver) {
TestCompletionCallback callback;
data_.reset(new StaticSocketDataProvider(reads, writes));
tcp_sock_ = new MockTCPClientSocket(address_list_, data_.get());
@@ -79,7 +81,7 @@ SOCKS5ClientSocket* SOCKS5ClientSocketTest::BuildMockSocket(
return new SOCKS5ClientSocket(tcp_sock_,
HostResolver::RequestInfo(hostname, port),
- host_resolver_);
+ host_resolver);
}
const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
@@ -104,7 +106,8 @@ TEST_F(SOCKS5ClientSocketTest, CompleteHandshake) {
MockRead(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)),
MockRead(true, payload_read.data(), payload_read.size()) };
- user_sock_.reset(BuildMockSocket(data_reads, data_writes, "localhost", 80));
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, "localhost", 80,
+ new MockHostResolver));
// At this state the TCP connection is completed but not the SOCKS handshake.
EXPECT_TRUE(tcp_sock_->IsConnected());
@@ -150,7 +153,8 @@ TEST_F(SOCKS5ClientSocketTest, FailedDNS) {
const std::string hostname = "unresolved.ipv4.address";
const char kSOCKS5DomainRequest[] = { 0x05, 0x01, 0x00, 0x03 };
- host_resolver_->rules()->AddSimulatedFailure(hostname.c_str());
+ scoped_refptr<MockHostResolver> mock_resolver = new MockHostResolver;
+ mock_resolver->rules()->AddSimulatedFailure(hostname);
std::string request(kSOCKS5DomainRequest,
arraysize(kSOCKS5DomainRequest));
@@ -165,7 +169,8 @@ TEST_F(SOCKS5ClientSocketTest, FailedDNS) {
MockRead(false, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
MockRead(false, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) };
- user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80));
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80,
+ mock_resolver));
scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
int rv = user_sock_->Connect(&callback_, log);
@@ -181,6 +186,40 @@ TEST_F(SOCKS5ClientSocketTest, FailedDNS) {
*log, -1, LoadLog::TYPE_SOCKS5_CONNECT, LoadLog::PHASE_END));
}
+// Connect to a domain, making sure to defer the host resolving to the proxy
+// server.
+TEST_F(SOCKS5ClientSocketTest, ResolveHostsProxySide) {
+ const std::string hostname = "my-host-name";
+ const char kSOCKS5DomainRequest[] = {
+ 0x05, // VER
+ 0x01, // CMD
+ 0x00, // RSV
+ 0x03, // ATYPE
+ };
+
+ std::string request(kSOCKS5DomainRequest,
+ arraysize(kSOCKS5DomainRequest));
+ request.push_back(hostname.size());
+ request.append(hostname);
+ request.append(reinterpret_cast<const char*>(&kNwPort), sizeof(kNwPort));
+
+ MockWrite data_writes[] = {
+ MockWrite(false, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
+ MockWrite(false, request.data(), request.size())
+ };
+ MockRead data_reads[] = {
+ MockRead(false, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
+ MockRead(false, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse))
+ };
+
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80,
+ NULL));
+
+ int rv = user_sock_->Connect(&callback_, NULL);
+ EXPECT_EQ(OK, rv);
+ EXPECT_TRUE(user_sock_->IsConnected());
+}
+
// Tries to connect to a domain that resolves to IPv6.
TEST_F(SOCKS5ClientSocketTest, IPv6Domain) {
const std::string hostname = "an.ipv6.address";
@@ -188,7 +227,8 @@ TEST_F(SOCKS5ClientSocketTest, IPv6Domain) {
const uint8 ipv6_addr[] = { 0x20, 0x01, 0x0d, 0xb8, 0x87, 0x14, 0x3a, 0x90,
0x00, 0x00, 0x00, 0x00, 0x00, 0x000, 0x00, 0x12 };
- host_resolver_->rules()->AddIPv6Rule(hostname, "2001:db8:8714:3a90::12");
+ scoped_refptr<MockHostResolver> mock_resolver = new MockHostResolver;
+ mock_resolver->rules()->AddIPv6Rule(hostname, "2001:db8:8714:3a90::12");
std::string request(kSOCKS5IPv6Request,
arraysize(kSOCKS5IPv6Request));
@@ -202,7 +242,8 @@ TEST_F(SOCKS5ClientSocketTest, IPv6Domain) {
MockRead(false, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
MockRead(false, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) };
- user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80));
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80,
+ mock_resolver));
scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
int rv = user_sock_->Connect(&callback_, log);
@@ -232,7 +273,8 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) {
MockRead data_reads[] = {
MockRead(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
MockRead(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) };
- user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80));
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80,
+ new MockHostResolver));
scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
int rv = user_sock_->Connect(&callback_, log);
EXPECT_EQ(ERR_IO_PENDING, rv);
@@ -256,7 +298,8 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) {
MockRead(true, partial1, arraysize(partial1)),
MockRead(true, partial2, arraysize(partial2)),
MockRead(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) };
- user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80));
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80,
+ new MockHostResolver));
scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
int rv = user_sock_->Connect(&callback_, log);
EXPECT_EQ(ERR_IO_PENDING, rv);
@@ -280,7 +323,8 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) {
MockRead data_reads[] = {
MockRead(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
MockRead(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) };
- user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80));
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80,
+ new MockHostResolver));
scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
int rv = user_sock_->Connect(&callback_, log);
EXPECT_EQ(ERR_IO_PENDING, rv);
@@ -304,7 +348,8 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) {
MockRead(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
MockRead(true, partial1, arraysize(partial1)),
MockRead(true, partial2, arraysize(partial2)) };
- user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80));
+ user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80,
+ new MockHostResolver));
scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
int rv = user_sock_->Connect(&callback_, log);
EXPECT_EQ(ERR_IO_PENDING, rv);