示例#1
0
    def test_open(self, connection, find, add_transports, ssl_domain):
        url = TEST_URL
        connector = Connector(url)
        connector.ssl.ca_certificate = 'test-ca'
        connector.ssl.client_key = 'test-key'
        connector.ssl.client_certificate = 'test-crt'
        connector.heartbeat = '4'
        find.return_value = connector

        ssl_properties = {'A': 1, 'B': 2}
        ssl_domain.return_value = ssl_properties

        # test
        c = Connection(url)
        c._ssh = Mock()
        c.open()

        # validation
        add_transports.assert_called_once_with()
        connection.assert_called_once_with(host=connector.host,
                                           port=connector.port,
                                           tcp_nodelay=True,
                                           transport=connector.scheme,
                                           username=connector.userid,
                                           password=connector.password,
                                           heartbeat=connector.heartbeat,
                                           **ssl_properties)

        ssl_domain.assert_called_once_with(connector)
        c._impl.open.assert_called_once_with()
        self.assertEqual(c._impl, connection.return_value)
示例#2
0
 def test_use_ssl(self):
     # False
     connector = Connector('amqp://localhost')
     self.assertFalse(connector.use_ssl())
     # True by port
     connector = Connector('amqps://localhost')
     self.assertTrue(connector.use_ssl())
示例#3
0
    def test_open(self, connection, find, add_transports, ssl_domain):
        url = TEST_URL
        connector = Connector(url)
        connector.ssl.ca_certificate = 'test-ca'
        connector.ssl.client_key = 'test-key'
        connector.ssl.client_certificate = 'test-crt'
        connector.heartbeat = '4'
        find.return_value = connector

        ssl_properties = {'A': 1, 'B': 2}
        ssl_domain.return_value = ssl_properties

        # test
        c = Connection(url)
        c._ssh = Mock()
        c.open()

        # validation
        add_transports.assert_called_once_with()
        connection.assert_called_once_with(
            host=connector.host,
            port=connector.port,
            tcp_nodelay=True,
            transport=connector.scheme,
            username=connector.userid,
            password=connector.password,
            heartbeat=connector.heartbeat,
            **ssl_properties)

        ssl_domain.assert_called_once_with(connector)
        c._impl.open.assert_called_once_with()
        self.assertEqual(c._impl, connection.return_value)
示例#4
0
    def test_open(self, connection, ssl_domain, find):
        url = TEST_URL
        connector = Connector(url)
        connector.ssl.ca_certificate = 'test-ca'
        connector.ssl.client_key = 'test-key'
        connector.ssl.client_certificate = 'test-crt'
        find.return_value = connector

        # test
        c = Connection(url)
        c._ssh = Mock()
        c.open()

        # validation
        ssl_domain.assert_called_once_with(connector)
        connection.assert_called_once_with(
            host=':'.join((connector.host, str(connector.port))),
            virtual_host=connector.virtual_host,
            userid=connector.userid,
            password=connector.password,
            ssl=ssl_domain.return_value,
            confirm_publish=True)

        connection.return_value.connect.assert_called_once_with()
        self.assertEqual(c._impl, connection.return_value)
示例#5
0
 def test_str(self):
     url = TEST_URL
     b = Connector(url)
     b.ssl.ca_certificate = 'test-ca'
     b.ssl.client_key = 'test-key'
     b.ssl.client_certificate = 'test-cert'
     self.assertEqual(
         str(b), 'URL: amqp://elmer:[email protected]|SSL: ca: test-ca|'
         'key: test-key|certificate: test-cert|host-validation: False')
示例#6
0
    def test_ssl_not_ssl(self):
        url = 'amqp://*****:*****@redhat.com:1234'

        # test
        b = Connector(url)
        ssl = Connection.ssl_domain(b)

        self.assertEqual(str(b.url), url)

        # validation
        self.assertEqual(ssl, None)
示例#7
0
 def test_use_ssl(self):
     # False
     connector = Connector('amqp://localhost')
     self.assertFalse(connector.use_ssl())
     # True by port
     connector = Connector('amqps://localhost')
     self.assertTrue(connector.use_ssl())
示例#8
0
 def open(self):
     """
     Open a connection to the broker.
     """
     if self.is_open():
         # already open
         return
     connector = Connector.find(self.url)
     domain = self.ssl_domain(connector)
     log.info('open: %s', connector)
     self._impl = BlockingConnection(connector.url.canonical,
                                     ssl_domain=domain)
     log.info('opened: %s', self.url)
示例#9
0
 def open(self):
     """
     Open a connection to the broker.
     """
     if self.is_open():
         # already open
         return
     connector = Connector.find(self.url)
     domain = self.ssl_domain(connector)
     log.info('open: %s', connector)
     self._impl = BlockingConnection(
         connector.url.canonical,
         heartbeat=connector.heartbeat,
         ssl_domain=domain)
     log.info('opened: %s', self.url)
示例#10
0
 def test_init(self):
     url = TEST_URL
     b = Connector(url)
     self.assertEqual(b.url, URL(url))
     self.assertEqual(b.adapter, URL(url).adapter)
     self.assertEqual(b.scheme, URL(url).scheme)
     self.assertEqual(b.host, URL(url).host)
     self.assertEqual(b.port, URL(url).port)
     self.assertEqual(b.userid, URL(url).userid)
     self.assertEqual(b.password, URL(url).password)
     self.assertEqual(b.virtual_host, URL(url).path)
     self.assertEqual(b.ssl.ca_certificate, None)
     self.assertEqual(b.ssl.client_key, None)
     self.assertEqual(b.ssl.client_certificate, None)
     self.assertFalse(b.ssl.host_validation)
示例#11
0
    def test_ssl_no_certs(self):
        url = TEST_URL

        # test
        b = Connector(url)
        ssl = Connection.ssl_domain(b)

        # validation
        self.assertEqual(
            ssl,
            {
                'ca_certs': None,
                'certfile': None,
                'keyfile': None,
                'cert_reqs': 0
            })
示例#12
0
    def test_ssl_domain(self, validate):
        url = TEST_URL

        # test
        b = Connector(url)
        b.ssl.ca_certificate = 'test-ca'
        b.ssl.client_key = 'test-key'
        b.ssl.client_certificate = 'test-crt'
        ssl = Connection.ssl_domain(b)

        # validation
        validate.assert_called_once_with()
        self.assertEqual(
            ssl, {
                'ssl_trustfile': b.ssl.ca_certificate,
                'ssl_keyfile': b.ssl.client_key,
                'ssl_certfile': b.ssl.client_certificate,
                'ssl_skip_hostname_check': (not b.ssl.host_validation)
            })
示例#13
0
    def test_ssl_domain(self, validate):
        url = TEST_URL

        # test
        b = Connector(url)
        b.ssl.ca_certificate = 'test-ca'
        b.ssl.client_key = 'test-key'
        b.ssl.client_certificate = 'test-crt'
        ssl = Connection.ssl_domain(b)

        # validation
        validate.assert_called_once_with()
        self.assertEqual(
            ssl,
            {
                'ca_certs': b.ssl.ca_certificate,
                'cert_reqs': 2,
                'certfile': b.ssl.client_certificate,
                'keyfile': b.ssl.client_key
            })
示例#14
0
 def open(self):
     """
     Open a connection to the broker.
     """
     if self.is_open():
         # already open
         return
     connector = Connector.find(self.url)
     host = ':'.join((connector.host, utf8(connector.port)))
     virtual_host = connector.virtual_host or VIRTUAL_HOST
     domain = self.ssl_domain(connector)
     userid = connector.userid or USERID
     password = connector.password or PASSWORD
     log.info('open: %s', connector)
     self._impl = RealConnection(host=host,
                                 virtual_host=virtual_host,
                                 ssl=domain,
                                 userid=userid,
                                 password=password,
                                 confirm_publish=True)
     log.info('opened: %s', self.url)
示例#15
0
    def test_ssl_domain(self, ssl_domain, validate):
        ssl_domain.MODE_CLIENT = 0x01
        ssl_domain.VERIFY_PEER = 0x02
        ssl_domain.VERIFY_PEER_NAME = 0x03
        connector = Connector('amqps://localhost')
        connector.ssl.ca_certificate = 'ca'
        connector.ssl.client_certificate = 'client'
        connector.ssl.client_key = 'key'

        # test
        domain = Connection.ssl_domain(connector)

        # validation
        validate.assert_called_once_with()
        ssl_domain.assert_called_once_with(ssl_domain.MODE_CLIENT)
        domain.set_trusted_ca_db.assert_called_once_with(
            connector.ssl.ca_certificate)
        domain.set_credentials.assert_called_once_with(
            connector.ssl.client_certificate, connector.ssl.client_key, None)
        domain.set_peer_authentication.assert_called_once_with(
            ssl_domain.VERIFY_PEER)
示例#16
0
 def open(self):
     """
     Open a connection to the broker.
     """
     if self.is_open():
         # already open
         return
     connector = Connector.find(self.url)
     host = ':'.join((connector.host, utf8(connector.port)))
     virtual_host = connector.virtual_host or VIRTUAL_HOST
     domain = self.ssl_domain(connector)
     userid = connector.userid or USERID
     password = connector.password or PASSWORD
     log.info('open: %s', connector)
     self._impl = RealConnection(
         host=host,
         virtual_host=virtual_host,
         ssl=domain,
         userid=userid,
         password=password,
         confirm_publish=True)
     log.info('opened: %s', self.url)
示例#17
0
 def open(self):
     """
     Open a connection to the broker.
     """
     if self.is_open():
         # already open
         return
     connector = Connector.find(self.url)
     Connection.add_transports()
     domain = self.ssl_domain(connector)
     log.info('open: %s', connector)
     impl = RealConnection(host=connector.host,
                           port=connector.port,
                           tcp_nodelay=True,
                           transport=connector.url.scheme,
                           username=connector.userid,
                           password=connector.password,
                           heartbeat=10,
                           **domain)
     impl.open()
     self._impl = impl
     log.info('opened: %s', self.url)
示例#18
0
 def open(self):
     """
     Open a connection to the broker.
     """
     if self.is_open():
         # already open
         return
     connector = Connector.find(self.url)
     Connection.add_transports()
     domain = self.ssl_domain(connector)
     log.info('open: %s', connector)
     impl = RealConnection(
         host=connector.host,
         port=connector.port,
         tcp_nodelay=True,
         transport=connector.url.scheme,
         username=connector.userid,
         password=connector.password,
         heartbeat=10,
         **domain)
     impl.open()
     self._impl = impl
     log.info('opened: %s', self.url)
示例#19
0
 def test_add(self, add):
     connector = Connector('amqp://localhost')
     connector.add()
     add.assert_called_once_with(connector)
示例#20
0
 def test_domain_id(self):
     url = 'adapter+amqp://localhost'
     b = Connector(url)
     self.assertEqual(b.domain_id, 'amqp://localhost')
示例#21
0
 def test_find(self, find):
     url = 'amqp://localhost'
     found = Connector.find(url)
     find.assert_called_once_with(URL(url).canonical)
     self.assertEqual(found, find.return_value)
示例#22
0
 def test_find(self, find):
     url = 'amqp://localhost'
     found = Connector.find(url)
     find.assert_called_once_with(URL(url).canonical)
     self.assertEqual(found, find.return_value)
示例#23
0
 def test_add(self, add):
     connector = Connector('amqp://localhost')
     connector.add()
     add.assert_called_once_with(connector)