diff options
author | Craig Tiller <ctiller@google.com> | 2015-12-22 14:19:40 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-12-22 14:19:40 -0800 |
commit | 2e14b1f588a5a198a4b20d2801e199de49ac5f9c (patch) | |
tree | 4cf68c469facbf15ab3e22ca021968ea74f7bfc6 /test | |
parent | dacb38990735e0aacbb5a52cec840f72748314e9 (diff) | |
parent | d491897c4050bce09025d8ad0011d38c14ab0dad (diff) |
Merge github.com:grpc/grpc into proto_names
Diffstat (limited to 'test')
-rwxr-xr-x | test/core/bad_client/gen_build_yaml.py | 1 | ||||
-rw-r--r-- | test/core/bad_client/tests/window_overflow.c | 106 | ||||
-rw-r--r-- | test/core/bad_ssl/bad_ssl_test.c | 2 | ||||
-rw-r--r-- | test/core/bad_ssl/server.c | 7 | ||||
-rw-r--r-- | test/core/client_config/lb_policies_test.c | 21 | ||||
-rw-r--r-- | test/core/security/security_connector_test.c | 57 | ||||
-rw-r--r-- | test/core/support/alloc_test.c | 4 | ||||
-rw-r--r-- | test/core/transport/connectivity_state_test.c | 2 |
8 files changed, 182 insertions, 18 deletions
diff --git a/test/core/bad_client/gen_build_yaml.py b/test/core/bad_client/gen_build_yaml.py index 45fcb6982b..22b99e7cb4 100755 --- a/test/core/bad_client/gen_build_yaml.py +++ b/test/core/bad_client/gen_build_yaml.py @@ -46,6 +46,7 @@ BAD_CLIENT_TESTS = { 'initial_settings_frame': default_test_options, 'server_registered_method': default_test_options, 'simple_request': default_test_options, + 'window_overflow': default_test_options, 'unknown_frame': default_test_options, } diff --git a/test/core/bad_client/tests/window_overflow.c b/test/core/bad_client/tests/window_overflow.c new file mode 100644 index 0000000000..1c898f352d --- /dev/null +++ b/test/core/bad_client/tests/window_overflow.c @@ -0,0 +1,106 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include <string.h> + +#include <grpc/support/alloc.h> + +#include "src/core/surface/server.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request.headers in this \ + directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x0a:authority\x09localhost" \ + "\x10\x0c" \ + "content-type\x10" \ + "application/grpc" \ + "\x10\x14grpc-accept-encoding\x15" \ + "deflate,identity,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next(cq, + GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20), + NULL).type == GRPC_QUEUE_TIMEOUT); + } +} + +char *g_buffer; +size_t g_cap = 0; +size_t g_count = 0; + +static void addbuf(const void *data, size_t len) { + if (g_count + len > g_cap) { + g_cap = GPR_MAX(g_count + len, g_cap * 2); + g_buffer = gpr_realloc(g_buffer, g_cap); + } + memcpy(g_buffer + g_count, data, len); + g_count += len; +} + +int main(int argc, char **argv) { + int i, j; +#define MAX_FRAME_SIZE 16384 +#define MESSAGES_PER_FRAME (MAX_FRAME_SIZE / 5) +#define FRAME_SIZE (MESSAGES_PER_FRAME * 5) +#define SEND_SIZE (100 * 1024) +#define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) + grpc_test_init(argc, argv); + + addbuf(PFX_STR, sizeof(PFX_STR) - 1); + for (i = 0; i < NUM_FRAMES; i++) { + gpr_uint8 hdr[9] = {(gpr_uint8)(FRAME_SIZE >> 16), + (gpr_uint8)(FRAME_SIZE >> 8), (gpr_uint8)FRAME_SIZE, 0, + 0, 0, 0, 0, 1}; + addbuf(hdr, sizeof(hdr)); + for (j = 0; j < MESSAGES_PER_FRAME; j++) { + gpr_uint8 message[5] = {0, 0, 0, 0, 0}; + addbuf(message, sizeof(message)); + } + } + grpc_run_bad_client_test(verifier, g_buffer, g_count, 0); + gpr_free(g_buffer); + + return 0; +} diff --git a/test/core/bad_ssl/bad_ssl_test.c b/test/core/bad_ssl/bad_ssl_test.c index 54ac6d0e1c..08ab482c58 100644 --- a/test/core/bad_ssl/bad_ssl_test.c +++ b/test/core/bad_ssl/bad_ssl_test.c @@ -163,7 +163,7 @@ int main(int argc, char **argv) { grpc_shutdown(); } gpr_free(args[2]); - + gpr_subprocess_interrupt(svr); status = gpr_subprocess_join(svr); gpr_subprocess_destroy(svr); diff --git a/test/core/bad_ssl/server.c b/test/core/bad_ssl/server.c index 2ed94de099..6113d364c9 100644 --- a/test/core/bad_ssl/server.c +++ b/test/core/bad_ssl/server.c @@ -74,9 +74,8 @@ void bad_ssl_run(grpc_server *server) { grpc_server_register_completion_queue(server, cq, NULL); grpc_server_start(server); - error = - grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, (void*)1); + error = grpc_server_request_call(server, &s, &call_details, + &request_metadata_recv, cq, cq, (void *)1); GPR_ASSERT(GRPC_CALL_OK == error); signal(SIGINT, sigint_handler); @@ -96,7 +95,7 @@ void bad_ssl_run(grpc_server *server) { NULL); switch (ev.type) { case GRPC_OP_COMPLETE: - GPR_ASSERT(ev.tag == (void*)1); + GPR_ASSERT(ev.tag == (void *)1); GPR_ASSERT(ev.success == 0); break; case GRPC_QUEUE_SHUTDOWN: diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_config/lb_policies_test.c index c088fe2c09..5f6166cbb5 100644 --- a/test/core/client_config/lb_policies_test.c +++ b/test/core/client_config/lb_policies_test.c @@ -137,9 +137,8 @@ static void kill_server(const servers_fixture *f, size_t i) { gpr_log(GPR_INFO, "KILLING SERVER %d", i); GPR_ASSERT(f->servers[i] != NULL); grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); - GPR_ASSERT( - grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), NULL) - .type == GRPC_OP_COMPLETE); + GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), + NULL).type == GRPC_OP_COMPLETE); grpc_server_destroy(f->servers[i]); f->servers[i] = NULL; } @@ -205,8 +204,8 @@ static void teardown_servers(servers_fixture *f) { if (f->servers[i] == NULL) continue; grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), - n_millis_time(5000), NULL) - .type == GRPC_OP_COMPLETE); + n_millis_time(5000), + NULL).type == GRPC_OP_COMPLETE); grpc_server_destroy(f->servers[i]); } grpc_completion_queue_shutdown(f->cq); @@ -304,8 +303,8 @@ static int *perform_request(servers_fixture *f, grpc_channel *client, s_idx = -1; while ((ev = grpc_completion_queue_next( - f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), NULL)) - .type != GRPC_QUEUE_TIMEOUT) { + f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), NULL)).type != + GRPC_QUEUE_TIMEOUT) { GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); read_tag = ((int)(gpr_intptr)ev.tag); gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%d", @@ -377,8 +376,9 @@ static int *perform_request(servers_fixture *f, grpc_channel *client, } } - GPR_ASSERT(grpc_completion_queue_next( - f->cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(200), NULL).type == GRPC_QUEUE_TIMEOUT); + GPR_ASSERT(grpc_completion_queue_next(f->cq, + GRPC_TIMEOUT_MILLIS_TO_DEADLINE(200), + NULL).type == GRPC_QUEUE_TIMEOUT); grpc_metadata_array_destroy(&rdata->initial_metadata_recv); grpc_metadata_array_destroy(&rdata->trailing_metadata_recv); @@ -800,7 +800,8 @@ static void verify_rebirth_round_robin(const servers_fixture *f, const size_t expected_seq_length = f->num_servers; int *seen_elements; - dump_array("actual_connection_sequence", actual_connection_sequence, num_iters); + dump_array("actual_connection_sequence", actual_connection_sequence, + num_iters); /* verify conn. seq. expectation */ /* get the first unique run of length "num_servers". */ diff --git a/test/core/security/security_connector_test.c b/test/core/security/security_connector_test.c index 3f6c592b0b..0dcffa40ce 100644 --- a/test/core/security/security_connector_test.c +++ b/test/core/security/security_connector_test.c @@ -60,8 +60,39 @@ static int check_transport_security_type(const grpc_auth_context *ctx) { return 1; } +static int check_peer_property(const tsi_peer *peer, + const tsi_peer_property *expected) { + size_t i; + for (i = 0; i < peer->property_count; i++) { + const tsi_peer_property *prop = &peer->properties[i]; + if ((strcmp(prop->name, expected->name) == 0) && + (prop->value.length == expected->value.length) && + (memcmp(prop->value.data, expected->value.data, + expected->value.length) == 0)) { + return 1; + } + } + return 0; /* Not found... */ +} + +static int check_ssl_peer_equivalence(const tsi_peer *original, + const tsi_peer *reconstructed) { + /* The reconstructed peer only has CN and SAN properties. */ + size_t i; + for (i = 0; i < original->property_count; i++) { + const tsi_peer_property *prop = &original->properties[i]; + if ((strcmp(prop->name, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY) == 0) || + (strcmp(prop->name, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == + 0)) { + if (!check_peer_property(reconstructed, prop)) return 0; + } + } + return 1; +} + static void test_unauthenticated_ssl_peer(void) { tsi_peer peer; + tsi_peer rpeer; grpc_auth_context *ctx; GPR_ASSERT(tsi_construct_peer(1, &peer) == TSI_OK); GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( @@ -72,6 +103,10 @@ static void test_unauthenticated_ssl_peer(void) { GPR_ASSERT(!grpc_auth_context_peer_is_authenticated(ctx)); GPR_ASSERT(check_transport_security_type(ctx)); + rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx); + GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer)); + + tsi_shallow_peer_destruct(&rpeer); tsi_peer_destruct(&peer); GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); } @@ -128,6 +163,7 @@ static int check_x509_cn(const grpc_auth_context *ctx, static void test_cn_only_ssl_peer_to_auth_context(void) { tsi_peer peer; + tsi_peer rpeer; grpc_auth_context *ctx; const char *expected_cn = "cn1"; GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK); @@ -144,12 +180,17 @@ static void test_cn_only_ssl_peer_to_auth_context(void) { GPR_ASSERT(check_transport_security_type(ctx)); GPR_ASSERT(check_x509_cn(ctx, expected_cn)); + rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx); + GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer)); + + tsi_shallow_peer_destruct(&rpeer); tsi_peer_destruct(&peer); GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); } static void test_cn_and_one_san_ssl_peer_to_auth_context(void) { tsi_peer peer; + tsi_peer rpeer; grpc_auth_context *ctx; const char *expected_cn = "cn1"; const char *expected_san = "san1"; @@ -171,12 +212,17 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) { GPR_ASSERT(check_transport_security_type(ctx)); GPR_ASSERT(check_x509_cn(ctx, expected_cn)); + rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx); + GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer)); + + tsi_shallow_peer_destruct(&rpeer); tsi_peer_destruct(&peer); GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); } static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) { tsi_peer peer; + tsi_peer rpeer; grpc_auth_context *ctx; const char *expected_cn = "cn1"; const char *expected_sans[] = {"san1", "san2", "san3"}; @@ -202,6 +248,10 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) { GPR_ASSERT(check_transport_security_type(ctx)); GPR_ASSERT(check_x509_cn(ctx, expected_cn)); + rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx); + GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer)); + + tsi_shallow_peer_destruct(&rpeer); tsi_peer_destruct(&peer); GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); } @@ -209,6 +259,7 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) { static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context( void) { tsi_peer peer; + tsi_peer rpeer; grpc_auth_context *ctx; const char *expected_cn = "cn1"; const char *expected_sans[] = {"san1", "san2", "san3"}; @@ -238,10 +289,16 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context( GPR_ASSERT(check_transport_security_type(ctx)); GPR_ASSERT(check_x509_cn(ctx, expected_cn)); + rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx); + GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer)); + + tsi_shallow_peer_destruct(&rpeer); tsi_peer_destruct(&peer); GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); } +/* TODO(jboeuf): Unit-test tsi_shallow_peer_from_auth_context. */ + int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); diff --git a/test/core/support/alloc_test.c b/test/core/support/alloc_test.c index b950f0ab49..dc0a2acfa5 100644 --- a/test/core/support/alloc_test.c +++ b/test/core/support/alloc_test.c @@ -48,8 +48,8 @@ static void test_custom_allocs() { gpr_allocation_functions fns = {fake_malloc, fake_realloc, fake_free}; gpr_set_allocation_functions(fns); - GPR_ASSERT((void *)0xdeadbeef == gpr_malloc(0xdeadbeef)); - GPR_ASSERT((void *)0xcafed00d == gpr_realloc(0, 0xcafed00d)); + GPR_ASSERT((void*)(size_t)0xdeadbeef == gpr_malloc(0xdeadbeef)); + GPR_ASSERT((void*)(size_t)0xcafed00d == gpr_realloc(0, 0xcafed00d)); gpr_free(&addr_to_free); GPR_ASSERT(addr_to_free == 0xdeadd00d); diff --git a/test/core/transport/connectivity_state_test.c b/test/core/transport/connectivity_state_test.c index 1f23221812..34ab45d260 100644 --- a/test/core/transport/connectivity_state_test.c +++ b/test/core/transport/connectivity_state_test.c @@ -39,7 +39,7 @@ #include "test/core/util/test_config.h" -#define THE_ARG ((void *)0xcafebabe) +#define THE_ARG ((void *)(size_t)0xcafebabe) int g_counter; |