コード例 #1
0
    def f():
        is_test_func = True  # noqa

        # This should clean everything!
        @sensitive_variables()
        def login_user(username, password):
            is_inside_func = True  # noqa
            to_clean = {"dict": "a"}  # noqa
            print("logging in " + username + password)

        try:
            login_user(None, "secret123")
        except TypeError:
            test_locals, wrapper_locals, locals = get_all_variables()
        else:
            assert False

        # Assert that we got the right frames
        assert test_locals["is_test_func"]
        assert locals["is_inside_func"]
        assert wrapper_locals["f"]

        # Assert real functionality
        assert locals["password"] == PLACEHOLDER
        assert "secret123" not in list(locals.values())
        assert locals["to_clean"] == PLACEHOLDER
コード例 #2
0
    def f():
        is_test_func = True  # noqa

        def _login_user(username, password):
            is_inside_nested_func = True  # noqa
            print("logging in " + username + password)

        @sensitive_variables("password", depth=2)
        def login_user(username, password):
            is_inside_func = True  # noqa
            _login_user(username, password)

        try:
            login_user(None, "secret123")
        except TypeError:
            test_locals, wrapper_locals, login_user_locals, locals = get_all_variables(
            )
        else:
            assert False

        # Assert that we got the right frames
        assert test_locals["is_test_func"]
        assert locals["is_inside_nested_func"]
        assert wrapper_locals["f"]
        assert login_user_locals["_login_user"]

        # Assert real functionality
        assert locals["password"] == PLACEHOLDER
        assert "secret123" not in list(locals.values())
コード例 #3
0
    def f():
        is_test_func = True  # noqa

        @sensitive_variables(custom_scrub_fn=scrub_dict)
        def login_user(username, password):
            is_inside_func = True  # noqa
            test_dict = {
                "field_special": "secret123",
                "normal": "not secret"
            }  # noqa
            print("logging in " + username + password)

        try:
            login_user(None, "secret123")
        except TypeError:
            test_locals, wrapper_locals, locals = get_all_variables()
        else:
            assert False

        # Assert that we got the right frames
        assert test_locals["is_test_func"]
        assert locals["is_inside_func"]
        assert wrapper_locals["f"]
        # Assert real functionality
        assert locals["test_dict"] == {"new_dict": "a"}