Exemple #1
0
def _stub(args):
  if args.oauth_scope:
    if args.test_case == 'oauth2_auth_token':
      # TODO(jtattermusch): This testcase sets the auth metadata key-value
      # manually, which also means that the user would need to do the same
      # thing every time he/she would like to use and out of band oauth token.
      # The transformer function that produces the metadata key-value from
      # the access token should be provided by gRPC auth library.
      access_token = _oauth_access_token(args)
      metadata_transformer = lambda x: [
          ('authorization', 'Bearer %s' % access_token)]
    else:
      metadata_transformer = lambda x: [
          ('authorization', 'Bearer %s' % _oauth_access_token(args))]
  else:
    metadata_transformer = lambda x: []
  if args.use_tls:
    if args.use_test_ca:
      root_certificates = resources.test_root_certificates()
    else:
      root_certificates = resources.prod_root_certificates()

    channel = test_utilities.not_really_secure_channel(
        args.server_host, args.server_port,
        implementations.ssl_client_credentials(root_certificates, None, None),
        args.server_host_override)
    stub = test_pb2.beta_create_TestService_stub(
        channel, metadata_transformer=metadata_transformer)
  else:
    channel = implementations.insecure_channel(
        args.server_host, args.server_port)
    stub = test_pb2.beta_create_TestService_stub(channel)
  return stub
Exemple #2
0
def _stub(args):
    if args.oauth_scope:
        if args.test_case == 'oauth2_auth_token':
            # TODO(jtattermusch): This testcase sets the auth metadata key-value
            # manually, which also means that the user would need to do the same
            # thing every time he/she would like to use and out of band oauth token.
            # The transformer function that produces the metadata key-value from
            # the access token should be provided by gRPC auth library.
            access_token = _oauth_access_token(args)
            metadata_transformer = lambda x: [('authorization', 'Bearer %s' %
                                               access_token)]
        else:
            metadata_transformer = lambda x: [('authorization', 'Bearer %s' %
                                               _oauth_access_token(args))]
    else:
        metadata_transformer = lambda x: []
    if args.use_tls:
        if args.use_test_ca:
            root_certificates = resources.test_root_certificates()
        else:
            root_certificates = resources.prod_root_certificates()

        channel = test_utilities.not_really_secure_channel(
            args.server_host, args.server_port,
            implementations.ssl_client_credentials(root_certificates, None,
                                                   None),
            args.server_host_override)
        stub = test_pb2.beta_create_TestService_stub(
            channel, metadata_transformer=metadata_transformer)
    else:
        channel = implementations.insecure_channel(args.server_host,
                                                   args.server_port)
        stub = test_pb2.beta_create_TestService_stub(channel)
    return stub
Exemple #3
0
 def setUp(self):
   self.server = test_pb2.beta_create_TestService_server(methods.TestService())
   port = self.server.add_secure_port(
       '[::]:0', implementations.ssl_server_credentials(
           [(resources.private_key(), resources.certificate_chain())]))
   self.server.start()
   self.stub = test_pb2.beta_create_TestService_stub(
       test_utilities.not_really_secure_channel(
           '[::]', port, implementations.ssl_client_credentials(
               resources.test_root_certificates(), None, None),
               _SERVER_HOST_OVERRIDE))
 def setUp(self):
   self.server = test_pb2.beta_create_TestService_server(methods.TestService())
   port = self.server.add_insecure_port('[::]:0')
   self.server.start()
   self.stub = test_pb2.beta_create_TestService_stub(
       implementations.insecure_channel('[::]', port))