diff options
| -rw-r--r-- | cpp/src/qpid/cluster/Connection.cpp | 14 | ||||
| -rw-r--r-- | cpp/src/tests/Makefile.am | 6 | ||||
| -rwxr-xr-x | cpp/src/tests/cluster_tests.py | 12 | ||||
| -rwxr-xr-x | cpp/src/tests/sasl_test_setup.sh | 3 | ||||
| -rw-r--r-- | python/qpid/brokertest.py | 16 |
5 files changed, 37 insertions, 14 deletions
diff --git a/cpp/src/qpid/cluster/Connection.cpp b/cpp/src/qpid/cluster/Connection.cpp index 18d0e0e599..0772215b83 100644 --- a/cpp/src/qpid/cluster/Connection.cpp +++ b/cpp/src/qpid/cluster/Connection.cpp @@ -573,12 +573,22 @@ void Connection::queue(const std::string& encoded) { } void Connection::sessionError(uint16_t , const std::string& msg) { - cluster.flagError(*this, ERROR_TYPE_SESSION, msg); + // If we are negotiating the connection when it fails just close the connectoin. + // If it fails after that then we have to flag the error to the cluster. + if (inConnectionNegotiation) + cluster.getMulticast().mcastControl(ClusterConnectionDeliverCloseBody(), self); + else + cluster.flagError(*this, ERROR_TYPE_SESSION, msg); } void Connection::connectionError(const std::string& msg) { - cluster.flagError(*this, ERROR_TYPE_CONNECTION, msg); + // If we are negotiating the connection when it fails just close the connectoin. + // If it fails after that then we have to flag the error to the cluster. + if (inConnectionNegotiation) + cluster.getMulticast().mcastControl(ClusterConnectionDeliverCloseBody(), self); + else + cluster.flagError(*this, ERROR_TYPE_CONNECTION, msg); } void Connection::addQueueListener(const std::string& q, uint32_t listener) { diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 061d7e88f6..5e5bfdec37 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -376,7 +376,7 @@ EXTRA_DIST+= \ check-long: $(MAKE) check TESTS="$(LONG_TESTS)" VALGRIND= -check: python_prep test_env.sh +check: python_prep test_env.sh sasl_config PYTHON_SRC_DIR=$(abs_srcdir)/../../../python PYTHON_BLD_DIR=$(abs_builddir)/python @@ -391,4 +391,8 @@ python_prep: --install-scripts=$(PYTHON_BLD_DIR)/commands; \ else echo "WARNING: python client not built, missing $(PYTHON_SRC_DIR)"; fi +sasl_config: sasl_test_setup.sh + sh $(srcdir)/sasl_test_setup.sh + touch sasl_config + include testagent.mk diff --git a/cpp/src/tests/cluster_tests.py b/cpp/src/tests/cluster_tests.py index f36cde9ecc..02b3b29571 100755 --- a/cpp/src/tests/cluster_tests.py +++ b/cpp/src/tests/cluster_tests.py @@ -101,6 +101,18 @@ class ShortTests(BrokerTest): assert readfile("direct.dump") == readfile("updatee.dump") os.remove("direct.dump") os.remove("updatee.dump") + + def test_sasl(self): + """Test SASL authentication and encryption in a cluster""" + sasl_config=os.path.join(self.rootdir, "sasl_config") + cluster = self.cluster(3, ["--auth", "yes", "--sasl-config", sasl_config]) + # Try a bad user ID + try: + c = messaging.Connection.establish("nosuch/user@%s"%(cluster[0].host_port())) + self.fail("Expected exception") + except messaging.exceptions.ConnectionError: pass + for b in cluster: b.ready() # Make sure all brokers still running. + class LongTests(BrokerTest): """Tests that can run for a long time if -DDURATION=<minutes> is set""" diff --git a/cpp/src/tests/sasl_test_setup.sh b/cpp/src/tests/sasl_test_setup.sh index 68858b2c0a..69748beece 100755 --- a/cpp/src/tests/sasl_test_setup.sh +++ b/cpp/src/tests/sasl_test_setup.sh @@ -9,13 +9,14 @@ mkdir -p sasl_config cat > sasl_config/qpidd.conf <<EOF pwcheck_method: auxprop auxprop_plugin: sasldb -sasldb_path: ./sasl_config/qpidd.sasldb +sasldb_path: $PWD/sasl_config/qpidd.sasldb sql_select: dummy select EOF # Populate temporary sasl db. SASLTEST_DB=./sasl_config/qpidd.sasldb rm -f $SASLTEST_DB +echo guest | $SASL_PW -c -p -f $SASLTEST_DB -u QPID guest echo zig | $SASL_PW -c -p -f $SASLTEST_DB -u QPID zig echo zag | $SASL_PW -c -p -f $SASLTEST_DB -u QPID zag diff --git a/python/qpid/brokertest.py b/python/qpid/brokertest.py index 2242dcb88c..1debabf3df 100644 --- a/python/qpid/brokertest.py +++ b/python/qpid/brokertest.py @@ -272,7 +272,8 @@ class Broker(Popen): self.test = test self._port=port - cmd = [BrokerTest.qpidd_exec, "--port", port, "--no-module-dir", "--auth=no"] + args + cmd = [BrokerTest.qpidd_exec, "--port", port, "--no-module-dir"] + args + if not "--auth" in args: cmd.append("--auth=no") if name: self.name = name else: self.name = "broker%d" % Broker._broker_count @@ -304,10 +305,9 @@ class Broker(Popen): def unexpected(self,msg): raise BadProcessStatus("%s: %s (%s)" % (msg, self.name, self.pname)) - def connect(self): + def connect(self, **kwargs): """New API connection to the broker.""" - return messaging.Connection.establish(host=self.host(), - port=self.port()) + return messaging.Connection.establish(self.host_port(), **kwargs) def connect_old(self): """Old API connection to the broker.""" @@ -376,13 +376,13 @@ class Broker(Popen): return False finally: f.close() - def ready(self): + def ready(self, **kwargs): """Wait till broker is ready to serve clients""" # First make sure the broker is listening by checking the log. if not retry(self.log_ready): raise Exception("Timed out waiting for broker %s" % self.name) # Make a connection, this will wait for extended cluster init to finish. - try: self.connect().close() + try: self.connect(**kwargs).close() except: raise RethrownException("Broker %s failed ready test"%self.name) def store_state(self): @@ -485,10 +485,6 @@ class BrokerTest(TestCase): cluster = Cluster(self, count, args, expect=expect, wait=wait) return cluster -# def wait(self): -# """Wait for all brokers in the cluster to be ready""" -# for b in _brokers: b.connect().close() - class RethrownException(Exception): """Captures the stack trace of the current exception to be thrown later""" def __init__(self, msg=""): |
