aboutsummaryrefslogtreecommitdiff
path: root/test/core/security
diff options
context:
space:
mode:
authorJustin Burke <burkej@google.com>2017-10-03 18:09:41 -0700
committerJustin Burke <burkej@google.com>2017-10-23 15:08:45 -0700
commit9b9a44e4dd1087a1cbdde3a3884cc7beea031d58 (patch)
tree84203e2a9c563499fb3ffbda03176f5f5fb7e7d7 /test/core/security
parentc563b583cb9b7fecc33971581368796d2df4759d (diff)
downloadgrpc-grpc-9b9a44e4dd1087a1cbdde3a3884cc7beea031d58.tar.gz
Expose conversion of grpc to tsi cert pairs
Diffstat (limited to 'test/core/security')
-rw-r--r--test/core/security/BUILD12
-rw-r--r--test/core/security/ssl_credentials_test.c66
2 files changed, 78 insertions, 0 deletions
diff --git a/test/core/security/BUILD b/test/core/security/BUILD
index dc41759922..83b1747648 100644
--- a/test/core/security/BUILD
+++ b/test/core/security/BUILD
@@ -91,6 +91,18 @@ grpc_cc_test(
],
)
+grpc_cc_test(
+ name = "ssl_credentials_test",
+ srcs = ["ssl_credentials_test.c"],
+ language = "C",
+ deps = [
+ "//:gpr",
+ "//:grpc",
+ "//test/core/util:gpr_test_util",
+ "//test/core/util:grpc_test_util",
+ ]
+)
+
grpc_cc_binary(
name = "create_jwt",
srcs = ["create_jwt.c"],
diff --git a/test/core/security/ssl_credentials_test.c b/test/core/security/ssl_credentials_test.c
new file mode 100644
index 0000000000..3c838faa60
--- /dev/null
+++ b/test/core/security/ssl_credentials_test.c
@@ -0,0 +1,66 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/grpc_security.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
+#include "src/core/tsi/ssl_transport_security.h"
+#include "test/core/util/test_config.h"
+
+static void test_convert_grpc_to_tsi_cert_pairs() {
+ grpc_ssl_pem_key_cert_pair grpc_pairs[] = {{"private_key1", "cert_chain1"},
+ {"private_key2", "cert_chain2"},
+ {"private_key3", "cert_chain3"}};
+ const size_t num_pairs = 3;
+
+ {
+ tsi_ssl_pem_key_cert_pair *tsi_pairs =
+ grpc_convert_grpc_to_tsi_cert_pairs(grpc_pairs, 0);
+ GPR_ASSERT(tsi_pairs == NULL);
+ }
+
+ {
+ tsi_ssl_pem_key_cert_pair *tsi_pairs =
+ grpc_convert_grpc_to_tsi_cert_pairs(grpc_pairs, num_pairs);
+
+ GPR_ASSERT(tsi_pairs != NULL);
+ for (size_t i = 0; i < num_pairs; i++) {
+ GPR_ASSERT(strncmp(grpc_pairs[i].private_key, tsi_pairs[i].private_key,
+ strlen(grpc_pairs[i].private_key)) == 0);
+ GPR_ASSERT(strncmp(grpc_pairs[i].cert_chain, tsi_pairs[i].cert_chain,
+ strlen(grpc_pairs[i].cert_chain)) == 0);
+ }
+
+ grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_pairs, num_pairs);
+ }
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+
+ test_convert_grpc_to_tsi_cert_pairs();
+
+ grpc_shutdown();
+ return 0;
+}