|
|
|
@ -26,16 +26,16 @@ namespace grpc_core { |
|
|
|
|
|
|
|
|
|
namespace testing { |
|
|
|
|
|
|
|
|
|
TmpFile::TmpFile(absl::string_view credential_data) { |
|
|
|
|
name_ = CreateTmpFileAndWriteData(credential_data); |
|
|
|
|
TmpFile::TmpFile(absl::string_view data) { |
|
|
|
|
name_ = CreateTmpFileAndWriteData(data); |
|
|
|
|
GPR_ASSERT(!name_.empty()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TmpFile::~TmpFile() { GPR_ASSERT(remove(name_.c_str()) == 0); } |
|
|
|
|
|
|
|
|
|
void TmpFile::RewriteFile(absl::string_view credential_data) { |
|
|
|
|
void TmpFile::RewriteFile(absl::string_view data) { |
|
|
|
|
// Create a new file containing new data.
|
|
|
|
|
std::string new_name = CreateTmpFileAndWriteData(credential_data); |
|
|
|
|
std::string new_name = CreateTmpFileAndWriteData(data); |
|
|
|
|
GPR_ASSERT(!new_name.empty()); |
|
|
|
|
// Remove the old file.
|
|
|
|
|
GPR_ASSERT(remove(name_.c_str()) == 0); |
|
|
|
@ -43,12 +43,11 @@ void TmpFile::RewriteFile(absl::string_view credential_data) { |
|
|
|
|
GPR_ASSERT(rename(new_name.c_str(), name_.c_str()) == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string TmpFile::CreateTmpFileAndWriteData( |
|
|
|
|
absl::string_view credential_data) { |
|
|
|
|
std::string TmpFile::CreateTmpFileAndWriteData(absl::string_view data) { |
|
|
|
|
char* name = nullptr; |
|
|
|
|
FILE* file_descriptor = gpr_tmpfile("GrpcTlsCertificateProviderTest", &name); |
|
|
|
|
GPR_ASSERT(fwrite(credential_data.data(), 1, credential_data.size(), |
|
|
|
|
file_descriptor) == credential_data.size()); |
|
|
|
|
FILE* file_descriptor = gpr_tmpfile("test", &name); |
|
|
|
|
GPR_ASSERT(fwrite(data.data(), 1, data.size(), file_descriptor) == |
|
|
|
|
data.size()); |
|
|
|
|
GPR_ASSERT(fclose(file_descriptor) == 0); |
|
|
|
|
GPR_ASSERT(file_descriptor != nullptr); |
|
|
|
|
GPR_ASSERT(name != nullptr); |
|
|
|
@ -68,9 +67,9 @@ PemKeyCertPairList MakeCertKeyPairs(absl::string_view private_key, |
|
|
|
|
std::string GetFileContents(const char* path) { |
|
|
|
|
grpc_slice slice = grpc_empty_slice(); |
|
|
|
|
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(path, 0, &slice))); |
|
|
|
|
std::string credential = std::string(StringViewFromSlice(slice)); |
|
|
|
|
std::string data = std::string(StringViewFromSlice(slice)); |
|
|
|
|
grpc_slice_unref(slice); |
|
|
|
|
return credential; |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int SyncExternalVerifier::Verify(void* user_data, |
|
|
|
|