Пример #1
0
def test_sanitize_object():
    filters = ["password", "credit_card"]
    crazy_dict = {
        "password": "******",
        "metadata": {
            "another_password": "******",
            "regular": "text"
        },
        "bad_utf8": "a test of \xe9 char",
        "list": ["list", "of", "things"],
        "unicode": u("string"),
        "obj": Exception(),
        "valid_unicode": u("\u2603"),
    }

    # Sanitize our object
    sane_dict = sanitize_object(crazy_dict, filters=filters)

    # Check the values have been sanitized
    assert(sane_dict["password"] == "[FILTERED]")
    assert(sane_dict["metadata"]["another_password"] == "[FILTERED]")
    assert(sane_dict["metadata"]["regular"] == "text")
    assert("things" in sane_dict["list"])
Пример #2
0
def test_sanitize_object():
    filters = ["password", "credit_card"]
    crazy_dict = {
        "password": "******",
        "metadata": {
            "another_password": "******",
            "regular": "text"
        },
        "bad_utf8": "a test of \xe9 char",
        "list": ["list", "of", "things"],
        "unicode": u("string"),
        "obj": Exception(),
        "valid_unicode": u("\u2603"),
    }

    # Sanitize our object
    sane_dict = sanitize_object(crazy_dict, filters=filters)

    # Check the values have been sanitized
    assert (sane_dict["password"] == "[FILTERED]")
    assert (sane_dict["metadata"]["another_password"] == "[FILTERED]")
    assert (sane_dict["metadata"]["regular"] == "text")
    assert ("things" in sane_dict["list"])
Пример #3
0
def test_json_encode():
    payload = {"a": u("a") * 512 * 1024}
    eq_(json_encode(payload), ('{"a": "' + 'a' * 1024 + '"}').encode('utf-8', 'replace'))
Пример #4
0
def test_json_encode():
    payload = {"a": u("a") * 512 * 1024}
    eq_(json_encode(payload),
        ('{"a": "' + 'a' * 1024 + '"}').encode('utf-8', 'replace'))