summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-10-17 13:45:27 +0000
committerGordon Sim <gsim@apache.org>2007-10-17 13:45:27 +0000
commit2b382c2ab784f310d0ed36825668a6368f22a668 (patch)
tree3dc733e109354142fd60350b9da724401bcd5174
parent3bd42ed62494d189cee70087ead1794a4e685a2a (diff)
downloadqpid-python-2b382c2ab784f310d0ed36825668a6368f22a668.tar.gz
Fix to headers exchanges bind: need to check the match value is present before dereferencing
Added tests for this. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@585503 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/broker/HeadersExchange.cpp2
-rw-r--r--qpid/cpp/src/tests/HeadersExchangeTest.cpp16
-rw-r--r--qpid/python/tests_0-10/exchange.py8
3 files changed, 25 insertions, 1 deletions
diff --git a/qpid/cpp/src/qpid/broker/HeadersExchange.cpp b/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
index 55cdb73ac1..215a002517 100644
--- a/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
+++ b/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
@@ -46,7 +46,7 @@ HeadersExchange::HeadersExchange(const std::string& _name, bool _durable, const
bool HeadersExchange::bind(Queue::shared_ptr queue, const string& /*routingKey*/, const FieldTable* args){
RWlock::ScopedWlock locker(lock);
FieldTable::ValuePtr what = args->get(x_match);
- if (*what != all && *what != any) {
+ if (!what || (*what != all && *what != any)) {
THROW_QPID_ERROR(PROTOCOL_ERROR, "Invalid x-match value binding to headers exchange.");
}
Binding binding(*args, queue);
diff --git a/qpid/cpp/src/tests/HeadersExchangeTest.cpp b/qpid/cpp/src/tests/HeadersExchangeTest.cpp
index 14c60449ec..c47266caa6 100644
--- a/qpid/cpp/src/tests/HeadersExchangeTest.cpp
+++ b/qpid/cpp/src/tests/HeadersExchangeTest.cpp
@@ -19,6 +19,7 @@
*
*/
+#include "qpid/QpidError.h"
#include "qpid/broker/HeadersExchange.h"
#include "qpid/framing/FieldTable.h"
#include "qpid/framing/FieldValue.h"
@@ -35,6 +36,7 @@ class HeadersExchangeTest : public CppUnit::TestCase
CPPUNIT_TEST(testMatchEmptyValue);
CPPUNIT_TEST(testMatchEmptyArgs);
CPPUNIT_TEST(testMatchNoXMatch);
+ CPPUNIT_TEST(testBindNoXMatch);
CPPUNIT_TEST_SUITE_END();
public:
@@ -107,6 +109,20 @@ class HeadersExchangeTest : public CppUnit::TestCase
CPPUNIT_ASSERT(!HeadersExchange::match(b, m));
}
+ void testBindNoXMatch()
+ {
+ HeadersExchange exchange("test");
+ Queue::shared_ptr queue;
+ std::string key;
+ FieldTable args;
+ try {
+ //just checking this doesn't cause assertion etc
+ exchange.bind(queue, key, &args);
+ } catch(qpid::QpidError&) {
+ //expected
+ }
+ }
+
};
diff --git a/qpid/python/tests_0-10/exchange.py b/qpid/python/tests_0-10/exchange.py
index 4d8b254df7..86c39b7736 100644
--- a/qpid/python/tests_0-10/exchange.py
+++ b/qpid/python/tests_0-10/exchange.py
@@ -325,3 +325,11 @@ class MiscellaneousErrorsTests(TestBase):
c2.session_open()
c2.exchange_delete(exchange="test_different_declared_type_exchange")
+class ExchangeTests(TestBase):
+ def testHeadersBindNoMatchArg(self):
+ self.channel.queue_declare(queue="q", exclusive=True, auto_delete=True)
+ try:
+ self.channel.queue_bind(queue="q", exchange="amq.match", arguments={"name":"fred" , "age":3} )
+ self.fail("Expected failure for missing x-match arg.")
+ except Closed, e:
+ self.assertConnectionException(541, e.args[0])