Skip to content

Commit

Permalink
impl(universe_domain): update implementation to reflect testing resul…
Browse files Browse the repository at this point in the history
…ts (#13530)
  • Loading branch information
scotthart committed Jan 31, 2024
1 parent 39fdf04 commit 3f8954c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion google/cloud/internal/compute_engine_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::string GceMetadataScheme() { return "http"; }

std::string GceMetadataHostname() {
return google::cloud::internal::GetEnv(GceMetadataHostnameEnvVar())
.value_or("metadata.google.internal.");
.value_or("metadata.google.internal");
}

} // namespace internal
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/internal/compute_engine_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST(ComputeEngineUtilTest, CanOverrideGceMetadataHostname) {
// If not overridden for testing, we should get the actual hostname.
google::cloud::testing_util::ScopedEnvironment gce_metadata_hostname_unset(
GceMetadataHostnameEnvVar(), {});
EXPECT_EQ(std::string("metadata.google.internal."), GceMetadataHostname());
EXPECT_EQ(std::string("metadata.google.internal"), GceMetadataHostname());
}

} // namespace
Expand Down
8 changes: 5 additions & 3 deletions google/cloud/internal/oauth2_compute_engine_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ StatusOr<std::string> ComputeEngineCredentials::RetrieveUniverseDomain(
}
return AsStatus(std::move(**response));
}
auto metadata = ParseMetadataServerResponse(**response);
if (!metadata) return std::move(metadata).status();
universe_domain_ = std::move(metadata->universe_domain);

auto payload =
rest_internal::ReadAll((std::move(**response)).ExtractPayload());
if (!payload.ok()) return payload.status();
universe_domain_ = *std::move(payload);
return *universe_domain_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,7 @@ auto expected_universe_domain_request = []() {
};

TEST(ComputeEngineCredentialsTest, UniverseDomainSuccess) {
auto const universe_domain_resp = std::string{R"""({
"universe_domain": "my-ud.net"
})"""};
auto const universe_domain_resp = std::string{R"""(my-ud.net)"""};

auto client = std::make_unique<MockRestClient>();
EXPECT_CALL(*client, Get(_, expected_universe_domain_request()))
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/internal/unified_rest_credentials_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ TEST(UnifiedRestCredentialsTest, AdcIsComputeEngine) {
auto client = std::make_unique<MockRestClient>();
auto expected_request = AllOf(
Property(&RestRequest::path,
absl::StrCat("http://metadata.google.internal./",
absl::StrCat("http://metadata.google.internal/",
"computeMetadata/v1/instance/service-accounts/",
"default/")),
Property(&RestRequest::headers,
Expand All @@ -259,7 +259,7 @@ TEST(UnifiedRestCredentialsTest, AdcIsComputeEngine) {
auto client = std::make_unique<MockRestClient>();
auto expected_request = AllOf(
Property(&RestRequest::path,
absl::StrCat("http://metadata.google.internal./",
absl::StrCat("http://metadata.google.internal/",
"computeMetadata/v1/instance/service-accounts/",
"default/", "token")),
Property(&RestRequest::headers,
Expand Down

0 comments on commit 3f8954c

Please sign in to comment.