aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-08-12 12:00:36 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-08-12 12:00:36 -0700
commitd067c263b250657891de4ad96ae51249435c6066 (patch)
tree03611c21ff494f0652e70d424af1dddae4c1da28 /test/core/security
parentd5689305612f5597716a4337ce934883a472a266 (diff)
parent826f07eb6f8dc2366375b7c96cc12bca1302518c (diff)
Merge github.com:grpc/grpc into y12kdm3
Conflicts: src/core/security/google_default_credentials.c test/core/security/verify_jwt.c
Diffstat (limited to 'test/core/security')
-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
3 files changed, 54 insertions, 43 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 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;