def test_get_redacted_args_invocation(self, args, kwargs): class Service(object): name = "service" @rpc(sensitive_variables="a") def method(self, a, b=None): pass expected = {'a': REDACTED, 'b': 'B'} container = ServiceContainer(Service, {}) entrypoint = get_extension(container, Rpc) redacted = get_redacted_args(entrypoint, *args, **kwargs) assert redacted == expected
def test_get_redacted_args_invocation(self, args, kwargs, rabbit_config): class Service(object): name = "service" @rpc(sensitive_arguments="a") def method(self, a, b=None): pass # pragma: no cover expected = {'a': REDACTED, 'b': 'B'} container = ServiceContainer(Service, rabbit_config) entrypoint = get_extension(container, Rpc) redacted = get_redacted_args(entrypoint, *args, **kwargs) assert redacted == expected
def test_get_redacted_args(self, sensitive_variables, expected): class Service(object): name = "service" @rpc(sensitive_variables=sensitive_variables) def method(self, a, b): pass args = ("A", "B") kwargs = {} container = ServiceContainer(Service, {}) entrypoint = get_extension(container, Rpc) redacted = get_redacted_args(entrypoint, *args, **kwargs) assert redacted == expected
def test_get_redacted_args_partial(self, sensitive_variables, expected): class Service(object): name = "service" @rpc(sensitive_variables=sensitive_variables) def method(self, a, b): pass complex_arg = {'foo': [1, 2, 3], 'bar': "BAR"} args = ("A", complex_arg) kwargs = {} container = ServiceContainer(Service, {}) entrypoint = get_extension(container, Rpc) redacted = get_redacted_args(entrypoint, *args, **kwargs) assert redacted == expected
def test_get_redacted_args( self, sensitive_arguments, expected, rabbit_config ): class Service(object): name = "service" @rpc(sensitive_arguments=sensitive_arguments) def method(self, a, b): pass # pragma: no cover args = ("A", "B") kwargs = {} container = ServiceContainer(Service, rabbit_config) entrypoint = get_extension(container, Rpc) redacted = get_redacted_args(entrypoint, *args, **kwargs) assert redacted == expected
def get_call_args(self, worker_ctx): """ Return serialisable call arguments """ entrypoint = worker_ctx.entrypoint if getattr(entrypoint, 'sensitive_variables', None): call_args = get_redacted_args(entrypoint, *worker_ctx.args, **worker_ctx.kwargs) redacted = True else: method = getattr(entrypoint.container.service_cls, entrypoint.method_name) call_args = inspect.getcallargs(method, None, *worker_ctx.args, **worker_ctx.kwargs) del call_args['self'] redacted = False return call_args, redacted
def test_get_redacted_args_partial(self, sensitive_variables, expected): class Service(object): name = "service" @rpc(sensitive_variables=sensitive_variables) def method(self, a, b): pass complex_arg = { 'foo': [1, 2, 3], 'bar': "BAR" } args = ("A", complex_arg) kwargs = {} container = ServiceContainer(Service, {}) entrypoint = get_extension(container, Rpc) redacted = get_redacted_args(entrypoint, *args, **kwargs) assert redacted == expected
def test_get_redacted_args_partial( self, sensitive_arguments, expected, rabbit_config ): class Service(object): name = "service" @rpc(sensitive_arguments=sensitive_arguments) def method(self, a, b): pass # pragma: no cover complex_arg = { 'foo': [1, 2, 3], 'bar': "BAR" } args = ("A", complex_arg) kwargs = {} container = ServiceContainer(Service, rabbit_config) entrypoint = get_extension(container, Rpc) redacted = get_redacted_args(entrypoint, *args, **kwargs) assert redacted == expected
def worker_setup(self, worker_ctx): entrypoint = worker_ctx.entrypoint args = worker_ctx.args kwargs = worker_ctx.kwargs redacted.update(get_redacted_args(entrypoint, *args, **kwargs))