Exemple #1
0
def zaqar_to_proton(message):
    """Convert a message retrieved from storage to a Proton message"""
    msg = Message()

    msg.ttl = message.get('ttl')
    msg.body = message.get('body')

    # NOTE(vkmc) This won't work for now - there is no 'amqp10' field yet
    if message.get('amqp10'):
        msg.priority = message.get('amqp10').get('priority')
        msg.first_acquirer = message.get('amqp10').get('first_acquirer')
        msg.delivery_count = message.get('amqp10').get('delivery_count')
        msg.id = message.get('amqp10').get('id'),
        msg.user_id = message.get('amqp10').get('user_id')
        msg.address = message.get('amqp10').get('address')
        msg.subject = message.get('amqp10').get('subject')
        msg.reply_to = message.get('amqp10').get('reply_to')
        msg.correlation_id = message.get('amqp10').get('correlation_id')
        msg.content_type = message.get('amqp10').get('content_type')
        msg.content_encoding = message.get('amqp10').get('content_encoding')
        msg.expiry_time = message.get('amqp10').get('expiry_time')
        msg.creation_time = message.get('amqp10').get('creation_time'),
        msg.group_id = message.get('amqp10').get('group_id')
        msg.group_sequence = message.get('amqp10').get('group_sequence')
        msg.reply_to_group_id = message.get('amqp10').get('reply_to_group_id')
        msg.format = message.get('amqp10').get('format')

    return msg
Exemple #2
0
 def on_sendable(self, event):
     if not self.sent:
         msg = Message()
         msg.address = self.address
         msg.id = '123455'
         msg.user_id = BINARY('testuser')
         msg.subject = 'test-subject'
         msg.content_type = 'text/html; charset=utf-8'
         msg.correlation_id = 89
         msg.creation_time = 1487772623.883
         msg.group_id = "group1"
         msg.reply_to = 'hello_world'
         msg.content_encoding = 'gzip, deflate'
         msg.reply_to_group_id = "group0"
         application_properties = dict()
         application_properties['app-property'] = [10, 20, 30]
         application_properties['some-other'] = symbol("O_one")
         msg.properties = application_properties
         msg.body = u"Hello World!"
         event.sender.send(msg)
         self.sent = True
 def on_sendable(self, event):
     if not self.sent:
         msg = Message()
         msg.address = self.address
         msg.id = '123455'
         msg.user_id = 'testuser'
         msg.subject = 'test-subject'
         msg.content_type = 'text/html; charset=utf-8'
         msg.correlation_id = 89
         msg.creation_time = 1487772623.883
         msg.group_id = "group1"
         msg.reply_to = 'hello_world'
         msg.content_encoding = 'gzip, deflate'
         msg.reply_to_group_id = "group0"
         application_properties = dict()
         application_properties['app-property'] = [10, 20, 30]
         application_properties['some-other'] = symbol("O_one")
         msg.properties = application_properties
         msg.body = u"Hello World!"
         event.sender.send(msg)
         self.sent = True
    def test_message_user_id_proxy_correct_name_allowed(self):
        # Send a message with a good user_id that should be allowed
        M2 = self.messenger()
        M2.route("amqp:/*", self.address(14) + "/$1")

        subscription = M2.subscribe("amqp:/#")

        reply_to = subscription.address
        addr = 'amqp:/_local/$displayname'

        tm = Message()
        rm = Message()
        tm.address = addr
        tm.reply_to = reply_to
        tm.user_id = "anonymous"
        tm.body = {'profilename': 'server-ssl10', 'opcode': 'QUERY',
                   'userid': '94745961c5646ee0129536b3acef1eea0d8d2f26f8c353455233027bcd47'}
        M2.put(tm)

        M2.send()
        M2.recv(1)
        M2.get(rm)
        self.assertEqual('elaine', rm.body['user_name'])
    def test_ssl_user_id(self):
        ssl_opts = dict()
        ssl_opts['ssl-trustfile'] = self.ssl_file('ca-certificate.pem')
        ssl_opts['ssl-certificate'] = self.ssl_file('client-certificate.pem')
        ssl_opts['ssl-key'] = self.ssl_file('client-private-key.pem')
        ssl_opts['ssl-password'] = '******'

        # create the SSL domain object
        domain = self.create_ssl_domain(ssl_opts)

        addr = self.address(0).replace("amqp", "amqps")

        node = Node.connect(addr, ssl_domain=domain)
        user_id = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[0][0]
        self.assertEqual("60f5dbd7ed14a5ea243785e81745ac8463494298",
                         user_id)

        addr = self.address(1).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("7c87f0c974f9e1aa5cb98f13fae9675625f240c98034b888753140da28094879",
                         node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[1][0])

        addr = self.address(2).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("82244216b6d02ffdfb886c8da3c803e0f7a7b330a7b665dccabd30bd25d0f35e2a4fff5f0a2a01d56eb7dbae085c108e71a32b84bab16c9ec243a1f6d014900d",
                         node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[2][0])

        addr = self.address(3).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("7c87f0c974f9e1aa5cb98f13fae9675625f240c98034b888753140da28094879;127.0.0.1;Client;Dev;US;NC",
        node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[3][0])

        addr = self.address(4).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("60f5dbd7ed14a5ea243785e81745ac8463494298;US;NC",
        node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[4][0])

        addr = self.address(5).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("US;NC;82244216b6d02ffdfb886c8da3c803e0f7a7b330a7b665dccabd30bd25d0f35e2a4fff5f0a2a01d56eb7dbae085c108e71a32b84bab16c9ec243a1f6d014900d",
        node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[5][0])

        addr = self.address(6).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("127.0.0.1;NC;Dev;US;Client",
        node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[6][0])

        addr = self.address(7).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("NC;US;Client;Dev;127.0.0.1;Raleigh",
        node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[7][0])

        addr = self.address(8).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("C=US,ST=NC,L=Raleigh,OU=Dev,O=Client,CN=127.0.0.1",
        node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[8][0])

        addr = self.address(9).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        self.assertEqual("C=US,ST=NC,L=Raleigh,OU=Dev,O=Client,CN=127.0.0.1",
        node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[9][0])

        addr = self.address(10).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[10][0]
        self.assertEqual("C=US,ST=NC,L=Raleigh,OU=Dev,O=Client,CN=127.0.0.1", str(user))

        addr = self.address(11).replace("amqp", "amqps")
        node = Node.connect(addr)
        user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[11][0]
        self.assertEqual("anonymous", user)

        addr = self.address(12).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[12][0]
        self.assertEqual("user12", str(user))

        addr = self.address(13).replace("amqp", "amqps")
        node = Node.connect(addr, ssl_domain=domain)
        user_id = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[13][0]
        self.assertEqual("user13", user_id)

        M1 = self.messenger()
        M1.route("amqp:/*", self.address(14)+"/$1")

        subscription = M1.subscribe("amqp:/#")

        reply_to = subscription.address
        addr = 'amqp:/_local/$displayname'

        tm = Message()
        rm = Message()
        tm.address = addr
        tm.reply_to = reply_to
        tm.body = {'profilename': 'server-ssl10', 'opcode': 'QUERY', 'userid': '94745961c5646ee0129536b3acef1eea0d8d2f26f8c353455233027bcd47'}
        M1.put(tm)

        M1.send()
        M1.recv(1)
        M1.get(rm)
        self.assertEqual('elaine', rm.body['user_name'])

        tm = Message()
        rm = Message()
        tm.address = addr
        tm.reply_to = reply_to
        tm.body =  {'profilename': 'server-ssl-unknown', 'opcode': 'QUERY', 'userid': '94745961c5646ee0129536b3acef1eea0d8d2f26f8c3ed08ece4f8f3027bcd48'}
        M1.put(tm)
        M1.send()
        M1.recv(1)
        M1.get(rm)
        self.assertEqual('94745961c5646ee0129536b3acef1eea0d8d2f26f8c3ed08ece4f8f3027bcd48', rm.body['user_name'])

        # The profile name, userid pair have a matching user name
        tm = Message()
        rm = Message()
        tm.address = addr
        tm.reply_to = reply_to
        tm.body = {'profilename': 'server-ssl12', 'opcode': 'QUERY', 'userid': '94745961c5646ee0129536b3acef1eea0d8d2f26f8c3ed08ece4f8f3027bcd48'}
        M1.put(tm)
        M1.send()
        M1.recv(1)
        M1.get(rm)
        self.assertEqual('johndoe', rm.body['user_name'])

        tm = Message()
        rm = Message()
        tm.address = addr
        tm.reply_to = reply_to
        tm.body =  {'profilename': 'server-ssl10', 'opcode': 'QUERY', 'userid': '12345'}
        M1.put(tm)
        M1.send()
        M1.recv(1)
        M1.get(rm)
        self.assertEqual('12345', rm.body['user_name'])

        tm = Message()
        rm = Message()
        tm.address = addr
        tm.reply_to = reply_to
        tm.user_id = "bad-user-id" # policy is disabled; user proxy is allowed
        tm.body = {'profilename': 'server-ssl10', 'opcode': 'QUERY', 'userid': '12345'}
        M1.put(tm)
        M1.send()
        M1.recv(1)
        M1.get(rm)
        self.assertEqual('12345', rm.body['user_name'])

        M1.stop()

        node.close()