aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
Diffstat (limited to 'test/core')
-rw-r--r--test/core/end2end/fixtures/chttp2_fake_security.c5
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c9
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c9
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c15
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c54
-rw-r--r--test/core/end2end/tests/request_response_with_payload_and_call_creds.c8
-rw-r--r--test/core/fling/server.c4
-rw-r--r--test/core/iomgr/udp_server_test.c2
-rw-r--r--test/core/security/credentials_test.c203
-rw-r--r--test/core/security/fetch_oauth2.c49
-rw-r--r--test/core/util/test_config.h2
11 files changed, 123 insertions, 237 deletions
diff --git a/test/core/end2end/fixtures/chttp2_fake_security.c b/test/core/end2end/fixtures/chttp2_fake_security.c
index a0a67939a2..3e64cc08e8 100644
--- a/test/core/end2end/fixtures/chttp2_fake_security.c
+++ b/test/core/end2end/fixtures/chttp2_fake_security.c
@@ -77,7 +77,8 @@ static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
fullstack_secure_fixture_data *ffd = f->fixture_data;
- f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args);
+ f->client =
+ grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL);
GPR_ASSERT(f->client != NULL);
grpc_credentials_release(creds);
}
@@ -127,7 +128,7 @@ static void chttp2_init_server_fake_secure_fullstack(
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_auth_metadata_processor processor = {process_auth_failure, NULL, NULL};
grpc_server_credentials_set_auth_metadata_processor(fake_ts_creds,
processor);
}
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
index beae24136c..9193a09b17 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
@@ -80,7 +80,8 @@ static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
fullstack_secure_fixture_data *ffd = f->fixture_data;
- f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args);
+ f->client =
+ grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL);
GPR_ASSERT(f->client != NULL);
grpc_credentials_release(creds);
}
@@ -108,7 +109,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
- grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL);
+ grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
{"foo.test.google.fr"}};
@@ -135,9 +136,9 @@ static void chttp2_init_server_simple_ssl_secure_fullstack(
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);
+ grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
- grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL, 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 c8971be596..2c605d1471 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
@@ -80,7 +80,8 @@ static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
fullstack_secure_fixture_data *ffd = f->fixture_data;
- f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args);
+ f->client =
+ grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL);
GPR_ASSERT(f->client != NULL);
grpc_credentials_release(creds);
}
@@ -108,7 +109,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
- grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL);
+ grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
{"foo.test.google.fr"}};
@@ -135,9 +136,9 @@ static void chttp2_init_server_simple_ssl_secure_fullstack(
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);
+ grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
- grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL, 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 a518a7da15..8133a69a0c 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
@@ -58,7 +58,7 @@ static grpc_server *create_proxy_server(const char *port) {
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);
+ grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
GPR_ASSERT(grpc_server_add_secure_http2_port(s, port, ssl_creds));
grpc_server_credentials_release(ssl_creds);
return s;
@@ -66,14 +66,14 @@ static grpc_server *create_proxy_server(const char *port) {
static grpc_channel *create_proxy_client(const char *target) {
grpc_channel *channel;
- grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL);
+ grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
{"foo.test.google.fr"}};
grpc_channel_args client_args;
client_args.num_args = 1;
client_args.args = &ssl_name_override;
- channel = grpc_secure_channel_create(ssl_creds, target, &client_args);
+ channel = grpc_secure_channel_create(ssl_creds, target, &client_args, NULL);
grpc_credentials_release(ssl_creds);
return channel;
}
@@ -109,7 +109,8 @@ static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_credentials *creds) {
fullstack_secure_fixture_data *ffd = f->fixture_data;
f->client = grpc_secure_channel_create(
- creds, grpc_end2end_proxy_get_client_target(ffd->proxy), client_args);
+ creds, grpc_end2end_proxy_get_client_target(ffd->proxy), client_args,
+ NULL);
GPR_ASSERT(f->client != NULL);
grpc_credentials_release(creds);
}
@@ -137,7 +138,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
- grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL);
+ grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
{"foo.test.google.fr"}};
@@ -164,9 +165,9 @@ static void chttp2_init_server_simple_ssl_secure_fullstack(
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);
+ grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
- grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL, 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 7f11028cb5..e61e276fff 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
@@ -67,13 +67,21 @@ static const grpc_metadata *find_metadata(const grpc_metadata *md,
return NULL;
}
+typedef struct {
+ size_t pseudo_refcount;
+} test_processor_state;
+
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);
+ test_processor_state *s;
+
+ GPR_ASSERT(state != NULL);
+ s = (test_processor_state *)state;
+ GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != NULL);
grpc_auth_context_add_cstring_property(ctx, client_identity_property_name,
client_identity);
@@ -88,7 +96,10 @@ static void process_oauth2_failure(void *state, grpc_auth_context *ctx,
void *user_data) {
const grpc_metadata *oauth2 =
find_metadata(md, md_count, "Authorization", oauth2_md);
- GPR_ASSERT(state == NULL);
+ test_processor_state *s;
+ GPR_ASSERT(state != NULL);
+ s = (test_processor_state *)state;
+ GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != NULL);
cb(user_data, oauth2, 1, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL);
}
@@ -113,7 +124,8 @@ static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
grpc_credentials *creds) {
fullstack_secure_fixture_data *ffd = f->fixture_data;
- f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args);
+ f->client =
+ grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL);
GPR_ASSERT(f->client != NULL);
grpc_credentials_release(creds);
}
@@ -142,11 +154,11 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
grpc_credentials *ssl_creds =
- grpc_ssl_credentials_create(test_root_cert, NULL);
+ grpc_ssl_credentials_create(test_root_cert, NULL, NULL);
grpc_credentials *oauth2_creds =
grpc_md_only_test_credentials_create("Authorization", oauth2_md, 1);
grpc_credentials *ssl_oauth2_creds =
- grpc_composite_credentials_create(ssl_creds, oauth2_creds);
+ grpc_composite_credentials_create(ssl_creds, oauth2_creds, NULL);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
{"foo.test.google.fr"}};
@@ -170,20 +182,34 @@ static int fail_server_auth_check(grpc_channel_args *server_args) {
return 0;
}
+static void processor_destroy(void *state) {
+ test_processor_state *s = (test_processor_state *)state;
+ GPR_ASSERT((s->pseudo_refcount--) == 1);
+ gpr_free(s);
+}
+
+static grpc_auth_metadata_processor test_processor_create(int failing) {
+ test_processor_state *s = gpr_malloc(sizeof(*s));
+ grpc_auth_metadata_processor result;
+ s->pseudo_refcount = 1;
+ result.state = s;
+ result.destroy = processor_destroy;
+ if (failing) {
+ result.process = process_oauth2_failure;
+ } else {
+ result.process = process_oauth2_success;
+ }
+ return result;
+}
+
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);
+ grpc_ssl_server_credentials_create(NULL, &pem_key_cert_pair, 1, 0, NULL);
+ grpc_server_credentials_set_auth_metadata_processor(
+ ssl_creds, test_processor_create(fail_server_auth_check(server_args)));
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
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 d862274fe3..75c5bba5bd 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
@@ -190,7 +190,7 @@ static void request_response_with_payload_and_call_creds(
c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
"/foo", "foo.test.google.fr", deadline, NULL);
GPR_ASSERT(c);
- creds = grpc_iam_credentials_create(iam_token, iam_selector);
+ creds = grpc_google_iam_credentials_create(iam_token, iam_selector, NULL);
GPR_ASSERT(creds != NULL);
GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK);
switch (mode) {
@@ -198,8 +198,8 @@ static void request_response_with_payload_and_call_creds(
break;
case OVERRIDE:
grpc_credentials_release(creds);
- creds = grpc_iam_credentials_create(overridden_iam_token,
- overridden_iam_selector);
+ creds = grpc_google_iam_credentials_create(overridden_iam_token,
+ overridden_iam_selector, NULL);
GPR_ASSERT(creds != NULL);
GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK);
break;
@@ -421,7 +421,7 @@ static void test_request_with_server_rejecting_client_creds(
"/foo", "foo.test.google.fr", deadline, NULL);
GPR_ASSERT(c);
- creds = grpc_iam_credentials_create(iam_token, iam_selector);
+ creds = grpc_google_iam_credentials_create(iam_token, iam_selector, NULL);
GPR_ASSERT(creds != NULL);
GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK);
grpc_credentials_release(creds);
diff --git a/test/core/fling/server.c b/test/core/fling/server.c
index 010217939d..0430ff9ab7 100644
--- a/test/core/fling/server.c
+++ b/test/core/fling/server.c
@@ -215,8 +215,8 @@ int main(int argc, char **argv) {
if (secure) {
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_server_credentials *ssl_creds = grpc_ssl_server_credentials_create(
+ NULL, &pem_key_cert_pair, 1, 0, NULL);
server = grpc_server_create(NULL, NULL);
GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds));
grpc_server_credentials_release(ssl_creds);
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 471d5b50c7..c91752b937 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -135,7 +135,7 @@ static void test_receive(int number_of_clients) {
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
for (i = 0; i < number_of_clients; i++) {
- deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(4000);
+ deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
number_of_reads_before = g_number_of_reads;
/* Create a socket, send a packet to the UDP server. */
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index e4a8144eaf..97ebaa0570 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -50,8 +50,8 @@
#include <openssl/rsa.h>
-static const char test_iam_authorization_token[] = "blahblahblhahb";
-static const char test_iam_authority_selector[] = "respectmyauthoritah";
+static const char test_google_iam_authorization_token[] = "blahblahblhahb";
+static const char test_google_iam_authority_selector[] = "respectmyauthoritah";
static const char test_oauth2_bearer_token[] =
"Bearer blaaslkdjfaslkdfasdsfasf";
static const char test_root_cert[] = "I am the root!";
@@ -315,25 +315,29 @@ static void check_metadata(expected_md *expected, grpc_credentials_md *md_elems,
}
}
-static void check_iam_metadata(void *user_data, grpc_credentials_md *md_elems,
- size_t num_md, grpc_credentials_status status) {
+static void check_google_iam_metadata(void *user_data,
+ grpc_credentials_md *md_elems,
+ size_t num_md,
+ grpc_credentials_status status) {
grpc_credentials *c = (grpc_credentials *)user_data;
- expected_md emd[] = {
- {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_iam_authorization_token},
- {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, test_iam_authority_selector}};
+ expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
+ test_google_iam_authorization_token},
+ {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
+ test_google_iam_authority_selector}};
GPR_ASSERT(status == GRPC_CREDENTIALS_OK);
GPR_ASSERT(num_md == 2);
check_metadata(emd, md_elems, num_md);
grpc_credentials_unref(c);
}
-static void test_iam_creds(void) {
- grpc_credentials *creds = grpc_iam_credentials_create(
- test_iam_authorization_token, test_iam_authority_selector);
+static void test_google_iam_creds(void) {
+ grpc_credentials *creds = grpc_google_iam_credentials_create(
+ test_google_iam_authorization_token, test_google_iam_authority_selector,
+ NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(creds));
grpc_credentials_get_request_metadata(creds, NULL, test_service_url,
- check_iam_metadata, creds);
+ check_google_iam_metadata, creds);
}
static void check_access_token_metadata(void *user_data,
@@ -349,7 +353,7 @@ static void check_access_token_metadata(void *user_data,
}
static void test_access_token_creds(void) {
- grpc_credentials *creds = grpc_access_token_credentials_create("blah");
+ grpc_credentials *creds = grpc_access_token_credentials_create("blah", NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(creds));
GPR_ASSERT(strcmp(creds->type, GRPC_CREDENTIALS_TYPE_OAUTH2) == 0);
@@ -371,12 +375,12 @@ static void check_ssl_oauth2_composite_metadata(
static void test_ssl_oauth2_composite_creds(void) {
grpc_credentials *ssl_creds =
- grpc_ssl_credentials_create(test_root_cert, NULL);
+ grpc_ssl_credentials_create(test_root_cert, NULL, NULL);
const grpc_credentials_array *creds_array;
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_composite_credentials_create(ssl_creds, oauth2_creds, NULL);
grpc_credentials_unref(ssl_creds);
grpc_credentials_unref(oauth2_creds);
GPR_ASSERT(strcmp(composite_creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE) ==
@@ -395,47 +399,50 @@ static void test_ssl_oauth2_composite_creds(void) {
}
void test_ssl_fake_transport_security_composite_creds_failure(void) {
- grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL);
+ grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL);
grpc_credentials *fake_transport_security_creds =
grpc_fake_transport_security_credentials_create();
/* 2 connector credentials: should not work. */
GPR_ASSERT(grpc_composite_credentials_create(
- ssl_creds, fake_transport_security_creds) == NULL);
+ ssl_creds, fake_transport_security_creds, NULL) == NULL);
grpc_credentials_unref(ssl_creds);
grpc_credentials_unref(fake_transport_security_creds);
}
-static void check_ssl_oauth2_iam_composite_metadata(
+static void check_ssl_oauth2_google_iam_composite_metadata(
void *user_data, grpc_credentials_md *md_elems, size_t num_md,
grpc_credentials_status status) {
grpc_credentials *c = (grpc_credentials *)user_data;
expected_md emd[] = {
{GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token},
- {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_iam_authorization_token},
- {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, test_iam_authority_selector}};
+ {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
+ test_google_iam_authorization_token},
+ {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
+ test_google_iam_authority_selector}};
GPR_ASSERT(status == GRPC_CREDENTIALS_OK);
GPR_ASSERT(num_md == 3);
check_metadata(emd, md_elems, num_md);
grpc_credentials_unref(c);
}
-static void test_ssl_oauth2_iam_composite_creds(void) {
+static void test_ssl_oauth2_google_iam_composite_creds(void) {
grpc_credentials *ssl_creds =
- grpc_ssl_credentials_create(test_root_cert, NULL);
+ grpc_ssl_credentials_create(test_root_cert, NULL, NULL);
const grpc_credentials_array *creds_array;
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(
- test_iam_authorization_token, test_iam_authority_selector);
+ grpc_composite_credentials_create(ssl_creds, oauth2_creds, NULL);
+ grpc_credentials *google_iam_creds = grpc_google_iam_credentials_create(
+ test_google_iam_authorization_token, test_google_iam_authority_selector,
+ NULL);
grpc_credentials *composite_creds =
- grpc_composite_credentials_create(aux_creds, iam_creds);
+ grpc_composite_credentials_create(aux_creds, google_iam_creds, NULL);
grpc_credentials_unref(ssl_creds);
grpc_credentials_unref(oauth2_creds);
grpc_credentials_unref(aux_creds);
- grpc_credentials_unref(iam_creds);
+ grpc_credentials_unref(google_iam_creds);
GPR_ASSERT(strcmp(composite_creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE) ==
0);
GPR_ASSERT(grpc_credentials_has_request_metadata(composite_creds));
@@ -448,9 +455,9 @@ static void test_ssl_oauth2_iam_composite_creds(void) {
GRPC_CREDENTIALS_TYPE_OAUTH2) == 0);
GPR_ASSERT(strcmp(creds_array->creds_array[2]->type,
GRPC_CREDENTIALS_TYPE_IAM) == 0);
- grpc_credentials_get_request_metadata(composite_creds, NULL, test_service_url,
- check_ssl_oauth2_iam_composite_metadata,
- composite_creds);
+ grpc_credentials_get_request_metadata(
+ composite_creds, NULL, test_service_url,
+ check_ssl_oauth2_google_iam_composite_metadata, composite_creds);
}
static void on_oauth2_creds_get_metadata_success(
@@ -524,7 +531,7 @@ static int httpcli_get_should_not_be_called(
static void test_compute_engine_creds_success(void) {
grpc_credentials *compute_engine_creds =
- grpc_compute_engine_credentials_create();
+ grpc_google_compute_engine_credentials_create(NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(compute_engine_creds));
@@ -548,7 +555,7 @@ static void test_compute_engine_creds_success(void) {
static void test_compute_engine_creds_failure(void) {
grpc_credentials *compute_engine_creds =
- grpc_compute_engine_credentials_create();
+ grpc_google_compute_engine_credentials_create(NULL);
grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override,
httpcli_post_should_not_be_called);
GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds));
@@ -605,7 +612,8 @@ static int refresh_token_httpcli_post_failure(
static void test_refresh_token_creds_success(void) {
grpc_credentials *refresh_token_creds =
- grpc_refresh_token_credentials_create(test_refresh_token_str);
+ grpc_google_refresh_token_credentials_create(test_refresh_token_str,
+ NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(refresh_token_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(refresh_token_creds));
@@ -629,7 +637,8 @@ static void test_refresh_token_creds_success(void) {
static void test_refresh_token_creds_failure(void) {
grpc_credentials *refresh_token_creds =
- grpc_refresh_token_credentials_create(test_refresh_token_str);
+ grpc_google_refresh_token_credentials_create(test_refresh_token_str,
+ NULL);
grpc_httpcli_set_override(httpcli_get_should_not_be_called,
refresh_token_httpcli_post_failure);
GPR_ASSERT(grpc_credentials_has_request_metadata(refresh_token_creds));
@@ -686,119 +695,6 @@ static char *encode_and_sign_jwt_should_not_be_called(
GPR_ASSERT("grpc_jwt_encode_and_sign should not be called" == NULL);
}
-static void validate_service_account_http_request(
- const grpc_httpcli_request *request, const char *body, size_t body_size) {
- /* The content of the assertion is tested extensively in json_token_test. */
- char *expected_body = NULL;
- GPR_ASSERT(body != NULL);
- GPR_ASSERT(body_size != 0);
- gpr_asprintf(&expected_body, "%s%s", GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX,
- test_signed_jwt);
- GPR_ASSERT(strlen(expected_body) == body_size);
- GPR_ASSERT(memcmp(expected_body, body, body_size) == 0);
- gpr_free(expected_body);
- 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);
- GPR_ASSERT(strcmp(request->hdrs[0].key, "Content-Type") == 0);
- GPR_ASSERT(
- strcmp(request->hdrs[0].value, "application/x-www-form-urlencoded") == 0);
-}
-
-static int service_account_httpcli_post_success(
- const grpc_httpcli_request *request, const char *body, size_t body_size,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
- grpc_httpcli_response response =
- http_response(200, valid_oauth2_json_response);
- validate_service_account_http_request(request, body, body_size);
- on_response(user_data, &response);
- return 1;
-}
-
-static int service_account_httpcli_post_failure(
- const grpc_httpcli_request *request, const char *body, size_t body_size,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
- grpc_httpcli_response response = http_response(403, "Not Authorized.");
- validate_service_account_http_request(request, body, body_size);
- on_response(user_data, &response);
- return 1;
-}
-
-static void test_service_account_creds_success(void) {
- char *json_key_string = test_json_key_str();
- grpc_credentials *service_account_creds =
- grpc_service_account_credentials_create(json_key_string, test_scope,
- grpc_max_auth_token_lifetime);
- GPR_ASSERT(grpc_credentials_has_request_metadata(service_account_creds));
- GPR_ASSERT(grpc_credentials_has_request_metadata_only(service_account_creds));
-
- /* First request: http get should be called. */
- grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- service_account_httpcli_post_success);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_success, (void *)test_user_data);
-
- /* Second request: the cached token should be served directly. */
- grpc_jwt_encode_and_sign_set_override(
- encode_and_sign_jwt_should_not_be_called);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- httpcli_post_should_not_be_called);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_success, (void *)test_user_data);
-
- gpr_free(json_key_string);
- grpc_credentials_unref(service_account_creds);
- grpc_jwt_encode_and_sign_set_override(NULL);
- grpc_httpcli_set_override(NULL, NULL);
-}
-
-static void test_service_account_creds_http_failure(void) {
- char *json_key_string = test_json_key_str();
- grpc_credentials *service_account_creds =
- grpc_service_account_credentials_create(json_key_string, test_scope,
- grpc_max_auth_token_lifetime);
- GPR_ASSERT(grpc_credentials_has_request_metadata(service_account_creds));
- GPR_ASSERT(grpc_credentials_has_request_metadata_only(service_account_creds));
-
- grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- service_account_httpcli_post_failure);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_failure, (void *)test_user_data);
-
- gpr_free(json_key_string);
- grpc_credentials_unref(service_account_creds);
- grpc_httpcli_set_override(NULL, NULL);
-}
-
-static void test_service_account_creds_signing_failure(void) {
- char *json_key_string = test_json_key_str();
- grpc_credentials *service_account_creds =
- grpc_service_account_credentials_create(json_key_string, test_scope,
- grpc_max_auth_token_lifetime);
- GPR_ASSERT(grpc_credentials_has_request_metadata(service_account_creds));
- GPR_ASSERT(grpc_credentials_has_request_metadata_only(service_account_creds));
-
- grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- httpcli_post_should_not_be_called);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_failure, (void *)test_user_data);
-
- gpr_free(json_key_string);
- grpc_credentials_unref(service_account_creds);
- grpc_httpcli_set_override(NULL, NULL);
- grpc_jwt_encode_and_sign_set_override(NULL);
-}
-
static void on_jwt_creds_get_metadata_success(void *user_data,
grpc_credentials_md *md_elems,
size_t num_md,
@@ -828,7 +724,7 @@ static void test_jwt_creds_success(void) {
char *json_key_string = test_json_key_str();
grpc_credentials *jwt_creds =
grpc_service_account_jwt_access_credentials_create(
- json_key_string, grpc_max_auth_token_lifetime);
+ json_key_string, grpc_max_auth_token_lifetime, NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds));
@@ -861,7 +757,7 @@ static void test_jwt_creds_signing_failure(void) {
char *json_key_string = test_json_key_str();
grpc_credentials *jwt_creds =
grpc_service_account_jwt_access_credentials_create(
- json_key_string, grpc_max_auth_token_lifetime);
+ json_key_string, grpc_max_auth_token_lifetime, NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds));
@@ -922,14 +818,14 @@ static void test_google_default_creds_auth_key(void) {
}
static void test_google_default_creds_access_token(void) {
- grpc_refresh_token_credentials *refresh;
+ grpc_google_refresh_token_credentials *refresh;
grpc_credentials *creds;
grpc_flush_cached_google_default_credentials();
set_google_default_creds_env_var_with_file_contents(
"refresh_token_google_default_creds", test_refresh_token_str);
creds = grpc_google_default_credentials_create();
GPR_ASSERT(creds != NULL);
- refresh = (grpc_refresh_token_credentials *)composite_inner_creds(
+ refresh = (grpc_google_refresh_token_credentials *)composite_inner_creds(
creds, GRPC_CREDENTIALS_TYPE_OAUTH2);
GPR_ASSERT(strcmp(refresh->refresh_token.client_id,
"32555999999.apps.googleusercontent.com") == 0);
@@ -952,17 +848,14 @@ int main(int argc, char **argv) {
test_oauth2_token_fetcher_creds_parsing_missing_token();
test_oauth2_token_fetcher_creds_parsing_missing_token_type();
test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime();
- test_iam_creds();
+ test_google_iam_creds();
test_access_token_creds();
test_ssl_oauth2_composite_creds();
- test_ssl_oauth2_iam_composite_creds();
+ test_ssl_oauth2_google_iam_composite_creds();
test_compute_engine_creds_success();
test_compute_engine_creds_failure();
test_refresh_token_creds_success();
test_refresh_token_creds_failure();
- test_service_account_creds_success();
- test_service_account_creds_http_failure();
- test_service_account_creds_signing_failure();
test_jwt_creds_success();
test_jwt_creds_signing_failure();
test_google_default_creds_auth_key();
diff --git a/test/core/security/fetch_oauth2.c b/test/core/security/fetch_oauth2.c
index 64c4dde5d9..764d8da9b6 100644
--- a/test/core/security/fetch_oauth2.c
+++ b/test/core/security/fetch_oauth2.c
@@ -46,19 +46,6 @@
#include "src/core/support/file.h"
#include "test/core/security/oauth2_utils.h"
-static grpc_credentials *create_service_account_creds(
- const char *json_key_file_path, const char *scope) {
- int success;
- gpr_slice json_key = gpr_load_file(json_key_file_path, 1, &success);
- if (!success) {
- gpr_log(GPR_ERROR, "Could not read file %s.", json_key_file_path);
- exit(1);
- }
- return grpc_service_account_credentials_create(
- (const char *)GPR_SLICE_START_PTR(json_key), scope,
- grpc_max_auth_token_lifetime);
-}
-
static grpc_credentials *create_refresh_token_creds(
const char *json_refresh_token_file_path) {
int success;
@@ -68,8 +55,8 @@ static grpc_credentials *create_refresh_token_creds(
gpr_log(GPR_ERROR, "Could not read file %s.", json_refresh_token_file_path);
exit(1);
}
- return grpc_refresh_token_credentials_create(
- (const char *)GPR_SLICE_START_PTR(refresh_token));
+ return grpc_google_refresh_token_credentials_create(
+ (const char *)GPR_SLICE_START_PTR(refresh_token), NULL);
}
int main(int argc, char **argv) {
@@ -80,18 +67,9 @@ int main(int argc, char **argv) {
int use_gce = 0;
char *scope = NULL;
gpr_cmdline *cl = gpr_cmdline_create("fetch_oauth2");
- gpr_cmdline_add_string(cl, "json_key",
- "File path of the json key. Mutually exclusive with "
- "--json_refresh_token.",
- &json_key_file_path);
gpr_cmdline_add_string(cl, "json_refresh_token",
- "File path of the json refresh token. Mutually "
- "exclusive with --json_key.",
+ "File path of the json refresh token.",
&json_refresh_token_file_path);
- gpr_cmdline_add_string(cl, "scope",
- "Space delimited permissions. Only used for "
- "--json_key, ignored otherwise.",
- &scope);
gpr_cmdline_add_flag(
cl, "gce",
"Get a token from the GCE metadata server (only works in GCE).",
@@ -112,7 +90,7 @@ int main(int argc, char **argv) {
"Ignoring json key and scope to get a token from the GCE "
"metadata server.");
}
- creds = grpc_compute_engine_credentials_create();
+ creds = grpc_google_compute_engine_credentials_create(NULL);
if (creds == NULL) {
gpr_log(GPR_ERROR, "Could not create gce credentials.");
exit(1);
@@ -127,23 +105,8 @@ int main(int argc, char **argv) {
exit(1);
}
} else {
- if (json_key_file_path == NULL) {
- gpr_log(GPR_ERROR, "Missing --json_key option.");
- exit(1);
- }
- if (scope == NULL) {
- gpr_log(GPR_ERROR, "Missing --scope option.");
- exit(1);
- }
-
- creds = create_service_account_creds(json_key_file_path, scope);
- if (creds == NULL) {
- gpr_log(GPR_ERROR,
- "Could not create service account creds. %s does probably not "
- "contain a valid json key.",
- json_key_file_path);
- exit(1);
- }
+ gpr_log(GPR_ERROR, "Missing --gce or --json_refresh_token option.");
+ exit(1);
}
GPR_ASSERT(creds != NULL);
diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h
index b2cc40bb47..ccef8620c1 100644
--- a/test/core/util/test_config.h
+++ b/test/core/util/test_config.h
@@ -56,7 +56,7 @@ extern double g_fixture_slowdown_factor;
#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \
- gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x), \
+ gpr_time_from_millis(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \
GPR_TIMESPAN))
#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \