def __init__(self, url): """ :param url: The broker URL. :type url: str """ queue = Queue(ReplyHandler.REPLY_QUEUE) queue.durable = True queue.declare(url) self.consumer = ReplyConsumer(queue, url=url, authenticator=Authenticator())
def test_signing(self): message = 'hello' key = RSA.load_key_bio(BIO.MemoryBuffer(RSA_KEY)) authenticator = Authenticator() authenticator.rsa_key = key signature = authenticator.sign(message) self.assertEqual(signature, key.sign(message))
def test_validated_not_raised(self, mock_get): mock_get.return_value.verify = Mock(return_value=False) consumer_id = 'test-consumer_id' document = Mock() document.any = {'consumer_id': consumer_id} # test authenticator = Authenticator() self.assertRaises(ValidationFailed, authenticator.validate, document, '', '') mock_get.assert_called_with(consumer_id)
def __init__(self, url, transport): """ :param url: The broker URL. :type url: str :param transport: The gofer transport. :type transport: str """ queue = Queue(Services.REPLY_QUEUE, transport=transport) self.consumer = ReplyConsumer(queue, url=url, transport=transport, authenticator=Authenticator())
def test_not_validated(self, mock_get): message = 'hello' consumer_id = 'test-consumer_id' document = Mock() document.any = {'consumer_id': consumer_id} key = RSA.load_key_bio(BIO.MemoryBuffer(OTHER_KEY)) mock_get.return_value = RSA.load_pub_key_bio(BIO.MemoryBuffer(RSA_PUB)) authenticator = Authenticator() self.assertRaises(ValidationFailed, authenticator.validate, document, message, key.sign(message)) mock_get.assert_called_with(consumer_id)
def __init__(self, consumer, **details): """ :param consumer: A consumer DB model object. :type consumer: dict :param details: A dictionary of information to be round-tripped. Primarily used to correlate asynchronous replies. :type details: dict """ self.address = 'pulp.agent.%s' % consumer['id'] self.secret = str(consumer['_id']) self.url = get_url() self.details = details self.reply_queue = ReplyHandler.REPLY_QUEUE self.authenticator = Authenticator() self.authenticator.load()
def test_load(self, mock_open): mock_fp = Mock() mock_fp.read = Mock(return_value=RSA_KEY) mock_fp.__enter__ = Mock(return_value=mock_fp) mock_fp.__exit__ = Mock() mock_open.return_value = mock_fp # test authenticator = Authenticator() authenticator.load() # validation self.assertTrue(mock_fp.__exit__.called) self.assertTrue(isinstance(authenticator.rsa_key, RSA.RSA))
def __init__(self, consumer, **details): """ :param consumer: A consumer DB model object. :type consumer: dict :param details: A dictionary of information to be round-tripped. Primarily used to correlate asynchronous replies. :type details: dict """ self.agent_id = 'pulp.agent.%s' % consumer['id'] self.secret = str(consumer['_id']) self.url = pulp_conf.get('messaging', 'url') self.transport = pulp_conf.get('messaging', 'transport') self.details = details self.reply_queue = Services.REPLY_QUEUE self.authenticator = Authenticator() self.authenticator.load()
def test_validate_not_enabled(self): authenticator = Authenticator() authenticator.enabled = False authenticator.validate('', '', '')
def test_signing_not_enabled(self): authenticator = Authenticator() authenticator.enabled = False signature = authenticator.sign('hello') self.assertEqual(signature, '')