Revert of Implement argument validation for chrome.cast.channel.{open,send}...

Revert of Implement argument validation for chrome.cast.channel.{open,send} (https://codereview.chromium.org/255443002/)

Reason for revert:
Causing leaks: http://build.chromium.org/p/chromium.memory/builders/Linux%20ASan%20LSan%20Tests%20%282%29/builds/2069

Original issue's description:
> Implement argument validation for chrome.cast.channel.{open,send}
> 
> TESTED=Unit test.  Manually with Cast extension
> BUG=331165
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=266804

TBR=munjal@chromium.org,imcheng@chromium.org,mfoltz@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=331165

Review URL: https://codereview.chromium.org/256333002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266833 0039d316-1c4b-4281-b951-d872f2087c98
parent 98913573
...@@ -280,8 +280,6 @@ bool CastChannelOpenFunction::Prepare() { ...@@ -280,8 +280,6 @@ bool CastChannelOpenFunction::Prepare() {
connect_info_.reset(new ConnectInfo); connect_info_.reset(new ConnectInfo);
if (!ParseChannelUrl(GURL(cast_url), connect_info_.get())) { if (!ParseChannelUrl(GURL(cast_url), connect_info_.get())) {
connect_info_.reset(); connect_info_.reset();
SetError("Invalid Cast URL " + cast_url);
return false;
} }
break; break;
case base::Value::TYPE_DICTIONARY: case base::Value::TYPE_DICTIONARY:
...@@ -290,17 +288,12 @@ bool CastChannelOpenFunction::Prepare() { ...@@ -290,17 +288,12 @@ bool CastChannelOpenFunction::Prepare() {
default: default:
break; break;
} }
if (!connect_info_.get()) { if (connect_info_.get()) {
SetError("Invalid connect_info"); channel_auth_ = connect_info_->auth;
return false; ip_endpoint_.reset(ParseConnectInfo(*connect_info_));
} return ip_endpoint_.get() != NULL;
channel_auth_ = connect_info_->auth;
ip_endpoint_.reset(ParseConnectInfo(*connect_info_));
if (!ip_endpoint_.get()) {
SetError("Invalid connect_info");
return false;
} }
return true; return false;
} }
void CastChannelOpenFunction::AsyncWorkStart() { void CastChannelOpenFunction::AsyncWorkStart() {
...@@ -326,26 +319,6 @@ CastChannelSendFunction::~CastChannelSendFunction() { } ...@@ -326,26 +319,6 @@ CastChannelSendFunction::~CastChannelSendFunction() { }
bool CastChannelSendFunction::Prepare() { bool CastChannelSendFunction::Prepare() {
params_ = Send::Params::Create(*args_); params_ = Send::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get()); EXTENSION_FUNCTION_VALIDATE(params_.get());
if (params_->message.namespace_.empty()) {
SetError("message_info.namespace_ is required");
return false;
}
if (params_->message.source_id.empty()) {
SetError("message_info.source_id is required");
return false;
}
if (params_->message.destination_id.empty()) {
SetError("message_info.destination_id is required");
return false;
}
switch (params_->message.data->GetType()) {
case base::Value::TYPE_STRING:
case base::Value::TYPE_BINARY:
break;
default:
SetError("Invalid type of message_info.data");
return false;
}
return true; return true;
} }
......
...@@ -137,12 +137,12 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction { ...@@ -137,12 +137,12 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction {
// corresponding details, and returns true. Returns false if |url| is not a // corresponding details, and returns true. Returns false if |url| is not a
// valid Cast URL. // valid Cast URL.
static bool ParseChannelUrl(const GURL& url, static bool ParseChannelUrl(const GURL& url,
cast_channel::ConnectInfo* connect_info); api::cast_channel::ConnectInfo* connect_info);
// Validates that |connect_info| represents a valid IP end point and returns a // Validates that |connect_info| represents a valid IP end point and returns a
// new IPEndPoint if so. Otherwise returns NULL. // new IPEndPoint if so. Otherwise returns NULL.
static net::IPEndPoint* ParseConnectInfo( static net::IPEndPoint* ParseConnectInfo(
const cast_channel::ConnectInfo& connect_info); const api::cast_channel::ConnectInfo& connect_info);
void OnOpen(int result); void OnOpen(int result);
...@@ -150,18 +150,12 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction { ...@@ -150,18 +150,12 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction {
// The id of the newly opened socket. // The id of the newly opened socket.
int new_channel_id_; int new_channel_id_;
CastChannelAPI* api_; CastChannelAPI* api_;
scoped_ptr<cast_channel::ConnectInfo> connect_info_; scoped_ptr<api::cast_channel::ConnectInfo> connect_info_;
scoped_ptr<net::IPEndPoint> ip_endpoint_; scoped_ptr<net::IPEndPoint> ip_endpoint_;
cast_channel::ChannelAuthType channel_auth_; api::cast_channel::ChannelAuthType channel_auth_;
FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseChannelUrl); FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseChannelUrl);
FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo);
FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestPrepareValidUrl);
FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestPrepareInvalidUrl);
FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest,
TestPrepareValidConnectInfo);
FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest,
TestPrepareInvalidConnectInfo);
DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction);
}; };
...@@ -183,10 +177,6 @@ class CastChannelSendFunction : public CastChannelAsyncApiFunction { ...@@ -183,10 +177,6 @@ class CastChannelSendFunction : public CastChannelAsyncApiFunction {
scoped_ptr<cast_channel::Send::Params> params_; scoped_ptr<cast_channel::Send::Params> params_;
FRIEND_TEST_ALL_PREFIXES(CastChannelSendFunctionTest,
TestPrepareValidMessageInfo);
FRIEND_TEST_ALL_PREFIXES(CastChannelSendFunctionTest,
TestPrepareInvalidMessageInfo);
DISALLOW_COPY_AND_ASSIGN(CastChannelSendFunction); DISALLOW_COPY_AND_ASSIGN(CastChannelSendFunction);
}; };
......
...@@ -4,46 +4,31 @@ ...@@ -4,46 +4,31 @@
#include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" #include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "net/base/ip_endpoint.h" #include "net/base/ip_endpoint.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace {
base::ListValue* parseList(const std::string& json) {
base::ListValue* result = NULL;
base::Value* parsed = base::JSONReader::Read(json);
CHECK(parsed);
CHECK(parsed->GetAsList(&result));
CHECK(result);
return result;
}
} // namespace
namespace extensions { namespace extensions {
namespace api {
namespace cast_channel {
// Tests URL parsing and validation. // Tests URL parsing and validation.
TEST(CastChannelOpenFunctionTest, TestParseChannelUrl) { TEST(CastChannelOpenFunctionTest, TestParseChannelUrl) {
typedef CastChannelOpenFunction ccof; typedef CastChannelOpenFunction ccof;
cast_channel::ConnectInfo connect_info; ConnectInfo connect_info;
EXPECT_TRUE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:8009"), EXPECT_TRUE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:8009"),
&connect_info)); &connect_info));
EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); EXPECT_EQ(connect_info.ip_address, "192.0.0.1");
EXPECT_EQ(connect_info.port, 8009); EXPECT_EQ(connect_info.port, 8009);
EXPECT_EQ(connect_info.auth, cast_channel::CHANNEL_AUTH_TYPE_SSL); EXPECT_EQ(connect_info.auth, CHANNEL_AUTH_TYPE_SSL);
EXPECT_TRUE(ccof::ParseChannelUrl(GURL("casts://192.0.0.1:12345"), EXPECT_TRUE(ccof::ParseChannelUrl(GURL("casts://192.0.0.1:12345"),
&connect_info)); &connect_info));
EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); EXPECT_EQ(connect_info.ip_address, "192.0.0.1");
EXPECT_EQ(connect_info.port, 12345); EXPECT_EQ(connect_info.port, 12345);
EXPECT_EQ(connect_info.auth, cast_channel::CHANNEL_AUTH_TYPE_SSL_VERIFIED); EXPECT_EQ(connect_info.auth, CHANNEL_AUTH_TYPE_SSL_VERIFIED);
EXPECT_FALSE(ccof::ParseChannelUrl(GURL("http://192.0.0.1:12345"), EXPECT_FALSE(ccof::ParseChannelUrl(GURL("http://192.0.0.1:12345"),
&connect_info)); &connect_info));
...@@ -67,107 +52,40 @@ TEST(CastChannelOpenFunctionTest, TestParseConnectInfo) { ...@@ -67,107 +52,40 @@ TEST(CastChannelOpenFunctionTest, TestParseConnectInfo) {
scoped_ptr<net::IPEndPoint> ip_endpoint; scoped_ptr<net::IPEndPoint> ip_endpoint;
// Valid ConnectInfo // Valid ConnectInfo
cast_channel::ConnectInfo connect_info; ConnectInfo connect_info;
connect_info.ip_address = "192.0.0.1"; connect_info.ip_address = "192.0.0.1";
connect_info.port = 8009; connect_info.port = 8009;
connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL; connect_info.auth = CHANNEL_AUTH_TYPE_SSL;
ip_endpoint.reset(ccof::ParseConnectInfo(connect_info)); ip_endpoint.reset(ccof::ParseConnectInfo(connect_info));
EXPECT_TRUE(ip_endpoint.get() != NULL); EXPECT_TRUE(ip_endpoint.get() != NULL);
EXPECT_EQ(ip_endpoint->ToString(), "192.0.0.1:8009"); EXPECT_EQ(ip_endpoint->ToString(), "192.0.0.1:8009");
// Invalid IP // Invalid IP
cast_channel::ConnectInfo invalid_ip_connect_info; ConnectInfo invalid_ip_connect_info;
invalid_ip_connect_info.ip_address = "blargh"; invalid_ip_connect_info.ip_address = "blargh";
invalid_ip_connect_info.port = 8009; invalid_ip_connect_info.port = 8009;
invalid_ip_connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL; invalid_ip_connect_info.auth = CHANNEL_AUTH_TYPE_SSL;
ip_endpoint.reset(ccof::ParseConnectInfo(invalid_ip_connect_info)); ip_endpoint.reset(ccof::ParseConnectInfo(invalid_ip_connect_info));
EXPECT_TRUE(ip_endpoint.get() == NULL); EXPECT_TRUE(ip_endpoint.get() == NULL);
// Invalid port // Invalid port
cast_channel::ConnectInfo invalid_port_connect_info; ConnectInfo invalid_port_connect_info;
invalid_port_connect_info.ip_address = "192.0.0.1"; invalid_port_connect_info.ip_address = "192.0.0.1";
invalid_port_connect_info.port = -1; invalid_port_connect_info.port = -1;
invalid_port_connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL; invalid_port_connect_info.auth = CHANNEL_AUTH_TYPE_SSL;
ip_endpoint.reset(ccof::ParseConnectInfo(invalid_port_connect_info)); ip_endpoint.reset(ccof::ParseConnectInfo(invalid_port_connect_info));
EXPECT_TRUE(ip_endpoint.get() == NULL); EXPECT_TRUE(ip_endpoint.get() == NULL);
// Invalid auth // Invalid auth
cast_channel::ConnectInfo invalid_auth_connect_info; ConnectInfo invalid_auth_connect_info;
invalid_auth_connect_info.ip_address = "192.0.0.1"; invalid_auth_connect_info.ip_address = "192.0.0.1";
invalid_auth_connect_info.port = 8009; invalid_auth_connect_info.port = 8009;
invalid_auth_connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_NONE; invalid_auth_connect_info.auth = CHANNEL_AUTH_TYPE_NONE;
ip_endpoint.reset(ccof::ParseConnectInfo(invalid_auth_connect_info)); ip_endpoint.reset(ccof::ParseConnectInfo(invalid_auth_connect_info));
EXPECT_TRUE(ip_endpoint.get() == NULL); EXPECT_TRUE(ip_endpoint.get() == NULL);
} }
TEST(CastChannelOpenFunctionTest, TestPrepareValidUrl) { } // namespace cast_channel
scoped_refptr<CastChannelOpenFunction> ccof(new CastChannelOpenFunction); } // namespace api
scoped_ptr<base::ListValue> params_json(
parseList("[\"casts://127.0.0.1:8009\"]"));
ccof->SetArgs(params_json.get());
EXPECT_TRUE(ccof->Prepare());
EXPECT_TRUE(ccof->GetError().empty());
}
TEST(CastChannelOpenFunctionTest, TestPrepareInvalidUrl) {
scoped_refptr<CastChannelOpenFunction> ccof(new CastChannelOpenFunction);
scoped_ptr<base::ListValue> params_json(parseList("[\"blargh\"]"));
ccof->SetArgs(params_json.get());
EXPECT_FALSE(ccof->Prepare());
EXPECT_EQ(ccof->GetError(), "Invalid Cast URL blargh");
}
TEST(CastChannelOpenFunctionTest, TestPrepareValidConnectInfo) {
scoped_refptr<CastChannelOpenFunction> ccof(new CastChannelOpenFunction);
scoped_ptr<base::ListValue> params_json(
parseList("[{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
"\"auth\": \"ssl\"}]"));
ccof->SetArgs(params_json.get());
EXPECT_TRUE(ccof->Prepare());
EXPECT_TRUE(ccof->GetError().empty());
}
TEST(CastChannelOpenFunctionTest, TestPrepareInvalidConnectInfo) {
scoped_refptr<CastChannelOpenFunction> ccof(new CastChannelOpenFunction);
scoped_ptr<base::ListValue> params_json(parseList("[12345]"));
ccof->SetArgs(params_json.get());
EXPECT_FALSE(ccof->Prepare());
EXPECT_EQ(ccof->GetError(), "Invalid connect_info");
}
TEST(CastChannelSendFunctionTest, TestPrepareValidMessageInfo) {
scoped_refptr<CastChannelSendFunction> ccsf(new CastChannelSendFunction);
scoped_ptr<base::ListValue> params_json(
parseList("[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
"\"connectInfo\": "
"{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
"\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
"{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
"\"destinationId\": \"bar\", \"data\": \"string\"}]"));
ccsf->SetArgs(params_json.get());
EXPECT_TRUE(ccsf->Prepare());
EXPECT_TRUE(ccsf->GetError().empty());
}
TEST(CastChannelSendFunctionTest, TestPrepareInvalidMessageInfo) {
scoped_refptr<CastChannelSendFunction> ccsf(new CastChannelSendFunction);
scoped_ptr<base::ListValue> params_json(
parseList("[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
"\"connectInfo\": "
"{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
"\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
"{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
"\"destinationId\": \"bar\", \"data\": 1235}]"));
ccsf->SetArgs(params_json.get());
EXPECT_FALSE(ccsf->Prepare());
EXPECT_EQ(ccsf->GetError(), "Invalid type of message_info.data");
}
} // namespace extensions } // namespace extensions
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment