diff options
author | Alan Conway <aconway@apache.org> | 2009-02-12 19:01:51 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-02-12 19:01:51 +0000 |
commit | 55946250faf17c32ef8f49c724e622e9eedfbdfa (patch) | |
tree | ec6f972bbb5985eb1803f50584eecce606781631 /qpid/cpp/src/tests | |
parent | 64b26d7ac98b821e176f97d96a6580dafac353f6 (diff) | |
download | qpid-python-55946250faf17c32ef8f49c724e622e9eedfbdfa.tar.gz |
Cluster security support:
- Set correct user ID on update connections.
- Allow configuration of user, pass and mechanism used for update connections.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@743839 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests')
-rw-r--r-- | qpid/cpp/src/tests/BrokerFixture.h | 8 | ||||
-rw-r--r-- | qpid/cpp/src/tests/ClusterFixture.cpp | 5 | ||||
-rw-r--r-- | qpid/cpp/src/tests/ClusterFixture.h | 4 | ||||
-rw-r--r-- | qpid/cpp/src/tests/cluster_test.cpp | 58 |
4 files changed, 63 insertions, 12 deletions
diff --git a/qpid/cpp/src/tests/BrokerFixture.h b/qpid/cpp/src/tests/BrokerFixture.h index 205b4d90ef..f55560739d 100644 --- a/qpid/cpp/src/tests/BrokerFixture.h +++ b/qpid/cpp/src/tests/BrokerFixture.h @@ -88,6 +88,7 @@ struct BrokerFixture : private boost::noncopyable { /** Connection that opens in its constructor */ struct LocalConnection : public qpid::client::Connection { LocalConnection(uint16_t port) { open("localhost", port); } + LocalConnection(const qpid::client::ConnectionSettings& s) { open(s); } }; /** A local client connection via a socket proxy. */ @@ -96,6 +97,11 @@ struct ProxyConnection : public qpid::client::Connection { ProxyConnection(int brokerPort) : proxy(brokerPort) { open("localhost", proxy.getPort()); } + ProxyConnection(const qpid::client::ConnectionSettings& s) : proxy(s.port) { + qpid::client::ConnectionSettings proxySettings(s); + proxySettings.port = proxy.getPort(); + open(proxySettings); + } ~ProxyConnection() { close(); } }; @@ -110,6 +116,8 @@ struct ClientT { qpid::client::LocalQueue lq; ClientT(uint16_t port, const std::string& name=std::string()) : connection(port), session(connection.newSession(name)), subs(session) {} + ClientT(const qpid::client::ConnectionSettings& settings, const std::string& name=std::string()) + : connection(settings), session(connection.newSession(name)), subs(session) {} ~ClientT() { connection.close(); } }; diff --git a/qpid/cpp/src/tests/ClusterFixture.cpp b/qpid/cpp/src/tests/ClusterFixture.cpp index 4a373e3811..3a0ea74098 100644 --- a/qpid/cpp/src/tests/ClusterFixture.cpp +++ b/qpid/cpp/src/tests/ClusterFixture.cpp @@ -67,13 +67,14 @@ ClusterFixture::ClusterFixture(size_t n, int localIndex_, const Args& args_) add(n); } +const ClusterFixture::Args ClusterFixture::DEFAULT_ARGS = + list_of<string>("--auth=no")("--no-data-dir"); + ClusterFixture::Args ClusterFixture::makeArgs(const std::string& prefix) { Args args = list_of<string>("qpidd " __FILE__) ("--no-module-dir") ("--load-module=../.libs/cluster.so") ("--cluster-name")(name) - ("--auth=no") - ("--no-data-dir") ("--log-prefix")(prefix); args.insert(args.end(), userArgs.begin(), userArgs.end()); return args; diff --git a/qpid/cpp/src/tests/ClusterFixture.h b/qpid/cpp/src/tests/ClusterFixture.h index d1acfaa9cb..84fb9f2202 100644 --- a/qpid/cpp/src/tests/ClusterFixture.h +++ b/qpid/cpp/src/tests/ClusterFixture.h @@ -72,7 +72,7 @@ class ClusterFixture : public vector<uint16_t> { /** @param localIndex can be -1 meaning don't automatically start a local broker. * A local broker can be started with addLocal(). */ - ClusterFixture(size_t n, int localIndex=0, const Args& args=Args()); + ClusterFixture(size_t n, int localIndex=0, const Args& args=DEFAULT_ARGS); void add(size_t n) { for (size_t i=0; i < n; ++i) add(); } void add(); // Add a broker. void setup(); @@ -86,6 +86,8 @@ class ClusterFixture : public vector<uint16_t> { void killWithSilencer(size_t n, client::Connection& c, int sig=SIGINT); private: + static const Args DEFAULT_ARGS; + void addLocal(); // Add a local broker. Args makeArgs(const std::string& prefix); string name; diff --git a/qpid/cpp/src/tests/cluster_test.cpp b/qpid/cpp/src/tests/cluster_test.cpp index 14b7659b65..c880f30e6b 100644 --- a/qpid/cpp/src/tests/cluster_test.cpp +++ b/qpid/cpp/src/tests/cluster_test.cpp @@ -23,6 +23,7 @@ #include "ClusterFixture.h" #include "qpid/client/Connection.h" +#include "qpid/client/ConnectionSettings.h" #include "qpid/client/ConnectionAccess.h" #include "qpid/client/Session.h" #include "qpid/client/FailoverListener.h" @@ -41,6 +42,7 @@ #include <string> #include <iostream> +#include <fstream> #include <iterator> #include <vector> #include <set> @@ -86,11 +88,11 @@ ostream& operator<<(ostream& o, const pair<T*, int>& array) { template <class C> set<uint16_t> makeSet(const C& c) { set<uint16_t> s; - std::copy(c.begin(), c.end(), std::inserter(s, s.begin())); + copy(c.begin(), c.end(), inserter(s, s.begin())); return s; } -template <class T> std::set<uint16_t> knownBrokerPorts(T& source, int n=-1) { +template <class T> set<uint16_t> knownBrokerPorts(T& source, int n=-1) { vector<Url> urls = source.getKnownBrokers(); if (n >= 0 && unsigned(n) != urls.size()) { BOOST_MESSAGE("knownBrokerPorts waiting for " << n << ": " << urls); @@ -129,13 +131,13 @@ int64_t getMsgSequence(const Message& m) { return m.getMessageProperties().getApplicationHeaders().getAsInt64("qpid.msg_sequence"); } -Message ttlMessage(const std::string& data, const std::string& key, uint64_t ttl) { +Message ttlMessage(const string& data, const string& key, uint64_t ttl) { Message m(data, key); m.getDeliveryProperties().setTtl(ttl); return m; } -vector<std::string> browse(Client& c, const std::string& q, int n) { +vector<string> browse(Client& c, const string& q, int n) { SubscriptionSettings browseSettings( FlowControl::unlimited(), ACCEPT_MODE_NONE, @@ -144,7 +146,7 @@ vector<std::string> browse(Client& c, const std::string& q, int n) { ); LocalQueue lq; c.subs.subscribe(lq, q, browseSettings); - vector<std::string> result; + vector<string> result; for (int i = 0; i < n; ++i) { result.push_back(lq.get(TIMEOUT).getData()); } @@ -152,6 +154,44 @@ vector<std::string> browse(Client& c, const std::string& q, int n) { return result; } + +// FIXME aconway 2009-02-12: need to figure out how to test this properly. +// Current problems: +// - all brokers share the same data-dir (set ACL without data dir?) +// - updater's user name not making it through to updatee for ACL checks. +// +// QPID_AUTO_TEST_CASE(testAcl) { +// ofstream policyFile("cluster_test.acl"); +// // FIXME aconway 2009-02-12: guest -> qpidd? +// policyFile << "acl allow guest@QPID all all" << endl +// << "acl allow foo@QPID create queue name=foo" << endl +// << "acl allow bar@QPID create queue name=bar" << endl +// << "acl deny all create queue" << endl +// << "acl allow all all" << endl; +// policyFile.close(); +// ClusterFixture cluster(2,-1, list_of<string> +// ("--data-dir=.") ("--auth=no") +// ("--acl-file=cluster_test.acl") +// ("--cluster-mechanism=PLAIN") +// ("--load-module=../.libs/acl.so")); +// Client c0(cluster[0], "c0"); +// Client c1(cluster[1], "c1"); + +// ConnectionSettings settings; +// settings.port = cluster[0]; +// settings.username = "foo"; +// Client foo(settings, "foo"); + +// foo.session.queueDeclare("foo"); +// BOOST_CHECK_EQUAL(c0.session.queueQuery("foo").getQueue(), "foo"); +// BOOST_CHECK_EQUAL(c1.session.queueQuery("foo").getQueue(), "foo"); + +// BOOST_CHECK_THROW(foo.session.queueDeclare("bar"), int); +// BOOST_CHECK_EQUAL(c0.session.queueQuery("bar").getQueue(), ""); +// BOOST_CHECK_EQUAL(c1.session.queueQuery("bar").getQueue(), ""); +// } + + QPID_AUTO_TEST_CASE(testMessageTimeToLive) { // Note: this doesn't actually test for cluster race conditions around TTL, // it just verifies that basic TTL functionality works. @@ -162,10 +202,10 @@ QPID_AUTO_TEST_CASE(testMessageTimeToLive) { c0.session.queueDeclare("q"); c0.session.messageTransfer(arg::content=ttlMessage("a", "q", 200)); c0.session.messageTransfer(arg::content=Message("b", "q")); - BOOST_CHECK_EQUAL(browse(c1, "q", 2), list_of<std::string>("a")("b")); + BOOST_CHECK_EQUAL(browse(c1, "q", 2), list_of<string>("a")("b")); sys::usleep(300*1000); - BOOST_CHECK_EQUAL(browse(c0, "q", 1), list_of<std::string>("b")); - BOOST_CHECK_EQUAL(browse(c1, "q", 1), list_of<std::string>("b")); + BOOST_CHECK_EQUAL(browse(c0, "q", 1), list_of<string>("b")); + BOOST_CHECK_EQUAL(browse(c1, "q", 1), list_of<string>("b")); } QPID_AUTO_TEST_CASE(testSequenceOptions) { @@ -349,7 +389,7 @@ QPID_AUTO_TEST_CASE(testUpdateMessageBuilder) { // Send first 2 frames of message. MessageTransferBody transfer( - ProtocolVersion(), std::string(), // default exchange. + ProtocolVersion(), string(), // default exchange. framing::message::ACCEPT_MODE_NONE, framing::message::ACQUIRE_MODE_PRE_ACQUIRED); sender.send(transfer, true, false, true, true); |