You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2015/12/30 22:13:18 UTC

[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 <gs...@redhat.com>
Authored: Tue Dec 15 21:26:50 2015 +0000
Committer: Gordon Sim <gs...@redhat.com>
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