def test_url_with_client_properties(self): """Assert when URL contains client props, values are not taken from config.""" test_url = "amqp://*****:*****@rabbit.example.com/vhost?client_properties={'k':'v'}" with mock.patch.dict(config.conf, {"amqp_url": test_url}): consumer = _session.ConsumerSession() self.assertEqual(consumer._parameters.client_properties, {"k": "v"}) self.assertIsInstance(consumer._parameters.credentials, credentials.PlainCredentials)
def setUp(self): self.consumer = _session.ConsumerSession() self.callback = self.consumer._consumer_callback = mock.Mock() self.channel = mock.Mock() self.consumer._connection = mock.Mock() self.consumer._running = True self.frame = mock.Mock() self.frame.delivery_tag = "testtag" self.frame.routing_key = "test.topic" self.properties = mock.Mock() self.properties.headers = {} self.properties.content_encoding = "utf-8" self.validate_patch = mock.patch("fedora_messaging.message.Message.validate") self.validate_mock = self.validate_patch.start()
def setUp(self): message._class_registry["FakeMessageClass"] = FakeMessageClass self.consumer = _session.ConsumerSession() self.callback = self.consumer._consumer_callback = mock.Mock() self.channel = mock.Mock() self.consumer._connection = mock.Mock() self.consumer._running = True self.frame = mock.Mock() self.frame.delivery_tag = "testtag" self.frame.routing_key = "test.topic" self.properties = mock.Mock() self.properties.headers = { "fedora_messaging_schema": "FakeMessageClass" } self.properties.content_encoding = "utf-8"
def test_tls_parameters(self): """Assert TLS settings translate to a TLS connection for consumers.""" tls_conf = { 'amqp_url': 'amqps://', 'tls': { 'keyfile': os.path.join(FIXTURES_DIR, 'key.pem'), 'certfile': os.path.join(FIXTURES_DIR, 'cert.pem'), 'ca_cert': os.path.join(FIXTURES_DIR, 'ca_bundle.pem'), } } with mock.patch.dict(config.conf, tls_conf): consumer = _session.ConsumerSession() self.assertTrue(consumer._parameters.ssl_options is not None)
def test_external_auth(self): """Assert when there's both a key and certfile, external auth is used""" tls_conf = { "amqp_url": "amqps://", "tls": { "keyfile": os.path.join(FIXTURES_DIR, "key.pem"), "certfile": os.path.join(FIXTURES_DIR, "cert.pem"), "ca_cert": os.path.join(FIXTURES_DIR, "ca_bundle.pem"), }, } with mock.patch.dict(config.conf, tls_conf): consumer = _session.ConsumerSession() self.assertTrue(consumer._parameters.ssl_options is not None) self.assertIsInstance(consumer._parameters.credentials, credentials.ExternalCredentials)
def test_plain_auth(self): """Assert when there's no key or certfile, plain authentication is used""" tls_conf = { "amqp_url": "amqps://", "tls": { "keyfile": None, "certfile": None, "ca_cert": os.path.join(FIXTURES_DIR, "ca_bundle.pem"), }, } with mock.patch.dict(config.conf, tls_conf): consumer = _session.ConsumerSession() self.assertTrue(consumer._parameters.ssl_options is not None) self.assertIsInstance(consumer._parameters.credentials, credentials.PlainCredentials)
def setUp(self): self.consumer = _session.ConsumerSession()