コード例 #1
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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))
コード例 #2
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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))
コード例 #3
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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)
コード例 #4
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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)
コード例 #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()
コード例 #6
0
ファイル: context.py プロジェクト: 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()
コード例 #7
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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))
コード例 #8
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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))
コード例 #9
0
ファイル: services.py プロジェクト: taftsanders/pulp
 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())
コード例 #10
0
ファイル: context.py プロジェクト: 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()
コード例 #11
0
ファイル: test_auth.py プロジェクト: omps/pulp
    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)
コード例 #12
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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))
コード例 #13
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
    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))
コード例 #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())
コード例 #15
0
ファイル: context.py プロジェクト: pcreech/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.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()
コード例 #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
コード例 #17
0
ファイル: context.py プロジェクト: pcreech/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 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
コード例 #18
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
 def test_validate_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     authenticator.validate('', '', '')
コード例 #19
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
 def test_signing_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     signature = authenticator.sign('hello')
     self.assertEqual(signature, '')
コード例 #20
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
 def test_signing_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     signature = authenticator.sign('hello')
     self.assertEqual(signature, '')
コード例 #21
0
ファイル: test_auth.py プロジェクト: ipanova/pulp
 def test_validate_not_enabled(self):
     authenticator = Authenticator()
     authenticator.enabled = False
     authenticator.validate('', '', '')