summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth
diff options
context:
space:
mode:
authortengs <tengs@chromium.org>2015-08-05 17:22:24 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-06 00:22:58 +0000
commitf946f7f9d1e91104ee6df3b5060ff9bccc2b3117 (patch)
tree65029a941790122a815e4355f86b219f452bce52 /components/proximity_auth
parent4b646b20bd31db5683be4d129e246d03096c28e9 (diff)
downloadchromium_src-f946f7f9d1e91104ee6df3b5060ff9bccc2b3117.zip
chromium_src-f946f7f9d1e91104ee6df3b5060ff9bccc2b3117.tar.gz
chromium_src-f946f7f9d1e91104ee6df3b5060ff9bccc2b3117.tar.bz2
Fix bug when CryptAuth requests are made with an empty protobuf serialization.
Do fix this edge case, we refactor OAuth2ApiCallFlow to allow overriding the RequestType of the API call. BUG=516849 TEST=unit tests Review URL: https://codereview.chromium.org/1267393002 Cr-Commit-Position: refs/heads/master@{#342022}
Diffstat (limited to 'components/proximity_auth')
-rw-r--r--components/proximity_auth/cryptauth/cryptauth_api_call_flow.cc5
-rw-r--r--components/proximity_auth/cryptauth/cryptauth_api_call_flow.h2
-rw-r--r--components/proximity_auth/cryptauth/cryptauth_api_call_flow_unittest.cc20
3 files changed, 23 insertions, 4 deletions
diff --git a/components/proximity_auth/cryptauth/cryptauth_api_call_flow.cc b/components/proximity_auth/cryptauth/cryptauth_api_call_flow.cc
index c72e867..6f0f7f6 100644
--- a/components/proximity_auth/cryptauth/cryptauth_api_call_flow.cc
+++ b/components/proximity_auth/cryptauth/cryptauth_api_call_flow.cc
@@ -49,6 +49,11 @@ std::string CryptAuthApiCallFlow::CreateApiCallBodyContentType() {
return "application/x-protobuf";
}
+net::URLFetcher::RequestType CryptAuthApiCallFlow::GetRequestTypeForBody(
+ const std::string& body) {
+ return net::URLFetcher::POST;
+}
+
void CryptAuthApiCallFlow::ProcessApiCallSuccess(
const net::URLFetcher* source) {
std::string serialized_response;
diff --git a/components/proximity_auth/cryptauth/cryptauth_api_call_flow.h b/components/proximity_auth/cryptauth/cryptauth_api_call_flow.h
index f351aed..76ec6cb 100644
--- a/components/proximity_auth/cryptauth/cryptauth_api_call_flow.h
+++ b/components/proximity_auth/cryptauth/cryptauth_api_call_flow.h
@@ -49,6 +49,8 @@ class CryptAuthApiCallFlow : public OAuth2ApiCallFlow {
GURL CreateApiCallUrl() override;
std::string CreateApiCallBody() override;
std::string CreateApiCallBodyContentType() override;
+ net::URLFetcher::RequestType GetRequestTypeForBody(
+ const std::string& body) override;
void ProcessApiCallSuccess(const net::URLFetcher* source) override;
void ProcessApiCallFailure(const net::URLFetcher* source) override;
diff --git a/components/proximity_auth/cryptauth/cryptauth_api_call_flow_unittest.cc b/components/proximity_auth/cryptauth/cryptauth_api_call_flow_unittest.cc
index d7a15b6..dadbfda 100644
--- a/components/proximity_auth/cryptauth/cryptauth_api_call_flow_unittest.cc
+++ b/components/proximity_auth/cryptauth/cryptauth_api_call_flow_unittest.cc
@@ -37,14 +37,18 @@ class ProximityAuthCryptAuthApiCallFlowTest
}
void StartApiCallFlow() {
+ StartApiCallFlowWithRequest(kSerializedRequestProto);
+ }
+
+ void StartApiCallFlowWithRequest(const std::string& serialized_request) {
flow_.Start(GURL(kRequestUrl), url_request_context_getter_.get(),
- "access_token", kSerializedRequestProto,
+ "access_token", serialized_request,
base::Bind(&ProximityAuthCryptAuthApiCallFlowTest::OnResult,
base::Unretained(this)),
base::Bind(&ProximityAuthCryptAuthApiCallFlowTest::OnError,
base::Unretained(this)));
// URLFetcher object for the API request should be created.
- CheckCryptAuthHttpRequest();
+ CheckCryptAuthHttpRequest(serialized_request);
}
void OnResult(const std::string& result) {
@@ -57,10 +61,10 @@ class ProximityAuthCryptAuthApiCallFlowTest
error_message_.reset(new std::string(error_message));
}
- void CheckCryptAuthHttpRequest() {
+ void CheckCryptAuthHttpRequest(const std::string& serialized_request) {
ASSERT_TRUE(url_fetcher_);
EXPECT_EQ(GURL(kRequestUrl), url_fetcher_->GetOriginalURL());
- EXPECT_EQ(kSerializedRequestProto, url_fetcher_->upload_data());
+ EXPECT_EQ(serialized_request, url_fetcher_->upload_data());
net::HttpRequestHeaders request_headers;
url_fetcher_->GetExtraRequestHeaders(&request_headers);
@@ -128,6 +132,14 @@ TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestStatus500) {
}
// The empty string is a valid protocol buffer message serialization.
+TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestWithNoBody) {
+ StartApiCallFlowWithRequest(std::string());
+ CompleteCurrentRequest(net::OK, net::HTTP_OK, kSerializedResponseProto);
+ EXPECT_EQ(kSerializedResponseProto, *result_);
+ EXPECT_FALSE(error_message_);
+}
+
+// The empty string is a valid protocol buffer message serialization.
TEST_F(ProximityAuthCryptAuthApiCallFlowTest, ResponseWithNoBody) {
StartApiCallFlow();
CompleteCurrentRequest(net::OK, net::HTTP_OK, std::string());