Skip to content

Commit 3388994

Browse files
committed
check for empty authorization header
1 parent e64f424 commit 3388994

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

google/cloud/internal/oauth2_credentials.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Credentials::AuthenticationHeaders(std::chrono::system_clock::time_point tp,
2828
std::vector<rest_internal::HttpHeader> headers;
2929
auto authorization = Authorization(tp);
3030
if (!authorization) return std::move(authorization).status();
31-
headers.push_back(*std::move(authorization));
31+
if (!authorization->empty()) headers.push_back(*std::move(authorization));
3232

3333
auto allowed_locations = AllowedLocations(tp, endpoint);
3434
// Not all credential types support the x-allowed-locations header. For those

google/cloud/internal/oauth2_credentials_test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ TEST(Credentials, AuthenticationHeaderError) {
6060
EXPECT_EQ(actual.status(), UnavailableError("try-again"));
6161
}
6262

63+
TEST(Credentials, AuthenticationHeaderEmpty) {
64+
MockCredentials mock;
65+
EXPECT_CALL(mock, GetToken)
66+
.WillOnce(Return(AccessToken{"", std::chrono::system_clock::now()}));
67+
EXPECT_CALL(mock, AllowedLocations)
68+
.WillOnce(Return(rest_internal::HttpHeader()));
69+
auto actual = mock.AuthenticationHeaders(std::chrono::system_clock::now(),
70+
"my-endpoint");
71+
EXPECT_THAT(actual, IsOkAndHolds(std::vector<rest_internal::HttpHeader>{}));
72+
}
73+
6374
TEST(Credentials, ProjectId) {
6475
MockCredentials mock;
6576
EXPECT_THAT(mock.project_id(), Not(IsOk()));

0 commit comments

Comments
 (0)