示例#1
0
    def test_safe_log_sanitizes_cells_route_message(self):
        def logger_method(msg, data):
            vals = data['args']['message']['args']['method_info']
            self.assertEquals('<SANITIZED>', vals['method_kwargs']['password'])

        meth_info = {
            'method_args': ['aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'],
            'method': 'set_admin_password',
            'method_kwargs': {
                'password': '******'
            }
        }
        data = {
            'method': 'route_message',
            'args': {
                'routing_path': 'a.fake.path',
                'direction': 'down',
                'message': {
                    'args': {
                        'is_broadcast': False,
                        'service_name': 'compute',
                        'method_info': meth_info
                    },
                    'method': 'run_service_api_method'
                },
                'dest_cell_name': 'cell!0001'
            }
        }
        rpc_common._safe_log(logger_method, 'foo', data)
示例#2
0
    def __call__(self, message_data):
        """Consumer callback to call a method on a proxy object.

        Parses the message for validity and fires off a thread to call the
        proxy object method.

        Message data should be a dictionary with two keys:
            method: string representing the method to call
            args: dictionary of arg: value

        Example: {'method': 'echo', 'args': {'value': 42}}

        """
        # It is important to clear the context here, because at this point
        # the previous context is stored in local.store.context
        if hasattr(local.store, 'context'):
            del local.store.context
        rpc_common._safe_log(LOG.debug, 'received %s', message_data)
        self.msg_id_cache.check_duplicate_message(message_data)
        ctxt = unpack_context(self.conf, message_data)
        method = message_data.get('method')
        args = message_data.get('args', {})
        version = message_data.get('version')
        namespace = message_data.get('namespace')
        if not method:
            LOG.warn(_('no method for message: %s') % message_data)
            ctxt.reply(_('No method for message: %s') % message_data,
                       connection_pool=self.connection_pool)
            return
        self.pool.spawn_n(self._process_data, ctxt, version, method,
                          namespace, args)
示例#3
0
    def test_safe_log_sanitizes_globals(self):
        def logger_method(msg, data):
            self.assertEquals('<SANITIZED>', data['_context_auth_token'])
            self.assertEquals('<SANITIZED>', data['auth_token'])

        data = {'_context_auth_token': 'banana', 'auth_token': 'cheese'}
        rpc_common._safe_log(logger_method, 'foo', data)
示例#4
0
    def __call__(self, message_data):
        """Consumer callback to call a method on a proxy object.

        Parses the message for validity and fires off a thread to call the
        proxy object method.

        Message data should be a dictionary with two keys:
            method: string representing the method to call
            args: dictionary of arg: value

        Example: {'method': 'echo', 'args': {'value': 42}}

        """
        # It is important to clear the context here, because at this point
        # the previous context is stored in local.store.context
        if hasattr(local.store, 'context'):
            del local.store.context
        rpc_common._safe_log(LOG.debug, _('received %s'), message_data)
        self.msg_id_cache.check_duplicate_message(message_data)
        ctxt = unpack_context(self.conf, message_data)
        method = message_data.get('method')
        args = message_data.get('args', {})
        version = message_data.get('version')
        namespace = message_data.get('namespace')
        if not method:
            LOG.warn(_('no method for message: %s') % message_data)
            ctxt.reply(_('No method for message: %s') % message_data,
                       connection_pool=self.connection_pool)
            return
        self.pool.spawn_n(self._process_data, ctxt, version, method, namespace,
                          args)
示例#5
0
    def test_safe_log_sanitizes_globals(self):
        def logger_method(msg, data):
            self.assertEquals('<SANITIZED>', data['_context_auth_token'])
            self.assertEquals('<SANITIZED>', data['auth_token'])

        data = {'_context_auth_token': 'banana',
                'auth_token': 'cheese'}
        rpc_common._safe_log(logger_method, 'foo', data)
示例#6
0
    def test_safe_log_sanitizes_run_instance(self):
        def logger_method(msg, data):
            self.assertEquals('<SANITIZED>', data['args']['admin_password'])

        data = {'_context_auth_token': 'banana',
                'auth_token': 'cheese',
                'method': 'run_instance',
                'args': {'admin_password': '******'}}
        rpc_common._safe_log(logger_method, 'foo', data)
示例#7
0
    def test_safe_log_sanitizes_run_instance(self):
        def logger_method(msg, data):
            self.assertEquals('<SANITIZED>', data['args']['admin_password'])

        data = {'_context_auth_token': 'banana',
                'auth_token': 'cheese',
                'method': 'run_instance',
                'args': {'admin_password': '******'}}
        rpc_common._safe_log(logger_method, 'foo', data)
    def test_safe_log_sanitizes_any_password_in_list_of_dicts(self):
        def logger_method(msg, data):
            self.assertEqual('<SANITIZED>', data['users'][0]['_password'])
            self.assertEqual('<SANITIZED>', data['users'][1]['_password'])

        users = [{'_host': '%', '_password': '******', '_name': 'mydb'},
                 {'_host': '%', '_password': '******', '_name': 'newdb'}]
        data = {'_request_id': 'req-44adf4ac-12bb-44c5-be3d-da2cc73b2e05',
                'users': users}
        rpc_common._safe_log(logger_method, 'foo', data)
示例#9
0
    def test_safe_log_sanitizes_any_password_in_context(self):
        def logger_method(msg, data):
            self.assertEquals('<SANITIZED>', data['_context_password'])
            self.assertEquals('<SANITIZED>', data['password'])

        data = {'_context_auth_token': 'banana',
                'auth_token': 'cheese',
                'password': '******',
                '_context_password': '******'
                }
        rpc_common._safe_log(logger_method, 'foo', data)
示例#10
0
    def test_safe_log_sanitizes_any_password_in_context(self):
        def logger_method(msg, data):
            self.assertEqual('<SANITIZED>', data['_context_password'])
            self.assertEqual('<SANITIZED>', data['password'])

        data = {
            '_context_auth_token': 'banana',
            'auth_token': 'cheese',
            'password': '******',
            '_context_password': '******'
        }
        rpc_common._safe_log(logger_method, 'foo', data)
示例#11
0
def unpack_context(conf, msg):
    """Unpack context from msg."""
    context_dict = {}
    for key in list(msg.keys()):
        # NOTE(vish): Some versions of python don't like unicode keys
        #             in kwargs.
        key = str(key)
        if key.startswith('_context_'):
            value = msg.pop(key)
            context_dict[key[9:]] = value
    context_dict['msg_id'] = msg.pop('_msg_id', None)
    context_dict['conf'] = conf
    ctx = RpcContext.from_dict(context_dict)
    rpc_common._safe_log(LOG.debug, _('unpacked context: %s'), ctx.to_dict())
    return ctx
示例#12
0
def unpack_context(conf, msg):
    """Unpack context from msg."""
    context_dict = {}
    for key in list(msg.keys()):
        # NOTE(vish): Some versions of python don't like unicode keys
        #             in kwargs.
        key = str(key)
        if key.startswith('_context_'):
            value = msg.pop(key)
            context_dict[key[9:]] = value
    context_dict['msg_id'] = msg.pop('_msg_id', None)
    context_dict['conf'] = conf
    ctx = RpcContext.from_dict(context_dict)
    rpc_common._safe_log(LOG.debug, _('unpacked context: %s'), ctx.to_dict())
    return ctx
示例#13
0
    def test_safe_log_sanitizes_cells_route_message(self):
        def logger_method(msg, data):
            vals = data['args']['message']['args']['method_info']
            self.assertEquals('<SANITIZED>', vals['method_kwargs']['password'])

        meth_info = {'method_args': ['aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'],
                     'method': 'set_admin_password',
                     'method_kwargs': {'password': '******'}}
        data = {'method': 'route_message',
                'args': {'routing_path': 'a.fake.path',
                         'direction': 'down',
                         'message': {'args': {'is_broadcast': False,
                                              'service_name': 'compute',
                                              'method_info': meth_info},
                                     'method': 'run_service_api_method'},
                         'dest_cell_name': 'cell!0001'}}
        rpc_common._safe_log(logger_method, 'foo', data)