# Path: gslib/context_config.py
# _DEFAULT_METADATA_PATH = os.path.expanduser(
#     os.path.join('~', '.secureConnect', 'context_aware_metadata.json'))
# _CERT_PROVIDER_COMMAND = "cert_provider_command"
# _CERT_PROVIDER_COMMAND_PASSPHRASE_OPTION = "--with_passphrase"
# class CertProvisionError(Exception):
# class ContextConfigSingletonAlreadyExistsError(Exception):
# class _ContextConfig(object):
# def _is_pem_section_marker(line):
# def _split_pem_into_sections(contents, logger):
# def _check_path():
# def _read_metadata_file(metadata_path):
# def _default_command():
#   def __init__(self, logger):
#   def _provision_client_cert(self, cert_path):
#   def _unprovision_client_cert(self):
# def create_context_config(logger):
# def get_context_config():
# 
# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):


import json
import os
import subprocess
import six
from unittest import mock
from gslib import context_config
from gslib import exception
from gslib.tests import testcase
from gslib.tests.testcase import base
from gslib.tests.util import SetBotoConfigForTest
  @mock.patch.object(subprocess, 'Popen')
  def test_converts_and_logs_provisioning_cert_provider_unexpected_exit_error(
      self, mock_Popen):
    mock_command_process = mock.Mock()
    mock_command_process.communicate.return_value = (None, 'oh no')
    mock_Popen.return_value = mock_command_process

    with SetBotoConfigForTest([
        ('Credentials', 'use_client_certificate', 'True'),
        ('Credentials', 'cert_provider_command', 'some/path')
    ]):
      context_config.create_context_config(self.mock_logger)
      self.mock_logger.error.assert_called_once_with(
          'Failed to provision client certificate: oh no')

  @mock.patch.object(subprocess, 'Popen')
  def test_converts_and_logs_provisioning_os_error(self, mock_Popen):
    mock_Popen.side_effect = OSError('foobar')

    with SetBotoConfigForTest([
        ('Credentials', 'use_client_certificate', 'True'),
        ('Credentials', 'cert_provider_command', 'some/path')
    ]):
      context_config.create_context_config(self.mock_logger)
      self.mock_logger.error.assert_called_once_with(
          'Failed to provision client certificate: foobar')

  @mock.patch.object(subprocess, 'Popen')
  def test_converts_and_logs_provisioning_external_binary_error(
      self, mock_Popen):

# Path: gslib/context_config.py
# _DEFAULT_METADATA_PATH = os.path.expanduser(
#     os.path.join('~', '.secureConnect', 'context_aware_metadata.json'))
# _CERT_PROVIDER_COMMAND = "cert_provider_command"
# _CERT_PROVIDER_COMMAND_PASSPHRASE_OPTION = "--with_passphrase"
# class CertProvisionError(Exception):
# class ContextConfigSingletonAlreadyExistsError(Exception):
# class _ContextConfig(object):
# def _is_pem_section_marker(line):
# def _split_pem_into_sections(contents, logger):
# def _check_path():
# def _read_metadata_file(metadata_path):
# def _default_command():
#   def __init__(self, logger):
#   def _provision_client_cert(self, cert_path):
#   def _unprovision_client_cert(self):
# def create_context_config(logger):
# def get_context_config():
# 
# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):


# Path: gslib/tests/test_context_config.py
import json
import os
import subprocess
import six
from unittest import mock
from gslib import context_config
from gslib import exception
from gslib.tests import testcase
from gslib.tests.testcase import base
from gslib.tests.util import SetBotoConfigForTest

  @mock.patch.object(subprocess, 'Popen')
  def test_converts_and_logs_provisioning_cert_provider_unexpected_exit_error(
      self, mock_Popen):
    mock_command_process = mock.Mock()
    mock_command_process.communicate.return_value = (None, 'oh no')
    mock_Popen.return_value = mock_command_process

    with SetBotoConfigForTest([
        ('Credentials', 'use_client_certificate', 'True'),
        ('Credentials', 'cert_provider_command', 'some/path')
    ]):
      context_config.create_context_config(self.mock_logger)
      self.mock_logger.error.assert_called_once_with(
          'Failed to provision client certificate: oh no')

  @mock.patch.object(subprocess, 'Popen')
  def test_converts_and_logs_provisioning_os_error(self, mock_Popen):
    mock_Popen.side_effect = OSError('foobar')

    with SetBotoConfigForTest([
        ('Credentials', 'use_client_certificate', 'True'),
        ('Credentials', 'cert_provider_command', 'some/path')
    ]):
      context_config.create_context_config(self.mock_logger)
      self.mock_logger.error.assert_called_once_with(
          'Failed to provision client certificate: foobar')

  @mock.patch.object(subprocess, 'Popen')
  def test_converts_and_logs_provisioning_external_binary_error(
      self, mock_Popen):

    mock_Popen.side_effect = exception.ExternalBinaryError('foobar')