-
Notifications
You must be signed in to change notification settings - Fork 436
ci: add SA to SA impersonation integration tests for universe domain #14862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cuiy0006
merged 8 commits into
googleapis:main
from
cuiy0006:universe-domain-add-impersonation-integration-tests
Dec 2, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a07fed2
ci: add impersonation integration tests for universe domain
cuiy0006 b9ee124
remove integration tests tag
cuiy0006 3f4a742
add integration tests tag
cuiy0006 4e76980
revert renaming
cuiy0006 b1dafb7
exclude tag ud-only
cuiy0006 051b10e
format
cuiy0006 3244b04
fix
cuiy0006 ca65bd4
address comments
cuiy0006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
google/cloud/universe_domain/integration_tests/BUILD.bazel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright 2024 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| package(default_visibility = ["//visibility:private"]) | ||
|
|
||
| licenses(["notice"]) # Apache 2.0 | ||
|
|
||
| cc_test( | ||
| name = "impersonation_tests", | ||
| timeout = "long", | ||
| srcs = ["impersonation_tests.cc"], | ||
| tags = [ | ||
| "integration-test", | ||
| "ud-only", | ||
| ], | ||
| deps = [ | ||
| "//:common", | ||
| "//:experimental-universe_domain", | ||
| "//google/cloud/testing_util:google_cloud_cpp_testing_private", | ||
| "@com_google_googletest//:gtest_main", | ||
| "@google_cloud_cpp//:compute", | ||
| "@google_cloud_cpp//:kms", | ||
| ], | ||
| ) |
112 changes: 112 additions & 0 deletions
112
google/cloud/universe_domain/integration_tests/impersonation_tests.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "google/cloud/compute/disks/v1/disks_client.h" | ||
cuiy0006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include "google/cloud/compute/disks/v1/disks_options.h" | ||
| #include "google/cloud/kms/v1/key_management_client.h" | ||
| #include "google/cloud/kms/v1/key_management_options.h" | ||
| #include "google/cloud/internal/getenv.h" | ||
| #include "google/cloud/internal/rest_options.h" | ||
| #include "google/cloud/location.h" | ||
| #include "google/cloud/testing_util/integration_test.h" | ||
| #include "google/cloud/testing_util/status_matchers.h" | ||
| #include "google/cloud/universe_domain.h" | ||
| #include "google/cloud/universe_domain_options.h" | ||
| #include <gmock/gmock.h> | ||
| #include <fstream> | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace universe_domain { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
| namespace { | ||
|
|
||
| namespace gc = ::google::cloud; | ||
| using ::google::cloud::testing_util::StatusIs; | ||
|
|
||
| class DomainUniverseImpersonationTest | ||
| : public ::google::cloud::testing_util::IntegrationTest { | ||
| protected: | ||
| void SetUp() override { | ||
| project_id_ = gc::internal::GetEnv("UD_PROJECT").value_or(""); | ||
| ASSERT_FALSE(project_id_.empty()); | ||
| zone_id_ = gc::internal::GetEnv("UD_ZONE").value_or(""); | ||
| ASSERT_FALSE(zone_id_.empty()); | ||
| region_id_ = gc::internal::GetEnv("UD_REGION").value_or(""); | ||
| ASSERT_FALSE(region_id_.empty()); | ||
| impersonated_sa_ = | ||
| gc::internal::GetEnv("UD_IMPERSONATED_SERVICE_ACCOUNT_NAME") | ||
| .value_or(""); | ||
| ASSERT_FALSE(impersonated_sa_.empty()); | ||
| std::string const sa_key_file = | ||
| gc::internal::GetEnv("UD_SA_KEY_FILE").value_or(""); | ||
| ASSERT_FALSE(sa_key_file.empty()); | ||
|
|
||
| auto is = std::ifstream(sa_key_file); | ||
| is.exceptions(std::ios::badbit); | ||
| credential_ = std::string(std::istreambuf_iterator<char>(is.rdbuf()), {}); | ||
| } | ||
|
|
||
| std::string project_id_; | ||
| std::string zone_id_; | ||
| std::string region_id_; | ||
| std::string impersonated_sa_; | ||
| std::string credential_; | ||
| }; | ||
|
|
||
| TEST_F(DomainUniverseImpersonationTest, SAToSAImpersonationRest) { | ||
| namespace disks = ::google::cloud::compute_disks_v1; | ||
|
|
||
| gc::Options options; | ||
| options.set<google::cloud::UnifiedCredentialsOption>( | ||
| google::cloud::MakeImpersonateServiceAccountCredentials( | ||
| google::cloud::MakeServiceAccountCredentials(credential_), | ||
| impersonated_sa_)); | ||
|
|
||
| auto ud_options = gc::AddUniverseDomainOption(gc::ExperimentalTag{}, options); | ||
| ASSERT_STATUS_OK(ud_options); | ||
|
|
||
| auto client = disks::DisksClient(disks::MakeDisksConnectionRest(*ud_options)); | ||
|
|
||
| for (auto disk : client.ListDisks(project_id_, zone_id_)) { | ||
| EXPECT_STATUS_OK(disk); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(DomainUniverseImpersonationTest, SAToSAImpersonationGrpc) { | ||
| namespace kms = ::google::cloud::kms_v1; | ||
|
|
||
| auto const location = gc::Location(project_id_, region_id_); | ||
| gc::Options options; | ||
| options.set<google::cloud::UnifiedCredentialsOption>( | ||
| google::cloud::MakeImpersonateServiceAccountCredentials( | ||
| google::cloud::MakeServiceAccountCredentials(credential_), | ||
| impersonated_sa_)); | ||
|
|
||
| auto ud_options = gc::AddUniverseDomainOption(gc::ExperimentalTag{}, options); | ||
| ASSERT_STATUS_OK(ud_options); | ||
|
|
||
| auto client = kms::KeyManagementServiceClient( | ||
| kms::MakeKeyManagementServiceConnection(*ud_options)); | ||
|
|
||
| for (auto kr : client.ListKeyRings(location.FullName())) { | ||
| EXPECT_STATUS_OK(kr); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace universe_domain | ||
| } // namespace cloud | ||
| } // namespace google | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.