File size: 953 Bytes
c392a82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import logging
import sys

from logging_setup import QueryRedactingFormatter


def test_http_status_survives_but_query_credentials_do_not():
    record=logging.LogRecord("httpx",logging.INFO,"",0,'HTTP Request: POST %s "HTTP/1.1 200 OK"',
                             ('http://device-api.zero/release?allowToken=test-secret&fail=false',),None)
    result=QueryRedactingFormatter('%(message)s').format(record)
    assert 'test-secret' not in result and 'allowToken' not in result
    assert '/release?[redacted]' in result and '200 OK' in result


def test_exception_urls_are_redacted_too():
    try:
        raise ValueError('https://example.test/path?token=test-secret')
    except ValueError:
        record=logging.LogRecord('httpx',logging.ERROR,'',0,'Request failed',(),sys.exc_info())
    result=QueryRedactingFormatter('%(message)s').format(record)
    assert 'test-secret' not in result and 'ValueError' in result and 'Request failed' in result