Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    def test_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(RSA_KEY))

        mock_get.return_value = RSA.load_pub_key_bio(BIO.MemoryBuffer(RSA_PUB))

        authenticator = Authenticator()
        authenticator.validate(document, message, key.sign(message))

        mock_get.assert_called_with(consumer_id)
Ejemplo n.º 4
0
    def test_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(RSA_KEY))

        mock_get.return_value = RSA.load_pub_key_bio(BIO.MemoryBuffer(RSA_PUB))

        authenticator = Authenticator()
        authenticator.validate(document, message, key.sign(message))

        mock_get.assert_called_with(consumer_id)
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
Archivo: context.py Proyecto: omps/pulp
 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()
Ejemplo n.º 7
0
    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))
Ejemplo n.º 8
0
    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))
Ejemplo n.º 9
0
 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())
Ejemplo n.º 10
0
Archivo: context.py Proyecto: omps/pulp
class Context(object):
    """
    The context bundles together all of the information needed to invoke the
    remote method on the agent and where the asynchronous reply is to be sent.
    Further, gofer supports including arbitrary information to be round tripped.
    This is contextual information that the asynchronous reply handler will need
    to process the reply.  The context also determines the agent UUID based on the
    consumer ID.  It also generates the shared secret based on the SHA256 hex
    digest of the consumer certificate. We include such things as: The task_id and in
    some cases DB entity IDs so we can update the DB based on the result of the
    operation on the agent.

    :ivar agent_id: The agent ID.
        The agent id has the form: 'pulp.agent.<consumer_id>'.
    :type agent_id: str
    :ivar secret: The shared secret which is the DB consumer object's _id.
    :type secret: str
    :ivar url: The broker URL.
    :type url: str
    :ivar transport: The name of the gofer transport to be used.
    :type transport: str
    :ivar details: Data round tripped to that agent and back.
        Used by the reply consumer.
    :type details: dict
    :ivar reply_queue: The reply queue name.
    :type reply_queue: str
    """

    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()
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    def test_key(self, mock_factory):
        consumer_id = 'test-consumer'
        mock_manager = Mock()
        mock_manager.get_consumer = Mock(return_value={'rsa_pub': RSA_PUB})
        mock_factory.return_value = mock_manager

        # test

        key = Authenticator.get_key(consumer_id)

        self.assertTrue(isinstance(key, RSA.RSA))
Ejemplo n.º 13
0
    def test_key(self, mock_factory):
        consumer_id = 'test-consumer'
        mock_manager = Mock()
        mock_manager.get_consumer = Mock(return_value={'rsa_pub': RSA_PUB})
        mock_factory.return_value = mock_manager

        # test

        key = Authenticator.get_key(consumer_id)

        self.assertTrue(isinstance(key, RSA.RSA))
Ejemplo n.º 14
0
 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())
Ejemplo n.º 15
0
 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()
Ejemplo n.º 16
0
class Context(object):
    """
    The context bundles together all of the information needed to invoke the
    remote method on the agent and where the asynchronous reply is to be sent.
    Further, gofer supports including arbitrary information to be round tripped.
    This is contextual information that the asynchronous reply handler will need
    to process the reply.  The context also determines the agent UUID based on the
    consumer ID.  It also generates the shared secret based on the SHA256 hex
    digest of the consumer certificate. We include such things as: The task_id and in
    some cases DB entity IDs so we can update the DB based on the result of the
    operation on the agent.

    :ivar address: The AMQP address.
        The address has the form: 'pulp.agent.<consumer_id>'.
    :type address: basestring
    :ivar secret: The shared secret which is the DB consumer object's _id.
    :type secret: str
    :ivar url: The broker URL.
    :type url: str
    :ivar transport: The name of the gofer transport to be used.
    :type transport: str
    :ivar details: Data round tripped to that agent and back.
        Used by the reply consumer.
    :type details: dict
    :ivar reply_queue: The reply queue name.
    :type reply_queue: str
    """
    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 __enter__(self):
        """
        Enter the context.
          1. add the configured gofer connector.
          2. declare the agent queue.

        :return: self
        :rtype: Context
        """
        add_connector()
        queue = Queue(self.address, self.url)
        queue.declare()
        return self

    def __exit__(self, *args):
        """
        Exit the context.
        Releasing resources such as AMQP connections *could* be done here.

        :param args: Unused parameters.
        :type args: tuple
        """
        pass
Ejemplo n.º 17
0
class Context(object):
    """
    The context bundles together all of the information needed to invoke the
    remote method on the agent and where the asynchronous reply is to be sent.
    Further, gofer supports including arbitrary information to be round tripped.
    This is contextual information that the asynchronous reply handler will need
    to process the reply.  The context also determines the agent UUID based on the
    consumer ID.  It also generates the shared secret based on the SHA256 hex
    digest of the consumer certificate. We include such things as: The task_id and in
    some cases DB entity IDs so we can update the DB based on the result of the
    operation on the agent.

    :ivar address: The AMQP address.
        The address has the form: 'pulp.agent.<consumer_id>'.
    :type address: basestring
    :ivar secret: The shared secret which is the DB consumer object's _id.
    :type secret: str
    :ivar url: The broker URL.
    :type url: str
    :ivar transport: The name of the gofer transport to be used.
    :type transport: str
    :ivar details: Data round tripped to that agent and back.
        Used by the reply consumer.
    :type details: dict
    :ivar reply_queue: The reply queue name.
    :type reply_queue: str
    """

    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 __enter__(self):
        """
        Enter the context.
          1. add the configured gofer connector.
          2. declare the agent queue.

        :return: self
        :rtype: Context
        """
        add_connector()
        queue = Queue(self.address, self.url)
        queue.declare()
        return self

    def __exit__(self, *args):
        """
        Exit the context.
        Releasing resources such as AMQP connections *could* be done here.

        :param args: Unused parameters.
        :type args: tuple
        """
        pass
Ejemplo n.º 18
0
 def test_validate_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     authenticator.validate('', '', '')
Ejemplo n.º 19
0
 def test_signing_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     signature = authenticator.sign('hello')
     self.assertEqual(signature, '')
Ejemplo n.º 20
0
 def test_signing_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     signature = authenticator.sign('hello')
     self.assertEqual(signature, '')
Ejemplo n.º 21
0
 def test_validate_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     authenticator.validate('', '', '')