forked from microsoft/azure-devops-python-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_http_logging.py
More file actions
40 lines (32 loc) · 1023 Bytes
/
test_http_logging.py
File metadata and controls
40 lines (32 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from argparse import Namespace
import io
import http_logging
def test_logging():
f = io.StringIO()
response = Namespace(
request = Namespace(
url = 'https://example.com/fake',
headers = {
'X-Request-Test-Header': 'keep',
'Authorization': 'filter-out',
},
body = '',
method = 'GET'
),
headers = {
'X-Response-Test-Header': 'keep',
'Cookie': 'filter-out',
},
status_code = 200,
url = 'https://example.com/fake/response',
json = lambda: ""
)
http_logging.log_request(response, f)
f.seek(0)
contents = f.read()
# ensure we don't strip arbitrary headers
assert 'X-Request-Test-Header' in contents
assert 'X-Response-Test-Header' in contents
# ensure we strip sensitive headers
assert 'Authorization' not in contents
assert 'Cookie' not in contents