blob: c1ac9163edc6a51618dd4891b66566d1b1f9a90f [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include "test/core/end2end/end2end_tests.h"
35
36#include <stdio.h>
37#include <string.h>
38
39#include "src/core/channel/channel_args.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080040#include "src/core/security/credentials.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080041#include <grpc/support/alloc.h>
42#include <grpc/support/host_port.h>
43#include <grpc/support/log.h>
44#include "test/core/util/test_config.h"
45#include "test/core/util/port.h"
46#include "test/core/end2end/data/ssl_test_data.h"
47
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080048typedef struct fullstack_secure_fixture_data {
49 char *localaddr;
50} fullstack_secure_fixture_data;
51
52static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
53 grpc_channel_args *client_args, grpc_channel_args *server_args) {
54 grpc_end2end_test_fixture f;
55 int port = grpc_pick_unused_port_or_die();
56 fullstack_secure_fixture_data *ffd =
57 gpr_malloc(sizeof(fullstack_secure_fixture_data));
58
ctillerc6d61c42014-12-15 14:52:08 -080059 memset(&f, 0, sizeof(f));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080060 gpr_join_host_port(&ffd->localaddr, "localhost", port);
61
62 f.fixture_data = ffd;
63 f.client_cq = grpc_completion_queue_create();
64 f.server_cq = grpc_completion_queue_create();
65
66 return f;
67}
68
69static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
70 grpc_channel_args *client_args,
71 grpc_credentials *creds) {
72 fullstack_secure_fixture_data *ffd = f->fixture_data;
73 f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args);
74 GPR_ASSERT(f->client != NULL);
75 grpc_credentials_release(creds);
76}
77
78static void chttp2_init_server_secure_fullstack(
79 grpc_end2end_test_fixture *f, grpc_channel_args *server_args,
80 grpc_server_credentials *server_creds) {
81 fullstack_secure_fixture_data *ffd = f->fixture_data;
ctillerc6d61c42014-12-15 14:52:08 -080082 if (f->server) {
83 grpc_server_destroy(f->server);
84 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080085 f->server =
Craig Tiller759026c2015-02-22 23:09:45 -080086 grpc_server_create(f->server_cq, server_args);
87 GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080088 grpc_server_credentials_release(server_creds);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080089 grpc_server_start(f->server);
90}
91
92void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
93 fullstack_secure_fixture_data *ffd = f->fixture_data;
94 gpr_free(ffd->localaddr);
95 gpr_free(ffd);
96}
97
98static void chttp2_init_client_fake_secure_fullstack(
99 grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
100 grpc_credentials *fake_ts_creds =
101 grpc_fake_transport_security_credentials_create();
102 chttp2_init_client_secure_fullstack(f, client_args, fake_ts_creds);
103}
104
105static void chttp2_init_server_fake_secure_fullstack(
106 grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
107 grpc_server_credentials *fake_ts_creds =
108 grpc_fake_transport_security_server_credentials_create();
109 chttp2_init_server_secure_fullstack(f, server_args, fake_ts_creds);
110}
111
112/* All test configurations */
113
114static grpc_end2end_test_config configs[] = {
Julien Boeuf9f218dd2015-04-23 10:24:02 -0700115 {"chttp2/fake_secure_fullstack",
116 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
117 FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS,
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800118 chttp2_create_fixture_secure_fullstack,
119 chttp2_init_client_fake_secure_fullstack,
120 chttp2_init_server_fake_secure_fullstack,
Craig Tiller8ad8a412015-02-25 08:36:40 -0800121 chttp2_tear_down_secure_fullstack},
122};
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800123
124int main(int argc, char **argv) {
125 size_t i;
126 grpc_test_init(argc, argv);
127
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800128 grpc_init();
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800129
130 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
131 grpc_end2end_tests(configs[i]);
132 }
133
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800134 grpc_shutdown();
135
136 return 0;
Craig Tiller190d3602015-02-18 09:23:38 -0800137}