const char kRPCName[] = "testRpc";
const char kTracingToken[] = "trace me!";
const char kApiKey[] = "unlock ALL the APIz";
+const char kAuthToken[] = "oogabooga";
} // namespace
proto_.set_client("test_client");
proto_.set_version_code(123);
}
- virtual ~HttpPostTest() {}
+ ~HttpPostTest() override {}
// Record the response sent back to the client for verification.
void TestResponseCallback(int response_code,
protected:
bool ResponsePassedThrough(int response_code, const std::string& response) {
- pending_post_ = new HttpPost(context_getter_.get(),
- std::string("http://") + kFakeServerHost,
- kRPCName,
- "",
- kApiKey,
- proto_);
- pending_post_->Start(base::Bind(&HttpPostTest::TestResponseCallback,
- base::Unretained(this)));
+ scoped_ptr<HttpPost> post(
+ new HttpPost(context_getter_.get(),
+ std::string("http://") + kFakeServerHost,
+ kRPCName,
+ kApiKey,
+ "", // auth token
+ "", // tracing token
+ proto_));
+ post->Start(base::Bind(&HttpPostTest::TestResponseCallback,
+ base::Unretained(this)));
net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(
HttpPost::kUrlFetcherId);
fetcher->set_response_code(response_code);
fetcher->SetResponseString(response);
fetcher->delegate()->OnURLFetchComplete(fetcher);
- delete pending_post_;
return received_response_code_ == response_code &&
- received_response_ == response;
+ received_response_ == response &&
+ GetApiKeySent() == kApiKey &&
+ GetAuthHeaderSent().empty();
}
net::TestURLFetcher* GetFetcher() {
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(),
int received_response_code_;
std::string received_response_;
-
- private:
- HttpPost* pending_post_;
};
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)));
EXPECT_EQ(kFakeServerHost, requested_url.host());
EXPECT_EQ(std::string("/") + kRPCName, requested_url.path());
- // Check query parameters.
- EXPECT_EQ(kApiKey, GetApiKeySent());
+ // Check parameters.
+ EXPECT_EQ("", GetApiKeySent()); // No API key when using an auth token.
+ EXPECT_EQ(std::string("Bearer ") + kAuthToken, GetAuthHeaderSent());
EXPECT_EQ(std::string("token:") + kTracingToken, GetTracingTokenSent());
// Verify that the right data was sent.