You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2015/12/15 23:03:11 UTC

[1/2] qpid-proton git commit: PROTON-1049: allow username/password to be specified on conatiner or via keyword args to connect() method

Repository: qpid-proton
Updated Branches:
  refs/heads/master 87ece507e -> fefb81d2c


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/master
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


[2/2] qpid-proton git commit: PROTON-1080: add alias for reactor when using any Reactor subclass

Posted by gs...@apache.org.
PROTON-1080: add alias for reactor when using any Reactor subclass


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/7ccd6329
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/7ccd6329
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/7ccd6329

Branch: refs/heads/master
Commit: 7ccd632974cc643030a8580ca72da645f6a22766
Parents: 87ece50
Author: Gordon Sim <gs...@redhat.com>
Authored: Tue Dec 15 20:20:28 2015 +0000
Committer: Gordon Sim <gs...@redhat.com>
Committed: Tue Dec 15 21:47:11 2015 +0000

----------------------------------------------------------------------
 proton-c/bindings/python/proton/__init__.py |  7 +++++
 tests/python/proton_tests/reactor.py        | 36 ++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7ccd6329/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index 2a87fe7..f3a8e8d 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -3805,6 +3805,13 @@ class Event(Wrapper, EventBase):
     """Returns the reactor associated with the event."""
     return wrappers.get("pn_reactor", _none)(pn_event_reactor(self._impl))
 
+  def __getattr__(self, name):
+    r = self.reactor
+    if r and hasattr(r, 'subclass') and r.subclass.__name__.lower() == name:
+      return r
+    else:
+      return super(Event, self).__getattr__(name)
+
   @property
   def transport(self):
     """Returns the transport associated with the event, or null if none is associated with it."""

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7ccd6329/tests/python/proton_tests/reactor.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/reactor.py b/tests/python/proton_tests/reactor.py
index eeddb2f..c58530a 100644
--- a/tests/python/proton_tests/reactor.py
+++ b/tests/python/proton_tests/reactor.py
@@ -19,9 +19,9 @@ from __future__ import absolute_import
 #
 
 import time
-from .common import Test, SkipTest, TestServer
-from proton.reactor import Reactor, ApplicationEvent, EventInjector
-from proton.handlers import CHandshaker
+from .common import Test, SkipTest, TestServer, free_tcp_port
+from proton.reactor import Container, Reactor, ApplicationEvent, EventInjector
+from proton.handlers import CHandshaker, MessagingHandler
 from proton import Handler
 
 class Barf(Exception):
@@ -457,3 +457,33 @@ class ApplicationEventTest(Test):
         self._wait_for(lambda: self.hello_rcvd is not None)
         self.event_injector.trigger(self.goodbye_event)
         self._wait_for(lambda: self.goodbye_rcvd is not None)
+
+
+class ContainerTest(Test):
+    """Test container subclass of reactor."""
+
+    def test_event_container(self):
+        class TestHandler(MessagingHandler):
+            def __init__(self):
+                super(TestHandler, 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_closing(self, event):
+                event.connection.close()
+                self.listener.close()
+        test_handler = TestHandler()
+        container = Container(test_handler)
+        class ConnectionHandler(MessagingHandler):
+            def __init__(self):
+                super(ConnectionHandler, self).__init__()
+
+            def on_connection_opened(self, event):
+                event.connection.close()
+                assert event.container == event.reactor
+                assert event.container == container
+        container.connect(test_handler.url, handler=ConnectionHandler())
+        container.run()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org