Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 88e87944c -> 88aeed899


DISPATCH-519: Rejected inbound deliveries do not handle credit

Issue credit to cover the rejected message.
Free the rejected message.
Add self test to demonstrate fix. Note the magic number 250 is
how much credit the router issues.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/88aeed89
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/88aeed89
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/88aeed89

Branch: refs/heads/master
Commit: 88aeed899bc1b27e60ddb101ca2d6a796912e588
Parents: 88e8794
Author: Chuck Rolke <cro...@redhat.com>
Authored: Tue Sep 20 15:46:19 2016 -0400
Committer: Chuck Rolke <cro...@redhat.com>
Committed: Tue Sep 20 15:46:19 2016 -0400

----------------------------------------------------------------------
 src/router_node.c                   |  6 ++++++
 tests/system_tests_user_id_proxy.py | 36 ++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/88aeed89/src/router_node.c
----------------------------------------------------------------------
diff --git a/src/router_node.c b/src/router_node.c
index 115bf2e..7b46873 100644
--- a/src/router_node.c
+++ b/src/router_node.c
@@ -297,8 +297,10 @@ static void AMQP_rx_handler(void* context, qd_link_t 
*link, pn_delivery_t *pnd)
                     if (!qd_field_iterator_equal(userid_iter, (const unsigned 
char *)conn->user_id)) {
                         // This message is rejected: attempted user proxy is 
disallowed
                         qd_log(router->log_source, QD_LOG_DEBUG, "Message 
rejected due to user_id proxy violation. User:%s", conn->user_id);
+                        pn_link_flow(pn_link, 1);
                         pn_delivery_update(pnd, PN_REJECTED);
                         pn_delivery_settle(pnd);
+                        qd_message_free(msg);
                         return;
                     }
                 }
@@ -366,8 +368,10 @@ static void AMQP_rx_handler(void* context, qd_link_t 
*link, pn_delivery_t *pnd)
             //
             // The message is now and will always be unroutable because there 
is no address.
             //
+            pn_link_flow(pn_link, 1);
             pn_delivery_update(pnd, PN_REJECTED);
             pn_delivery_settle(pnd);
+            qd_message_free(msg);
         }
 
         //
@@ -388,8 +392,10 @@ static void AMQP_rx_handler(void* context, qd_link_t 
*link, pn_delivery_t *pnd)
         //
         // Message is invalid.  Reject the message and don't involve the 
router core.
         //
+        pn_link_flow(pn_link, 1);
         pn_delivery_update(pnd, PN_REJECTED);
         pn_delivery_settle(pnd);
+        qd_message_free(msg);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/88aeed89/tests/system_tests_user_id_proxy.py
----------------------------------------------------------------------
diff --git a/tests/system_tests_user_id_proxy.py 
b/tests/system_tests_user_id_proxy.py
index b82617b..3f0e0ed 100644
--- a/tests/system_tests_user_id_proxy.py
+++ b/tests/system_tests_user_id_proxy.py
@@ -311,5 +311,41 @@ class QdSSLUseridProxy(QdSSLUseridTest):
         self.assertEqual('elaine', rm.body['user_name'])
 
 
+    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'] = 'client-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 = u"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.assertTrue(False, "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")
+
+
 if __name__ == '__main__':
     unittest.main(main_module())


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to