Put validation of host name in a function

pull/8241/head
Muxi Yan 8 years ago
parent 56456c38e0
commit ea3b568b8f
  1. 6
      test/core/end2end/end2end_nosec_tests.c
  2. 6
      test/core/end2end/end2end_tests.c
  3. 2
      test/core/end2end/end2end_tests.h
  4. 4
      test/core/end2end/tests/binary_metadata.c
  5. 4
      test/core/end2end/tests/call_creds.c
  6. 8
      test/core/end2end/tests/compressed_payload.c
  7. 4
      test/core/end2end/tests/disappearing_server.c
  8. 4
      test/core/end2end/tests/graceful_server_shutdown.c
  9. 4
      test/core/end2end/tests/high_initial_seqno.c
  10. 4
      test/core/end2end/tests/hpack_size.c
  11. 4
      test/core/end2end/tests/idempotent_request.c
  12. 4
      test/core/end2end/tests/invoke_large_request.c
  13. 4
      test/core/end2end/tests/large_metadata.c
  14. 4
      test/core/end2end/tests/max_concurrent_streams.c
  15. 4
      test/core/end2end/tests/max_message_length.c
  16. 4
      test/core/end2end/tests/network_status_change.c
  17. 4
      test/core/end2end/tests/no_logging.c
  18. 4
      test/core/end2end/tests/payload.c
  19. 10
      test/core/end2end/tests/registered_call.c
  20. 4
      test/core/end2end/tests/request_with_payload.c
  21. 4
      test/core/end2end/tests/server_finishes_request.c
  22. 4
      test/core/end2end/tests/shutdown_finishes_calls.c
  23. 4
      test/core/end2end/tests/simple_cacheable_request.c
  24. 4
      test/core/end2end/tests/simple_delayed_request.c
  25. 4
      test/core/end2end/tests/simple_metadata.c
  26. 4
      test/core/end2end/tests/simple_request.c
  27. 4
      test/core/end2end/tests/streaming_error_response.c
  28. 4
      test/core/end2end/tests/trailing_metadata.c

@ -412,3 +412,9 @@ void grpc_end2end_tests(int argc, char **argv,
const char *get_host_override_string(const char *str, grpc_end2end_test_config config) {
return (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER ? str : NULL);
}
void validate_host_override_string(const char *pattern, const char *str, grpc_end2end_test_config config) {
if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) {
GPR_ASSERT(0 == strcmp(str, pattern));
}
}

@ -420,3 +420,9 @@ void grpc_end2end_tests(int argc, char **argv,
const char *get_host_override_string(const char *str, grpc_end2end_test_config config) {
return (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER ? str : NULL);
}
void validate_host_override_string(const char *pattern, const char *str, grpc_end2end_test_config config) {
if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) {
GPR_ASSERT(0 == strcmp(str, pattern));
}
}

@ -71,4 +71,6 @@ void grpc_end2end_tests(int argc, char **argv, grpc_end2end_test_config config);
const char *get_host_override_string(const char *str, grpc_end2end_test_config config);
void validate_host_override_string(const char *pattern, const char *str, grpc_end2end_test_config config);
#endif /* GRPC_TEST_CORE_END2END_END2END_TESTS_H */

@ -248,9 +248,7 @@ static void test_request_response_with_metadata_and_payload(
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));

@ -294,9 +294,7 @@ static void request_response_with_payload_and_call_creds(
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));

@ -242,9 +242,7 @@ static void request_for_disabled_algorithm(
GPR_ASSERT(0 == strcmp(details, expected_details));
gpr_free(expected_details);
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
gpr_free(details);
grpc_metadata_array_destroy(&initial_metadata_recv);
@ -493,9 +491,7 @@ static void request_with_payload_template(
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
gpr_free(details);

@ -174,9 +174,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config,
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -190,9 +190,7 @@ static void test_early_server_shutdown_finishes_inflight_calls(
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -189,9 +189,7 @@ static void simple_request_body(grpc_end2end_test_config config,
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -341,9 +341,7 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_end2end_te
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -201,9 +201,7 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_end2end_te
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST == call_details.flags);
GPR_ASSERT(was_cancelled == 1);

@ -244,9 +244,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config,
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -227,9 +227,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) {
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
GPR_ASSERT(contains_metadata(&request_metadata_recv, "key", meta.value));

@ -185,9 +185,7 @@ static void simple_request_body(grpc_end2end_test_config config,
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -215,9 +215,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config,
cq_verify(cqv);
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
done:

@ -212,9 +212,7 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) {
// Expected behavior of a RPC when network is lost.
GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE);
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
gpr_free(details);

@ -226,9 +226,7 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_end2end_te
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(0 == call_details.flags);
GPR_ASSERT(was_cancelled == 1);

@ -220,9 +220,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, grpc_
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));

@ -97,7 +97,7 @@ static void end_test(grpc_end2end_test_fixture *f) {
grpc_completion_queue_destroy(f->cq);
}
static void simple_request_body(grpc_end2end_test_fixture f, void *rc) {
static void simple_request_body(grpc_end2end_test_config config, grpc_end2end_test_fixture f, void *rc) {
grpc_call *c;
grpc_call *s;
gpr_timespec deadline = five_seconds_time();
@ -186,9 +186,7 @@ static void simple_request_body(grpc_end2end_test_fixture f, void *rc) {
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);
@ -208,7 +206,7 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
begin_test(config, "test_invoke_simple_request", NULL, NULL);
void *rc = grpc_channel_register_call(f.client, "/foo", get_host_override_string("foo.test.google.fr:1234", config), NULL);
simple_request_body(f, rc);
simple_request_body(config, f, rc);
end_test(&f);
config.tear_down_data(&f);
}
@ -220,7 +218,7 @@ static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
void *rc = grpc_channel_register_call(f.client, "/foo", get_host_override_string("foo.test.google.fr:1234", config), NULL);
for (i = 0; i < 10; i++) {
simple_request_body(f, rc);
simple_request_body(config, f, rc);
gpr_log(GPR_INFO, "Passed simple request %d", i);
}
end_test(&f);

@ -208,9 +208,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));

@ -182,9 +182,7 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_end2end_te
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -171,9 +171,7 @@ static void test_early_server_shutdown_finishes_inflight_calls(
GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE);
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -235,9 +235,7 @@ static void test_cacheable_request_response_with_metadata_and_payload(
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
if (config.feature_mask & FEATURE_MASK_SUPPORTS_REQUEST_PROXYING) {
// Our simple proxy does not support cacheable requests
} else {

@ -180,9 +180,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config,
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -232,9 +232,7 @@ static void test_request_response_with_metadata_and_payload(
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));

@ -201,9 +201,7 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_end2end_te
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234"));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(0 == call_details.flags);
GPR_ASSERT(was_cancelled == 1);

@ -245,9 +245,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) {
GPR_ASSERT(status == GRPC_STATUS_FAILED_PRECONDITION);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(was_cancelled == 1);
gpr_free(details);

@ -236,9 +236,7 @@ static void test_request_response_with_metadata_and_payload(
GPR_ASSERT(status == GRPC_STATUS_OK);
GPR_ASSERT(0 == strcmp(details, "xyz"));
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
if (authority) {
GPR_ASSERT(0 == strcmp(call_details.host, authority));
}
validate_host_override_string("foo.test.google.fr:1234", call_details.host, config);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));
GPR_ASSERT(contains_metadata(&request_metadata_recv, "key1", "val1"));

Loading…
Cancel
Save