Skip to content

Commit

Permalink
revert irrelevant changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rockspore committed Feb 9, 2024
1 parent 082a767 commit 72e8fbf
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 62 deletions.
5 changes: 2 additions & 3 deletions src/core/lib/iomgr/load_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

#include <grpc/support/port_platform.h>

#include <stdio.h>

#include <grpc/slice.h>

#include "src/core/lib/iomgr/error.h"

// Loads the content of a file into a slice. add_null_terminator will add
// a NULL terminator if non-zero.
// This API is NOT thread-safe and requires proper synchronization when used by
// multiple threads, especially when they can happen to be reading from the same
// file.
grpc_error_handle grpc_load_file(const char* filename, int add_null_terminator,
grpc_slice* output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ FileExternalAccountCredentials::FileExternalAccountCredentials(
format_subject_token_field_name_ = format_it->second.string();
}
}
gpr_mu_init(&mu_);
}

void FileExternalAccountCredentials::RetrieveSubjectToken(
Expand All @@ -106,12 +105,10 @@ void FileExternalAccountCredentials::RetrieveSubjectToken(
grpc_slice slice = grpc_empty_slice();
};
SliceWrapper content_slice;
gpr_mu_lock(&mu_);
// To retrieve the subject token, we read the file every time we make a
// request because it may have changed since the last request.
grpc_error_handle error =
grpc_load_file(file_.c_str(), 0, &content_slice.slice);
gpr_mu_unlock(&mu_);
if (!error.ok()) {
cb("", error);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#include "absl/strings/string_view.h"

#include <grpc/support/sync.h>

#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/security/credentials/external/external_account_credentials.h"
Expand Down Expand Up @@ -54,8 +52,6 @@ class FileExternalAccountCredentials final : public ExternalAccountCredentials {
std::string file_;
std::string format_type_;
std::string format_subject_token_field_name_;
// Used to lock the file loading.
gpr_mu mu_;
};

} // namespace grpc_core
Expand Down
52 changes: 0 additions & 52 deletions test/core/security/credentials_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3038,58 +3038,6 @@ TEST(CredentialsTest, TestFileExternalAccountCredsSuccessFormatJson) {
gpr_free(subject_token_path);
}

TEST(CredentialsTest,
TestFileExternalAccountCredsSuccessFormatJsonManyRequests) {
ExecCtx exec_ctx;
char* subject_token_path =
write_tmp_jwt_file("{\"access_token\":\"test_subject_token\"}");
auto credential_source = JsonParse(absl::StrFormat(
"{\n"
"\"file\":\"%s\",\n"
"\"format\":\n"
"{\n"
"\"type\":\"json\",\n"
"\"subject_token_field_name\":\"access_token\"\n"
"}\n"
"}",
absl::StrReplaceAll(subject_token_path, {{"\\", "\\\\"}})));
GPR_ASSERT(credential_source.ok());
TestExternalAccountCredentials::ServiceAccountImpersonation
service_account_impersonation;
service_account_impersonation.token_lifetime_seconds = 3600;
ExternalAccountCredentials::Options options = {
"external_account", // type;
"audience", // audience;
"subject_token_type", // subject_token_type;
"", // service_account_impersonation_url;
service_account_impersonation, // service_account_impersonation;
"https://foo.com:5555/token", // token_url;
"https://foo.com:5555/token_info", // token_info_url;
*credential_source, // credential_source;
"quota_project_id", // quota_project_id;
"client_id", // client_id;
"client_secret", // client_secret;
"", // workforce_pool_user_project;
};
grpc_error_handle error;
auto creds = FileExternalAccountCredentials::Create(options, {}, &error);
GPR_ASSERT(creds != nullptr);
GPR_ASSERT(error.ok());
GPR_ASSERT(creds->min_security_level() == GRPC_PRIVACY_AND_INTEGRITY);
for (int i = 0; i < 100; ++i) {
auto state = RequestMetadataState::NewInstance(
absl::OkStatus(), "authorization: Bearer token_exchange_access_token");
HttpRequest::SetOverride(httpcli_get_should_not_be_called,
external_account_creds_httpcli_post_success,
httpcli_put_should_not_be_called);
state->RunRequestMetadataTest(creds.get(), kTestUrlScheme, kTestAuthority,
kTestPath);
}
ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr);
gpr_free(subject_token_path);
}

TEST(CredentialsTest, TestFileExternalAccountCredsFailureFileNotFound) {
ExecCtx exec_ctx;
auto credential_source = JsonParse("{\"file\":\"non_exisiting_file\"}");
Expand Down

0 comments on commit 72e8fbf

Please sign in to comment.