Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * 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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 40 | #include "src/core/security/credentials.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | #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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | typedef struct fullstack_secure_fixture_data { |
| 49 | char *localaddr; |
| 50 | } fullstack_secure_fixture_data; |
| 51 | |
| 52 | static 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 | |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 59 | memset(&f, 0, sizeof(f)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 60 | 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 | |
| 69 | static 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 | |
| 78 | static 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; |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 82 | if (f->server) { |
| 83 | grpc_server_destroy(f->server); |
| 84 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 85 | f->server = |
Craig Tiller | 759026c | 2015-02-22 23:09:45 -0800 | [diff] [blame] | 86 | grpc_server_create(f->server_cq, server_args); |
| 87 | GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 88 | grpc_server_credentials_release(server_creds); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 89 | grpc_server_start(f->server); |
| 90 | } |
| 91 | |
| 92 | void 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 | |
| 98 | static 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 | |
| 105 | static 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 | |
| 114 | static grpc_end2end_test_config configs[] = { |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame^] | 115 | {"chttp2/fake_secure_fullstack", |
| 116 | FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | |
| 117 | FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 118 | chttp2_create_fixture_secure_fullstack, |
| 119 | chttp2_init_client_fake_secure_fullstack, |
| 120 | chttp2_init_server_fake_secure_fullstack, |
Craig Tiller | 8ad8a41 | 2015-02-25 08:36:40 -0800 | [diff] [blame] | 121 | chttp2_tear_down_secure_fullstack}, |
| 122 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 123 | |
| 124 | int main(int argc, char **argv) { |
| 125 | size_t i; |
| 126 | grpc_test_init(argc, argv); |
| 127 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 128 | grpc_init(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 129 | |
| 130 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
| 131 | grpc_end2end_tests(configs[i]); |
| 132 | } |
| 133 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 134 | grpc_shutdown(); |
| 135 | |
| 136 | return 0; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 137 | } |