diff options
author | machenbach@chromium.org <machenbach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 10:48:34 +0000 |
---|---|---|
committer | machenbach@chromium.org <machenbach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 10:48:34 +0000 |
commit | 47a756f010f1fbd309260016212187b3277b43dd (patch) | |
tree | b7b5336d38255e533e798ba527860c3b74525a62 | |
parent | 989135730bfaee4ed3847e222b3c4da3c57cc723 (diff) | |
download | chromium_src-47a756f010f1fbd309260016212187b3277b43dd.zip chromium_src-47a756f010f1fbd309260016212187b3277b43dd.tar.gz chromium_src-47a756f010f1fbd309260016212187b3277b43dd.tar.bz2 |
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
3 files changed, 24 insertions, 143 deletions
diff --git a/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc b/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc index ae2d98d..d1a84e4 100644 --- a/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc +++ b/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc @@ -280,8 +280,6 @@ bool CastChannelOpenFunction::Prepare() { connect_info_.reset(new ConnectInfo); if (!ParseChannelUrl(GURL(cast_url), connect_info_.get())) { connect_info_.reset(); - SetError("Invalid Cast URL " + cast_url); - return false; } break; case base::Value::TYPE_DICTIONARY: @@ -290,17 +288,12 @@ bool CastChannelOpenFunction::Prepare() { default: break; } - if (!connect_info_.get()) { - SetError("Invalid connect_info"); - return false; - } - channel_auth_ = connect_info_->auth; - ip_endpoint_.reset(ParseConnectInfo(*connect_info_)); - if (!ip_endpoint_.get()) { - SetError("Invalid connect_info"); - return false; + if (connect_info_.get()) { + channel_auth_ = connect_info_->auth; + ip_endpoint_.reset(ParseConnectInfo(*connect_info_)); + return ip_endpoint_.get() != NULL; } - return true; + return false; } void CastChannelOpenFunction::AsyncWorkStart() { @@ -326,26 +319,6 @@ CastChannelSendFunction::~CastChannelSendFunction() { } bool CastChannelSendFunction::Prepare() { params_ = Send::Params::Create(*args_); 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; } diff --git a/chrome/browser/extensions/api/cast_channel/cast_channel_api.h b/chrome/browser/extensions/api/cast_channel/cast_channel_api.h index e24b7a7..6d60de2 100644 --- a/chrome/browser/extensions/api/cast_channel/cast_channel_api.h +++ b/chrome/browser/extensions/api/cast_channel/cast_channel_api.h @@ -137,12 +137,12 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction { // corresponding details, and returns true. Returns false if |url| is not a // valid Cast 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 // new IPEndPoint if so. Otherwise returns NULL. static net::IPEndPoint* ParseConnectInfo( - const cast_channel::ConnectInfo& connect_info); + const api::cast_channel::ConnectInfo& connect_info); void OnOpen(int result); @@ -150,18 +150,12 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction { // The id of the newly opened socket. int new_channel_id_; CastChannelAPI* api_; - scoped_ptr<cast_channel::ConnectInfo> connect_info_; + scoped_ptr<api::cast_channel::ConnectInfo> connect_info_; 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, 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); }; @@ -183,10 +177,6 @@ class CastChannelSendFunction : public CastChannelAsyncApiFunction { scoped_ptr<cast_channel::Send::Params> params_; - FRIEND_TEST_ALL_PREFIXES(CastChannelSendFunctionTest, - TestPrepareValidMessageInfo); - FRIEND_TEST_ALL_PREFIXES(CastChannelSendFunctionTest, - TestPrepareInvalidMessageInfo); DISALLOW_COPY_AND_ASSIGN(CastChannelSendFunction); }; diff --git a/chrome/browser/extensions/api/cast_channel/cast_channel_api_unittest.cc b/chrome/browser/extensions/api/cast_channel/cast_channel_api_unittest.cc index 265795a..631e299 100644 --- a/chrome/browser/extensions/api/cast_channel/cast_channel_api_unittest.cc +++ b/chrome/browser/extensions/api/cast_channel/cast_channel_api_unittest.cc @@ -4,46 +4,31 @@ #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/values.h" #include "net/base/ip_endpoint.h" #include "testing/gtest/include/gtest/gtest.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 api { +namespace cast_channel { // Tests URL parsing and validation. TEST(CastChannelOpenFunctionTest, TestParseChannelUrl) { typedef CastChannelOpenFunction ccof; - cast_channel::ConnectInfo connect_info; + ConnectInfo connect_info; EXPECT_TRUE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:8009"), &connect_info)); EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); 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"), &connect_info)); EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); 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"), &connect_info)); @@ -67,107 +52,40 @@ TEST(CastChannelOpenFunctionTest, TestParseConnectInfo) { scoped_ptr<net::IPEndPoint> ip_endpoint; // Valid ConnectInfo - cast_channel::ConnectInfo connect_info; + ConnectInfo connect_info; connect_info.ip_address = "192.0.0.1"; 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)); EXPECT_TRUE(ip_endpoint.get() != NULL); EXPECT_EQ(ip_endpoint->ToString(), "192.0.0.1:8009"); // 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.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)); EXPECT_TRUE(ip_endpoint.get() == NULL); // 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.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)); EXPECT_TRUE(ip_endpoint.get() == NULL); // 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.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)); EXPECT_TRUE(ip_endpoint.get() == NULL); } -TEST(CastChannelOpenFunctionTest, TestPrepareValidUrl) { - scoped_refptr<CastChannelOpenFunction> ccof(new CastChannelOpenFunction); - 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 cast_channel +} // namespace api } // namespace extensions |