Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: components/copresence/rpc/http_post_unittest.cc

Issue 671573003: Adding support for authenticated copresence calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing histograms Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/copresence/rpc/http_post_unittest.cc
diff --git a/components/copresence/rpc/http_post_unittest.cc b/components/copresence/rpc/http_post_unittest.cc
index 9a847506efdab64752feb15e5530ee4b2e17ed12..ebbb07e841b6f8f8ba55c90925a8734c9425d8f6 100644
--- a/components/copresence/rpc/http_post_unittest.cc
+++ b/components/copresence/rpc/http_post_unittest.cc
@@ -19,6 +19,7 @@ const char kFakeServerHost[] = "test.server.google.com";
const char kRPCName[] = "testRpc";
const char kTracingToken[] = "trace me!";
const char kApiKey[] = "unlock ALL the APIz";
+const char kAuthToken[] = "oogabooga";
} // namespace
@@ -49,8 +50,9 @@ class HttpPostTest : public testing::Test {
pending_post_ = new HttpPost(context_getter_.get(),
std::string("http://") + kFakeServerHost,
kRPCName,
- "",
kApiKey,
+ "", // auth token
+ "", // tracing token
proto_);
pending_post_->Start(base::Bind(&HttpPostTest::TestResponseCallback,
base::Unretained(this)));
@@ -61,7 +63,8 @@ class HttpPostTest : public testing::Test {
fetcher->delegate()->OnURLFetchComplete(fetcher);
delete pending_post_;
return received_response_code_ == response_code &&
- received_response_ == response;
+ received_response_ == response &&
+ GetAuthHeaderSent().empty();
}
net::TestURLFetcher* GetFetcher() {
@@ -76,6 +79,13 @@ class HttpPostTest : public testing::Test {
return api_key_sent;
}
+ const std::string GetAuthHeaderSent() {
+ net::HttpRequestHeaders headers;
+ std::string header;
+ GetFetcher()->GetExtraRequestHeaders(&headers);
+ return headers.GetHeader("Authorization", &header) ? header : "";
+ }
+
const std::string GetTracingTokenSent() {
std::string tracing_token_sent;
net::GetValueForKeyInQuery(GetFetcher()->GetOriginalURL(),
@@ -101,8 +111,9 @@ TEST_F(HttpPostTest, OKResponse) {
HttpPost* post = new HttpPost(context_getter_.get(),
std::string("http://") + kFakeServerHost,
kRPCName,
- kTracingToken,
kApiKey,
+ kAuthToken,
+ kTracingToken,
proto_);
post->Start(base::Bind(&HttpPostTest::TestResponseCallback,
base::Unretained(this)));
@@ -112,8 +123,9 @@ TEST_F(HttpPostTest, OKResponse) {
EXPECT_EQ(kFakeServerHost, requested_url.host());
EXPECT_EQ(std::string("/") + kRPCName, requested_url.path());
- // Check query parameters.
+ // Check parameters.
EXPECT_EQ(kApiKey, GetApiKeySent());
+ EXPECT_EQ(std::string("Bearer ") + kAuthToken, GetAuthHeaderSent());
EXPECT_EQ(std::string("token:") + kTracingToken, GetTracingTokenSent());
// Verify that the right data was sent.

Powered by Google App Engine
This is Rietveld 408576698