aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Robbie Shade <rjshade@google.com>2015-08-13 16:12:26 -0400
committerGravatar Robbie Shade <rjshade@google.com>2015-08-13 16:12:26 -0400
commit37ad56b469836b7d4b3e9753913e37aae3ac46c7 (patch)
treed8d3cdf9f50f66ac567523872096f2f555a13b43 /test/core
parent98981efe0d29626645abc2ff495737a078bab021 (diff)
parent118f65dc8c5df39872aff5f6bf269b16ce82c259 (diff)
Merge remote-tracking branch 'upstream/master' into add_udp_server_2
Diffstat (limited to 'test/core')
-rw-r--r--test/core/end2end/end2end_tests.h2
-rw-r--r--test/core/end2end/fixtures/chttp2_fake_security.c25
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c24
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c24
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c24
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c66
-rw-r--r--test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c5
-rwxr-xr-xtest/core/end2end/gen_build_json.py38
-rw-r--r--test/core/end2end/tests/bad_hostname.c2
-rw-r--r--test/core/end2end/tests/request_response_with_payload_and_call_creds.c129
-rw-r--r--test/core/httpcli/httpcli_test.c4
-rw-r--r--test/core/security/auth_context_test.c73
-rw-r--r--test/core/security/credentials_test.c14
-rw-r--r--test/core/security/jwt_verifier_test.c10
-rw-r--r--test/core/security/verify_jwt.c2
-rw-r--r--test/core/util/port_posix.c74
-rw-r--r--test/core/util/test_config.c2
-rw-r--r--test/core/util/test_config.h7
18 files changed, 450 insertions, 75 deletions
diff --git a/test/core/end2end/end2end_tests.h b/test/core/end2end/end2end_tests.h
index a18c702951..3f1665613c 100644
--- a/test/core/end2end/end2end_tests.h
+++ b/test/core/end2end/end2end_tests.h
@@ -43,6 +43,8 @@ typedef struct grpc_end2end_test_config grpc_end2end_test_config;
#define FEATURE_MASK_SUPPORTS_HOSTNAME_VERIFICATION 2
#define FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS 4
+#define FAIL_AUTH_CHECK_SERVER_ARG_NAME "fail_auth_check"
+
struct grpc_end2end_test_fixture {
grpc_completion_queue *cq;
grpc_server *server;
diff --git a/test/core/end2end/fixtures/chttp2_fake_security.c b/test/core/end2end/fixtures/chttp2_fake_security.c
index f879b43f79..78b692a45d 100644
--- a/test/core/end2end/fixtures/chttp2_fake_security.c
+++ b/test/core/end2end/fixtures/chttp2_fake_security.c
@@ -65,6 +65,14 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
return f;
}
+static void process_auth_failure(void *state, grpc_auth_context *ctx,
+ const grpc_metadata *md, size_t md_count,
+ grpc_process_auth_metadata_done_cb cb,
+ void *user_data) {
+ GPR_ASSERT(state == NULL);
+ cb(user_data, NULL, 0, 0);
+}
+
static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
@@ -102,10 +110,27 @@ static void chttp2_init_client_fake_secure_fullstack(
chttp2_init_client_secure_fullstack(f, client_args, fake_ts_creds);
}
+static int fail_server_auth_check(grpc_channel_args *server_args) {
+ size_t i;
+ if (server_args == NULL) return 0;
+ for (i = 0; i < server_args->num_args; i++) {
+ if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
+ 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static void chttp2_init_server_fake_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
grpc_server_credentials *fake_ts_creds =
grpc_fake_transport_security_server_credentials_create();
+ if (fail_server_auth_check(server_args)) {
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_server_credentials_set_auth_metadata_processor(fake_ts_creds,
+ processor);
+ }
chttp2_init_server_secure_fullstack(f, server_args, fake_ts_creds);
}
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
index 6d5669d05a..9850aac69b 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
@@ -68,6 +68,14 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
return f;
}
+static void process_auth_failure(void *state, grpc_auth_context *ctx,
+ const grpc_metadata *md, size_t md_count,
+ grpc_process_auth_metadata_done_cb cb,
+ void *user_data) {
+ GPR_ASSERT(state == NULL);
+ cb(user_data, NULL, 0, 0);
+}
+
static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
@@ -110,12 +118,28 @@ static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_channel_args_destroy(new_client_args);
}
+static int fail_server_auth_check(grpc_channel_args *server_args) {
+ size_t i;
+ if (server_args == NULL) return 0;
+ for (i = 0; i < server_args->num_args; i++) {
+ if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
+ 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key,
test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0);
+ if (fail_server_auth_check(server_args)) {
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
+ }
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c
index d0cc3dd74a..3df2acd296 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c
@@ -68,6 +68,14 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
return f;
}
+static void process_auth_failure(void *state, grpc_auth_context *ctx,
+ const grpc_metadata *md, size_t md_count,
+ grpc_process_auth_metadata_done_cb cb,
+ void *user_data) {
+ GPR_ASSERT(state == NULL);
+ cb(user_data, NULL, 0, 0);
+}
+
static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
@@ -110,12 +118,28 @@ static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_channel_args_destroy(new_client_args);
}
+static int fail_server_auth_check(grpc_channel_args *server_args) {
+ size_t i;
+ if (server_args == NULL) return 0;
+ for (i = 0; i < server_args->num_args; i++) {
+ if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
+ 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key,
test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0);
+ if (fail_server_auth_check(server_args)) {
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
+ }
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c
index 46a64de6c5..4d77039cac 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c
@@ -96,6 +96,14 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
return f;
}
+static void process_auth_failure(void *state, grpc_auth_context *ctx,
+ const grpc_metadata *md, size_t md_count,
+ grpc_process_auth_metadata_done_cb cb,
+ void *user_data) {
+ GPR_ASSERT(state == NULL);
+ cb(user_data, NULL, 0, 0);
+}
+
static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
@@ -139,12 +147,28 @@ static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_channel_args_destroy(new_client_args);
}
+static int fail_server_auth_check(grpc_channel_args *server_args) {
+ size_t i;
+ if (server_args == NULL) return 0;
+ for (i = 0; i < server_args->num_args; i++) {
+ if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
+ 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key,
test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0);
+ if (fail_server_auth_check(server_args)) {
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
+ }
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
index f74ed9365f..284d5f07ae 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
@@ -46,10 +46,54 @@
#include "test/core/util/port.h"
#include "test/core/end2end/data/ssl_test_data.h"
+static const char oauth2_md[] = "Bearer aaslkfjs424535asdf";
+static const char *client_identity_property_name = "smurf_name";
+static const char *client_identity = "Brainy Smurf";
+
typedef struct fullstack_secure_fixture_data {
char *localaddr;
} fullstack_secure_fixture_data;
+static const grpc_metadata *find_metadata(const grpc_metadata *md,
+ size_t md_count,
+ const char *key,
+ const char *value) {
+ size_t i;
+ for (i = 0; i < md_count; i++) {
+ if (strcmp(key, md[i].key) == 0 && strlen(value) == md[i].value_length &&
+ memcmp(md[i].value, value, md[i].value_length) == 0) {
+ return &md[i];
+ }
+ }
+ return NULL;
+}
+
+static void process_oauth2_success(void *state, grpc_auth_context *ctx,
+ const grpc_metadata *md, size_t md_count,
+ grpc_process_auth_metadata_done_cb cb,
+ void *user_data) {
+ const grpc_metadata *oauth2 =
+ find_metadata(md, md_count, "Authorization", oauth2_md);
+ GPR_ASSERT(state == NULL);
+ GPR_ASSERT(oauth2 != NULL);
+ grpc_auth_context_add_cstring_property(ctx, client_identity_property_name,
+ client_identity);
+ GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(
+ ctx, client_identity_property_name) == 1);
+ cb(user_data, oauth2, 1, 1);
+}
+
+static void process_oauth2_failure(void *state, grpc_auth_context *ctx,
+ const grpc_metadata *md, size_t md_count,
+ grpc_process_auth_metadata_done_cb cb,
+ void *user_data) {
+ const grpc_metadata *oauth2 =
+ find_metadata(md, md_count, "Authorization", oauth2_md);
+ GPR_ASSERT(state == NULL);
+ GPR_ASSERT(oauth2 != NULL);
+ cb(user_data, oauth2, 1, 0);
+}
+
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_channel_args *client_args, grpc_channel_args *server_args) {
grpc_end2end_test_fixture f;
@@ -101,7 +145,7 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack(
grpc_credentials *ssl_creds =
grpc_ssl_credentials_create(test_root_cert, NULL);
grpc_credentials *oauth2_creds =
- grpc_fake_oauth2_credentials_create("Bearer aaslkfjs424535asdf", 1);
+ grpc_md_only_test_credentials_create("Authorization", oauth2_md, 1);
grpc_credentials *ssl_oauth2_creds =
grpc_composite_credentials_create(ssl_creds, oauth2_creds);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
@@ -115,12 +159,32 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack(
grpc_credentials_release(oauth2_creds);
}
+static int fail_server_auth_check(grpc_channel_args *server_args) {
+ size_t i;
+ if (server_args == NULL) return 0;
+ for (i = 0; i < server_args->num_args; i++) {
+ if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
+ 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {test_server1_key,
test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_key_cert_pair, 1, 0);
+ grpc_auth_metadata_processor processor;
+ processor.state = NULL;
+ if (fail_server_auth_check(server_args)) {
+ processor.process = process_oauth2_failure;
+ } else {
+ processor.process = process_oauth2_success;
+ }
+ grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c b/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c
index c59628b959..9d798ad1d2 100644
--- a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c
+++ b/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c
@@ -148,6 +148,11 @@ int main(int argc, char **argv) {
/* force tracing on, with a value to force many
code paths in trace.c to be taken */
gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
+#ifdef GPR_POSIX_SOCKET
+ g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
+#else
+ g_fixture_slowdown_factor = 10.0;
+#endif
grpc_test_init(argc, argv);
grpc_init();
diff --git a/test/core/end2end/gen_build_json.py b/test/core/end2end/gen_build_json.py
index c6e869364c..6f10b78dad 100755
--- a/test/core/end2end/gen_build_json.py
+++ b/test/core/end2end/gen_build_json.py
@@ -36,27 +36,27 @@ import simplejson
import collections
-FixtureOptions = collections.namedtuple('FixtureOptions', 'fullstack includes_proxy dns_resolver secure platforms')
-default_unsecure_fixture_options = FixtureOptions(True, False, True, False, ['windows', 'posix'])
+FixtureOptions = collections.namedtuple('FixtureOptions', 'fullstack includes_proxy dns_resolver secure platforms ci_mac')
+default_unsecure_fixture_options = FixtureOptions(True, False, True, False, ['windows', 'linux', 'mac', 'posix'], True)
socketpair_unsecure_fixture_options = default_unsecure_fixture_options._replace(fullstack=False, dns_resolver=False)
default_secure_fixture_options = default_unsecure_fixture_options._replace(secure=True)
-uds_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=False, platforms=['posix'])
+uds_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=False, platforms=['linux', 'mac', 'posix'])
# maps fixture name to whether it requires the security library
END2END_FIXTURES = {
- 'chttp2_fake_security': default_secure_fixture_options,
+ 'chttp2_fake_security': default_secure_fixture_options._replace(ci_mac=False),
'chttp2_fullstack': default_unsecure_fixture_options,
'chttp2_fullstack_compression': default_unsecure_fixture_options,
'chttp2_fullstack_uds_posix': uds_fixture_options,
- 'chttp2_fullstack_uds_posix_with_poll': uds_fixture_options,
- 'chttp2_fullstack_with_poll': default_unsecure_fixture_options._replace(platforms=['posix']),
- 'chttp2_fullstack_with_proxy': default_unsecure_fixture_options._replace(includes_proxy=True),
+ 'chttp2_fullstack_uds_posix_with_poll': uds_fixture_options._replace(platforms=['linux']),
+ 'chttp2_fullstack_with_poll': default_unsecure_fixture_options._replace(platforms=['linux']),
+ 'chttp2_fullstack_with_proxy': default_unsecure_fixture_options._replace(includes_proxy=True, ci_mac=False),
'chttp2_simple_ssl_fullstack': default_secure_fixture_options,
- 'chttp2_simple_ssl_fullstack_with_poll': default_secure_fixture_options._replace(platforms=['posix']),
- 'chttp2_simple_ssl_fullstack_with_proxy': default_secure_fixture_options._replace(includes_proxy=True),
- 'chttp2_simple_ssl_with_oauth2_fullstack': default_secure_fixture_options,
- 'chttp2_socket_pair': socketpair_unsecure_fixture_options,
- 'chttp2_socket_pair_one_byte_at_a_time': socketpair_unsecure_fixture_options,
+ 'chttp2_simple_ssl_fullstack_with_poll': default_secure_fixture_options._replace(platforms=['linux']),
+ 'chttp2_simple_ssl_fullstack_with_proxy': default_secure_fixture_options._replace(includes_proxy=True, ci_mac=False),
+ 'chttp2_simple_ssl_with_oauth2_fullstack': default_secure_fixture_options._replace(ci_mac=False),
+ 'chttp2_socket_pair': socketpair_unsecure_fixture_options._replace(ci_mac=False),
+ 'chttp2_socket_pair_one_byte_at_a_time': socketpair_unsecure_fixture_options._replace(ci_mac=False),
'chttp2_socket_pair_with_grpc_trace': socketpair_unsecure_fixture_options,
}
@@ -115,6 +115,12 @@ def compatible(f, t):
return True
+def without(l, e):
+ l = l[:]
+ l.remove(e)
+ return l
+
+
def main():
sec_deps = [
'end2end_certs',
@@ -138,7 +144,7 @@ def main():
'language': 'c',
'secure': 'check' if END2END_FIXTURES[f].secure else 'no',
'src': ['test/core/end2end/fixtures/%s.c' % f],
- 'platforms': [ 'posix' ] if f.endswith('_posix') else END2END_FIXTURES[f].platforms,
+ 'platforms': [ 'linux', 'mac', 'posix' ] if f.endswith('_posix') else END2END_FIXTURES[f].platforms,
'deps': sec_deps if END2END_FIXTURES[f].secure else unsec_deps,
'headers': ['test/core/end2end/end2end_tests.h'],
}
@@ -173,6 +179,9 @@ def main():
'src': [],
'flaky': END2END_TESTS[t].flaky,
'platforms': END2END_FIXTURES[f].platforms,
+ 'ci_platforms': (END2END_FIXTURES[f].platforms
+ if END2END_FIXTURES[f].ci_mac
+ else without(END2END_FIXTURES[f].platforms, 'mac')),
'deps': [
'end2end_fixture_%s' % f,
'end2end_test_%s' % t] + sec_deps
@@ -188,6 +197,9 @@ def main():
'src': [],
'flaky': END2END_TESTS[t].flaky,
'platforms': END2END_FIXTURES[f].platforms,
+ 'ci_platforms': (END2END_FIXTURES[f].platforms
+ if END2END_FIXTURES[f].ci_mac
+ else without(END2END_FIXTURES[f].platforms, 'mac')),
'deps': [
'end2end_fixture_%s' % f,
'end2end_test_%s' % t] + unsec_deps
diff --git a/test/core/end2end/tests/bad_hostname.c b/test/core/end2end/tests/bad_hostname.c
index 198ba46cd2..501db89b7b 100644
--- a/test/core/end2end/tests/bad_hostname.c
+++ b/test/core/end2end/tests/bad_hostname.c
@@ -146,7 +146,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
cq_expect_completion(cqv, tag(1), 1);
cq_verify(cqv);
- GPR_ASSERT(status == GRPC_STATUS_UNAUTHENTICATED);
+ GPR_ASSERT(status == GRPC_STATUS_INVALID_ARGUMENT);
gpr_free(details);
grpc_metadata_array_destroy(&initial_metadata_recv);
diff --git a/test/core/end2end/tests/request_response_with_payload_and_call_creds.c b/test/core/end2end/tests/request_response_with_payload_and_call_creds.c
index ba312d0d5c..342dfa03f6 100644
--- a/test/core/end2end/tests/request_response_with_payload_and_call_creds.c
+++ b/test/core/end2end/tests/request_response_with_payload_and_call_creds.c
@@ -59,13 +59,21 @@ static void *tag(gpr_intptr t) { return (void *)t; }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char *test_name,
- grpc_channel_args *client_args,
- grpc_channel_args *server_args) {
+ int fail_server_auth_check) {
grpc_end2end_test_fixture f;
gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
- f = config.create_fixture(client_args, server_args);
- config.init_client(&f, client_args);
- config.init_server(&f, server_args);
+ f = config.create_fixture(NULL, NULL);
+ config.init_client(&f, NULL);
+ if (fail_server_auth_check) {
+ grpc_arg fail_auth_arg = {
+ GRPC_ARG_STRING, FAIL_AUTH_CHECK_SERVER_ARG_NAME, {NULL}};
+ grpc_channel_args args;
+ args.num_args= 1;
+ args.args = &fail_auth_arg;
+ config.init_server(&f, &args);
+ } else {
+ config.init_server(&f, NULL);
+ }
return f;
}
@@ -128,7 +136,7 @@ static void test_call_creds_failure(grpc_end2end_test_config config) {
grpc_call *c;
grpc_credentials *creds = NULL;
grpc_end2end_test_fixture f =
- begin_test(config, "test_call_creds_failure", NULL, NULL);
+ begin_test(config, "test_call_creds_failure", 0);
gpr_timespec deadline = five_seconds_time();
c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
"/foo", "foo.test.google.fr", deadline);
@@ -157,9 +165,8 @@ static void request_response_with_payload_and_call_creds(
grpc_byte_buffer *response_payload =
grpc_raw_byte_buffer_create(&response_payload_slice, 1);
gpr_timespec deadline = five_seconds_time();
-
- grpc_end2end_test_fixture f = begin_test(config, test_name, NULL, NULL);
- cq_verifier *cqv = cq_verifier_create(f.cq);
+ grpc_end2end_test_fixture f;
+ cq_verifier *cqv;
grpc_op ops[6];
grpc_op *op;
grpc_metadata_array initial_metadata_recv;
@@ -174,6 +181,10 @@ static void request_response_with_payload_and_call_creds(
int was_cancelled = 2;
grpc_credentials *creds = NULL;
grpc_auth_context *s_auth_context = NULL;
+ grpc_auth_context *c_auth_context = NULL;
+
+ f = begin_test(config, test_name, 0);
+ cqv = cq_verifier_create(f.cq);
c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
"/foo", "foo.test.google.fr", deadline);
@@ -241,6 +252,11 @@ static void request_response_with_payload_and_call_creds(
print_auth_context(0, s_auth_context);
grpc_auth_context_release(s_auth_context);
+ c_auth_context = grpc_call_auth_context(c);
+ GPR_ASSERT(c_auth_context != NULL);
+ print_auth_context(1, c_auth_context);
+ grpc_auth_context_release(c_auth_context);
+
/* Cannot set creds on the server call object. */
GPR_ASSERT(grpc_call_set_credentials(s, NULL) != GRPC_CALL_OK);
@@ -340,31 +356,120 @@ static void request_response_with_payload_and_call_creds(
config.tear_down_data(&f);
}
-void test_request_response_with_payload_and_call_creds(
+static void test_request_response_with_payload_and_call_creds(
grpc_end2end_test_config config) {
request_response_with_payload_and_call_creds(
"test_request_response_with_payload_and_call_creds", config, NONE);
}
-void test_request_response_with_payload_and_overridden_call_creds(
+static void test_request_response_with_payload_and_overridden_call_creds(
grpc_end2end_test_config config) {
request_response_with_payload_and_call_creds(
"test_request_response_with_payload_and_overridden_call_creds", config,
OVERRIDE);
}
-void test_request_response_with_payload_and_deleted_call_creds(
+static void test_request_response_with_payload_and_deleted_call_creds(
grpc_end2end_test_config config) {
request_response_with_payload_and_call_creds(
"test_request_response_with_payload_and_deleted_call_creds", config,
DESTROY);
}
+static void test_request_with_server_rejecting_client_creds(
+ grpc_end2end_test_config config) {
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_call *c;
+ grpc_end2end_test_fixture f;
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *cqv;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload =
+ grpc_raw_byte_buffer_create(&request_payload_slice, 1);
+ grpc_credentials *creds;
+
+ f = begin_test(config, "test_request_with_server_rejecting_client_creds", 1);
+ cqv = cq_verifier_create(f.cq);
+
+ c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
+ "/foo", "foo.test.google.fr", deadline);
+ GPR_ASSERT(c);
+
+ creds = grpc_iam_credentials_create(iam_token, iam_selector);
+ GPR_ASSERT(creds != NULL);
+ GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK);
+ grpc_credentials_release(creds);
+
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op->flags = 0;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ cq_expect_completion(cqv, tag(1), 1);
+ cq_verify(cqv);
+
+ GPR_ASSERT(status == GRPC_STATUS_UNAUTHENTICATED);
+
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload_recv);
+ gpr_free(details);
+
+ grpc_call_destroy(c);
+
+ cq_verifier_destroy(cqv);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
void grpc_end2end_tests(grpc_end2end_test_config config) {
if (config.feature_mask & FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS) {
test_call_creds_failure(config);
test_request_response_with_payload_and_call_creds(config);
test_request_response_with_payload_and_overridden_call_creds(config);
test_request_response_with_payload_and_deleted_call_creds(config);
+ test_request_with_server_rejecting_client_creds(config);
}
}
diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c
index 390afcdf63..8dddfbee98 100644
--- a/test/core/httpcli/httpcli_test.c
+++ b/test/core/httpcli/httpcli_test.c
@@ -81,7 +81,7 @@ static void test_get(int use_ssl, int port) {
memset(&req, 0, sizeof(req));
req.host = host;
req.path = "/get";
- req.use_ssl = use_ssl;
+ req.handshaker = use_ssl ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
grpc_httpcli_get(&g_context, &g_pollset, &req, n_seconds_time(15), on_finish,
(void *)42);
@@ -107,7 +107,7 @@ static void test_post(int use_ssl, int port) {
memset(&req, 0, sizeof(req));
req.host = host;
req.path = "/post";
- req.use_ssl = use_ssl;
+ req.handshaker = use_ssl ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
grpc_httpcli_post(&g_context, &g_pollset, &req, "hello", 5,
n_seconds_time(15), on_finish, (void *)42);
diff --git a/test/core/security/auth_context_test.c b/test/core/security/auth_context_test.c
index a30505a63b..d785eb6064 100644
--- a/test/core/security/auth_context_test.c
+++ b/test/core/security/auth_context_test.c
@@ -40,7 +40,7 @@
#include <grpc/support/log.h>
static void test_empty_context(void) {
- grpc_auth_context *ctx = grpc_auth_context_create(NULL, 0);
+ grpc_auth_context *ctx = grpc_auth_context_create(NULL);
grpc_auth_property_iterator it;
gpr_log(GPR_INFO, "test_empty_context");
@@ -52,87 +52,98 @@ static void test_empty_context(void) {
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
it = grpc_auth_context_find_properties_by_name(ctx, "foo");
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
+ GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(ctx, "bar") ==
+ 0);
+ GPR_ASSERT(grpc_auth_context_peer_identity_property_name(ctx) == NULL);
GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static void test_simple_context(void) {
- grpc_auth_context *ctx = grpc_auth_context_create(NULL, 3);
+ grpc_auth_context *ctx = grpc_auth_context_create(NULL);
grpc_auth_property_iterator it;
size_t i;
gpr_log(GPR_INFO, "test_simple_context");
GPR_ASSERT(ctx != NULL);
- GPR_ASSERT(ctx->property_count == 3);
- ctx->properties[0] = grpc_auth_property_init_from_cstring("name", "chapi");
- ctx->properties[1] = grpc_auth_property_init_from_cstring("name", "chapo");
- ctx->properties[2] = grpc_auth_property_init_from_cstring("foo", "bar");
- ctx->peer_identity_property_name = ctx->properties[0].name;
+ grpc_auth_context_add_cstring_property(ctx, "name", "chapi");
+ grpc_auth_context_add_cstring_property(ctx, "name", "chapo");
+ grpc_auth_context_add_cstring_property(ctx, "foo", "bar");
+ GPR_ASSERT(ctx->properties.count == 3);
+ GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(ctx, "name") ==
+ 1);
GPR_ASSERT(
strcmp(grpc_auth_context_peer_identity_property_name(ctx), "name") == 0);
it = grpc_auth_context_property_iterator(ctx);
- for (i = 0; i < ctx->property_count; i++) {
+ for (i = 0; i < ctx->properties.count; i++) {
const grpc_auth_property *p = grpc_auth_property_iterator_next(&it);
- GPR_ASSERT(p == &ctx->properties[i]);
+ GPR_ASSERT(p == &ctx->properties.array[i]);
}
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
it = grpc_auth_context_find_properties_by_name(ctx, "foo");
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &ctx->properties[2]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &ctx->properties.array[2]);
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
it = grpc_auth_context_peer_identity(ctx);
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &ctx->properties[0]);
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &ctx->properties[1]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &ctx->properties.array[0]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &ctx->properties.array[1]);
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static void test_chained_context(void) {
- grpc_auth_context *chained = grpc_auth_context_create(NULL, 2);
- grpc_auth_context *ctx = grpc_auth_context_create(chained, 3);
+ grpc_auth_context *chained = grpc_auth_context_create(NULL);
+ grpc_auth_context *ctx = grpc_auth_context_create(chained);
grpc_auth_property_iterator it;
size_t i;
gpr_log(GPR_INFO, "test_chained_context");
GRPC_AUTH_CONTEXT_UNREF(chained, "chained");
- chained->properties[0] =
- grpc_auth_property_init_from_cstring("name", "padapo");
- chained->properties[1] = grpc_auth_property_init_from_cstring("foo", "baz");
- ctx->properties[0] = grpc_auth_property_init_from_cstring("name", "chapi");
- ctx->properties[1] = grpc_auth_property_init_from_cstring("name", "chapo");
- ctx->properties[2] = grpc_auth_property_init_from_cstring("foo", "bar");
- ctx->peer_identity_property_name = ctx->properties[0].name;
+ grpc_auth_context_add_cstring_property(chained, "name", "padapo");
+ grpc_auth_context_add_cstring_property(chained, "foo", "baz");
+ grpc_auth_context_add_cstring_property(ctx, "name", "chapi");
+ grpc_auth_context_add_cstring_property(ctx, "name", "chap0");
+ grpc_auth_context_add_cstring_property(ctx, "foo", "bar");
+ GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(ctx, "name") ==
+ 1);
GPR_ASSERT(
strcmp(grpc_auth_context_peer_identity_property_name(ctx), "name") == 0);
it = grpc_auth_context_property_iterator(ctx);
- for (i = 0; i < ctx->property_count; i++) {
+ for (i = 0; i < ctx->properties.count; i++) {
const grpc_auth_property *p = grpc_auth_property_iterator_next(&it);
- GPR_ASSERT(p == &ctx->properties[i]);
+ GPR_ASSERT(p == &ctx->properties.array[i]);
}
- for (i = 0; i < chained->property_count; i++) {
+ for (i = 0; i < chained->properties.count; i++) {
const grpc_auth_property *p = grpc_auth_property_iterator_next(&it);
- GPR_ASSERT(p == &chained->properties[i]);
+ GPR_ASSERT(p == &chained->properties.array[i]);
}
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
it = grpc_auth_context_find_properties_by_name(ctx, "foo");
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &ctx->properties[2]);
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &chained->properties[1]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &ctx->properties.array[2]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &chained->properties.array[1]);
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
it = grpc_auth_context_peer_identity(ctx);
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &ctx->properties[0]);
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &ctx->properties[1]);
- GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &chained->properties[0]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &ctx->properties.array[0]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &ctx->properties.array[1]);
+ GPR_ASSERT(grpc_auth_property_iterator_next(&it) ==
+ &chained->properties.array[0]);
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
-
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_empty_context();
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index dd6e0d7bb3..e4a8144eaf 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -373,8 +373,8 @@ static void test_ssl_oauth2_composite_creds(void) {
grpc_credentials *ssl_creds =
grpc_ssl_credentials_create(test_root_cert, NULL);
const grpc_credentials_array *creds_array;
- grpc_credentials *oauth2_creds =
- grpc_fake_oauth2_credentials_create(test_oauth2_bearer_token, 0);
+ grpc_credentials *oauth2_creds = grpc_md_only_test_credentials_create(
+ "Authorization", test_oauth2_bearer_token, 0);
grpc_credentials *composite_creds =
grpc_composite_credentials_create(ssl_creds, oauth2_creds);
grpc_credentials_unref(ssl_creds);
@@ -424,8 +424,8 @@ static void test_ssl_oauth2_iam_composite_creds(void) {
grpc_credentials *ssl_creds =
grpc_ssl_credentials_create(test_root_cert, NULL);
const grpc_credentials_array *creds_array;
- grpc_credentials *oauth2_creds =
- grpc_fake_oauth2_credentials_create(test_oauth2_bearer_token, 0);
+ grpc_credentials *oauth2_creds = grpc_md_only_test_credentials_create(
+ "Authorization", test_oauth2_bearer_token, 0);
grpc_credentials *aux_creds =
grpc_composite_credentials_create(ssl_creds, oauth2_creds);
grpc_credentials *iam_creds = grpc_iam_credentials_create(
@@ -477,7 +477,7 @@ static void on_oauth2_creds_get_metadata_failure(
static void validate_compute_engine_http_request(
const grpc_httpcli_request *request) {
- GPR_ASSERT(!request->use_ssl);
+ GPR_ASSERT(request->handshaker != &grpc_httpcli_ssl);
GPR_ASSERT(strcmp(request->host, "metadata") == 0);
GPR_ASSERT(
strcmp(request->path,
@@ -573,7 +573,7 @@ static void validate_refresh_token_http_request(
GPR_ASSERT(strlen(expected_body) == body_size);
GPR_ASSERT(memcmp(expected_body, body, body_size) == 0);
gpr_free(expected_body);
- GPR_ASSERT(request->use_ssl);
+ GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
GPR_ASSERT(strcmp(request->host, GRPC_GOOGLE_OAUTH2_SERVICE_HOST) == 0);
GPR_ASSERT(strcmp(request->path, GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH) == 0);
GPR_ASSERT(request->hdr_count == 1);
@@ -697,7 +697,7 @@ static void validate_service_account_http_request(
GPR_ASSERT(strlen(expected_body) == body_size);
GPR_ASSERT(memcmp(expected_body, body, body_size) == 0);
gpr_free(expected_body);
- GPR_ASSERT(request->use_ssl);
+ GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
GPR_ASSERT(strcmp(request->host, GRPC_GOOGLE_OAUTH2_SERVICE_HOST) == 0);
GPR_ASSERT(strcmp(request->path, GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH) == 0);
GPR_ASSERT(request->hdr_count == 1);
diff --git a/test/core/security/jwt_verifier_test.c b/test/core/security/jwt_verifier_test.c
index 98db56c0ef..440286ea1a 100644
--- a/test/core/security/jwt_verifier_test.c
+++ b/test/core/security/jwt_verifier_test.c
@@ -286,7 +286,7 @@ static int httpcli_get_google_keys_for_email(
const grpc_httpcli_request *request, gpr_timespec deadline,
grpc_httpcli_response_cb on_response, void *user_data) {
grpc_httpcli_response response = http_response(200, good_google_email_keys());
- GPR_ASSERT(request->use_ssl);
+ GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0);
GPR_ASSERT(strcmp(request->path,
"/robot/v1/metadata/x509/"
@@ -331,7 +331,7 @@ static int httpcli_get_custom_keys_for_email(
const grpc_httpcli_request *request, gpr_timespec deadline,
grpc_httpcli_response_cb on_response, void *user_data) {
grpc_httpcli_response response = http_response(200, gpr_strdup(good_jwk_set));
- GPR_ASSERT(request->use_ssl);
+ GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
GPR_ASSERT(strcmp(request->host, "keys.bar.com") == 0);
GPR_ASSERT(strcmp(request->path, "/jwk/foo@bar.com") == 0);
on_response(user_data, &response);
@@ -363,7 +363,7 @@ static int httpcli_get_jwk_set(
const grpc_httpcli_request *request, gpr_timespec deadline,
grpc_httpcli_response_cb on_response, void *user_data) {
grpc_httpcli_response response = http_response(200, gpr_strdup(good_jwk_set));
- GPR_ASSERT(request->use_ssl);
+ GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0);
GPR_ASSERT(strcmp(request->path, "/oauth2/v3/certs") == 0);
on_response(user_data, &response);
@@ -377,7 +377,7 @@ static int httpcli_get_openid_config(const grpc_httpcli_request *request,
void *user_data) {
grpc_httpcli_response response =
http_response(200, gpr_strdup(good_openid_config));
- GPR_ASSERT(request->use_ssl);
+ GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
GPR_ASSERT(strcmp(request->host, "accounts.google.com") == 0);
GPR_ASSERT(strcmp(request->path, GRPC_OPENID_CONFIG_URL_SUFFIX) == 0);
grpc_httpcli_set_override(httpcli_get_jwk_set,
@@ -421,7 +421,7 @@ static int httpcli_get_bad_json(const grpc_httpcli_request *request,
void *user_data) {
grpc_httpcli_response response =
http_response(200, gpr_strdup("{\"bad\": \"stuff\"}"));
- GPR_ASSERT(request->use_ssl);
+ GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
on_response(user_data, &response);
gpr_free(response.body);
return 1;
diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c
index 9b334b3c3e..69bbc3cc0c 100644
--- a/test/core/security/verify_jwt.c
+++ b/test/core/security/verify_jwt.c
@@ -112,7 +112,7 @@ int main(int argc, char **argv) {
while (!sync.is_done) {
grpc_pollset_worker worker;
grpc_pollset_work(&sync.pollset, &worker,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset));
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index b07df391f9..9bff18d311 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -44,9 +44,13 @@
#include <string.h>
#include <unistd.h>
+#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include "src/core/httpcli/httpcli.h"
+#include "src/core/support/env.h"
+
#define NUM_RANDOM_PORTS_TO_PICK 100
static int *chosen_ports = NULL;
@@ -126,6 +130,67 @@ static int is_port_available(int *port, int is_tcp) {
return 1;
}
+typedef struct portreq {
+ grpc_pollset pollset;
+ int port;
+} portreq;
+
+static void got_port_from_server(void *arg,
+ const grpc_httpcli_response *response) {
+ size_t i;
+ int port = 0;
+ portreq *pr = arg;
+ GPR_ASSERT(response);
+ GPR_ASSERT(response->status == 200);
+ for (i = 0; i < response->body_length; i++) {
+ GPR_ASSERT(response->body[i] >= '0' && response->body[i] <= '9');
+ port = port * 10 + response->body[i] - '0';
+ }
+ GPR_ASSERT(port > 1024);
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset));
+ pr->port = port;
+ grpc_pollset_kick(&pr->pollset, NULL);
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset));
+}
+
+static void destroy_pollset_and_shutdown(void *p) {
+ grpc_pollset_destroy(p);
+ grpc_shutdown();
+}
+
+static int pick_port_using_server(char *server) {
+ grpc_httpcli_context context;
+ grpc_httpcli_request req;
+ portreq pr;
+
+ grpc_init();
+
+ memset(&pr, 0, sizeof(pr));
+ memset(&req, 0, sizeof(req));
+ grpc_pollset_init(&pr.pollset);
+ pr.port = -1;
+
+ req.host = server;
+ req.path = "/get";
+
+ grpc_httpcli_context_init(&context);
+ grpc_httpcli_get(&context, &pr.pollset, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
+ &pr);
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset));
+ while (pr.port == -1) {
+ grpc_pollset_worker worker;
+ grpc_pollset_work(&pr.pollset, &worker,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
+ }
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset));
+
+ grpc_httpcli_context_destroy(&context);
+ grpc_pollset_shutdown(&pr.pollset, destroy_pollset_and_shutdown, &pr.pollset);
+
+ return pr.port;
+}
+
int grpc_pick_unused_port(void) {
/* We repeatedly pick a port and then see whether or not it is
available for use both as a TCP socket and a UDP socket. First, we
@@ -143,6 +208,15 @@ int grpc_pick_unused_port(void) {
int is_tcp = 1;
int try = 0;
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ if (env) {
+ int port = pick_port_using_server(env);
+ gpr_free(env);
+ if (port != 0) {
+ return port;
+ }
+ }
+
for (;;) {
int port;
try++;
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index 225658f5e2..cadf88a7c6 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -38,6 +38,8 @@
#include <stdlib.h>
#include <signal.h>
+double g_fixture_slowdown_factor = 1.0;
+
#if GPR_GETPID_IN_UNISTD_H
#include <unistd.h>
static int seed(void) { return getpid(); }
diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h
index 7028ade7b2..b2cc40bb47 100644
--- a/test/core/util/test_config.h
+++ b/test/core/util/test_config.h
@@ -48,8 +48,11 @@ extern "C" {
#define GRPC_TEST_SLOWDOWN_MACHINE_FACTOR 1.0
#endif
-#define GRPC_TEST_SLOWDOWN_FACTOR \
- (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR)
+extern double g_fixture_slowdown_factor;
+
+#define GRPC_TEST_SLOWDOWN_FACTOR \
+ (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \
+ g_fixture_slowdown_factor)
#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \