Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4ABD91885A for ; Wed, 30 Dec 2015 21:12:51 +0000 (UTC) Received: (qmail 66519 invoked by uid 500); 30 Dec 2015 21:12:50 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 66332 invoked by uid 500); 30 Dec 2015 21:12:50 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 65664 invoked by uid 99); 30 Dec 2015 21:12:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Dec 2015 21:12:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3BC4AE0B53; Wed, 30 Dec 2015 21:12:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aconway@apache.org To: commits@qpid.apache.org Date: Wed, 30 Dec 2015 21:13:18 -0000 Message-Id: In-Reply-To: <2f9bc23054864a0aad0675b27e0ef8e5@git.apache.org> References: <2f9bc23054864a0aad0675b27e0ef8e5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [30/50] [abbrv] qpid-proton git commit: PROTON-1049: allow username/password to be specified on conatiner or via keyword args to connect() method PROTON-1049: allow username/password to be specified on conatiner or via keyword args to connect() method Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/fefb81d2 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/fefb81d2 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/fefb81d2 Branch: refs/heads/go1 Commit: fefb81d2c506074cbb6d1eea9d8432ddd3e1fa53 Parents: 7ccd632 Author: Gordon Sim Authored: Tue Dec 15 21:26:50 2015 +0000 Committer: Gordon Sim Committed: Tue Dec 15 21:47:11 2015 +0000 ---------------------------------------------------------------------- proton-c/bindings/python/proton/reactor.py | 10 ++++++ tests/python/proton_tests/reactor.py | 41 ++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fefb81d2/proton-c/bindings/python/proton/reactor.py ---------------------------------------------------------------------- diff --git a/proton-c/bindings/python/proton/reactor.py b/proton-c/bindings/python/proton/reactor.py index 0f59682..195ff28 100644 --- a/proton-c/bindings/python/proton/reactor.py +++ b/proton-c/bindings/python/proton/reactor.py @@ -500,6 +500,8 @@ class Connector(Handler): self.allow_insecure_mechs = True self.allowed_mechs = None self.sasl_enabled = True + self.user = None + self.password = None def _connect(self, connection): url = self.address.next() @@ -513,8 +515,12 @@ class Connector(Handler): sasl.allow_insecure_mechs = self.allow_insecure_mechs if url.username: connection.user = url.username + elif self.user: + connection.user = self.user if url.password: connection.password = url.password + elif self.password: + connection.password = self.password if self.allowed_mechs: sasl.allowed_mechs(self.allowed_mechs) transport.bind(connection) @@ -625,6 +631,8 @@ class Container(Reactor): self.allow_insecure_mechs = True self.allowed_mechs = None self.sasl_enabled = True + self.user = None + self.password = None Wrapper.__setattr__(self, 'subclass', self.__class__) def connect(self, url=None, urls=None, address=None, handler=None, reconnect=None, heartbeat=None, ssl_domain=None, **kwargs): @@ -668,6 +676,8 @@ class Container(Reactor): connector.allow_insecure_mechs = kwargs.get('allow_insecure_mechs', self.allow_insecure_mechs) connector.allowed_mechs = kwargs.get('allowed_mechs', self.allowed_mechs) connector.sasl_enabled = kwargs.get('sasl_enabled', self.sasl_enabled) + connector.user = kwargs.get('user', self.user) + connector.password = kwargs.get('password', self.password) conn._overrides = connector if url: connector.address = Urls([url]) elif urls: connector.address = Urls(urls) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fefb81d2/tests/python/proton_tests/reactor.py ---------------------------------------------------------------------- diff --git a/tests/python/proton_tests/reactor.py b/tests/python/proton_tests/reactor.py index c58530a..e8446ca 100644 --- a/tests/python/proton_tests/reactor.py +++ b/tests/python/proton_tests/reactor.py @@ -459,10 +459,29 @@ class ApplicationEventTest(Test): self._wait_for(lambda: self.goodbye_rcvd is not None) +class AuthenticationTestHandler(MessagingHandler): + def __init__(self): + super(AuthenticationTestHandler, self).__init__() + port = free_tcp_port() + self.url = "localhost:%i" % port + + def on_start(self, event): + self.listener = event.container.listen(self.url) + + def on_connection_opened(self, event): + event.connection.close() + + def on_connection_opening(self, event): + assert event.connection.transport.user == "user@proton" + + def on_connection_closed(self, event): + event.connection.close() + self.listener.close() + class ContainerTest(Test): """Test container subclass of reactor.""" - def test_event_container(self): + def test_event_has_container_attribute(self): class TestHandler(MessagingHandler): def __init__(self): super(TestHandler, self).__init__() @@ -487,3 +506,23 @@ class ContainerTest(Test): assert event.container == container container.connect(test_handler.url, handler=ConnectionHandler()) container.run() + + def test_authentication_via_url(self): + test_handler = AuthenticationTestHandler() + container = Container(test_handler) + container.connect("%s:password@%s" % ("user%40proton", test_handler.url)) + container.run() + + def test_authentication_via_container_attributes(self): + test_handler = AuthenticationTestHandler() + container = Container(test_handler) + container.user = "user@proton" + container.password = "password" + container.connect(test_handler.url) + container.run() + + def test_authentication_via_kwargs(self): + test_handler = AuthenticationTestHandler() + container = Container(test_handler) + container.connect(test_handler.url, user="user@proton", password="password") + container.run() --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org