Exemple #1
0
    def _get_credential(self, project, webhook_id, key):
        """Get credential for the given webhook using the provided key.

        :param webhook_id: ID of the webhook.
        :param key: The key string to be used for decryption.
        """
        # Build a dummy RequestContext for DB APIs
        dbctx = context.RequestContext(is_admin=True, project=project)
        webhook = webhook_mod.Webhook.load(dbctx, webhook_id)
        credential = webhook.credential
        # Decrypt the credential using provided key
        try:
            cdata = utils.decrypt(webhook.credential, key)
            credential = jsonutils.loads(cdata)
        except Exception as ex:
            LOG.exception(six.text_type(ex))
            raise exc.Forbidden()

        return credential
Exemple #2
0
    def test_encrypt_credential(self):
        kwargs = {
            'id': 'WEBHOOK_ID',
            'name': 'test-webhook',
            'user': '******',
            'project': 'test-project',
            'domain': 'test-domain',
            'created_time': timeutils.utcnow(),
            'deleted_time': None,
            'credential': self.credential,
            'params': self.params
        }

        webhook = webhook_mod.Webhook('test-obj-id', 'test-obj-type',
                                      'test-action', **kwargs)

        key = webhook.encrypt_credential()
        cdata = encrypt_utils.decrypt(webhook.credential, key)
        credential = jsonutils.loads(cdata)
        self.assertEqual('abc', credential['password'])
Exemple #3
0
    def test_encrypt_credential(self):
        kwargs = {
            'id': 'WEBHOOK_ID',
            'name': 'test-webhook',
            'user': '******',
            'project': 'test-project',
            'domain': 'test-domain',
            'created_time': timeutils.utcnow(),
            'deleted_time': None,
            'credential': self.credential,
            'params': self.params
        }

        webhook = webhook_mod.Webhook('test-obj-id', 'test-obj-type',
                                      'test-action', **kwargs)

        key = webhook.encrypt_credential()
        cdata = encrypt_utils.decrypt(webhook.credential, key)
        credential = jsonutils.loads(cdata)
        self.assertEqual('abc', credential['password'])
    def test_decrypt(self):
        msg = 'test-string'
        msg_encrypted, key = utils.encrypt(msg)

        msg_decrypted = utils.decrypt(msg_encrypted, key)
        self.assertEqual(msg, msg_decrypted)
    def test_decrypt(self):
        msg = 'test-string'
        msg_encrypted, key = utils.encrypt(msg)

        msg_decrypted = utils.decrypt(msg_encrypted, key)
        self.assertEqual(msg, msg_decrypted)