def test_complete_insecure(self):
        transport = {
            'username': '******',
            'password': '******',
            'hostname': 'example.com',
            'port': 2345,
            'virtual_host': 'virtual',
        }

        result = rpc_driver.unparse_transport_url(transport, False)

        self.assertEqual(result, "rabbit://[email protected]:2345/virtual")
def upgrade_cell_data(table):
    # List of database columns
    columns = ['id', 'username', 'password', 'rpc_host', 'rpc_port',
               'rpc_virtual_host']

    # List of names to give the data from those columns; the fields
    # are chosen so that the dictionary matches that expected by
    # unparse_transport_url()
    fields = ['id', 'username', 'password', 'hostname', 'port', 'virtual_host']

    query = select([get_column(table, c) for c in columns])
    for row in [dict(zip(fields, result)) for result in query.execute()]:
        # Compute the transport URL
        url = rpc_driver.unparse_transport_url(row)

        # Store the transport URL in the database
        table.update().where(table.c.id == row['id']).\
            values(transport_url=url).execute()
Beispiel #3
0
    def _normalize_cell(self, cell, existing=None):
        """
        Normalize input cell data.  Normalizations include:

        * Converting cell['type'] to is_parent boolean.
        * Merging existing transport URL with transport information.
        """

        # Start with the cell type conversion
        if 'type' in cell:
            self._validate_cell_type(cell['type'])
            cell['is_parent'] = cell['type'] == 'parent'
            del cell['type']
        # Avoid cell type being overwritten to 'child'
        elif existing:
            cell['is_parent'] = existing['is_parent']
        else:
            cell['is_parent'] = False

        # Now we disassemble the existing transport URL...
        transport = {}
        if existing and 'transport_url' in existing:
            transport = rpc_driver.parse_transport_url(
                existing['transport_url'])

        # Copy over the input fields
        transport_field_map = {
            'username': '******',
            'password': '******',
            'hostname': 'rpc_host',
            'port': 'rpc_port',
            'virtual_host': 'rpc_virtual_host',
        }
        for key, input_field in transport_field_map.items():
            # Set the default value of the field; using setdefault()
            # lets us avoid overriding the existing transport URL
            transport.setdefault(key, None)

            # Only override the value if we're given an override
            if input_field in cell:
                transport[key] = cell.pop(input_field)

        # Now set the transport URL
        cell['transport_url'] = rpc_driver.unparse_transport_url(transport)
Beispiel #4
0
 def insecure_transport_url(url):
     transport = rpc_driver.parse_transport_url(url)
     return rpc_driver.unparse_transport_url(transport, False)
    def test_port_only(self):
        result = rpc_driver.unparse_transport_url({'port': 2345})

        self.assertEqual(result, "rabbit://:2345/")
    def test_virtual_host_only(self):
        result = rpc_driver.unparse_transport_url({'virtual_host': 'virtual/'})

        self.assertEqual(result, "rabbit:///virtual%2F")
    def test_hostname_v6_only(self):
        result = rpc_driver.unparse_transport_url({'hostname': 'ffff::1'})

        self.assertEqual(result, "rabbit://[ffff::1]/")
    def test_hostname_only(self):
        result = rpc_driver.unparse_transport_url({'hostname': 'example.com'})

        self.assertEqual(result, "rabbit://example.com/")
    def test_password_only(self):
        result = rpc_driver.unparse_transport_url({'password': '******'})

        self.assertEqual(result, "rabbit://:pass%[email protected]/")
    def test_username_only(self):
        result = rpc_driver.unparse_transport_url({'username': '******'})

        self.assertEqual(result, "rabbit://user%[email protected]/")
    def test_empty(self):
        result = rpc_driver.unparse_transport_url({})

        self.assertEqual(result, "rabbit:///")