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.c8
-rw-r--r--test/core/security/base64_test.c38
-rw-r--r--test/core/security/print_google_default_creds_token.c7
-rw-r--r--test/core/security/security_connector_test.c11
4 files changed, 52 insertions, 12 deletions
diff --git a/test/core/security/auth_context_test.c b/test/core/security/auth_context_test.c
index 2fb0c01f6f..2b12551a06 100644
--- a/test/core/security/auth_context_test.c
+++ b/test/core/security/auth_context_test.c
@@ -52,7 +52,7 @@ 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);
- grpc_auth_context_unref(ctx);
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static void test_simple_context(void) {
@@ -86,7 +86,7 @@ static void test_simple_context(void) {
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &ctx->properties[1]);
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
- grpc_auth_context_unref(ctx);
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static void test_chained_context(void) {
@@ -96,7 +96,7 @@ static void test_chained_context(void) {
size_t i;
gpr_log(GPR_INFO, "test_chained_context");
- grpc_auth_context_unref(chained);
+ 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");
@@ -129,7 +129,7 @@ static void test_chained_context(void) {
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == &chained->properties[0]);
GPR_ASSERT(grpc_auth_property_iterator_next(&it) == NULL);
- grpc_auth_context_unref(ctx);
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
diff --git a/test/core/security/base64_test.c b/test/core/security/base64_test.c
index a922896bc3..f8b7ebf554 100644
--- a/test/core/security/base64_test.c
+++ b/test/core/security/base64_test.c
@@ -169,6 +169,43 @@ static void test_rfc4648_test_vectors(void) {
gpr_free(b64);
}
+static void test_unpadded_decode(void) {
+ gpr_slice decoded;
+
+ decoded = grpc_base64_decode("Zm9vYmFy", 0);
+ GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded));
+ GPR_ASSERT(gpr_slice_str_cmp(decoded, "foobar") == 0);
+ gpr_slice_unref(decoded);
+
+ decoded = grpc_base64_decode("Zm9vYmE", 0);
+ GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded));
+ GPR_ASSERT(gpr_slice_str_cmp(decoded, "fooba") == 0);
+ gpr_slice_unref(decoded);
+
+ decoded = grpc_base64_decode("Zm9vYg", 0);
+ GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded));
+ GPR_ASSERT(gpr_slice_str_cmp(decoded, "foob") == 0);
+ gpr_slice_unref(decoded);
+
+ decoded = grpc_base64_decode("Zm9v", 0);
+ GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded));
+ GPR_ASSERT(gpr_slice_str_cmp(decoded, "foo") == 0);
+ gpr_slice_unref(decoded);
+
+ decoded = grpc_base64_decode("Zm8", 0);
+ GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded));
+ GPR_ASSERT(gpr_slice_str_cmp(decoded, "fo") == 0);
+ gpr_slice_unref(decoded);
+
+ decoded = grpc_base64_decode("Zg", 0);
+ GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded));
+ GPR_ASSERT(gpr_slice_str_cmp(decoded, "f") == 0);
+ gpr_slice_unref(decoded);
+
+ decoded = grpc_base64_decode("", 0);
+ GPR_ASSERT(GPR_SLICE_IS_EMPTY(decoded));
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_simple_encode_decode_b64_no_multiline();
@@ -181,5 +218,6 @@ int main(int argc, char **argv) {
test_full_range_encode_decode_b64_urlsafe_multiline();
test_url_safe_unsafe_mismtach_failure();
test_rfc4648_test_vectors();
+ test_unpadded_decode();
return 0;
}
diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c
index dc49760438..5b55a4da13 100644
--- a/test/core/security/print_google_default_creds_token.c
+++ b/test/core/security/print_google_default_creds_token.c
@@ -35,6 +35,7 @@
#include <string.h>
#include "src/core/security/credentials.h"
+#include "src/core/support/string.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
@@ -56,9 +57,11 @@ static void on_metadata_response(void *user_data,
if (status == GRPC_CREDENTIALS_ERROR) {
fprintf(stderr, "Fetching token failed.\n");
} else {
+ char *token;
GPR_ASSERT(num_md == 1);
- printf("\nGot token: %s\n\n",
- (const char *)GPR_SLICE_START_PTR(md_elems[0].value));
+ token = gpr_dump_slice(md_elems[0].value, GPR_DUMP_ASCII);
+ printf("\nGot token: %s\n\n", token);
+ gpr_free(token);
}
gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset));
sync->is_done = 1;
diff --git a/test/core/security/security_connector_test.c b/test/core/security/security_connector_test.c
index 4ad8beb727..b37fd7213d 100644
--- a/test/core/security/security_connector_test.c
+++ b/test/core/security/security_connector_test.c
@@ -73,7 +73,7 @@ static void test_unauthenticated_ssl_peer(void) {
GPR_ASSERT(check_transport_security_type(ctx));
tsi_peer_destruct(&peer);
- grpc_auth_context_unref(ctx);
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static int check_identity(const grpc_auth_context *ctx,
@@ -145,7 +145,7 @@ static void test_cn_only_ssl_peer_to_auth_context(void) {
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
tsi_peer_destruct(&peer);
- grpc_auth_context_unref(ctx);
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static void test_cn_and_one_san_ssl_peer_to_auth_context(void) {
@@ -171,7 +171,7 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) {
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
tsi_peer_destruct(&peer);
- grpc_auth_context_unref(ctx);
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) {
@@ -202,7 +202,7 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) {
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
tsi_peer_destruct(&peer);
- grpc_auth_context_unref(ctx);
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(
@@ -238,8 +238,7 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
tsi_peer_destruct(&peer);
- grpc_auth_context_unref(ctx);
-
+ GRPC_AUTH_CONTEXT_UNREF(ctx, "test");
}
int main(int argc, char **argv) {