def stream(self):
     self.sender1.stream(BINARY(self.long_data))
     self.sent_stream += len(self.long_data)
     if self.sent_stream >= 1000000:
         self.streaming = False
         self.sender1.close()
         self.send()
    def test_message_user_id_proxy_bad_name_disallowed(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)

        # Send a message with bad user_id. This message should be rejected.
        # Connection has user_id 'user13'.
        addr = self.address(13).replace("amqp", "amqps")
        blocking_connection = BlockingConnection(addr, ssl_domain=domain)
        blocking_sender = blocking_connection.create_sender("$management")

        request = proton.Message()
        request.user_id = BINARY("bad-user-id")

        result = Delivery.ACCEPTED
        try:
            delivery = blocking_sender.send(request, timeout=10)
            result = delivery.remote_state
        except proton.utils.SendException as e:
            result = e.state

        self.assertTrue(
            result == Delivery.REJECTED,
            "Router accepted a message with user_id that did not match connection user_id"
        )
Exemple #3
0
    def test_message_user_id_proxy_zzz_credit_handled(self):
        # Test for DISPATCH-519. Make sure the REJECTED messages result
        # in the client receiving credit.
        credit_limit = 250   # router issues 250 credits
        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)

        # Send a message with bad user_id. This message should be rejected.
        # Connection has user_id 'user13'.
        addr = self.address(13).replace("amqp", "amqps")
        blocking_connection = BlockingConnection(addr, ssl_domain=domain)
        blocking_sender = blocking_connection.create_sender("$management")

        request = proton.Message()
        request.user_id = BINARY("bad-user-id")

        for i in range(0, credit_limit + 1):
            result = Delivery.ACCEPTED
            try:
                delivery = blocking_sender.send(request, timeout=10)
                result = delivery.remote_state
            except proton.utils.SendException as e:
                result = e.state
            except proton.utils.Timeout as e:
                self.fail("Timed out waiting for send credit")

            self.assertTrue(result == Delivery.REJECTED,
                            "Router accepted a message with user_id that did not match connection user_id")
Exemple #4
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 test_dummy(self):
        """Test all operations on the dummy test entity"""
        entity = self.node.read(type=LISTENER, name='l0')
        self.assertEqual('l0', entity.name)
        self.assertEqual(str(self.router.ports[0]), entity.port)

        entity = self.node.read(type=LISTENER,
                                identity='listener/0.0.0.0:%s:l1' %
                                self.router.ports[1])
        self.assertEqual('l1', entity.name)
        self.assertEqual(str(self.router.ports[1]), entity.port)

        # Bad type
        self.assertRaises(BadRequestStatus,
                          self.node.read,
                          type=CONNECTOR,
                          name='l0')

        # Unknown entity
        self.assertRaises(NotFoundStatus,
                          self.node.read,
                          type=LISTENER,
                          name='nosuch')

        # Update is not allowed by the schema
        self.assertRaises(NotImplementedStatus, entity.update)

        # Non-standard request is not allowed by schema.
        self.assertRaises(NotImplementedStatus,
                          entity.call,
                          'nosuchop',
                          foo="bar")

        # Dummy entity supports all CRUD operations
        dummy = self.node.create(
            {'arg1': 'START'},
            type=DUMMY,
            name='MyDummy',
        )
        self.assertEqual(dummy.type, DUMMY)
        self.assertEqual(dummy.name, 'MyDummy')
        self.assertEqual(dummy.arg1, 'START')
        identity = dummy.identity
        self.assertEqual(
            dict(type=DUMMY, identity=identity, name='MyDummy', arg1='START'),
            dummy.attributes)

        dummy.attributes['num1'] = 42
        dummy.arg1 = 'one'
        self.assertEqual(
            dict(type=DUMMY,
                 identity=identity,
                 name='MyDummy',
                 arg1='one',
                 num1=42), dummy.attributes)
        dummy.update()

        dummy.attributes.update(dict(arg1='x', num1=0))
        dummy.read()
        self.assertEqual(
            dict(type=DUMMY,
                 name='MyDummy',
                 identity=identity,
                 arg1='one',
                 num1=42), dummy.attributes)

        dummy2 = self.node.read(type=DUMMY, name='MyDummy')
        self.assertEqual(dummy.attributes, dummy2.attributes)

        integers = [0, 1, 42, (2**63) - 1, -1, -42, -(2**63)]
        test_data = [BINARY("bytes"), "string"] + integers
        for data in test_data:
            try:
                self.assertEqual(
                    {
                        'operation': 'callme',
                        'type': DUMMY,
                        'identity': identity,
                        'data': data
                    }, dummy.call('callme', data=data))
            except TypeError as exc:
                raise TypeError("data=%r: %s" % (data, exc))

        dummy.badattribute = 'Bad'
        self.assertRaises(BadRequestStatus, dummy.update)

        dummy.delete()
        self.assertRaises(NotFoundStatus,
                          self.node.read,
                          type=DUMMY,
                          name='MyDummy')