LCOV - code coverage report
Current view: top level - test/core/end2end/fixtures - h2_fakesec.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 58 58 100.0 %
Date: 2015-10-10 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       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"
      40             : #include "src/core/security/credentials.h"
      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             : 
      48             : typedef struct fullstack_secure_fixture_data {
      49             :   char *localaddr;
      50             : } fullstack_secure_fixture_data;
      51             : 
      52          84 : 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          84 :   int port = grpc_pick_unused_port_or_die();
      56          84 :   fullstack_secure_fixture_data *ffd =
      57             :       gpr_malloc(sizeof(fullstack_secure_fixture_data));
      58             : 
      59          84 :   memset(&f, 0, sizeof(f));
      60          84 :   gpr_join_host_port(&ffd->localaddr, "localhost", port);
      61             : 
      62          84 :   f.fixture_data = ffd;
      63          84 :   f.cq = grpc_completion_queue_create(NULL);
      64             : 
      65          84 :   return f;
      66             : }
      67             : 
      68           1 : static void process_auth_failure(void *state, grpc_auth_context *ctx,
      69             :                                  const grpc_metadata *md, size_t md_count,
      70             :                                  grpc_process_auth_metadata_done_cb cb,
      71             :                                  void *user_data) {
      72           1 :   GPR_ASSERT(state == NULL);
      73           1 :   cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL);
      74           1 : }
      75             : 
      76          84 : static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
      77             :                                                 grpc_channel_args *client_args,
      78             :                                                 grpc_credentials *creds) {
      79          84 :   fullstack_secure_fixture_data *ffd = f->fixture_data;
      80          84 :   f->client =
      81          84 :       grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL);
      82          84 :   GPR_ASSERT(f->client != NULL);
      83          84 :   grpc_credentials_release(creds);
      84          84 : }
      85             : 
      86          85 : static void chttp2_init_server_secure_fullstack(
      87             :     grpc_end2end_test_fixture *f, grpc_channel_args *server_args,
      88             :     grpc_server_credentials *server_creds) {
      89          85 :   fullstack_secure_fixture_data *ffd = f->fixture_data;
      90          85 :   if (f->server) {
      91           1 :     grpc_server_destroy(f->server);
      92             :   }
      93          85 :   f->server = grpc_server_create(server_args, NULL);
      94          85 :   grpc_server_register_completion_queue(f->server, f->cq, NULL);
      95          85 :   GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
      96             :                                                server_creds));
      97          85 :   grpc_server_credentials_release(server_creds);
      98          85 :   grpc_server_start(f->server);
      99          85 : }
     100             : 
     101          84 : void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
     102          84 :   fullstack_secure_fixture_data *ffd = f->fixture_data;
     103          84 :   gpr_free(ffd->localaddr);
     104          84 :   gpr_free(ffd);
     105          84 : }
     106             : 
     107          84 : static void chttp2_init_client_fake_secure_fullstack(
     108             :     grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
     109          84 :   grpc_credentials *fake_ts_creds =
     110             :       grpc_fake_transport_security_credentials_create();
     111          84 :   chttp2_init_client_secure_fullstack(f, client_args, fake_ts_creds);
     112          84 : }
     113             : 
     114          85 : static int fail_server_auth_check(grpc_channel_args *server_args) {
     115             :   size_t i;
     116          85 :   if (server_args == NULL) return 0;
     117          19 :   for (i = 0; i < server_args->num_args; i++) {
     118          10 :     if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
     119             :         0) {
     120           1 :       return 1;
     121             :     }
     122             :   }
     123           9 :   return 0;
     124             : }
     125             : 
     126          85 : static void chttp2_init_server_fake_secure_fullstack(
     127             :     grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
     128          85 :   grpc_server_credentials *fake_ts_creds =
     129             :       grpc_fake_transport_security_server_credentials_create();
     130          85 :   if (fail_server_auth_check(server_args)) {
     131           1 :     grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL};
     132           1 :     grpc_server_credentials_set_auth_metadata_processor(fake_ts_creds,
     133             :                                                         processor);
     134             :   }
     135          85 :   chttp2_init_server_secure_fullstack(f, server_args, fake_ts_creds);
     136          85 : }
     137             : 
     138             : /* All test configurations */
     139             : 
     140             : static grpc_end2end_test_config configs[] = {
     141             :     {"chttp2/fake_secure_fullstack",
     142             :      FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
     143             :          FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS,
     144             :      chttp2_create_fixture_secure_fullstack,
     145             :      chttp2_init_client_fake_secure_fullstack,
     146             :      chttp2_init_server_fake_secure_fullstack,
     147             :      chttp2_tear_down_secure_fullstack},
     148             : };
     149             : 
     150          33 : int main(int argc, char **argv) {
     151             :   size_t i;
     152          33 :   grpc_test_init(argc, argv);
     153             : 
     154          33 :   grpc_init();
     155             : 
     156          66 :   for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
     157          33 :     grpc_end2end_tests(configs[i]);
     158             :   }
     159             : 
     160          33 :   grpc_shutdown();
     161             : 
     162          33 :   return 0;
     163             : }

Generated by: LCOV version 1.10