diff options
author | Craig Tiller <ctiller@google.com> | 2017-11-10 14:14:17 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-11-10 14:14:17 -0800 |
commit | 4ac2b8e585cbf7064f9bdde4eabaf8ff42801142 (patch) | |
tree | 5379629b43d287972916a87637a26251c1b0de5f /test/core/tsi | |
parent | e77b3c36d1b3e2033abd19d553748b678c22253f (diff) |
Enable clang-tidy as a sanity check, fix up all known failures
Diffstat (limited to 'test/core/tsi')
-rw-r--r-- | test/core/tsi/fake_transport_security_test.cc | 4 | ||||
-rw-r--r-- | test/core/tsi/ssl_transport_security_test.cc | 62 | ||||
-rw-r--r-- | test/core/tsi/transport_security_test.cc | 176 | ||||
-rw-r--r-- | test/core/tsi/transport_security_test_lib.cc | 116 |
4 files changed, 179 insertions, 179 deletions
diff --git a/test/core/tsi/fake_transport_security_test.cc b/test/core/tsi/fake_transport_security_test.cc index 32b0f898af..73643fc9fd 100644 --- a/test/core/tsi/fake_transport_security_test.cc +++ b/test/core/tsi/fake_transport_security_test.cc @@ -41,12 +41,12 @@ static void fake_test_setup_handshakers(tsi_test_fixture* fixture) { } static void validate_handshaker_peers(tsi_handshaker_result* result) { - GPR_ASSERT(result != NULL); + GPR_ASSERT(result != nullptr); tsi_peer peer; GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK); const tsi_peer_property* property = tsi_peer_get_property_by_name(&peer, TSI_CERTIFICATE_TYPE_PEER_PROPERTY); - GPR_ASSERT(property != NULL); + GPR_ASSERT(property != nullptr); GPR_ASSERT(memcmp(property->value.data, TSI_FAKE_CERTIFICATE_TYPE, property->value.length) == 0); tsi_peer_destruct(&peer); diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 0903ce8625..03367d85e5 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -82,19 +82,19 @@ typedef struct ssl_tsi_test_fixture { static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; - GPR_ASSERT(ssl_fixture != NULL); - GPR_ASSERT(ssl_fixture->key_cert_lib != NULL); - GPR_ASSERT(ssl_fixture->alpn_lib != NULL); + GPR_ASSERT(ssl_fixture != nullptr); + GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr); + GPR_ASSERT(ssl_fixture->alpn_lib != nullptr); ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib; ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib; /* Create client handshaker factory. */ - tsi_ssl_pem_key_cert_pair* client_key_cert_pair = NULL; + tsi_ssl_pem_key_cert_pair* client_key_cert_pair = nullptr; if (ssl_fixture->force_client_auth) { client_key_cert_pair = key_cert_lib->use_bad_client_cert ? &key_cert_lib->bad_client_pem_key_cert_pair : &key_cert_lib->client_pem_key_cert_pair; } - char** client_alpn_protocols = NULL; + char** client_alpn_protocols = nullptr; uint16_t num_client_alpn_protocols = 0; if (alpn_lib->alpn_mode == ALPN_CLIENT_NO_SERVER || alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK || @@ -103,11 +103,11 @@ static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { num_client_alpn_protocols = alpn_lib->num_client_alpn_protocols; } GPR_ASSERT(tsi_create_ssl_client_handshaker_factory( - client_key_cert_pair, key_cert_lib->root_cert, NULL, + client_key_cert_pair, key_cert_lib->root_cert, nullptr, (const char**)client_alpn_protocols, num_client_alpn_protocols, &ssl_fixture->client_handshaker_factory) == TSI_OK); /* Create server handshaker factory. */ - char** server_alpn_protocols = NULL; + char** server_alpn_protocols = nullptr; uint16_t num_server_alpn_protocols = 0; if (alpn_lib->alpn_mode == ALPN_SERVER_NO_CLIENT || alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK || @@ -125,18 +125,18 @@ static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { key_cert_lib->use_bad_server_cert ? key_cert_lib->bad_server_num_key_cert_pairs : key_cert_lib->server_num_key_cert_pairs, - key_cert_lib->root_cert, ssl_fixture->force_client_auth, NULL, + key_cert_lib->root_cert, ssl_fixture->force_client_auth, nullptr, (const char**)server_alpn_protocols, num_server_alpn_protocols, &ssl_fixture->server_handshaker_factory) == TSI_OK); /* Create server and client handshakers. */ - tsi_handshaker* client_handshaker = NULL; + tsi_handshaker* client_handshaker = nullptr; GPR_ASSERT(tsi_ssl_client_handshaker_factory_create_handshaker( ssl_fixture->client_handshaker_factory, ssl_fixture->server_name_indication, &client_handshaker) == TSI_OK); ssl_fixture->base.client_handshaker = tsi_create_adapter_handshaker(client_handshaker); - tsi_handshaker* server_handshaker = NULL; + tsi_handshaker* server_handshaker = nullptr; GPR_ASSERT(tsi_ssl_server_handshaker_factory_create_handshaker( ssl_fixture->server_handshaker_factory, &server_handshaker) == TSI_OK); @@ -146,15 +146,15 @@ static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { static void check_alpn(ssl_tsi_test_fixture* ssl_fixture, const tsi_peer* peer) { - GPR_ASSERT(ssl_fixture != NULL); - GPR_ASSERT(ssl_fixture->alpn_lib != NULL); + GPR_ASSERT(ssl_fixture != nullptr); + GPR_ASSERT(ssl_fixture->alpn_lib != nullptr); ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib; const tsi_peer_property* alpn_property = tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL); if (alpn_lib->alpn_mode != ALPN_CLIENT_SERVER_OK) { - GPR_ASSERT(alpn_property == NULL); + GPR_ASSERT(alpn_property == nullptr); } else { - GPR_ASSERT(alpn_property != NULL); + GPR_ASSERT(alpn_property != nullptr); const char* expected_match = "baz"; GPR_ASSERT(memcmp(alpn_property->value.data, expected_match, alpn_property->value.length) == 0); @@ -165,12 +165,12 @@ static const tsi_peer_property* check_basic_authenticated_peer_and_get_common_name(const tsi_peer* peer) { const tsi_peer_property* cert_type_property = tsi_peer_get_property_by_name(peer, TSI_CERTIFICATE_TYPE_PEER_PROPERTY); - GPR_ASSERT(cert_type_property != NULL); + GPR_ASSERT(cert_type_property != nullptr); GPR_ASSERT(memcmp(cert_type_property->value.data, TSI_X509_CERTIFICATE_TYPE, cert_type_property->value.length) == 0); const tsi_peer_property* property = tsi_peer_get_property_by_name( peer, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY); - GPR_ASSERT(property != NULL); + GPR_ASSERT(property != nullptr); return property; } @@ -182,7 +182,7 @@ void check_server0_peer(tsi_peer* peer) { property->value.length) == 0); GPR_ASSERT(tsi_peer_get_property_by_name( peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == - NULL); + nullptr); GPR_ASSERT(tsi_ssl_peer_matches_name(peer, "foo.test.google.com.au") == 1); GPR_ASSERT(tsi_ssl_peer_matches_name(peer, "bar.test.google.com.au") == 1); GPR_ASSERT(tsi_ssl_peer_matches_name(peer, "bar.test.google.blah") == 0); @@ -226,8 +226,8 @@ void check_server1_peer(tsi_peer* peer) { static void check_client_peer(ssl_tsi_test_fixture* ssl_fixture, tsi_peer* peer) { - GPR_ASSERT(ssl_fixture != NULL); - GPR_ASSERT(ssl_fixture->alpn_lib != NULL); + GPR_ASSERT(ssl_fixture != nullptr); + GPR_ASSERT(ssl_fixture->alpn_lib != nullptr); ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib; if (!ssl_fixture->force_client_auth) { GPR_ASSERT(peer->property_count == @@ -244,8 +244,8 @@ static void check_client_peer(ssl_tsi_test_fixture* ssl_fixture, static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) { ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; - GPR_ASSERT(ssl_fixture != NULL); - GPR_ASSERT(ssl_fixture->key_cert_lib != NULL); + GPR_ASSERT(ssl_fixture != nullptr); + GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr); ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib; tsi_peer peer; bool expect_success = @@ -256,13 +256,13 @@ static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) { ssl_fixture->base.client_result, &peer) == TSI_OK); check_alpn(ssl_fixture, &peer); - if (ssl_fixture->server_name_indication != NULL) { + if (ssl_fixture->server_name_indication != nullptr) { check_server1_peer(&peer); } else { check_server0_peer(&peer); } } else { - GPR_ASSERT(ssl_fixture->base.client_result == NULL); + GPR_ASSERT(ssl_fixture->base.client_result == nullptr); } if (expect_success) { GPR_ASSERT(tsi_handshaker_result_extract_peer( @@ -270,7 +270,7 @@ static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) { check_alpn(ssl_fixture, &peer); check_client_peer(ssl_fixture, &peer); } else { - GPR_ASSERT(ssl_fixture->base.server_result == NULL); + GPR_ASSERT(ssl_fixture->base.server_result == nullptr); } } @@ -281,7 +281,7 @@ static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp) { static void ssl_test_destruct(tsi_test_fixture* fixture) { ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; - if (ssl_fixture == NULL) { + if (ssl_fixture == nullptr) { return; } /* Destroy ssl_alpn_lib. */ @@ -397,7 +397,7 @@ static tsi_test_fixture* ssl_tsi_test_fixture_create() { alpn_lib->alpn_mode = NO_ALPN; ssl_fixture->alpn_lib = alpn_lib; ssl_fixture->base.vtable = &vtable; - ssl_fixture->server_name_indication = NULL; + ssl_fixture->server_name_indication = nullptr; ssl_fixture->force_client_auth = false; return &ssl_fixture->base; } @@ -548,9 +548,9 @@ static bool handshaker_factory_destructor_called; static void ssl_tsi_test_handshaker_factory_destructor( tsi_ssl_handshaker_factory* factory) { - GPR_ASSERT(factory != NULL); + GPR_ASSERT(factory != nullptr); handshaker_factory_destructor_called = true; - if (original_vtable != NULL && original_vtable->destroy != NULL) { + if (original_vtable != nullptr && original_vtable->destroy != nullptr) { original_vtable->destroy(factory); } } @@ -565,7 +565,7 @@ void test_tsi_ssl_client_handshaker_factory_refcounting() { tsi_ssl_client_handshaker_factory* client_handshaker_factory; GPR_ASSERT(tsi_create_ssl_client_handshaker_factory( - NULL, cert_chain, NULL, NULL, 0, &client_handshaker_factory) == + nullptr, cert_chain, nullptr, nullptr, 0, &client_handshaker_factory) == TSI_OK); handshaker_factory_destructor_called = false; @@ -609,7 +609,7 @@ void test_tsi_ssl_server_handshaker_factory_refcounting() { load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "server0.key"); GPR_ASSERT(tsi_create_ssl_server_handshaker_factory( - &cert_pair, 1, cert_chain, 0, NULL, NULL, 0, + &cert_pair, 1, cert_chain, 0, nullptr, nullptr, 0, &server_handshaker_factory) == TSI_OK); handshaker_factory_destructor_called = false; @@ -644,7 +644,7 @@ void test_tsi_ssl_client_handshaker_factory_bad_params() { tsi_ssl_client_handshaker_factory* client_handshaker_factory; GPR_ASSERT(tsi_create_ssl_client_handshaker_factory( - NULL, cert_chain, NULL, NULL, 0, &client_handshaker_factory) == + nullptr, cert_chain, nullptr, nullptr, 0, &client_handshaker_factory) == TSI_INVALID_ARGUMENT); tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory); } diff --git a/test/core/tsi/transport_security_test.cc b/test/core/tsi/transport_security_test.cc index 39adf2fab6..8dfe72e03b 100644 --- a/test/core/tsi/transport_security_test.cc +++ b/test/core/tsi/transport_security_test.cc @@ -54,29 +54,29 @@ typedef struct { chromium/src/net/cert/x509_certificate_unittest.cc. TODO(jboeuf) uncomment test cases as we fix tsi_ssl_peer_matches_name. */ const cert_name_test_entry cert_name_test_entries[] = { - {1, "foo.com", "foo.com", NULL, NULL}, - {1, "f", "f", NULL, NULL}, - {0, "h", "i", NULL, NULL}, - {1, "bar.foo.com", "*.foo.com", NULL, NULL}, + {1, "foo.com", "foo.com", nullptr, nullptr}, + {1, "f", "f", nullptr, nullptr}, + {0, "h", "i", nullptr, nullptr}, + {1, "bar.foo.com", "*.foo.com", nullptr, nullptr}, {1, "www.test.fr", "common.name", - "*.test.com,*.test.co.uk,*.test.de,*.test.fr", NULL}, + "*.test.com,*.test.co.uk,*.test.de,*.test.fr", nullptr}, /* {1, "wwW.tESt.fr", "common.name", ",*.*,*.test.de,*.test.FR,www"}, */ - {0, "f.uk", ".uk", NULL, NULL}, - {0, "w.bar.foo.com", "?.bar.foo.com", NULL, NULL}, - {0, "www.foo.com", "(www|ftp).foo.com", NULL, NULL}, - {0, "www.foo.com", "www.foo.com#", NULL, NULL}, /* # = null char. */ - {0, "www.foo.com", "", "www.foo.com#*.foo.com,#,#", NULL}, - {0, "www.house.example", "ww.house.example", NULL, NULL}, - {0, "test.org", "", "www.test.org,*.test.org,*.org", NULL}, - {0, "w.bar.foo.com", "w*.bar.foo.com", NULL, NULL}, - {0, "www.bar.foo.com", "ww*ww.bar.foo.com", NULL, NULL}, - {0, "wwww.bar.foo.com", "ww*ww.bar.foo.com", NULL, NULL}, - {0, "wwww.bar.foo.com", "w*w.bar.foo.com", NULL, NULL}, - {0, "wwww.bar.foo.com", "w*w.bar.foo.c0m", NULL, NULL}, - {0, "WALLY.bar.foo.com", "wa*.bar.foo.com", NULL, NULL}, - {0, "wally.bar.foo.com", "*Ly.bar.foo.com", NULL, NULL}, + {0, "f.uk", ".uk", nullptr, nullptr}, + {0, "w.bar.foo.com", "?.bar.foo.com", nullptr, nullptr}, + {0, "www.foo.com", "(www|ftp).foo.com", nullptr, nullptr}, + {0, "www.foo.com", "www.foo.com#", nullptr, nullptr}, /* # = null char. */ + {0, "www.foo.com", "", "www.foo.com#*.foo.com,#,#", nullptr}, + {0, "www.house.example", "ww.house.example", nullptr, nullptr}, + {0, "test.org", "", "www.test.org,*.test.org,*.org", nullptr}, + {0, "w.bar.foo.com", "w*.bar.foo.com", nullptr, nullptr}, + {0, "www.bar.foo.com", "ww*ww.bar.foo.com", nullptr, nullptr}, + {0, "wwww.bar.foo.com", "ww*ww.bar.foo.com", nullptr, nullptr}, + {0, "wwww.bar.foo.com", "w*w.bar.foo.com", nullptr, nullptr}, + {0, "wwww.bar.foo.com", "w*w.bar.foo.c0m", nullptr, nullptr}, + {0, "WALLY.bar.foo.com", "wa*.bar.foo.com", nullptr, nullptr}, + {0, "wally.bar.foo.com", "*Ly.bar.foo.com", nullptr, nullptr}, /* {1, "ww%57.foo.com", "", "www.foo.com"}, {1, "www&.foo.com", "www%26.foo.com", NULL}, @@ -84,107 +84,107 @@ const cert_name_test_entry cert_name_test_entries[] = { /* Common name must not be used if subject alternative name was provided. */ {0, "www.test.co.jp", "www.test.co.jp", - "*.test.de,*.jp,www.test.co.uk,www.*.co.jp", NULL}, + "*.test.de,*.jp,www.test.co.uk,www.*.co.jp", nullptr}, {0, "www.bar.foo.com", "www.bar.foo.com", - "*.foo.com,*.*.foo.com,*.*.bar.foo.com,*..bar.foo.com,", NULL}, + "*.foo.com,*.*.foo.com,*.*.bar.foo.com,*..bar.foo.com,", nullptr}, /* IDN tests */ - {1, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br", NULL, NULL}, - {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL, NULL}, + {1, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br", nullptr, nullptr}, + {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", nullptr, nullptr}, {0, "xn--poema-9qae5a.com.br", "", "*.xn--poema-9qae5a.com.br," "xn--poema-*.com.br," "xn--*-9qae5a.com.br," "*--poema-9qae5a.com.br", - NULL}, + nullptr}, /* The following are adapted from the examples quoted from http://tools.ietf.org/html/rfc6125#section-6.4.3 (e.g., *.example.com would match foo.example.com but not bar.foo.example.com or example.com). */ - {1, "foo.example.com", "*.example.com", NULL, NULL}, - {0, "bar.foo.example.com", "*.example.com", NULL, NULL}, - {0, "example.com", "*.example.com", NULL, NULL}, + {1, "foo.example.com", "*.example.com", nullptr, nullptr}, + {0, "bar.foo.example.com", "*.example.com", nullptr, nullptr}, + {0, "example.com", "*.example.com", nullptr, nullptr}, /* Partial wildcards are disallowed, though RFC 2818 rules allow them. That is, forms such as baz*.example.net, *baz.example.net, and b*z.example.net should NOT match domains. Instead, the wildcard must always be the left-most label, and only a single label. */ - {0, "baz1.example.net", "baz*.example.net", NULL, NULL}, - {0, "foobaz.example.net", "*baz.example.net", NULL, NULL}, - {0, "buzz.example.net", "b*z.example.net", NULL, NULL}, - {0, "www.test.example.net", "www.*.example.net", NULL, NULL}, + {0, "baz1.example.net", "baz*.example.net", nullptr, nullptr}, + {0, "foobaz.example.net", "*baz.example.net", nullptr, nullptr}, + {0, "buzz.example.net", "b*z.example.net", nullptr, nullptr}, + {0, "www.test.example.net", "www.*.example.net", nullptr, nullptr}, /* Wildcards should not be valid for public registry controlled domains, and unknown/unrecognized domains, at least three domain components must be present. */ - {1, "www.test.example", "*.test.example", NULL, NULL}, - {1, "test.example.co.uk", "*.example.co.uk", NULL, NULL}, - {0, "test.example", "*.example", NULL, NULL}, + {1, "www.test.example", "*.test.example", nullptr, nullptr}, + {1, "test.example.co.uk", "*.example.co.uk", nullptr, nullptr}, + {0, "test.example", "*.example", nullptr, nullptr}, /* {0, "example.co.uk", "*.co.uk", NULL}, */ - {0, "foo.com", "*.com", NULL, NULL}, - {0, "foo.us", "*.us", NULL, NULL}, - {0, "foo", "*", NULL, NULL}, + {0, "foo.com", "*.com", nullptr, nullptr}, + {0, "foo.us", "*.us", nullptr, nullptr}, + {0, "foo", "*", nullptr, nullptr}, /* IDN variants of wildcards and registry controlled domains. */ - {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL, NULL}, - {1, "test.example.xn--mgbaam7a8h", "*.example.xn--mgbaam7a8h", NULL, NULL}, + {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", nullptr, nullptr}, + {1, "test.example.xn--mgbaam7a8h", "*.example.xn--mgbaam7a8h", nullptr, nullptr}, /* {0, "xn--poema-9qae5a.com.br", "*.com.br", NULL}, */ - {0, "example.xn--mgbaam7a8h", "*.xn--mgbaam7a8h", NULL, NULL}, + {0, "example.xn--mgbaam7a8h", "*.xn--mgbaam7a8h", nullptr, nullptr}, /* Wildcards should be permissible for 'private' registry controlled domains. */ - {1, "www.appspot.com", "*.appspot.com", NULL, NULL}, - {1, "foo.s3.amazonaws.com", "*.s3.amazonaws.com", NULL, NULL}, + {1, "www.appspot.com", "*.appspot.com", nullptr, nullptr}, + {1, "foo.s3.amazonaws.com", "*.s3.amazonaws.com", nullptr, nullptr}, /* Multiple wildcards are not valid. */ - {0, "foo.example.com", "*.*.com", NULL, NULL}, - {0, "foo.bar.example.com", "*.bar.*.com", NULL, NULL}, + {0, "foo.example.com", "*.*.com", nullptr, nullptr}, + {0, "foo.bar.example.com", "*.bar.*.com", nullptr, nullptr}, /* Absolute vs relative DNS name tests. Although not explicitly specified in RFC 6125, absolute reference names (those ending in a .) should match either absolute or relative presented names. */ - {1, "foo.com", "foo.com.", NULL, NULL}, - {1, "foo.com.", "foo.com", NULL, NULL}, - {1, "foo.com.", "foo.com.", NULL, NULL}, - {1, "f", "f.", NULL, NULL}, - {1, "f.", "f", NULL, NULL}, - {1, "f.", "f.", NULL, NULL}, - {1, "www-3.bar.foo.com", "*.bar.foo.com.", NULL, NULL}, - {1, "www-3.bar.foo.com.", "*.bar.foo.com", NULL, NULL}, - {1, "www-3.bar.foo.com.", "*.bar.foo.com.", NULL, NULL}, - {0, ".", ".", NULL, NULL}, - {0, "example.com", "*.com.", NULL, NULL}, - {0, "example.com.", "*.com", NULL, NULL}, - {0, "example.com.", "*.com.", NULL, NULL}, - {0, "foo.", "*.", NULL, NULL}, - {0, "foo", "*.", NULL, NULL}, + {1, "foo.com", "foo.com.", nullptr, nullptr}, + {1, "foo.com.", "foo.com", nullptr, nullptr}, + {1, "foo.com.", "foo.com.", nullptr, nullptr}, + {1, "f", "f.", nullptr, nullptr}, + {1, "f.", "f", nullptr, nullptr}, + {1, "f.", "f.", nullptr, nullptr}, + {1, "www-3.bar.foo.com", "*.bar.foo.com.", nullptr, nullptr}, + {1, "www-3.bar.foo.com.", "*.bar.foo.com", nullptr, nullptr}, + {1, "www-3.bar.foo.com.", "*.bar.foo.com.", nullptr, nullptr}, + {0, ".", ".", nullptr, nullptr}, + {0, "example.com", "*.com.", nullptr, nullptr}, + {0, "example.com.", "*.com", nullptr, nullptr}, + {0, "example.com.", "*.com.", nullptr, nullptr}, + {0, "foo.", "*.", nullptr, nullptr}, + {0, "foo", "*.", nullptr, nullptr}, /* {0, "foo.co.uk", "*.co.uk.", NULL}, {0, "foo.co.uk.", "*.co.uk.", NULL}, */ /* An empty CN is OK. */ - {1, "test.foo.com", "", "test.foo.com", NULL}, + {1, "test.foo.com", "", "test.foo.com", nullptr}, /* An IP should not be used for the CN. */ - {0, "173.194.195.139", "173.194.195.139", NULL, NULL}, + {0, "173.194.195.139", "173.194.195.139", nullptr, nullptr}, /* An IP can be used if the SAN IP is present */ - {1, "173.194.195.139", "foo.example.com", NULL, "173.194.195.139"}, - {0, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8"}, - {0, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,8.8.4.4"}, - {1, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,173.194.195.139"}, - {0, "173.194.195.139", "foo.example.com", NULL, "173.194.195.13"}, - {0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL, "173.194.195.13"}, - {1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL, + {1, "173.194.195.139", "foo.example.com", nullptr, "173.194.195.139"}, + {0, "173.194.195.139", "foo.example.com", nullptr, "8.8.8.8"}, + {0, "173.194.195.139", "foo.example.com", nullptr, "8.8.8.8,8.8.4.4"}, + {1, "173.194.195.139", "foo.example.com", nullptr, "8.8.8.8,173.194.195.139"}, + {0, "173.194.195.139", "foo.example.com", nullptr, "173.194.195.13"}, + {0, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr, "173.194.195.13"}, + {1, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr, "2001:db8:a0b:12f0::1"}, - {0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL, + {0, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr, "2001:db8:a0b:12f0::2"}, - {1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL, + {1, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr, "2001:db8:a0b:12f0::2,2001:db8:a0b:12f0::1,8.8.8.8"}, }; @@ -202,7 +202,7 @@ typedef struct { name_list* name_list_add(const char* n) { name_list* result = static_cast<name_list*>(gpr_malloc(sizeof(name_list))); result->name = n; - result->next = NULL; + result->next = nullptr; return result; } @@ -211,7 +211,7 @@ static parsed_names parse_names(const char* names_str) { name_list* current_nl; size_t i; memset(&result, 0, sizeof(parsed_names)); - if (names_str == 0) return result; + if (names_str == nullptr) return result; result.name_count = 1; result.buffer = gpr_strdup(names_str); result.names = name_list_add(result.buffer); @@ -230,8 +230,8 @@ static parsed_names parse_names(const char* names_str) { static void destruct_parsed_names(parsed_names* pdn) { name_list* nl = pdn->names; - if (pdn->buffer != NULL) gpr_free(pdn->buffer); - while (nl != NULL) { + if (pdn->buffer != nullptr) gpr_free(pdn->buffer); + while (nl != nullptr) { name_list* to_be_free = nl; nl = nl->next; gpr_free(to_be_free); @@ -264,7 +264,7 @@ static tsi_peer peer_from_cert_name_test_entry( TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, entry->common_name, &peer.properties[0]) == TSI_OK); i = 1; - while (nl != NULL) { + while (nl != nullptr) { char* processed = processed_name(nl->name); GPR_ASSERT(tsi_construct_string_peer_property( TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed, @@ -274,7 +274,7 @@ static tsi_peer peer_from_cert_name_test_entry( } nl = ip_entries.names; - while (nl != NULL) { + while (nl != nullptr) { char* processed = processed_name(nl->name); GPR_ASSERT(tsi_construct_string_peer_property( TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed, @@ -294,8 +294,8 @@ char* cert_name_test_entry_to_string(const cert_name_test_entry* entry) { "%s, ip_names = %s}", entry->expected ? "true" : "false", entry->host_name, entry->common_name, - entry->dns_names != NULL ? entry->dns_names : "", - entry->ip_names != NULL ? entry->ip_names : ""); + entry->dns_names != nullptr ? entry->dns_names : "", + entry->ip_names != nullptr ? entry->ip_names : ""); return s; } @@ -344,24 +344,24 @@ static void test_result_strings(void) { } static void test_protector_invalid_args(void) { - GPR_ASSERT(tsi_frame_protector_protect(NULL, NULL, NULL, NULL, NULL) == + GPR_ASSERT(tsi_frame_protector_protect(nullptr, nullptr, nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(tsi_frame_protector_protect_flush(NULL, NULL, NULL, NULL) == + GPR_ASSERT(tsi_frame_protector_protect_flush(nullptr, nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(tsi_frame_protector_unprotect(NULL, NULL, NULL, NULL, NULL) == + GPR_ASSERT(tsi_frame_protector_unprotect(nullptr, nullptr, nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT); } static void test_handshaker_invalid_args(void) { - GPR_ASSERT(tsi_handshaker_get_result(NULL) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(tsi_handshaker_extract_peer(NULL, NULL) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(tsi_handshaker_create_frame_protector(NULL, NULL, NULL) == + GPR_ASSERT(tsi_handshaker_get_result(nullptr) == TSI_INVALID_ARGUMENT); + GPR_ASSERT(tsi_handshaker_extract_peer(nullptr, nullptr) == TSI_INVALID_ARGUMENT); + GPR_ASSERT(tsi_handshaker_create_frame_protector(nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(tsi_handshaker_process_bytes_from_peer(NULL, NULL, NULL) == + GPR_ASSERT(tsi_handshaker_process_bytes_from_peer(nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(tsi_handshaker_get_bytes_to_send_to_peer(NULL, NULL, NULL) == + GPR_ASSERT(tsi_handshaker_get_bytes_to_send_to_peer(nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(tsi_handshaker_next(NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL) == + GPR_ASSERT(tsi_handshaker_next(nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT); } @@ -370,7 +370,7 @@ static void test_handshaker_invalid_state(void) { tsi_peer peer; tsi_frame_protector* p; GPR_ASSERT(tsi_handshaker_extract_peer(h, &peer) == TSI_FAILED_PRECONDITION); - GPR_ASSERT(tsi_handshaker_create_frame_protector(h, NULL, &p) == + GPR_ASSERT(tsi_handshaker_create_frame_protector(h, nullptr, &p) == TSI_FAILED_PRECONDITION); tsi_handshaker_destroy(h); } diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index af8316873e..47a71717a6 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -55,8 +55,8 @@ typedef struct handshaker_args { static handshaker_args* handshaker_args_create(tsi_test_fixture* fixture, bool is_client) { - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(fixture->config != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->config != nullptr); handshaker_args* args = static_cast<handshaker_args*>(gpr_zalloc(sizeof(*args))); args->fixture = fixture; @@ -77,9 +77,9 @@ static void handshaker_args_destroy(handshaker_args* args) { static void do_handshaker_next(handshaker_args* args); static void setup_handshakers(tsi_test_fixture* fixture) { - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(fixture->vtable != NULL); - GPR_ASSERT(fixture->vtable->setup_handshakers != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->vtable != nullptr); + GPR_ASSERT(fixture->vtable->setup_handshakers != nullptr); fixture->vtable->setup_handshakers(fixture); } @@ -90,7 +90,7 @@ static void check_unused_bytes(tsi_test_fixture* fixture) { tsi_handshaker_result* result_without_unused_bytes = fixture->has_client_finished_first ? fixture->client_result : fixture->server_result; - const unsigned char* bytes = NULL; + const unsigned char* bytes = nullptr; size_t bytes_size = 0; GPR_ASSERT(tsi_handshaker_result_get_unused_bytes( result_with_unused_bytes, &bytes, &bytes_size) == TSI_OK); @@ -99,18 +99,18 @@ static void check_unused_bytes(tsi_test_fixture* fixture) { GPR_ASSERT(tsi_handshaker_result_get_unused_bytes( result_without_unused_bytes, &bytes, &bytes_size) == TSI_OK); GPR_ASSERT(bytes_size == 0); - GPR_ASSERT(bytes == NULL); + GPR_ASSERT(bytes == nullptr); } static void check_handshake_results(tsi_test_fixture* fixture) { - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(fixture->vtable != NULL); - GPR_ASSERT(fixture->vtable->check_handshaker_peers != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->vtable != nullptr); + GPR_ASSERT(fixture->vtable->check_handshaker_peers != nullptr); /* Check handshaker peers. */ fixture->vtable->check_handshaker_peers(fixture); /* Check unused bytes. */ if (fixture->test_unused_bytes) { - if (fixture->server_result != NULL && fixture->client_result != NULL) { + if (fixture->server_result != nullptr && fixture->client_result != nullptr) { check_unused_bytes(fixture); } fixture->bytes_written_to_server_channel = 0; @@ -123,14 +123,14 @@ static void check_handshake_results(tsi_test_fixture* fixture) { static void send_bytes_to_peer(tsi_test_fixture* fixture, const unsigned char* buf, size_t buf_size, bool is_client) { - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(buf != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(buf != nullptr); uint8_t* channel = is_client ? fixture->server_channel : fixture->client_channel; - GPR_ASSERT(channel != NULL); + GPR_ASSERT(channel != nullptr); size_t* bytes_written = is_client ? &fixture->bytes_written_to_server_channel : &fixture->bytes_written_to_client_channel; - GPR_ASSERT(bytes_written != NULL); + GPR_ASSERT(bytes_written != nullptr); GPR_ASSERT(*bytes_written + buf_size <= TSI_TEST_DEFAULT_CHANNEL_SIZE); /* Write data to channel. */ memcpy(channel + *bytes_written, buf, buf_size); @@ -138,14 +138,14 @@ static void send_bytes_to_peer(tsi_test_fixture* fixture, } static void maybe_append_unused_bytes(handshaker_args* args) { - GPR_ASSERT(args != NULL); - GPR_ASSERT(args->fixture != NULL); + GPR_ASSERT(args != nullptr); + GPR_ASSERT(args->fixture != nullptr); tsi_test_fixture* fixture = args->fixture; if (fixture->test_unused_bytes && !args->appended_unused_bytes) { args->appended_unused_bytes = true; send_bytes_to_peer(fixture, (const unsigned char*)TSI_TEST_UNUSED_BYTES, strlen(TSI_TEST_UNUSED_BYTES), args->is_client); - if (fixture->client_result != NULL && fixture->server_result == NULL) { + if (fixture->client_result != nullptr && fixture->server_result == nullptr) { fixture->has_client_finished_first = true; } } @@ -154,18 +154,18 @@ static void maybe_append_unused_bytes(handshaker_args* args) { static void receive_bytes_from_peer(tsi_test_fixture* fixture, unsigned char** buf, size_t* buf_size, bool is_client) { - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(*buf != NULL); - GPR_ASSERT(buf_size != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(*buf != nullptr); + GPR_ASSERT(buf_size != nullptr); uint8_t* channel = is_client ? fixture->client_channel : fixture->server_channel; - GPR_ASSERT(channel != NULL); + GPR_ASSERT(channel != nullptr); size_t* bytes_read = is_client ? &fixture->bytes_read_from_client_channel : &fixture->bytes_read_from_server_channel; size_t* bytes_written = is_client ? &fixture->bytes_written_to_client_channel : &fixture->bytes_written_to_server_channel; - GPR_ASSERT(bytes_read != NULL); - GPR_ASSERT(bytes_written != NULL); + GPR_ASSERT(bytes_read != nullptr); + GPR_ASSERT(bytes_written != nullptr); size_t to_read = *buf_size < *bytes_written - *bytes_read ? *buf_size : *bytes_written - *bytes_read; @@ -179,9 +179,9 @@ static void send_message_to_peer(tsi_test_fixture* fixture, tsi_frame_protector* protector, bool is_client) { /* Initialization. */ - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(fixture->config != NULL); - GPR_ASSERT(protector != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->config != nullptr); + GPR_ASSERT(protector != nullptr); tsi_test_frame_protector_config* config = fixture->config; unsigned char* protected_buffer = static_cast<unsigned char*>(gpr_zalloc(config->protected_buffer_size)); @@ -189,7 +189,7 @@ static void send_message_to_peer(tsi_test_fixture* fixture, is_client ? config->client_message_size : config->server_message_size; uint8_t* message = is_client ? config->client_message : config->server_message; - GPR_ASSERT(message != NULL); + GPR_ASSERT(message != nullptr); const unsigned char* message_bytes = (const unsigned char*)message; tsi_result result = TSI_OK; /* Do protect and send protected data to peer. */ @@ -230,11 +230,11 @@ static void receive_message_from_peer(tsi_test_fixture* fixture, unsigned char* message, size_t* bytes_received, bool is_client) { /* Initialization. */ - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(protector != NULL); - GPR_ASSERT(message != NULL); - GPR_ASSERT(bytes_received != NULL); - GPR_ASSERT(fixture->config != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(protector != nullptr); + GPR_ASSERT(message != nullptr); + GPR_ASSERT(bytes_received != nullptr); + GPR_ASSERT(fixture->config != nullptr); tsi_test_frame_protector_config* config = fixture->config; size_t read_offset = 0; size_t message_offset = 0; @@ -287,8 +287,8 @@ grpc_error* on_handshake_next_done(tsi_result result, void* user_data, size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) { handshaker_args* args = (handshaker_args*)user_data; - GPR_ASSERT(args != NULL); - GPR_ASSERT(args->fixture != NULL); + GPR_ASSERT(args != nullptr); + GPR_ASSERT(args->fixture != nullptr); tsi_test_fixture* fixture = args->fixture; grpc_error* error = GRPC_ERROR_NONE; /* Read more data if we need to. */ @@ -303,10 +303,10 @@ grpc_error* on_handshake_next_done(tsi_result result, void* user_data, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake failed"), result); } /* Update handshaker result. */ - if (handshaker_result != NULL) { + if (handshaker_result != nullptr) { tsi_handshaker_result** result_to_write = args->is_client ? &fixture->client_result : &fixture->server_result; - GPR_ASSERT(*result_to_write == NULL); + GPR_ASSERT(*result_to_write == nullptr); *result_to_write = handshaker_result; } /* Send data to peer, if needed. */ @@ -315,7 +315,7 @@ grpc_error* on_handshake_next_done(tsi_result result, void* user_data, args->is_client); args->transferred_data = true; } - if (handshaker_result != NULL) { + if (handshaker_result != nullptr) { maybe_append_unused_bytes(args); } notification_signal(fixture); @@ -331,11 +331,11 @@ static void on_handshake_next_done_wrapper( } static bool is_handshake_finished_properly(handshaker_args* args) { - GPR_ASSERT(args != NULL); - GPR_ASSERT(args->fixture != NULL); + GPR_ASSERT(args != nullptr); + GPR_ASSERT(args->fixture != nullptr); tsi_test_fixture* fixture = args->fixture; - if ((args->is_client && fixture->client_result != NULL) || - (!args->is_client && fixture->server_result != NULL)) { + if ((args->is_client && fixture->client_result != nullptr) || + (!args->is_client && fixture->server_result != nullptr)) { return true; } return false; @@ -343,16 +343,16 @@ static bool is_handshake_finished_properly(handshaker_args* args) { static void do_handshaker_next(handshaker_args* args) { /* Initialization. */ - GPR_ASSERT(args != NULL); - GPR_ASSERT(args->fixture != NULL); + GPR_ASSERT(args != nullptr); + GPR_ASSERT(args->fixture != nullptr); tsi_test_fixture* fixture = args->fixture; tsi_handshaker* handshaker = args->is_client ? fixture->client_handshaker : fixture->server_handshaker; if (is_handshake_finished_properly(args)) { return; } - tsi_handshaker_result* handshaker_result = NULL; - unsigned char* bytes_to_send = NULL; + tsi_handshaker_result* handshaker_result = nullptr; + unsigned char* bytes_to_send = nullptr; size_t bytes_to_send_size = 0; tsi_result result = TSI_OK; /* Receive data from peer, if available. */ @@ -399,7 +399,7 @@ void tsi_test_do_handshake(tsi_test_fixture* fixture) { break; } GPR_ASSERT(client_args->transferred_data || server_args->transferred_data); - } while (fixture->client_result == NULL || fixture->server_result == NULL); + } while (fixture->client_result == nullptr || fixture->server_result == nullptr); /* Verify handshake results. */ check_handshake_results(fixture); /* Cleanup. */ @@ -409,11 +409,11 @@ void tsi_test_do_handshake(tsi_test_fixture* fixture) { void tsi_test_do_round_trip(tsi_test_fixture* fixture) { /* Initialization. */ - GPR_ASSERT(fixture != NULL); - GPR_ASSERT(fixture->config != NULL); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->config != nullptr); tsi_test_frame_protector_config* config = fixture->config; - tsi_frame_protector* client_frame_protector = NULL; - tsi_frame_protector* server_frame_protector = NULL; + tsi_frame_protector* client_frame_protector = nullptr; + tsi_frame_protector* server_frame_protector = nullptr; /* Perform handshake. */ tsi_test_do_handshake(fixture); /* Create frame protectors.*/ @@ -422,7 +422,7 @@ void tsi_test_do_round_trip(tsi_test_fixture* fixture) { GPR_ASSERT(tsi_handshaker_result_create_frame_protector( fixture->client_result, client_max_output_protected_frame_size == 0 - ? NULL + ? nullptr : &client_max_output_protected_frame_size, &client_frame_protector) == TSI_OK); size_t server_max_output_protected_frame_size = @@ -430,7 +430,7 @@ void tsi_test_do_round_trip(tsi_test_fixture* fixture) { GPR_ASSERT(tsi_handshaker_result_create_frame_protector( fixture->server_result, server_max_output_protected_frame_size == 0 - ? NULL + ? nullptr : &server_max_output_protected_frame_size, &server_frame_protector) == TSI_OK); /* Client sends a message to server. */ @@ -536,7 +536,7 @@ void tsi_test_frame_protector_config_set_buffer_size( size_t message_buffer_allocated_size, size_t protected_buffer_size, size_t client_max_output_protected_frame_size, size_t server_max_output_protected_frame_size) { - GPR_ASSERT(config != NULL); + GPR_ASSERT(config != nullptr); config->read_buffer_allocated_size = read_buffer_allocated_size; config->message_buffer_allocated_size = message_buffer_allocated_size; config->protected_buffer_size = protected_buffer_size; @@ -548,7 +548,7 @@ void tsi_test_frame_protector_config_set_buffer_size( void tsi_test_frame_protector_config_destroy( tsi_test_frame_protector_config* config) { - GPR_ASSERT(config != NULL); + GPR_ASSERT(config != nullptr); gpr_free(config->client_message); gpr_free(config->server_message); gpr_free(config); @@ -574,7 +574,7 @@ void tsi_test_fixture_init(tsi_test_fixture* fixture) { } void tsi_test_fixture_destroy(tsi_test_fixture* fixture) { - GPR_ASSERT(fixture != NULL); + GPR_ASSERT(fixture != nullptr); tsi_test_frame_protector_config_destroy(fixture->config); tsi_handshaker_destroy(fixture->client_handshaker); tsi_handshaker_destroy(fixture->server_handshaker); @@ -582,8 +582,8 @@ void tsi_test_fixture_destroy(tsi_test_fixture* fixture) { tsi_handshaker_result_destroy(fixture->server_result); gpr_free(fixture->client_channel); gpr_free(fixture->server_channel); - GPR_ASSERT(fixture->vtable != NULL); - GPR_ASSERT(fixture->vtable->destruct != NULL); + GPR_ASSERT(fixture->vtable != nullptr); + GPR_ASSERT(fixture->vtable->destruct != nullptr); fixture->vtable->destruct(fixture); gpr_mu_destroy(&fixture->mu); gpr_cv_destroy(&fixture->cv); |