Skip to content

Commit c2056c2

Browse files
authored
cleanup: remove unused code (#9599)
1 parent fd2679c commit c2056c2

File tree

1 file changed

+11
-38
lines changed

1 file changed

+11
-38
lines changed

google/cloud/internal/oauth2_google_credentials_test.cc

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "google/cloud/internal/oauth2_compute_engine_credentials.h"
2121
#include "google/cloud/internal/oauth2_google_application_default_credentials_file.h"
2222
#include "google/cloud/internal/oauth2_service_account_credentials.h"
23-
#include "google/cloud/internal/random.h"
2423
#include "google/cloud/testing_util/scoped_environment.h"
2524
#include "google/cloud/testing_util/status_matchers.h"
2625
#include <gmock/gmock.h>
@@ -49,32 +48,20 @@ class GoogleCredentialsTest : public ::testing::Test {
4948
gcloud_path_override_env_var_(GoogleGcloudAdcFileEnvVar(), {}) {}
5049

5150
protected:
52-
std::string CreateRandomFileName() {
53-
// When running on the internal Google CI systems we cannot write to the
54-
// local directory, GTest has a good temporary directory in that case.
55-
return google::cloud::internal::PathAppend(
56-
::testing::TempDir(),
57-
google::cloud::internal::Sample(
58-
generator_, 8, "abcdefghijklmnopqrstuvwxyz0123456789"));
59-
}
60-
61-
google::cloud::internal::DefaultPRNG generator_ =
62-
google::cloud::internal::MakeDefaultPRNG();
63-
6451
ScopedEnvironment home_env_var_;
6552
ScopedEnvironment adc_env_var_;
6653
ScopedEnvironment gcloud_path_override_env_var_;
6754
};
6855

69-
std::string const kAuthorizedUserCredFilename = "oauth2-authorized-user.json";
70-
std::string const kAuthorizedUserCredContents = R"""({
56+
auto constexpr kAuthorizedUserCredFilename = "oauth2-authorized-user.json";
57+
auto constexpr kAuthorizedUserCredContents = R"""({
7158
"client_id": "test-invalid-test-invalid.apps.googleusercontent.com",
7259
"client_secret": "invalid-invalid-invalid",
7360
"refresh_token": "1/test-test-test",
7461
"type": "authorized_user"
7562
})""";
7663

77-
void SetupAuthorizedUserCredentialsFileForTest(std::string const& filename) {
64+
void SetUpAuthorizedUserCredentialsFileForTest(std::string const& filename) {
7865
std::ofstream os(filename);
7966
os << kAuthorizedUserCredContents;
8067
os.close();
@@ -93,7 +80,7 @@ void SetupAuthorizedUserCredentialsFileForTest(std::string const& filename) {
9380
TEST_F(GoogleCredentialsTest, LoadValidAuthorizedUserCredentialsViaEnvVar) {
9481
std::string filename = google::cloud::internal::PathAppend(
9582
::testing::TempDir(), kAuthorizedUserCredFilename);
96-
SetupAuthorizedUserCredentialsFileForTest(filename);
83+
SetUpAuthorizedUserCredentialsFileForTest(filename);
9784

9885
// Test that the authorized user credentials are loaded as the default when
9986
// specified via the well known environment variable.
@@ -109,9 +96,9 @@ TEST_F(GoogleCredentialsTest, LoadValidAuthorizedUserCredentialsViaEnvVar) {
10996
TEST_F(GoogleCredentialsTest, LoadValidAuthorizedUserCredentialsViaGcloudFile) {
11097
std::string filename = google::cloud::internal::PathAppend(
11198
::testing::TempDir(), kAuthorizedUserCredFilename);
112-
SetupAuthorizedUserCredentialsFileForTest(filename);
99+
SetUpAuthorizedUserCredentialsFileForTest(filename);
113100
// Test that the authorized user credentials are loaded as the default when
114-
// stored in the the well known gcloud ADC file path.
101+
// stored in the well known gcloud ADC file path.
115102
ScopedEnvironment gcloud_path_override_env_var(GoogleGcloudAdcFileEnvVar(),
116103
filename.c_str());
117104
auto creds = GoogleDefaultCredentials();
@@ -131,8 +118,7 @@ TEST_F(GoogleCredentialsTest, LoadValidAuthorizedUserCredentialsViaGcloudFile) {
131118
* make this an integration test.
132119
*/
133120

134-
std::string const kServiceAccountCredFilename = "service-account.json";
135-
std::string const kServiceAccountCredContents = R"""({
121+
auto constexpr kServiceAccountCredContents = R"""({
136122
"type": "service_account",
137123
"project_id": "foo-project",
138124
"private_key_id": "a1a111aa1111a11a11a11aa111a111a1a1111111",
@@ -145,20 +131,7 @@ std::string const kServiceAccountCredContents = R"""({
145131
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/foo-email%40foo-project.iam.gserviceaccount.com"
146132
})""";
147133

148-
std::string const kServiceAccountCredInvalidPrivateKey = R"""({
149-
"type": "service_account",
150-
"project_id": "foo-project",
151-
"private_key_id": "a1a111aa1111a11a11a11aa111a111a1a1111111",
152-
"private_key": "an-invalid-private-key",
153-
"client_email": "[email protected]",
154-
"client_id": "100000000000000000001",
155-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
156-
"token_uri": "https://accounts.google.com/o/oauth2/token",
157-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
158-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/foo-email%40foo-project.iam.gserviceaccount.com"
159-
})""";
160-
161-
void SetupServiceAccountCredentialsFileForTest(std::string const& filename) {
134+
void SetUpServiceAccountCredentialsFileForTest(std::string const& filename) {
162135
std::ofstream os(filename);
163136
os << kServiceAccountCredContents;
164137
os.close();
@@ -167,7 +140,7 @@ void SetupServiceAccountCredentialsFileForTest(std::string const& filename) {
167140
TEST_F(GoogleCredentialsTest, LoadValidServiceAccountCredentialsViaEnvVar) {
168141
std::string filename = google::cloud::internal::PathAppend(
169142
::testing::TempDir(), kAuthorizedUserCredFilename);
170-
SetupServiceAccountCredentialsFileForTest(filename);
143+
SetUpServiceAccountCredentialsFileForTest(filename);
171144

172145
// Test that the service account credentials are loaded as the default when
173146
// specified via the well known environment variable.
@@ -183,10 +156,10 @@ TEST_F(GoogleCredentialsTest, LoadValidServiceAccountCredentialsViaEnvVar) {
183156
TEST_F(GoogleCredentialsTest, LoadValidServiceAccountCredentialsViaGcloudFile) {
184157
std::string filename = google::cloud::internal::PathAppend(
185158
::testing::TempDir(), kAuthorizedUserCredFilename);
186-
SetupServiceAccountCredentialsFileForTest(filename);
159+
SetUpServiceAccountCredentialsFileForTest(filename);
187160

188161
// Test that the service account credentials are loaded as the default when
189-
// stored in the the well known gcloud ADC file path.
162+
// stored in the well known gcloud ADC file path.
190163
ScopedEnvironment gcloud_path_override_env_var(GoogleGcloudAdcFileEnvVar(),
191164
filename.c_str());
192165
auto creds = GoogleDefaultCredentials();

0 commit comments

Comments
 (0)