# Path: pymco/exc.py
# class PyMcoException(Exception):
# class ImproperlyConfigured(PyMcoException):
# class ConfigLookupError(PyMcoException):
# class BadFilterFactOperator(PyMcoException):
# class TimeoutError(PyMcoException):
# class VerificationError(PyMcoException):
# 
# Path: pymco/security/ssl.py
# LOG = logging.getLogger(__name__)
# class SSLProvider(SecurityProvider):
#     def __init__(self, config, logger=LOG):
#     def sign(self, msg):
#     def verify(self, msg):
#     def get_hash(self, msg):
#     def callerid(self):
#     def _load_rsa_key(self, key, cache):
#     def server_public_key(self):
#     def private_key(self):
#     def serializer(self):
# 
# Path: pymco/test/utils.py
# def get_template(name, package=__package__):
# def configfile(ctxt=None):


import base64
import os
import pytest
from pymco import exc
from pymco.security import ssl
from pymco.test import ctxt
from pymco.test.utils import mock

@mock.patch('pymco.security.ssl.SSLProvider._load_rsa_key')
def test_private_key_delegates__load_rsa_key(load_rsa_key, ssl_provider):
    assert ssl_provider.private_key == load_rsa_key.return_value
    load_rsa_key.assert_called_once_with(key='plugin.ssl_client_private',
                                         cache=ssl_provider._private_key)


@mock.patch('pymco.config.Config.get_serializer')
def test_serializer_delegates_to_config(get_serializer, ssl_provider):
    assert ssl_provider.serializer == get_serializer.return_value
    get_serializer.assert_called_once_with('plugin.ssl_serializer')


@mock.patch('pymco.security.ssl.SSLProvider.callerid',
            new_callable=mock.PropertyMock)
@mock.patch('pymco.security.ssl.SSLProvider.get_hash')
def test_sign(get_hash, callerid, ssl_provider, msg):
    signed_msg = ssl_provider.sign(msg)
    assert signed_msg[':callerid'] == callerid.return_value
    assert signed_msg[':hash'] == get_hash.return_value

    callerid.asert_called_once_with()
    get_hash.assert_called_once_with(msg)


@mock.patch('base64.b64encode')
@mock.patch('Crypto.Signature.PKCS1_v1_5.new')
@mock.patch('pymco.security.ssl.SSLProvider.private_key',
            new_callable=mock.PropertyMock)

# Path: pymco/exc.py
# class PyMcoException(Exception):
# class ImproperlyConfigured(PyMcoException):
# class ConfigLookupError(PyMcoException):
# class BadFilterFactOperator(PyMcoException):
# class TimeoutError(PyMcoException):
# class VerificationError(PyMcoException):
# 
# Path: pymco/security/ssl.py
# LOG = logging.getLogger(__name__)
# class SSLProvider(SecurityProvider):
#     def __init__(self, config, logger=LOG):
#     def sign(self, msg):
#     def verify(self, msg):
#     def get_hash(self, msg):
#     def callerid(self):
#     def _load_rsa_key(self, key, cache):
#     def server_public_key(self):
#     def private_key(self):
#     def serializer(self):
# 
# Path: pymco/test/utils.py
# def get_template(name, package=__package__):
# def configfile(ctxt=None):


# Path: tests/unit/security/test_ssl.py
import base64
import os
import pytest
from pymco import exc
from pymco.security import ssl
from pymco.test import ctxt
from pymco.test.utils import mock


@mock.patch('pymco.security.ssl.SSLProvider._load_rsa_key')
def test_private_key_delegates__load_rsa_key(load_rsa_key, ssl_provider):
    assert ssl_provider.private_key == load_rsa_key.return_value
    load_rsa_key.assert_called_once_with(key='plugin.ssl_client_private',
                                         cache=ssl_provider._private_key)


@mock.patch('pymco.config.Config.get_serializer')
def test_serializer_delegates_to_config(get_serializer, ssl_provider):
    assert ssl_provider.serializer == get_serializer.return_value
    get_serializer.assert_called_once_with('plugin.ssl_serializer')


@mock.patch('pymco.security.ssl.SSLProvider.callerid',
            new_callable=mock.PropertyMock)
@mock.patch('pymco.security.ssl.SSLProvider.get_hash')
def test_sign(get_hash, callerid, ssl_provider, msg):
    signed_msg = ssl_provider.sign(msg)
    assert signed_msg[':callerid'] == callerid.return_value
    assert signed_msg[':hash'] == get_hash.return_value

    callerid.asert_called_once_with()
    get_hash.assert_called_once_with(msg)


@mock.patch('base64.b64encode')
@mock.patch('Crypto.Signature.PKCS1_v1_5.new')
@mock.patch('pymco.security.ssl.SSLProvider.private_key',
            new_callable=mock.PropertyMock)

@mock.patch('Crypto.Hash.SHA.new')