Exemplo n.º 1
0
    def _connect(self, connection, reactor):
        assert (reactor is not None)
        url = self.address.next()
        reactor.set_connection_host(connection, url.host, str(url.port))
        # if virtual-host not set, use host from address as default
        if self.virtual_host is None:
            connection.hostname = url.host
        log.debug("connecting to %s..." % url)

        transport = Transport()
        if self.sasl_enabled:
            sasl = transport.sasl()
            sasl.allow_insecure_mechs = self.allow_insecure_mechs
            if url.username:
                connection.user = url.username
            elif self.user:
                connection.user = self.user
            if url.password:
                connection.password = url.password
            elif self.password:
                connection.password = self.password
            if self.allowed_mechs:
                sasl.allowed_mechs(self.allowed_mechs)
        transport.bind(connection)
        if self.heartbeat:
            transport.idle_timeout = self.heartbeat
        if url.scheme == 'amqps':
            if not self.ssl_domain:
                raise SSLUnavailable("amqps: SSL libraries not found")
            self.ssl = SSL(transport, self.ssl_domain)
            self.ssl.peer_hostname = self.ssl_sni or self.virtual_host or url.host
        if self.max_frame_size:
            transport.max_frame_size = self.max_frame_size
Exemplo n.º 2
0
 def listen(self, url, ssl_domain=None):
     """
     Initiates a server socket, accepting incoming AMQP connections
     on the interface and port specified.
     """
     url = Url(url)
     acceptor = self.acceptor(url.host, url.port)
     ssl_config = ssl_domain
     if not ssl_config and url.scheme == 'amqps':
         # use container's default server domain
         if self.ssl:
             ssl_config = self.ssl.server
         else:
             raise SSLUnavailable("amqps: SSL libraries not found")
     if ssl_config:
         acceptor.set_ssl_domain(ssl_config)
     return acceptor
Exemplo n.º 3
0
http://opensource.org/licenses/BSD-3-Clause

Details on EUROCONTROL: http://www.eurocontrol.int
"""
import logging
from unittest import mock

import pytest
from proton import SSLUnavailable, SSLDomain

from swim_pubsub.core import utils

__author__ = "EUROCONTROL (SWIM)"


@mock.patch('proton.SSLDomain.__init__', side_effect=SSLUnavailable('SSL unavailable'))
def test__get_ssl_domain__sslunavailable__returns_none_and_logs_a_warning(mock_ssldomain, caplog):
    caplog.set_level(logging.DEBUG)

    ssl_domain = utils._get_ssl_domain(SSLDomain.VERIFY_PEER)

    assert ssl_domain is None
    assert 'SSL unavailable' == caplog.messages[0]


def test__get_ssl_domain():
    ssl_domain = utils._get_ssl_domain(SSLDomain.VERIFY_PEER)

    assert isinstance(ssl_domain, SSLDomain)