def test_connection_properties(self): server = ConnPropertiesServer(Url(host="127.0.0.1", port=free_tcp_port()), timeout=self.timeout) server.start() server.wait() connection = BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES) client = SyncRequestResponse(connection) client.connection.close() server.join(timeout=self.timeout) self.assertEquals(server.properties_received, True) self.assertEquals(server.offered_capabilities_received, True) self.assertEquals(server.desired_capabilities_received, True)
def test_connection_properties(self): ensureCanTestExtendedSASL() server = ConnPropertiesServer(Url(host="127.0.0.1", port=free_tcp_port()), timeout=self.timeout) server.start() server.wait() connection = BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES) client = SyncRequestResponse(connection) client.connection.close() server.join(timeout=self.timeout) self.assertEquals(server.properties_received, True) self.assertEquals(server.offered_capabilities_received, True) self.assertEquals(server.desired_capabilities_received, True)
def test_allowed_mechs_anonymous(self): # All this test does it make sure that if we pass allowed_mechs to BlockingConnection, it is actually used. server = ConnPropertiesServer(Url(host="127.0.0.1", port=free_tcp_port()), timeout=self.timeout) server.start() server.wait() # An ANONYMOUS allowed_mechs will work, anonymous connections are allowed by ConnPropertiesServer connection = BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES, allowed_mechs=ANONYMOUS) client = SyncRequestResponse(connection) client.connection.close() server.join(timeout=self.timeout) self.assertEquals(server.properties_received, True) self.assertEquals(server.offered_capabilities_received, True) self.assertEquals(server.desired_capabilities_received, True)
def test_allowed_mechs_external(self): # All this test does it make sure that if we pass allowed_mechs to BlockingConnection, it is actually used. port = free_tcp_port() server = ConnPropertiesServer(Url(host="127.0.0.1", port=port), timeout=self.timeout) server.start() server.wait() try: # This will cause an exception because we are specifying allowed_mechs as EXTERNAL. The SASL handshake will fail because the server is not setup to handle EXTERNAL connection = BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES, allowed_mechs=EXTERNAL) self.fail("Expected ConnectionException") except ConnectionException as e: self.assertTrue('amqp:unauthorized-access' in str(e), "expected unauthorized-access") server.join(timeout=self.timeout)
def test_request_response(self): def test(name, address="x"): for i in range(5): body="%s%s" % (name, i) response = client.call(Message(address=address, body=body)) self.assertEquals(response.address, client.reply_to) self.assertEquals(response.body, body) server = EchoServer(Url(host="127.0.0.1", port=free_tcp_port()), self.timeout) server.start() server.wait() connection = BlockingConnection(server.url, timeout=self.timeout) client = SyncRequestResponse(connection) try: test("foo") # Simple request/resposne finally: client.connection.close() server.join(timeout=self.timeout)
def test_request_response(self): ensureCanTestExtendedSASL() def test(name, address="x"): for i in range(5): body="%s%s" % (name, i) response = client.call(Message(address=address, body=body)) self.assertEquals(response.address, client.reply_to) self.assertEquals(response.body, body) server = EchoServer(Url(host="127.0.0.1", port=free_tcp_port()), self.timeout) server.start() server.wait() connection = BlockingConnection(server.url, timeout=self.timeout) client = SyncRequestResponse(connection) try: test("foo") # Simple request/resposne finally: client.connection.close() server.join(timeout=self.timeout)
def test_allowed_mechs_external(self): # All this test does it make sure that if we pass allowed_mechs to BlockingConnection, it is actually used. if "java" in sys.platform: raise Skipped("") port = free_tcp_port() # We have constructed ConnPropertiesServer with host="127.0.0.1", so it is ok to hardcode the hostname in the error message string. error_message = 'Connection amqp://127.0.0.1:' + str(port) + ' disconnected' server = ConnPropertiesServer(Url(host="127.0.0.1", port=port), timeout=self.timeout) server.start() server.wait() exception_occurred = False try: # This will cause an exception because we are specifying allowed_mechs as EXTERNAL. The SASL handshake will fail because the server is not setup to handle EXTERNAL connection = BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES, allowed_mechs=EXTERNAL) except ConnectionException as e: exc_type, exc_value, exc_traceback = sys.exc_info() self.assertEquals(error_message, str(exc_value)) exception_occurred = True self.assertEquals(True, exception_occurred) server.join(timeout=self.timeout)