aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/security')
-rw-r--r--test/core/security/auth_context_test.c73
-rw-r--r--test/core/security/credentials_test.c28
-rw-r--r--test/core/security/jwt_verifier_test.c10
-rw-r--r--test/core/security/oauth2_utils.c9
-rw-r--r--test/core/security/print_google_default_creds_token.c9
-rw-r--r--test/core/security/verify_jwt.c9
6 files changed, 80 insertions, 58 deletions
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 d3fea9680a..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);
@@ -826,8 +826,9 @@ static void on_jwt_creds_get_metadata_failure(void *user_data,
static void test_jwt_creds_success(void) {
char *json_key_string = test_json_key_str();
- grpc_credentials *jwt_creds = grpc_jwt_credentials_create(
- json_key_string, grpc_max_auth_token_lifetime);
+ grpc_credentials *jwt_creds =
+ grpc_service_account_jwt_access_credentials_create(
+ json_key_string, grpc_max_auth_token_lifetime);
GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds));
@@ -858,8 +859,9 @@ static void test_jwt_creds_success(void) {
static void test_jwt_creds_signing_failure(void) {
char *json_key_string = test_json_key_str();
- grpc_credentials *jwt_creds = grpc_jwt_credentials_create(
- json_key_string, grpc_max_auth_token_lifetime);
+ grpc_credentials *jwt_creds =
+ grpc_service_account_jwt_access_credentials_create(
+ json_key_string, grpc_max_auth_token_lifetime);
GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds));
@@ -900,7 +902,7 @@ static grpc_credentials *composite_inner_creds(grpc_credentials *creds,
}
static void test_google_default_creds_auth_key(void) {
- grpc_jwt_credentials *jwt;
+ grpc_service_account_jwt_access_credentials *jwt;
grpc_credentials *creds;
char *json_key = test_json_key_str();
grpc_flush_cached_google_default_credentials();
@@ -909,7 +911,7 @@ static void test_google_default_creds_auth_key(void) {
gpr_free(json_key);
creds = grpc_google_default_credentials_create();
GPR_ASSERT(creds != NULL);
- jwt = (grpc_jwt_credentials *)composite_inner_creds(
+ jwt = (grpc_service_account_jwt_access_credentials *)composite_inner_creds(
creds, GRPC_CREDENTIALS_TYPE_JWT);
GPR_ASSERT(
strcmp(jwt->key.client_id,
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/oauth2_utils.c b/test/core/security/oauth2_utils.c
index ecd04fd9e1..990855ac6a 100644
--- a/test/core/security/oauth2_utils.c
+++ b/test/core/security/oauth2_utils.c
@@ -68,7 +68,7 @@ static void on_oauth2_response(void *user_data, grpc_credentials_md *md_elems,
gpr_mu_lock(GRPC_POLLSET_MU(&request->pollset));
request->is_done = 1;
request->token = token;
- grpc_pollset_kick(&request->pollset);
+ grpc_pollset_kick(&request->pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(&request->pollset));
}
@@ -83,8 +83,11 @@ char *grpc_test_fetch_oauth2_token_with_credentials(grpc_credentials *creds) {
on_oauth2_response, &request);
gpr_mu_lock(GRPC_POLLSET_MU(&request.pollset));
- while (!request.is_done)
- grpc_pollset_work(&request.pollset, gpr_inf_future(GPR_CLOCK_REALTIME));
+ while (!request.is_done) {
+ grpc_pollset_worker worker;
+ grpc_pollset_work(&request.pollset, &worker,
+ gpr_inf_future(GPR_CLOCK_MONOTONIC));
+ }
gpr_mu_unlock(GRPC_POLLSET_MU(&request.pollset));
grpc_pollset_shutdown(&request.pollset, do_nothing, NULL);
diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c
index 0875cfb4fb..7238efbbfd 100644
--- a/test/core/security/print_google_default_creds_token.c
+++ b/test/core/security/print_google_default_creds_token.c
@@ -65,7 +65,7 @@ static void on_metadata_response(void *user_data,
}
gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset));
sync->is_done = 1;
- grpc_pollset_kick(&sync->pollset);
+ grpc_pollset_kick(&sync->pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(&sync->pollset));
}
@@ -95,8 +95,11 @@ int main(int argc, char **argv) {
on_metadata_response, &sync);
gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset));
- while (!sync.is_done)
- grpc_pollset_work(&sync.pollset, gpr_inf_future(GPR_CLOCK_REALTIME));
+ while (!sync.is_done) {
+ grpc_pollset_worker worker;
+ grpc_pollset_work(&sync.pollset, &worker,
+ gpr_inf_future(GPR_CLOCK_REALTIME));
+ }
gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset));
grpc_credentials_release(creds);
diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c
index cb073f19c7..9b334b3c3e 100644
--- a/test/core/security/verify_jwt.c
+++ b/test/core/security/verify_jwt.c
@@ -79,7 +79,7 @@ static void on_jwt_verification_done(void *user_data,
gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset));
sync->is_done = 1;
- grpc_pollset_kick(&sync->pollset);
+ grpc_pollset_kick(&sync->pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(&sync->pollset));
}
@@ -109,8 +109,11 @@ int main(int argc, char **argv) {
on_jwt_verification_done, &sync);
gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset));
- while (!sync.is_done)
- grpc_pollset_work(&sync.pollset, gpr_inf_future(GPR_CLOCK_REALTIME));
+ while (!sync.is_done) {
+ grpc_pollset_worker worker;
+ grpc_pollset_work(&sync.pollset, &worker,
+ gpr_inf_future(GPR_CLOCK_REALTIME));
+ }
gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset));
grpc_jwt_verifier_destroy(verifier);