[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT (#36408)

[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT
Replacing GPR_ASSERT with absl CHECK

These changes have been made using string replacement and regex.

Will not be replacing all instances of CHECK with CHECK_EQ , CHECK_NE etc because there are too many callsites. Only ones which are doable using very simple regex with least chance of failure will be replaced.

Given that we have 5000+ instances of GPR_ASSERT to edit, Doing it manually is too much work for both the author and reviewer.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36408

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36408 from tanvi-jagtap:tjagtap_core_security f9eaf45140
PiperOrigin-RevId: 627264425
pull/36430/head
Tanvi Jagtap 7 months ago committed by Copybara-Service
parent 10a95e03d9
commit efc07580bf
  1. 4
      CMakeLists.txt
  2. 4
      build_autogenerated.yaml
  3. 20
      test/core/security/BUILD
  4. 10
      test/core/security/alts_credentials_fuzzer.cc
  5. 12
      test/core/security/aws_request_signer_test.cc
  6. 4
      test/core/security/fetch_oauth2.cc
  7. 12
      test/core/security/grpc_tls_certificate_distributor_test.cc
  8. 12
      test/core/security/grpc_tls_certificate_provider_test.cc
  9. 4
      test/core/security/print_google_default_creds_token.cc
  10. 9
      test/core/security/ssl_server_fuzzer.cc
  11. 208
      test/core/security/tls_security_connector_test.cc
  12. 6
      test/core/security/verify_jwt.cc

4
CMakeLists.txt generated

@ -7397,6 +7397,7 @@ target_include_directories(aws_request_signer_test
target_link_libraries(aws_request_signer_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc_test_util
)
@ -15807,6 +15808,7 @@ target_include_directories(grpc_tls_certificate_distributor_test
target_link_libraries(grpc_tls_certificate_distributor_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc_test_util
)
@ -15858,6 +15860,7 @@ target_include_directories(grpc_tls_certificate_provider_test
target_link_libraries(grpc_tls_certificate_provider_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc_test_util
)
@ -31284,6 +31287,7 @@ target_include_directories(tls_security_connector_test
target_link_libraries(tls_security_connector_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc_test_util
)

@ -5775,6 +5775,7 @@ targets:
- test/core/util/tracer_util.cc
deps:
- gtest
- absl/log:check
- grpc_test_util
- name: backend_metrics_lb_policy_test
gtest: true
@ -10697,6 +10698,7 @@ targets:
- test/core/util/tracer_util.cc
deps:
- gtest
- absl/log:check
- grpc_test_util
- name: grpc_tls_certificate_provider_test
gtest: true
@ -10727,6 +10729,7 @@ targets:
- test/core/util/tracer_util.cc
deps:
- gtest
- absl/log:check
- grpc_test_util
- name: grpc_tls_certificate_verifier_test
gtest: true
@ -19560,6 +19563,7 @@ targets:
- test/core/util/tracer_util.cc
deps:
- gtest
- absl/log:check
- grpc_test_util
- name: too_many_pings_test
gtest: true

@ -23,6 +23,7 @@ grpc_fuzzer(
name = "alts_credentials_fuzzer",
srcs = ["alts_credentials_fuzzer.cc"],
corpus = "corpus/alts_credentials_corpus",
external_deps = ["absl/log:check"],
language = "C++",
tags = ["no_windows"],
deps = [
@ -42,6 +43,7 @@ grpc_fuzzer(
"//src/core/tsi/test_creds:server1.key",
"//src/core/tsi/test_creds:server1.pem",
],
external_deps = ["absl/log:check"],
language = "C++",
tags = ["no_windows"],
deps = [
@ -112,7 +114,10 @@ grpc_cc_test(
grpc_cc_test(
name = "aws_request_signer_test",
srcs = ["aws_request_signer_test.cc"],
external_deps = ["gtest"],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
deps = [
"//:gpr",
@ -250,6 +255,7 @@ grpc_cc_binary(
grpc_cc_binary(
name = "fetch_oauth2",
srcs = ["fetch_oauth2.cc"],
external_deps = ["absl/log:check"],
language = "C++",
deps = [
":oauth2_utils",
@ -264,6 +270,7 @@ grpc_cc_binary(
grpc_cc_binary(
name = "verify_jwt",
srcs = ["verify_jwt.cc"],
external_deps = ["absl/log:check"],
language = "C++",
deps = [
"//:gpr",
@ -339,6 +346,7 @@ grpc_cc_test(
"//src/core/tsi/test_creds:server1.pem",
],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
@ -389,7 +397,10 @@ grpc_cc_test(
grpc_cc_test(
name = "grpc_tls_certificate_distributor_test",
srcs = ["grpc_tls_certificate_distributor_test.cc"],
external_deps = ["gtest"],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
deps = [
"//:gpr",
@ -412,7 +423,10 @@ grpc_cc_test(
"//src/core/tsi/test_creds:server1.key",
"//src/core/tsi/test_creds:server1.pem",
],
external_deps = ["gtest"],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
deps = [
"//:gpr",

@ -18,6 +18,8 @@
#include <string.h>
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
@ -82,9 +84,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_channel_credentials* cred = grpc_alts_credentials_create_customized(
options, handshaker_service_url, enable_untrusted_alts);
if (!enable_untrusted_alts && !is_on_gcp) {
GPR_ASSERT(cred == nullptr);
CHECK_EQ(cred, nullptr);
} else {
GPR_ASSERT(cred != nullptr);
CHECK_NE(cred, nullptr);
}
grpc_channel_credentials_release(cred);
grpc_alts_credentials_options_destroy(options);
@ -96,9 +98,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_alts_server_credentials_create_customized(
options, handshaker_service_url, enable_untrusted_alts);
if (!enable_untrusted_alts && !is_on_gcp) {
GPR_ASSERT(cred == nullptr);
CHECK_EQ(cred, nullptr);
} else {
GPR_ASSERT(cred != nullptr);
CHECK_NE(cred, nullptr);
}
grpc_server_credentials_release(cred);
grpc_alts_credentials_options_destroy(options);

@ -18,6 +18,8 @@
#include <gmock/gmock.h>
#include "absl/log/check.h"
#include <grpc/grpc_security.h>
#include "test/core/util/test_config.h"
@ -247,9 +249,8 @@ TEST(GrpcAwsRequestSignerTest, InvalidUrl) {
"token", "POST", "invalid_url",
"us-east-1", "", {}, &error);
std::string actual_error_description;
GPR_ASSERT(grpc_error_get_str(error,
grpc_core::StatusStrProperty::kDescription,
&actual_error_description));
CHECK(grpc_error_get_str(error, grpc_core::StatusStrProperty::kDescription,
&actual_error_description));
EXPECT_EQ(actual_error_description, "Invalid Aws request url.");
}
@ -260,9 +261,8 @@ TEST(GrpcAwsRequestSignerTest, DuplicateRequestDate) {
"us-east-1", "", {{"date", kBotoTestDate}, {"x-amz-date", kAmzTestDate}},
&error);
std::string actual_error_description;
GPR_ASSERT(grpc_error_get_str(error,
grpc_core::StatusStrProperty::kDescription,
&actual_error_description));
CHECK(grpc_error_get_str(error, grpc_core::StatusStrProperty::kDescription,
&actual_error_description));
EXPECT_EQ(actual_error_description,
"Only one of {date, x-amz-date} can be specified, not both.");
}

@ -19,6 +19,8 @@
#include <stdio.h>
#include <string.h>
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
@ -137,7 +139,7 @@ int main(int argc, char** argv) {
"Missing --gce, --json_sts_options, or --json_refresh_token option.");
exit(1);
}
GPR_ASSERT(creds != nullptr);
CHECK_NE(creds, nullptr);
token = grpc_test_fetch_oauth2_token_with_credentials(creds);
if (token != nullptr) {

@ -24,6 +24,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
@ -133,17 +135,17 @@ class GrpcTlsCertificateDistributorTest : public ::testing::Test {
void OnError(grpc_error_handle root_cert_error,
grpc_error_handle identity_cert_error) override {
GPR_ASSERT(!root_cert_error.ok() || !identity_cert_error.ok());
CHECK(!root_cert_error.ok() || !identity_cert_error.ok());
std::string root_error_str;
std::string identity_error_str;
if (!root_cert_error.ok()) {
GPR_ASSERT(grpc_error_get_str(
CHECK(grpc_error_get_str(
root_cert_error, StatusStrProperty::kDescription, &root_error_str));
}
if (!identity_cert_error.ok()) {
GPR_ASSERT(grpc_error_get_str(identity_cert_error,
StatusStrProperty::kDescription,
&identity_error_str));
CHECK(grpc_error_get_str(identity_cert_error,
StatusStrProperty::kDescription,
&identity_error_str));
}
state_->error_queue.emplace_back(std::move(root_error_str),
std::move(identity_error_str));

@ -22,6 +22,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
@ -134,17 +136,17 @@ class GrpcTlsCertificateProviderTest : public ::testing::Test {
void OnError(grpc_error_handle root_cert_error,
grpc_error_handle identity_cert_error) override {
MutexLock lock(&state_->mu);
GPR_ASSERT(!root_cert_error.ok() || !identity_cert_error.ok());
CHECK(!root_cert_error.ok() || !identity_cert_error.ok());
std::string root_error_str;
std::string identity_error_str;
if (!root_cert_error.ok()) {
GPR_ASSERT(grpc_error_get_str(
CHECK(grpc_error_get_str(
root_cert_error, StatusStrProperty::kDescription, &root_error_str));
}
if (!identity_cert_error.ok()) {
GPR_ASSERT(grpc_error_get_str(identity_cert_error,
StatusStrProperty::kDescription,
&identity_error_str));
CHECK(grpc_error_get_str(identity_cert_error,
StatusStrProperty::kDescription,
&identity_error_str));
}
state_->error_queue.emplace_back(std::move(root_error_str),
std::move(identity_error_str));

@ -19,6 +19,8 @@
#include <stdio.h>
#include <string.h>
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
@ -51,7 +53,7 @@ static void on_metadata_response(void* arg, grpc_error_handle error) {
fflush(stderr);
} else {
char* token;
GPR_ASSERT(sync->md_array.size == 1);
CHECK_EQ(sync->md_array.size, 1u);
token = grpc_slice_to_c_string(GRPC_MDVALUE(sync->md_array.md[0]));
printf("\nGot token: %s\n\n", token);
gpr_free(token);

@ -15,6 +15,7 @@
// limitations under the License.
//
//
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/event_engine/event_engine.h>
@ -54,10 +55,10 @@ static void on_handshake_done(void* arg, grpc_error_handle error) {
static_cast<grpc_core::HandshakerArgs*>(arg);
struct handshake_state* state =
static_cast<struct handshake_state*>(args->user_data);
GPR_ASSERT(state->done_callback_called == false);
CHECK(state->done_callback_called == false);
state->done_callback_called = true;
// The fuzzer should not pass the handshake.
GPR_ASSERT(!error.ok());
CHECK(!error.ok());
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
@ -86,7 +87,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Create security connector
grpc_core::RefCountedPtr<grpc_server_security_connector> sc =
creds->create_security_connector(grpc_core::ChannelArgs());
GPR_ASSERT(sc != nullptr);
CHECK(sc != nullptr);
grpc_core::Timestamp deadline =
grpc_core::Duration::Seconds(1) + grpc_core::Timestamp::Now();
@ -110,7 +111,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
GRPC_ERROR_CREATE("Explicit close"));
grpc_core::ExecCtx::Get()->Flush();
}
GPR_ASSERT(state.done_callback_called);
CHECK(state.done_callback_called);
sc.reset(DEBUG_LOCATION, "test");
grpc_server_credentials_release(creds);

@ -24,6 +24,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -82,7 +84,7 @@ class TlsSecurityConnectorTest : public ::testing::Test {
static std::string GetErrorMsg(grpc_error_handle error) {
std::string error_str;
GPR_ASSERT(
CHECK(
grpc_error_get_str(error, StatusStrProperty::kDescription, &error_str));
return error_str;
}
@ -368,13 +370,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE(tls_connector->ClientHandshakerFactoryForTesting(), nullptr);
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
ExecCtx exec_ctx;
grpc_closure* on_peer_checked = GRPC_CLOSURE_CREATE(
@ -404,13 +406,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE(tls_connector->ClientHandshakerFactoryForTesting(), nullptr);
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
const char* expected_error_msg =
"Custom verification check failed with error: UNAUTHENTICATED: "
@ -557,13 +559,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE(tls_connector->ClientHandshakerFactoryForTesting(), nullptr);
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
ExecCtx exec_ctx;
grpc_closure* on_peer_checked = GRPC_CLOSURE_CREATE(
@ -593,13 +595,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE(tls_connector->ClientHandshakerFactoryForTesting(), nullptr);
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
const char* expected_error_msg =
"Custom verification check failed with error: UNAUTHENTICATED: "
@ -631,29 +633,29 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE(tls_connector->ClientHandshakerFactoryForTesting(), nullptr);
// Construct a full TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(7, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_PROPERTY, "pem_cert", &peer.properties[2]) ==
TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_SECURITY_LEVEL_PEER_PROPERTY,
tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY),
&peer.properties[3]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_CHAIN_PROPERTY, "pem_cert_chain",
&peer.properties[4]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[5]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "foo.baz.com",
&peer.properties[6]) == TSI_OK);
CHECK(tsi_construct_peer(7, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_PROPERTY, "pem_cert", &peer.properties[2]) ==
TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_SECURITY_LEVEL_PEER_PROPERTY,
tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY),
&peer.properties[3]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_CHAIN_PROPERTY, "pem_cert_chain",
&peer.properties[4]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[5]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "foo.baz.com",
&peer.properties[6]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
ExecCtx exec_ctx;
grpc_closure* on_peer_checked = GRPC_CLOSURE_CREATE(
@ -679,29 +681,29 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE(tls_connector->ClientHandshakerFactoryForTesting(), nullptr);
// Construct a full TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(7, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.com",
&peer.properties[1]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_PROPERTY, "pem_cert", &peer.properties[2]) ==
TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_SECURITY_LEVEL_PEER_PROPERTY,
tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY),
&peer.properties[3]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_CHAIN_PROPERTY, "pem_cert_chain",
&peer.properties[4]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "*.com",
&peer.properties[5]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "foo.baz.com",
&peer.properties[6]) == TSI_OK);
CHECK(tsi_construct_peer(7, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_PROPERTY, "pem_cert", &peer.properties[2]) ==
TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_SECURITY_LEVEL_PEER_PROPERTY,
tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY),
&peer.properties[3]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_PEM_CERT_CHAIN_PROPERTY, "pem_cert_chain",
&peer.properties[4]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "*.com",
&peer.properties[5]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, "foo.baz.com",
&peer.properties[6]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
const char* expected_error_msg =
"Custom verification check failed with error: UNAUTHENTICATED: Hostname "
@ -988,13 +990,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials->create_security_connector(ChannelArgs());
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
ExecCtx exec_ctx;
grpc_closure* on_peer_checked = GRPC_CLOSURE_CREATE(
@ -1019,13 +1021,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials->create_security_connector(ChannelArgs());
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
const char* expected_error_msg =
"Custom verification check failed with error: UNAUTHENTICATED: "
@ -1054,13 +1056,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials->create_security_connector(ChannelArgs());
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
ExecCtx exec_ctx;
grpc_closure* on_peer_checked = GRPC_CLOSURE_CREATE(
@ -1087,13 +1089,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials->create_security_connector(ChannelArgs());
// Construct a basic TSI Peer.
tsi_peer peer;
GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL,
"h2", strlen("h2"),
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
CHECK(tsi_construct_peer(2, &peer) == TSI_OK);
CHECK(tsi_construct_string_peer_property(TSI_SSL_ALPN_SELECTED_PROTOCOL, "h2",
strlen("h2"),
&peer.properties[0]) == TSI_OK);
CHECK(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, "foo.bar.com",
&peer.properties[1]) == TSI_OK);
RefCountedPtr<grpc_auth_context> auth_context;
const char* expected_error_msg =
"Custom verification check failed with error: UNAUTHENTICATED: "

@ -19,6 +19,8 @@
#include <stdio.h>
#include <string.h>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/slice.h>
@ -55,13 +57,13 @@ static void on_jwt_verification_done(void* user_data,
sync->success = (status == GRPC_JWT_VERIFIER_OK);
if (sync->success) {
GPR_ASSERT(claims != nullptr);
CHECK_NE(claims, nullptr);
std::string claims_str =
grpc_core::JsonDump(*grpc_jwt_claims_json(claims), /*indent=*/2);
printf("Claims: \n\n%s\n", claims_str.c_str());
grpc_jwt_claims_destroy(claims);
} else {
GPR_ASSERT(claims == nullptr);
CHECK_EQ(claims, nullptr);
fprintf(stderr, "Verification failed with error %s\n",
grpc_jwt_verifier_status_to_string(status));
fflush(stderr);

Loading…
Cancel
Save