Exemple #1
0
def _stub(args):
  if args.test_case == 'oauth2_auth_token':
    creds = oauth2client_client.GoogleCredentials.get_application_default()
    scoped_creds = creds.create_scoped([args.oauth_scope])
    access_token = scoped_creds.get_access_token().access_token
    call_creds = implementations.access_token_call_credentials(access_token)
  elif args.test_case == 'compute_engine_creds':
    creds = oauth2client_client.GoogleCredentials.get_application_default()
    scoped_creds = creds.create_scoped([args.oauth_scope])
    call_creds = implementations.google_call_credentials(scoped_creds)
  elif args.test_case == 'jwt_token_creds':
    creds = oauth2client_client.GoogleCredentials.get_application_default()
    call_creds = implementations.google_call_credentials(creds)
  else:
    call_creds = None
  if args.use_tls:
    if args.use_test_ca:
      root_certificates = resources.test_root_certificates()
    else:
      root_certificates = None  # will load default roots.

    channel_creds = implementations.ssl_channel_credentials(root_certificates)
    if call_creds is not None:
      channel_creds = implementations.composite_channel_credentials(
          channel_creds, call_creds)

    channel = test_utilities.not_really_secure_channel(
        args.server_host, args.server_port, channel_creds,
        args.server_host_override)
    stub = test_pb2.beta_create_TestService_stub(channel)
  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.test_case == 'oauth2_auth_token':
        creds = oauth2client_client.GoogleCredentials.get_application_default()
        scoped_creds = creds.create_scoped([args.oauth_scope])
        access_token = scoped_creds.get_access_token().access_token
        call_creds = implementations.access_token_call_credentials(
            access_token)
    elif args.test_case == 'compute_engine_creds':
        creds = oauth2client_client.GoogleCredentials.get_application_default()
        scoped_creds = creds.create_scoped([args.oauth_scope])
        call_creds = implementations.google_call_credentials(scoped_creds)
    else:
        call_creds = None
    if args.use_tls:
        if args.use_test_ca:
            root_certificates = resources.test_root_certificates()
        else:
            root_certificates = None  # will load default roots.

        channel_creds = implementations.ssl_channel_credentials(
            root_certificates)
        if call_creds is not None:
            channel_creds = implementations.composite_channel_credentials(
                channel_creds, call_creds)

        channel = test_utilities.not_really_secure_channel(
            args.server_host, args.server_port, channel_creds,
            args.server_host_override)
        stub = test_pb2.beta_create_TestService_stub(channel)
    else:
        channel = implementations.insecure_channel(args.server_host,
                                                   args.server_port)
        stub = test_pb2.beta_create_TestService_stub(channel)
    return stub
 def test_access_token_call_credentials(self):
     call_creds = implementations.access_token_call_credentials('token')
     self.assertIsInstance(call_creds, implementations.CallCredentials)
 def test_access_token_call_credentials(self):
     call_creds = implementations.access_token_call_credentials('token')
     self.assertIsInstance(call_creds, implementations.CallCredentials)