# 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
      # Purposely end execution here to avoid writing a file.
      with self.assertRaises(ValueError):
        context_config.create_context_config(self.mock_logger)

        mock_open.assert_called_with(context_config._DEFAULT_METADATA_PATH)
        mock_Popen.assert_called_once_with(os.path.realpath('cert helper'),
                                           '--print_certificate',
                                           '--with_passphrase')

  @mock.patch('os.path.exists', new=mock.Mock(return_value=True))
  @mock.patch.object(json, 'load', autospec=True)
  @mock.patch(OPEN_TO_PATCH, new_callable=mock.mock_open)
  def test_default_provider_no_command_error(self, mock_open, mock_json_load):
    mock_json_load.return_value = DEFAULT_CERT_PROVIDER_FILE_NO_COMMAND

    with SetBotoConfigForTest([('Credentials', 'use_client_certificate',
                                'True'),
                               ('Credentials', 'cert_provider_command', None)]):
      context_config.create_context_config(self.mock_logger)

      mock_open.assert_called_with(context_config._DEFAULT_METADATA_PATH)
      self.mock_logger.error.assert_called_once_with(
          "Failed to provision client certificate: "
          "Client certificate provider command not found.")

  @mock.patch('os.path.exists', new=mock.Mock(return_value=False))
  def test_default_provider_not_found_error(self):
    with SetBotoConfigForTest([('Credentials', 'use_client_certificate',
                                'True'),
                               ('Credentials', 'cert_provider_command', None)]):

# 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

      # Purposely end execution here to avoid writing a file.
      with self.assertRaises(ValueError):
        context_config.create_context_config(self.mock_logger)

        mock_open.assert_called_with(context_config._DEFAULT_METADATA_PATH)
        mock_Popen.assert_called_once_with(os.path.realpath('cert helper'),
                                           '--print_certificate',
                                           '--with_passphrase')

  @mock.patch('os.path.exists', new=mock.Mock(return_value=True))
  @mock.patch.object(json, 'load', autospec=True)
  @mock.patch(OPEN_TO_PATCH, new_callable=mock.mock_open)
  def test_default_provider_no_command_error(self, mock_open, mock_json_load):
    mock_json_load.return_value = DEFAULT_CERT_PROVIDER_FILE_NO_COMMAND

    with SetBotoConfigForTest([('Credentials', 'use_client_certificate',
                                'True'),
                               ('Credentials', 'cert_provider_command', None)]):
      context_config.create_context_config(self.mock_logger)

      mock_open.assert_called_with(context_config._DEFAULT_METADATA_PATH)
      self.mock_logger.error.assert_called_once_with(
          "Failed to provision client certificate: "
          "Client certificate provider command not found.")

  @mock.patch('os.path.exists', new=mock.Mock(return_value=False))
  def test_default_provider_not_found_error(self):
    with SetBotoConfigForTest([('Credentials', 'use_client_certificate',
                                'True'),
                               ('Credentials', 'cert_provider_command', None)]):

      context_config.create_context_config(self.mock_logger)